Kodi Community Forum

Full Version: Raspbmc: Keymap for triggering shell script
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi together,

I have a problem:
I'm running Raspbmc and managed to install the device to turn on remote triggered sockets (433 Mhz transmitter).
This works fine and I can trigger the sockets with the browser of mobile devices.

Because this is not really comfortable in practice I want to trigger the sockets additionally with the wireless keyboard (for example: F12 on; F10 off)
So I created a keyboard.xml in /home/pi/.xbmc/userdata/keymaps/ and added the following:

<keymap>
<global>
<keyboard>
<F12>XBMC.RunScript(/home/pi/skripte/lighton.py)</F12>
<F10>XBMC.RunScript(/home/pi/skripte/lightoff.py)</F10>
</keyboard>
</global>
</keymap>

I will only describe the lighton.py script. The other one is similar.

lighton.py:

#!/usr/bin/python
import sys
import subprocess
subprocess.call(["/home/pi/skripte/lighton.sh"], shell=True)

I applied the rights to all scripts (py and sh): chmod +x ...

lighton.sh:

cd ~
./send 11010 2 1


This is my setup.
When I run the lighon.py script with:
./lighton.py
the script calls lighton.sh and triggers the socket! It works!

But when I press the F12 button on my keyboard, nothing happens. So the problem must be between the keyboard.xml and the lighton.py script.

Does anyone have an idea what to do?

Thank you very much!

greetings,
krassor
Let's see more detail in your keyboard.xml and how about an xbmc.log file to see if the keys are being pressed.
Thanks for your reply.

It's the complete keyboard.xml file. There's nothing else inside.
It should overwrite the existing system settings.
And it does! For example F10 is increasing the volume in the standard setting.
After assigning F10 to a custom keymap the volume does not increase, instead nothing happens. So I'm sure the system recognizes the button.

When I'm at home I will try to get the xbmc.log
Hi guys,

here is the xvmc.log file:

http://xbmclogs.com/show.php?id=250334

