Home Theater Automation RPi+bluetooth using command line

Discuss everything to do with GIMX here
Post Reply
elRey
Posts: 7
Joined: Thu Apr 27, 2017 6:46 pm

Home Theater Automation RPi+bluetooth using command line

Post by elRey » Thu Apr 27, 2017 7:15 pm

Hello,

I really enjoyed working with the software. Thank you for your time and effort on it!

My use case is that I wanted to just control the PS3 from an Home Theater Automation standpoint, not in game control. If I could get the RPi to power on/off the console I'd be set. Anything else is just bonus. Once the RPi had control, I could then integrate Amazon Alexa voice control to startup my TV, AV Receiver, and the PS3. And if I add IR (lirc) to the RPi I can control the PS3 with a IR universal remote instead of needing 2 remotes.

Here is what I did to get it working for me no adapter needed: (LONG!)

Code: Select all

mkdir gimx
cd gimx/
wget https://gimx.fr/download/gimx-raspbian -O gimx.deb
sudo dpkg -i gimx.deb
sudo apt-get update
sudo apt-get -f install
sudo apt-get upgrade
gimx --help

# connect my PS3 controller via usb to RPi
sixaddr
sixaddr > gimx/sixaxis_addr.txt
cat gimx/sixaxis_addr.txt 

# to get bluettoth working on RPi 3
sudo apt-get dist-upgrade
sudo reboot
bluetoothctl
cat gimx/sixaxis_addr.txt 
hciconfig -a
bdaddr -i hci0
bdaddr -r -i hci0 64:D4:BD:myPS3controllerAddress
bdaddr -i hci0
# confirmed RPi BT address matches my PS3 controller address - needed everytime after boot


# start instance of gimx in background
gimx -t Sixaxis -s 127.0.0.1:51000 -b 08:A9:5A:myConcleMasterAddress


#start send cmds to control PS3 from RPi manually typing cmds:

gimx -e "up(255)" -d 127.0.0.1:51000
gimx -e "up(0)" -d 127.0.0.1:51000

gimx -e "right(255)" -d 127.0.0.1:51000
gimx -e "right(0)" -d 127.0.0.1:51000

gimx -e "down(255)" -d 127.0.0.1:51000
gimx -e "down(0)" -d 127.0.0.1:51000

gimx -e "left(255)" -d 127.0.0.1:51000
gimx -e "left(0)" -d 127.0.0.1:51000

gimx -e "cross(255)" -d 127.0.0.1:51000
gimx -e "cross(0)" -d 127.0.0.1:51000

gimx -e "circle(255)" -d 127.0.0.1:51000
gimx -e "circle(0)" -d 127.0.0.1:51000

gimx -e 'PS(255)' -d 127.0.0.1:51000
gimx -e 'PS(0)' -d 127.0.0.1:51000


# yah it works!
Then I created a bash shell script for some automation: ~/gimx.ps3_cmds.sh

Code: Select all

#!/bin/bash

default_delayT=0.007
delayT=${default_delayT}
afterPause=0.15
dstAddr="127.0.0.1:51000"

