I have connected a Rii I7 Mini 2.4Gh remote as a simple Sonos remote with the functions:
vol up/down
pause/play
next/prev track
mute
start sonos with default station
http://www.kiwi-electronics.nl/index.php?route=product/search&search=i7
Instructions
Start with a working Raspberry Pi with Weezy (my version Linux pi-1 3.12.35+)
Connect the rii dongle and test if receiver available
lsusb
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 062a:1a9e Creative Labs ( the rii receiver)
Install pip python and socos librarys
sudo apt-get install python-pip
sudo pip install socos
test the connection to your sonos
socos list
my result I have 2 Play-1 in Stereo (Serre) and one Sonos Amp (Kamer)
pi@pi-1 ~ $ socos list
(1) 192.168.3.71 Kamer
(2) 192.168.3.72 Serre
(3) 192.168.3.73 Serre
test change volume
socos volume 192.168.3.72 +5 (volume up on the stereo Serre Sonos)
Test your remote
++++++++++++++++++++++++++++++++++++ create file test_i7.py
vi test_i7.py
+++++++++++++++++++++++++++++++++ code
#!/usr/bin/python
import struct
import time
import sys
infile_path = "/dev/input/event" + (sys.argv[1] if len(sys.argv) > 1 else "0")
#long int, long int, unsigned short, unsigned short, unsigned int
FORMAT = 'llHHI'
EVENT_SIZE = struct.calcsize(FORMAT)
#open file in binary mode
in_file = open(infile_path, "rb")
event = in_file.read(EVENT_SIZE)
while event:
(tv_sec, tv_usec, type, code, value) = struct.unpack(FORMAT, event)
if type != 0 or code != 0 or value != 0:
print("Event type %u, code %u, value: %u at %d, %d" % \
(type, code, value, tv_sec, tv_usec))
else:
# Events with code, type and value == 0 are "separator" events
print("===========================================")
event = in_file.read(EVENT_SIZE)
in_file.close()
+++++++++++++++++++++++++++++ code end +++++++++++++++++
test the keyboard buttons for volume up
python test_i7 1
press a button
test the mouse buttons
python test_i7 0
move mouse
Result for vol up
pi@pi-1 ~ $ python test_i7.py 1
Event type 4, code 4, value: 786665 at 1422559215, 765193
Event type 1, code 115, value: 1 at 1422559215, 765193
===========================================
Event type 4, code 4, value: 786665 at 1422559215, 901205
Event type 1, code 115, value: 0 at 1422559215, 901205
===========================================
Simple control script for
vol up
vol down
play-pause
home (start sonos with preset radio station at volume 10)
+++++++++++++++++++++++++++++create file i7.py
vi i7.py
++++++++++++++++++++++++++++++ code
#!/usr/bin/python
import struct
import time
import sys
from soco import SoCo
meta_template = """
<DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/"
xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/"
xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/">
<item id="R:0/0/0" parentID="R:0/0" restricted="true">
<dc:title>{title}</dc:title>
<upnp:class>object.item.audioItem.audioBroadcast</upnp:class>
<desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">
{service}
</desc>
</item>
</DIDL-Lite>' """
tunein_service = 'SA_RINCON65031_'
serre = SoCo('192.168.3.72')
infile_path = "/dev/input/event1"
#long int, long int, unsigned short, unsigned short, unsigned int
FORMAT = 'llHHI'
EVENT_SIZE = struct.calcsize(FORMAT)
#open file in binary mode
in_file = open(infile_path, "rb")
event = in_file.read(EVENT_SIZE)
while event:
(tv_sec, tv_usec, type, code, value) = struct.unpack(FORMAT, event)
try:
if type == 1 and code == 115 and value == 1:
print ("Vol Up")
serre.volume = serre.volume + 2
elif type == 1 and code == 115 and value == 2:
print ("Vol Up Cont")
serre.volume = serre.volume + 1
time.sleep(0.1)
in_file.close()
in_file = open(infile_path, "rb")
elif type == 1 and code == 114 and value == 1:
print ("Vol Down")
serre.volume = serre.volume - 2
elif type == 1 and code == 114 and value == 2:
print ("Vol Down Cont")
serre.volume = serre.volume - 2
time.sleep(0.1)
in_file.close()
in_file = open(infile_path, "rb")
elif type == 1 and code == 142 and value == 1:
print ("Off")
serre.mute = False
serre.stop()
serre.volume = 10
elif type == 1 and code == 164 and value == 1:
print ("Play Pause")
transport_info = serre.get_current_transport_info()
if transport_info['current_transport_state'] == 'PLAYING':
serre.stop()
else:
serre.play()
serre.mute = False
elif type == 1 and code == 164 and value == 2:
print ("Play Pause Cont")
elif type == 1 and code == 104 and value == 1:
print ("Page Up")
elif type == 1 and code == 104 and value == 2:
print ("Page Up Cont")
elif type == 1 and code == 109 and value == 1:
print ("Page Down")
elif type == 1 and code == 109 and value == 2:
print ("Page Down Cont")
elif type == 1 and code == 103 and value == 1:
print ("Up")
elif type == 1 and code == 108 and value == 1:
print ("Down")
elif type == 1 and code == 105 and value == 1:
print ("Left")
serre.previous()
elif type == 1 and code == 106 and value == 1:
print ("Right")
serre.next()
elif type == 1 and code == 28 and value == 1:
print ("Ok")
elif type == 1 and code == 28 and value == 2:
print ("Ok Cont")
elif type == 1 and code == 172 and value == 1:
print ("Home")
stations = serre.get_favorite_radio_stations( 0, 100)
serre.play()
serre.volume = 10
serre.mute = False
for fave in stations['favorites']:
if fave['title']=='NPO Radio 2':
print fave['title']
uri = fave['uri']
uri = uri.replace('&', '&')
metadata = meta_template.format(title=fave['title'], service=tunein_service)
serre.play_uri(uri,metadata)
elif type == 1 and code == 127 and value == 1:
print ("List")
#except serre.exceptions.SoCoUPnPException:
#print "exception caught", soco.exceptions.SoCoUPnPException
except:
print "error"
event = in_file.read(EVENT_SIZE)
in_file.close()
++++++++++++++++++++++++++++++++ end
+++++++++++++++File for deamon start create file in /home/pi
vi i7.sh
++++++++++++++++++ code ++++++++++
#!/bin/sh
script='/home/pi/i7.py'
exec /usr/bin/python $script
++++++++++++++++++++ code end +++++++++++++++
sudo chmod 755 i7.sh
++++++++++ create /etc/init.d/ i7
sudo vi /etc/init.d/i7
+++++++++++++++++ code ++++++++++++++++++
#!/bin/sh
### BEGIN INIT INFO
# Provides: myservice
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Put a short description of the service here
# Description: Put a long description of the service here
### END INIT INFO
# Change the next 3 lines to suit where you install your script and what you want to call it
DIR=/home/pi
DAEMON=$DIR/i7.sh
DAEMON_NAME=i7
# Add any command line options for your daemon here
DAEMON_OPTS=""
# This next line determines what user the script runs as.
# Root generally not recommended but necessary if you are using the Raspberry Pi GPIO from Python.
DAEMON_USER=root
# The process ID of the script when it runs is stored here:
PIDFILE=/var/run/$DAEMON_NAME.pid
. /lib/lsb/init-functions
do_start () {
log_daemon_msg "Starting system $DAEMON_NAME daemon"
start-stop-daemon --start --background --pidfile $PIDFILE --make-pidfile --user $DAEMON_USER --chuid $DAEMON_USER --startas $DAEMON -- $DAEMON_OPTS
log_end_msg $?
}
do_stop () {
log_daemon_msg "Stopping system $DAEMON_NAME daemon"
start-stop-daemon --stop --pidfile $PIDFILE --retry 10
log_end_msg $?
}
case "$1" in
start|stop)
do_${1}
;;
restart|reload|force-reload)
do_stop
do_start
;;
status)
status_of_proc "$DAEMON_NAME" "$DAEMON" && exit 0 || exit $?
;;
*)
echo "Usage: /etc/init.d/$DAEMON_NAME {start|stop|restart|status}"
exit 1
;;
esac
exit 0
++++++++++++++++++++ code end +++++++++++++
sudo chmod 755 i7
++++++++++++
make deamon start a boot
sudo update-rc.d i7 defaults
docu on Socos library
The soco module — SoCo (Sonos Controller) 0.10 documentation
Good luck , it works for me