you can find the interesting part from line 1257 on.
I pressed F12; F11 and F10 (all custom assigned keys with python script)
and F9 (standard setting: VolumeDown (i didn't change it)) each 2 times.

it says, the pi successfully ran the script...
any ideas? light stays off Sad
Your keyboard.xml didn't show up for me in tapatalk. I see it now using a browser.

The xbmc.log says f10 is running the lightoff.py script and f12 is running wzon.py (not lighton.py). Is that what you want?

Also, do you actually have the scripts named with the .py extension? This seems to be required in Gotham.
Sry yes,
I wanted to simplify the names as an example...
lighton.py stands for "wzon.py" ("Wohnzimmer" -> living room in german) and "szon.py" ("Schlafzimmer" -> bedroom in german).
So:
szon.py and wzon.py turn the lights on; lightsoff.py turns the lights off (both).

The command structure is the following:

F12 ->
keyboard.xml (<F12>XBMC.RunScript(/home/pi/skripte/wzon.py)</F12>) ->
wzon.py (triggers wzon.sh when I directly run the script in the command line: "./wzon.py" -> works; but when I press "F12" it won't do anything, despite of the fact, that the log-file says "Script succesfully ran") ->
wzon.sh (triggers the light...; works) ->
and we are done.

yes, I named the py-scripts' extensions: .py. The triggered bash-scripts' extensions are named: .sh

Conclusion:
The .py AND the .sh script both work!

Could there be problems with the rights? Does XBMC need root (I have root when I do sth in the command line) or sth to run the .py script?

I can feel it... I'm so close^^
But no idea which penny is missing Sad
I run OpenELEC which is root by default. You should make your scripts executable if they aren't already. Try some simple debugging by changing the Python script to something simple that can log if the script is executed.
I asked a programmer I know, he said it's all fine with the scripts...
The reason is, that the user, who run the scripts (the "XBMC user") doesn't have root, you need root to trigger GPIO pins with "send".
So I added the root right for "all" to run the script "send" in sudoers.

visudo

added: ALL ALL = (root) NOPASSWD = ~/raspberry-remote/send

and:
the sudoers file is now corrupted^^ It was my fault, I probably put in the wrong path...
I'll have to manually repair it...
but this should solve the problem.

thank you
but
Instead of

<F12>XBMC.RunScript(/home/pi/skripte/lighton.py)</F12>
<F10>XBMC.RunScript(/home/pi/skripte/lightoff.py)</F10>

Try System.Exec.
<F12>System.Exec(/home/pi/skripte/lighton.py)</F12>
<F10>System.Exec(/home/pi/skripte/lightoff.py)</F10>

It should work!
hi all i need your help please....


I would like to set the volume to a button , anytime thus control the TV , is that possible?

ive found a samsungmote.py

What should I write in the Keymap.xml now ?

Code:
#!  /usr/bin/python
#   Title: samsungremote.py
#   Author: Asif Iqbal
#   Date: 05APR2012
#   Info: To send remote control commands to the Samsung tv over LAN
#   TODO:

import socket
import base64
import time, datetime
import sys

cmdargs = str(sys.argv)

#IP Address of TV
tvip = "192.168.178.28"
#IP Address of TV
myip = "192.168.178.28"
#Used for the access control/validation, but not after that AFAIK
mymac = "5c:xxxxxxxxb"
#What the iPhone app reports
appstring = "iphone..iapp.samsung"
#Might need changing to match your TV type
tvappstring = "iphone.UE40D6500.iapp.samsung"
#What gets reported when it asks for permission
remotename = "Python Samsung Remote"

# Function to send keys
def sendKey(skey, dataSock, appstring):
messagepart3 = chr(0x00) + chr(0x00) + chr(0x00) + chr(len(
base64.b64encode(skey))) + chr(0x00) + base64.b64encode(skey);
part3 = chr(0x00) + chr(len(appstring)) + chr(0x00) \
+ appstring + chr(len(messagepart3)) + chr(0x00) + messagepart3
dataSock.send(part3);

# Open Socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((tvip, 55000))

# Key Reference
# Normal remote keys
#KEY_0
#KEY_1
#KEY_2
#KEY_3
#KEY_4
#KEY_5
#KEY_6
#KEY_7
#KEY_8
#KEY_9
#KEY_UP
#KEY_DOWN
#KEY_LEFT
#KEY_RIGHT
#KEY_MENU
#KEY_PRECH
#KEY_GUIDE
#KEY_INFO
#KEY_RETURN
#KEY_CH_LIST
#KEY_EXIT
#KEY_ENTER
#KEY_SOURCE
#KEY_AD #KEY_PLAY
#KEY_PAUSE
#KEY_MUTE
#KEY_PICTURE_SIZE
#KEY_VOLUP
#KEY_VOLDOWN
#KEY_TOOLS
#KEY_POWEROFF
#KEY_CHUP
#KEY_CHDOWN
#KEY_CONTENTS
#KEY_W_LINK #Media P
#KEY_RSS #Internet
#KEY_MTS #Dual
#KEY_CAPTION #Subt
#KEY_REWIND
#KEY_FF
#KEY_REC
#KEY_STOP
# Bonus buttons not on the normal remote:
#KEY_TV
#Don't work/wrong codes:
#KEY_CONTENT
#KEY_INTERNET
#KEY_PC
#KEY_HDMI1
#KEY_OFF
#KEY_POWER
#KEY_STANDBY
#KEY_DUAL
#KEY_SUBT
#KEY_CHANUP
#KEY_CHAN_UP
#KEY_PROGUP
#KEY_PROG_UP


# First configure the connection
ipencoded = base64.b64encode(myip)
macencoded = base64.b64encode(mymac)
messagepart1 = chr(0x64) + chr(0x00) + chr(len(ipencoded)) \
+ chr(0x00) + ipencoded + chr(len(macencoded)) + chr(0x00) \
+ macencoded + chr(len(base64.b64encode(remotename))) + chr(0x00) \
+ base64.b64encode(remotename)

part1 = chr(0x00) + chr(len(appstring)) + chr(0x00) + appstring \
+ chr(len(messagepart1)) + chr(0x00) + messagepart1
sock.send(part1)

messagepart2 = chr(0xc8) + chr(0x00)
part2 = chr(0x00) + chr(len(appstring)) + chr(0x00) + appstring \
+ chr(len(messagepart2)) + chr(0x00) + messagepart2
sock.send(part2)


# Now send the keys as you like, e.g.,
#sendKey("KEY_CHDOWN",sock,tvappstring)
sendKey(str(sys.argv[1]),sock,tvappstring)
print str(sys.argv[1])
# Close the socket when done
sock.close()