if [ $# -gt 1 ]; then
    delayT=$2
fi

sendCMD() {
startGIMX
gimx -e "$1(255)" -d ${dstAddr}
sleep ${delayT}
gimx -e "$1(0)" -d ${dstAddr}
sleep ${afterPause}
}

setBDAddr() {
   bdaddr -i hci0|grep 64:D4:myControllerAddr >/dev/null || bdaddr -r -i hci0 64:D4:myControllerAddr >/dev/null
}

startGIMX() {
   if ! pgrep -f "gimx -t Sixaxis -s 127.0.0.1:51000" >/dev/null
   then
      echo "no GIMX instance running. starting."
      setBDAddr
      gimx -t Sixaxis -s 127.0.0.1:51000 -b 08:A9:myConsoleMasterAddr >/dev/null &
      #sleep 17
      if [ "${1}" == "on" ]; then sleep 34; fi
   fi
}

stopGIMX() {
   gpid=`pgrep -f "gimx -t Sixaxis -s 127.0.0.1:51000"`
   if [ "$gpid" != '' ]; then
      echo "gimx pid $gpid found. killing."
      kill -9 $gpid
   fi
}

catTV() {
   for i in {1..9}
   do
      sendCMD "right"
   done
   for i in {1..4}
   do
      sendCMD "left"
   done
   for i in {1..9}
   do
      sendCMD "up"
   done
}


if [ "${1}" == "gimx_start" ]; then
   startGIMX
elif [ "${1}" == "gimx_stop" ]; then
   stopGIMX
elif [ "${1}" == "on" ]; then
   startGIMX "on"
elif [ "${1}" == "off" ]; then
   delayT=1.2
   sendCMD "PS"
   delayT=${default_delayT}
   for i in {1..5}
   do
      sendCMD "down"
   done
   sendCMD "up"
   sendCMD "cross"
   sendCMD "left"
   sleep 0.5
   sendCMD "cross"
   stopGIMX
elif [ "${1}" == "exit" ]; then
   delayT=1.2
   sendCMD "PS"
   delayT=${default_delayT}
   for i in {1..5}
   do
      sendCMD "up"
   done
   sendCMD "cross"
   sleep 0.5
   sendCMD "left"
   sleep 0.5
   sendCMD "cross"
elif [ "${1}" == "netflix" ]; then
   catTV
   sendCMD "down"
   sendCMD "cross"
   sleep 33
   sendCMD "cross"
elif [ "${1}" == "youtube" ]; then
   catTV
   for i in {1..4}
   do
        sendCMD "down"
   done
   sendCMD "cross"
elif [ "${1}" == "hulu" ]; then
   catTV
   for i in {1..3}
   do
   	sendCMD "down"
   done
   sendCMD "cross"
else
   sendCMD $1
fi

So, now I can send cmds like:

. ~/gimx/ps3_cmds.sh on #turn PS3 on
. ~/gimx/ps3_cmds.sh left
. ~/gimx/ps3_cmds.sh right
. ~/gimx/ps3_cmds.sh PS
. ~/gimx/ps3_cmds.sh PS 2 #holds PS button down for 2 sec overriding script default button press time
. ~/gimx/ps3_cmds.sh exit #quits current app/game
. ~/gimx/ps3_cmds.sh off

and any gmx instance cleanup/control:
. ~/gimx/ps3_cmds.sh gimx_stop
. ~/gimx/ps3_cmds.sh gimx_stop


Enjoy! And thanks again for this great software!

Rey

mnasir
Posts: 5
Joined: Wed Jun 21, 2017 3:21 pm

Re: Home Theater Automation RPi+bluetooth using command line

Post by mnasir » Wed Jun 21, 2017 3:28 pm

Hey ,
I need some help regarding RPI with PS4 for the same kind of stuff. Kindly can you enlighten me on this?

User avatar
Matlo
Posts: 4451
Joined: Wed Jul 06, 2011 7:01 am
Location: France
Contact:

Re: Home Theater Automation RPi+bluetooth using command line

Post by Matlo » Thu Jun 22, 2017 9:28 am

Hi,
It will be hard for you to get some help without knowing what your are doing and what issue you are having.
GIMX creator Donate Shop

mnasir
Posts: 5
Joined: Wed Jun 21, 2017 3:21 pm

Re: Home Theater Automation RPi+bluetooth using command line

Post by mnasir » Wed Jul 05, 2017 12:35 pm

Hi,
Actually am trying to automate the ps4 commands. I am trying to connect DS4 with RPI and then to pair with PS4 without using TINSY.
I have been looking around the WIKI for work around in similar way the guy used above with PS3. So i need exact solution with PS4. Kindly can you point me in right direction?


Thanks

User avatar
Matlo
Posts: 4451
Joined: Wed Jul 06, 2011 7:01 am
Location: France
Contact:

Re: Home Theater Automation RPi+bluetooth using command line

Post by Matlo » Thu Jul 06, 2017 8:48 pm

Hi,
There is currently no way to do this without a Teensy.
GIMX creator Donate Shop

Post Reply