Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
this is excellent.!! I have picoreplayer on my Rasp Model A and will try this over the weekend. so, for picoreplayer, what packages would I need - python, GPIO. anything else? ashwin.isaac's Profile: http://forums.slimdevices.com/member.php?userid=63055 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
TheD6Bel wrote: Hello RobbeD your script work perfectly! i change ip 127.0.0.1 to my nas ip (lms run on my synology) and and change GPIO.output(18, True) to GPIO.output(18, False) and GPIO.output(18, False) to GPIO.output(18, True) for work with my relay. Thanks ;) That's very good news! :-) The reason that I changed the relay pinouts is that the relay is automatically switched off when there is no connection to the server, or if the raspberry is switched off. RobbeD's Profile: http://forums.slimdevices.com/member.php?userid=56967 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
Hello, after few days of test i keep your first script. Your last script are some bugs, ei: -if i put my music on pause and switch power off, the script don't work. -if i listen my music and power off, the relay switch off but if i power on relay don't move, i need play music, power off and clic play music for it works. the problem are with my wife, if don't work perfectly, she don't agree and i can't install it in my house :( I need WAF certification :D (Woman Acceptance Factor) Thank you for your work, if you create a new script share it, its can help, a big thanks ;) TheD6Bel's Profile: http://forums.slimdevices.com/member.php?userid=58077 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
That's weird, I don't have those problems here.. Are you using the web user interface or another controller? You can run the script and check the output.. Maybe it has something to do with LMS settings? RobbeD's Profile: http://forums.slimdevices.com/member.php?userid=56967 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
hello, i tried for you on a new install of picoreplayer 1.18b, and i can't run script! on picoreplayer you need libraries and is not inclued, you don't have python, nano, gpio,... for you the best way, you install squeezeplug, boot time is not same but it's work ;) sorry for not can help you TheD6Bel's Profile: http://forums.slimdevices.com/member.php?userid=58077 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
Again BIG thanks TheD6Bel! I do no longer work with piCorePlayer, I have installed Squeezeplayer on wheezy debian. If I want to edit rc.local, I have got the Error writing /etc/rc.local: Permission denied I logged in as user pi is that wrong? #!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will exit 0 on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. # Print the IP address _IP=$(hostname -I) || true if [ $_IP ]; then printf My IP address is %s\n $_IP fi /yourpath/relay.py exit 0 palmerx's Profile: http://forums.slimdevices.com/member.php?userid=63498 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
Ok I did sudo nano /etc/rc.local then I could save! :-) Now it looks like this, ist that ok? #!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will exit 0 on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. # Print the IP address _IP=$(hostname -I) || true if [ $_IP ]; then printf My IP address is %s\n $_IP fi python /yourpath/relay.py exit 0 palmerx's Profile: http://forums.slimdevices.com/member.php?userid=63498 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
Hello, when i did /yourpath is your path directory. My script is in /home/script/ and i add on rc.local: python /home/script/relay.py ;) TheD6Bel's Profile: http://forums.slimdevices.com/member.php?userid=58077 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
A very BIG thank you *TheD6Bel* for your absolute perfect explenation. Now why it took so long that i didmy replay was because piCorePlayer was not good for me (I think) i coulnot even install or open nano. So I installed Whezzy debian iso and setup the squeezeslave like described in this tutorial: http://www.gerrelt.nl/RaspberryPi/wordpress/tutorial-installing-squeezelite-player-on-raspbian/ And what wonder even a total beginner like me was able to get it working. So I wast stright trying to get the AMP Code working, unluckily with no sucsess: pi@Esszimmer ~ $ python relay.py File relay.py, line 39 import sys, string, select from socket import * import RPi.GPIO as GPIO ^ SyntaxError: invalid syntax pi@Esszimmer ~ $ Can you tell me wehre I did go wrong ist this step is not working? My TXT FIle looks like this: LMS Server ist at 192.168.1.39 Playername is Esszimmer pi@Esszimmer ~ $ nano relay.py GNU nano 2.2.6 File: relay.py UDPSock.bind(addr) except : port += 1 print xPL Monitor for Python, bound to port + str(port) SendHeartbeat() while 1==1 : readable, writeable, errored = select.select([UDPSock],[],[],60) if len(readable) == 1 : data,addr = UDPSock.recvfrom(buff) print data radioname = Esszimmer if radioname in data : if POWER=1 in data : print radioname + is on GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(18, GPIO.OUT) GPIO.output(18, True) elif POWER=0 in data : print radioname + is off GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(18, GPIO.OUT) GPIO.output(18, False) else : print other message for + radioname palmerx's Profile: http://forums.slimdevices.com/member.php?userid=63498 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
hello, your script like this Code: import sys, string, select from socket import * import RPi.GPIO as GPIO # Define maximum xPL message size buff = 1500 # Define xPL base port port = 3865 # Sub routine for sending a heartbeat def SendHeartbeat() : hbSock = socket(AF_INET,SOCK_DGRAM) hbSock.setsockopt(SOL_SOCKET,SO_BROADCAST,1) msg = xpl-stat\n{\nhop=1\nsource=johnb-monitor.python\ntarget=*\n}\nhbeat.app\n{\ninterval=5\nport= + str(port) + \n}\n hbSock.sendto(msg,(192.168.1.255,3865)) # Initialise the socket UDPSock = socket(AF_INET,SOCK_DGRAM) addr = (0.0.0.0,port) # Try and bind to the base port try : UDPSock.bind(addr) except : # A hub is running, so bind to a high port port = 5 addr = (192.168.1.39,port) try : UDPSock.bind(addr) except : port += 1 print xPL Monitor for Python, bound to port + str(port) SendHeartbeat() while 1==1 : readable, writeable, errored = select.select([UDPSock],[],[],60) if len(readable) == 1 : data,addr = UDPSock.recvfrom(buff) print data radioname = Esszimmer if radioname in data : if POWER=1 in data : print radioname + is on GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(18, GPIO.OUT) GPIO.output(18, True) elif POWER=0 in data : print radioname + is off GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(18, GPIO.OUT) GPIO.output(18, False) else : print other message for + radioname and exactly the same ;) TheD6Bel's Profile: http://forums.slimdevices.com/member.php?userid=58077 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
Hi! That's strange, I thought the script would run without problems.. I am thinking if I did install something extra on the raspberry.. It's also weird that the script doesn't understand the import command.. I run the script like this: python relay.py Can you try that? RobbeD's Profile: http://forums.slimdevices.com/member.php?userid=56967 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
Sorry my mistake! for run script i make ./rxpl.py i'am on work now, i tried tonight TheD6Bel's Profile: http://forums.slimdevices.com/member.php?userid=58077 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
Hello RobbeD your script work perfectly! i change ip 127.0.0.1 to my nas ip (lms run on my synology) and and change GPIO.output(18, True) to GPIO.output(18, False) and GPIO.output(18, False) to GPIO.output(18, True) for work with my relay. Thanks ;) TheD6Bel's Profile: http://forums.slimdevices.com/member.php?userid=58077 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
I'm very sorry for beeing an absolut beginner, can anybody explain me in short words how I get this script on my running piCorePlayer and what pins its going to switch? Do I have to use Putty? Thank you very much for your time, all out there!! palmerx's Profile: http://forums.slimdevices.com/member.php?userid=63498 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
palmerx wrote: I'm very sorry for beeing an absolut beginner, can anybody explain me in short words how I get this script on my running piCorePlayer and what pins its going to switch? Do I have to use Putty? Thank you very much for your time, all out there!! Hello, yes you need putty. make ssh connection on rpi ip. I use nano for edit text on RPI if nano isn't install on picoplayer : Code: sudo apt-get install nano for your script you need make modification (name of player and ip of server) when you see 127.0.0.1 you put server ip and when you see radioname = Radio_Living you remplace Radio_Living by player name (and keep ) for make your script : Code: nano relay.py you copy your code (big thanks to RobbeD) and make CTRL+X for exit, y and enter for finish. you need give a good permission for execute your script Code: chmod 755 relay.py and for run your script and test it Code: python relay.py now for run your script on boot, (i don't tried yet, only with first script) Code: nano /etc/rc.local before exit 0 you put Code: /yourpath/relay.py CTRL+X, y and entre, for finish you need reboot your RPI I do not think I forgot something but requests if you need TheD6Bel's Profile: http://forums.slimdevices.com/member.php?userid=58077 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
Hello RobbeD, don't work for me : Code: root@squeezeplug:/home/pi/script# ./rxpl.py ./rxpl.py: line 1: import: command not found from: can't read /var/mail/socket ./rxpl.py: line 3: import: command not found ./rxpl.py: line 6: buff: command not found ./rxpl.py: line 9: port: command not found ./rxpl.py: line 12: syntax error near unexpected token `(' ./rxpl.py: line 12: `def SendHeartbeat() :' i need install only xpl plugin? TheD6Bel's Profile: http://forums.slimdevices.com/member.php?userid=58077 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
This looks amazing, would that work on the PiCorePlayer also to turn on my Amp?? https://sites.google.com/site/picoreplayer/home palmerx's Profile: http://forums.slimdevices.com/member.php?userid=63498 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
palmerx wrote: This looks amazing, would that work on the PiCorePlayer also to turn on my Amp?? https://sites.google.com/site/picoreplayer/home Hello, normally yes. You need only setup script with ip of server and mac from picoreplayer. I had to change the script for run every 2 sec 300 is to much, and my relay don't work normally, when i turn off LMS the relay is on ON and when i turn ON LMS relay is on OFF. just change end of script and work perfectly. If you need ask ;) TheD6Bel's Profile: http://forums.slimdevices.com/member.php?userid=58077 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
Hey guys, I recently changed the script so it now works with the XPL plugin.. This makes the script more smooth and lightweight! It also now reacts instant! :-) To make the script run you'll need to install the xPL plugin in LMS. After that you just change the name of the player in the script and it should work! :-) 16697 +---+ |Filename: relayscript.py.txt | |Download: http://forums.slimdevices.com/attachment.php?attachmentid=16697| +---+ RobbeD's Profile: http://forums.slimdevices.com/member.php?userid=56967 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
RobbeD wrote: Hey guys, I recently changed the script so it now works with the XPL plugin.. This makes the script more smooth and lightweight! It also now reacts instant! :-) To make the script run you'll need to install the xPL plugin in LMS. After that you just change the name of the player in the script and it should work! :-) 16697 Your are a boss! thanks i try tomorrow ;) TheD6Bel's Profile: http://forums.slimdevices.com/member.php?userid=58077 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
TheD6Bel, that's great news! :-) I have added another piece of code that checks every two seconds if the server is online. If the server is online, then the status of the player is checked, otherwise not. The file is in attachment. 14795 For your problem that the relay is on when LMS is turned off and the opposite, i think you should switch the outgoing wires on your relay.. Good luck, and if you have other questions, post them here! Greetings, Robbe +---+ |Filename: relay.py.txt | |Download: http://forums.slimdevices.com/attachment.php?attachmentid=14795| +---+ RobbeD's Profile: http://forums.slimdevices.com/member.php?userid=56967 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
hello, your file is the same script :) but thanks for you work ;) TheD6Bel's Profile: http://forums.slimdevices.com/member.php?userid=58077 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
Hi, indeed, the python script is indentation-sensitive. For me, the script works the way I copied it here on the forum.. But i'm aware that maybe the lay-out is not that good.. I'll add my script here in attachment.. 14774 I now did the indentation with WING-IDE and it looks correct.. Hope it works now! :-) To Julf: I think you are more experienced with Python than I am, is there a way to make the script use less resources? (now it uses between 3-6% CPU (of a total of 850 Mhz) of the raspberry pi and 1.5% of memory (of a total of 512MB).. Or are there things in the script that are not done? Thanks in advance! Greetings, Robbe +---+ |Filename: relay.py.txt | |Download: http://forums.slimdevices.com/attachment.php?attachmentid=14774| +---+ RobbeD's Profile: http://forums.slimdevices.com/member.php?userid=56967 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
RobbeD wrote: is there a way to make the script use less resources? Only had a quick look, but it is a busy loop that gets executed once per second. I would look at something like the xPL plugin or something else that can actively send you a message when the player gets activated. Julf's Profile: http://forums.slimdevices.com/member.php?userid=42050 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
it works !!! thanks I just have a problem is when LMS is off the relay is on ans when LMS is turn on relay switch off. i need change your script but it WORKS ! BIG THANKS TheD6Bel's Profile: http://forums.slimdevices.com/member.php?userid=58077 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
i resolve my first problem :) i change #!/usr/bin/env python to #!/usr/bin/env python3 but i have a error in line 82 : root@squeezeplug:/home# ./gpio.sh File ./gpio.sh, line 82 playerdetected = playerId ^ TheD6Bel's Profile: http://forums.slimdevices.com/member.php?userid=58077 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
I fixed the second error if (playerId == playermac): playerdetected = playerId not if (playerId == playermac): playerdetected = playerId but I have another error root@squeezeplug:/home# ./gpio.sh File ./gpio.sh, line 84 if playerdetected : ^ SyntaxError: invalid syntax I I'm not good in script, so I do not know fix it TheD6Bel's Profile: http://forums.slimdevices.com/member.php?userid=58077 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
TheD6Bel wrote: but I have another error root@squeezeplug:/home# ./gpio.sh File ./gpio.sh, line 84 if playerdetected : ^ SyntaxError: invalid syntax I I'm not good in script, so I do not know fix it This isn't really a script error, it is a python syntax error, and the error is in the lines before that line. Julf's Profile: http://forums.slimdevices.com/member.php?userid=42050 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
i tried but don't work :( i put the script in /hom/gpio.sh with chmod 777 i put before yout script #!/usr/bin/env python # -*- coding: utf-8 -*- i put ip of RPi : 192.168.1.9 and mac adress of squeezeslave (in web interface, setting, player, ) : b8:27:eb:e4:2a:af I edit /etc/rc.local and put before exit0 /home/gpio.sh I plugged my relay vcc in pin 2 of RPi (5V) ground in pin 6 of RPi (ground) ctrl in pin 12 of RPi (gpio18) i reboot but don't work, what I did wrong? thanks TheD6Bel's Profile: http://forums.slimdevices.com/member.php?userid=58077 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
if i execute gpio.sh i have error: root@squeezeplug:/home# ./gpio.sh Traceback (most recent call last): File ./gpio.sh, line 52, in module responce = json.loads(data) File /usr/lib/python2.7/json/__init__.py, line 326, in loads return _default_decoder.decode(s) File /usr/lib/python2.7/json/decoder.py, line 365, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File /usr/lib/python2.7/json/decoder.py, line 383, in raw_decode raise ValueError(No JSON object could be decoded) ValueError: No JSON object could be decoded TheD6Bel's Profile: http://forums.slimdevices.com/member.php?userid=58077 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
Hi, I'll tell you what I did to make it work: I saved the script as relay.py and ran it just with python relay.py (as root). Later I made a service script in etc\init.d to run it at boot.. Maybe you should try to add :9000 behind the ip adress of your server? Maybe that can be the problem. My relay is connected as follows: VCC pin 2, GND pin 6, CTRL pin 12.. RobbeD's Profile: http://forums.slimdevices.com/member.php?userid=56967 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
Hello, Sorry for bumping this thread, but for people who are still searching for an easy script to trigger a relay i've created a python script that runs at boot. The script checks the powerstate of the player every second (script runs on a raspberry pi where squeezelite is installed), and if powerstate = 1 then relay is turned on, otherwise the relay is turned off. It works perfectly. The only thing you need to enter is the mac-adress of your player and the adress of your server (ip adress or url). For the start up process i let the script wait 5 minutes before it gets executed, because if the player and the server are on the same machine, and the machine is rebooted, it takes a while to start lms. If there are things that can be changed in order to make the script better (I'm sure that will be easy, this was my first python script) , feel free to do so and post your changes please! :-) Code: import sys import httplib import RPi.GPIO as GPIO import time time.sleep (300) if float(sys.version[:3]) = 2.6: import json else: # python 2.4 or 2.5 can also import simplejson # as working alternative to the json included. import simplejson as json # change to your server server = yourserverip playermac = your player mac adresse # This provides http 1.1 keep alive so preventing DNS lookup # For each request. while True: conn = httplib.HTTPConnection(server) #Make a python dictionary for the request. data = { id: 1, method: slim.request, params: [ , [ player, count, ? ] ] } # So now we convert the dictionary data to a string params = json.dumps(data, sort_keys=True, indent=4) # Make the keep alive request conn.request(POST, /jsonrpc.js, params) httpResponse = conn.getresponse() #print httpResponse.status=%s, httpResponse.reason=%s % (httpResponse.status, httpResponse.reason) data = httpResponse.read() # Load the JSON string back to python dictionary responce = json.loads(data) # print the python dictionary as a JSON string. # print json.dumps(responce, sort_keys=True, indent=4) # Extract the number of players from the python dictionary numberplayers = responce['result'][_count] # print numberplayers=%s % numberplayers playerIdentifiers = [] playerdetected = for i in range(numberplayers): data = { id:1, method:slim.request, params:[ , [player,id,i,?] ] } params = json.dumps(data, sort_keys=True, indent=4) #print params conn.request(POST, /jsonrpc.js, params) httpResponse = conn.getresponse() # print httpResponse.status=%s, httpResponse.reason=%s % (httpResponse.status, httpResponse.reason) data = httpResponse.read() #print data responce = json.loads(data) playerId = responce['result'][_id] #print playerId #print id=%s % playerId #print playermac if (playerId == playermac): playerdetected = playerId if playerdetected : # print playerdetected data = { id:1, method:slim.request, params:[playerdetected, [power,?] ] } params = json.dumps(data, sort_keys=True, indent=4) # print params conn.request(POST, /jsonrpc.js, params) httpResponse = conn.getresponse() # print httpResponse.status=%s, httpResponse.reason=%s % (httpResponse.status, httpResponse.reason) data = httpResponse.read() # print data responce = json.loads(data) powerstate = responce['result'][_power] if powerstate == 1: # print player: + playerdetected + power state: + powerstate GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(18, GPIO.OUT) GPIO.output(18, True) else: powerstate = 0 # print player: + playerdetected + power state: + powerstate GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(18, GPIO.OUT) GPIO.output(18, False) time.sleep (1)
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
Thanks, i test now ;) TheD6Bel's Profile: http://forums.slimdevices.com/member.php?userid=58077 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
Ok! :-) Let me know if it works or not.. RobbeD's Profile: http://forums.slimdevices.com/member.php?userid=56967 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
epoch1970 wrote: did you see this one : http://forums.slimdevices.com/showthread.php?88269-Sample-code-JSON-API-in-your-languagep=636134viewfull=1#post636134 i see, but isn't for manage GPIO, is for have inforamtions over serveurs/player but thanks :) TheD6Bel's Profile: http://forums.slimdevices.com/member.php?userid=58077 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
epoch1970 wrote: Wha?? Have you tried gpio raspberry pi python on google ? On google! I searched on the forum, on RPi forum i open un post and i have a python script for manage GPIO but is only with MPD not LMS. I try change this script for LMS http://www.raspberrypi.org/phpBB3/viewtopic.php?f=65t=17048sid=b081c7bdc97882d2bca4bc66807eda87start=25 If MPD playing music, GPIO is opens, if in pause/stop GPIO closes. script wrote: #!/usr/bin/env python # -*- coding: utf-8 -*- from mpd import MPDClient import RPi.GPIO as GPIO import time RELAIS_ACTIF=False PIN_RELAIS=12 def relai(etat): GPIO.output(PIN_RELAIS, etat)# Bascule le pin du relai à l'état voulu RELAIS_ACTIF=etat def main(): # Test de lecture audio client = MPDClient() while(1): try: # Connection au client mpd et lecture du status client.connect(host='localhost', port='6600') client.password('password') status=client.status() if status['state']=='play' and RELAIS_ACTIF is False: relai(True) elif status['state']=='stop' or status['state']=='pause': relai(False) client.disconnect() except: print 'Erreur connection' raise time.sleep(1) # On fait dodo pendant une seconde, et on recommence ! if __name__ == __main__: GPIO.setup(PIN_RELAIS, GPIO.OUT) # paramétrage du pin en sortie relai(False) main() TheD6Bel's Profile: http://forums.slimdevices.com/member.php?userid=58077 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
did you see this one : http://forums.slimdevices.com/showthread.php?88269-Sample-code-JSON-API-in-your-languagep=636134viewfull=1#post636134 epoch1970's Profile: http://forums.slimdevices.com/member.php?userid=16711 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
TheD6Bel wrote: my problem is to create a python script with the status of every player :( Well you have to ask the server for the available players, then query in a loop each player for its status. Players can come and go, so the first step is never a waste of time; also when a player is gone (hard power off, switched to mySB.com#8230; ) the server may continue report it as present for a short while. A subsequent query for status on this very player will end in error. You have to gracefully catch the error and do what seems reasonable. The perl code attached to 'this post' (http://forums.slimdevices.com/showthread.php?93986-Alarm-fails-only-on-Mondaysp=700283viewfull=1#post700283) does a bit of all that. It was geared at looking for player state on mysqueezebox.com, but the same logic applies to a local server. I guess there is relevant python scripts around here. Did you search on the forums ? epoch1970's Profile: http://forums.slimdevices.com/member.php?userid=16711 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
hello, I did a search but I have not found a script to manage GPIO over RPi TheD6Bel's Profile: http://forums.slimdevices.com/member.php?userid=58077 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
Wha?? Have you tried gpio raspberry pi python on google ? epoch1970's Profile: http://forums.slimdevices.com/member.php?userid=16711 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
Hello i instal a python for LMS and is very easy to have status of server PYLMS https://github.com/jingleman/PyLMS TheD6Bel's Profile: http://forums.slimdevices.com/member.php?userid=58077 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
Hello, I also looking for a solution to control an amp with GPIO ports RPi. For the moment there is a script that works with MPD, must modify it to work under squeezebox. This script based on the status of mpd. TheD6Bel's Profile: http://forums.slimdevices.com/member.php?userid=58077 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
TheD6Bel wrote: it is possible to know the status of squeezebox go to IPSQUEEZEBOX:9000/status.txt You're better off using the CLI available on port 9090. Available commands are listed in LMS: click help at the bottom of the LMS main page (http://IPSQUEEZEBOX:9000), then Technical Information and then The Squeezebox Server Command Line Interface. You can use something like netcat or telnet to communicate w/ LMS, or use a JSON client. You can search the forums there are many example scripts available. Here is an idea of what you can get w/ the CLI (power, mode, volume are probably interesting to you): Code: me@pc:~# echo serverstatus |netcat -w1 127.0.0.1 9090 serverstatus lastscan:1337002005 version:7.6.2 uuid:0125ee2a-1022-4117-9923-c0b1526324e5 info total albums:1259 info total artists:529 info total genres:17 info total songs:16493 player count:4 sn player count:0 other player count:0 me@pc:~# echo players list|netcat -w1 127.0.0.1 9090 players list count:4 playerindex:list playerid:00:04:20:01:02:03 uuid: ip:172.17.10.2:39550 name:Georgetown model:squeezebox3 isplayer:1 displaytype:graphic-320x32 canpoweroff:1 connected:1 playerindex:1 playerid:00:04:20:04:05:06 uuid: ip:172.17.10.3:39386 name:Illadelph model:squeezebox3 isplayer:1 displaytype:graphic-320x32 canpoweroff:1 connected:1 playerindex:2 playerid:00:04:20:07:08:09 uuid: ip:172.17.10.1:35490 name:Yalta model:squeezebox3 isplayer:1 displaytype:graphic-320x32 canpoweroff:1 connected:1 playerindex:3 playerid:00:04:20:0A:0B:0C uuid: ip:172.17.10.5:39795 name:Safranier model:squeezebox3 isplayer:1 displaytype:graphic-320x32 canpoweroff:1 connected:1 me@pc:~# echo 00:04:20:01:02:03 status|netcat -w1 127.0.0.1 9090 00:04:20:01:02:03 status player_name:Georgetown player_connected:1 player_ip:172.17.10.2:39551 power:1 signalstrength:0 mode:play time:67.8596518573761 rate:1 duration:474.106 can_seek:1 sync_master:00:04:20:0A:0B:0C sync_slaves:00:04:20:01:02:03 mixer volume:100 playlist repeat:0 playlist shuffle:0 playlist mode:off seq_no:0 playlist_cur_index:10 playlist_timestamp:1352654181.28605 playlist_tracks:21 epoch1970's Profile: http://forums.slimdevices.com/member.php?userid=16711 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
I do not even answer root@squeezeplug:~# echo serverstatus |netcat -w1 127.0.0.1 9090 root@squeezeplug:~# echo players list|netcat -w1 127.0.0.1 9090 :( TheD6Bel's Profile: http://forums.slimdevices.com/member.php?userid=58077 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
TheD6Bel wrote: I do not even answer root@squeezeplug:~# echo serverstatus |netcat -w1 127.0.0.1 9090 root@squeezeplug:~# echo players list|netcat -w1 127.0.0.1 9090 :( -verify netcat is installed. Use telnet 127.0.0.1 9090 if you don't have netcat (type 'exit' to quit from telnet if you're stuck) -The server is running on the localhost (127.0.0.1) ? Use the right IP, maybe it doesn't listen to this address (??) Also, make sure you haven't disabled the CLI from the server. The CLI is a plugin, make sure it is active. To check if the server is listening (and where) you can use lsof on the machine: Code: lsof -n |grep squeeze|grep LISTEN squeezebo 4732 squeezeboxserver9u IPv4 4973370t0 TCP *:3483 (LISTEN) squeezebo 4732 squeezeboxserver 18u IPv4 4973530t0 TCP *:9090 (LISTEN) squeezebo 4732 squeezeboxserver 28u IPv4 4973650t0 TCP *:9000 (LISTEN) epoch1970's Profile: http://forums.slimdevices.com/member.php?userid=16711 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
hello, for me netcat is instaled: root@squeezeplug:~# netcat usage: nc [-46bCDdhjklnrStUuvZz] [-I length] [-i interval] [-O length] [-P proxy_username] [-p source_port] [-q seconds] [-s source] [-T toskeyword] [-V rtable] [-w timeout] [-X proxy_protocol] [-x proxy_address[:port]] [destination] [port] if i type telnet localhost 9090: root@squeezeplug:~# telnet localhost 9090 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. and if i type serverstatus or serverstatus serverstatus serverstatus lastscan%3A1352124017 version%3A7.7.2 uuid%3A40adacd5-c19a-4c10-bea4-fe1b4481dbce info%20total%20albums%3A4 info%20total%20artists%3A3 info%20total%20genres%3A3 info%20total%20songs%3A67 player%20count%3A1 sn%20player%20count%3A0 other%20player%20count%3A0 players list players list count%3A1 playerindex%3Alist playerid%3A00%3A00%3A00%3A00%3A00%3A01 uuid%3A ip%3A127.0.0.1%3A49493 name%3AMusique%20Salon model%3Asqueezeslave isplayer%3A1 displaytype%3Asqueezeslave canpoweroff%3A1 connected%3A1 with lsof -n |grep squeeze|grep LISTEN: root@squeezeplug:~# lsof -n |grep squeeze|grep LISTEN squeezebo 2239 squeezeboxserver9u IPv4 3878 0t0 TCP *:3483 (LISTEN) squeezebo 2239 squeezeboxserver 23u IPv4 3888 0t0 TCP *:9090 (LISTEN) squeezebo 2239 squeezeboxserver 29u IPv4 3898 0t0 TCP *:59743 (LISTEN) squeezebo 2239 squeezeboxserver 30u IPv4 3902 0t0 TCP *:9000 (LISTEN) TheD6Bel's Profile: http://forums.slimdevices.com/member.php?userid=58077 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
mhh. I think there are 2 versions of netcat in existence and they behave slightly differently when it comes to end of lines. Perhaps something like this would work better for you: echo -e serverstatus\nexit\n | netcat localhost 9090 . I am not sure. But anyway, it looks like the server is fine, that's a good start. (BTW, all the %3A, %20 and so on you get on return are normal, the server url-encodes characters. %3A is :, %20 is and so on (The ASCII code for : is 3A in hexadecimal notation. Grab an ASCII table and you can work your way around. Or use an escaping/unescaping lib. Or use json.) epoch1970's Profile: http://forums.slimdevices.com/member.php?userid=16711 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
root@squeezeplug:~# echo -e serverstatus\nexit\n | netcat localhost 9090 serverstatus lastscan%3A1352124017 version%3A7.7.2 uuid%3A40adacd5-c19a-4c10-bea4-fe1b4481dbce info%20total%20albums%3A4 info%20total%20artists%3A3 info%20total%20genres%3A3 info%20total%20songs%3A67 player%20count%3A1 sn%20player%20count%3A0 other%20player%20count%3A0 root@squeezeplug:~# echo -e players list\nexit\n | netcat localhost 9090 players list count%3A1 playerindex%3Alist playerid%3A00%3A00%3A00%3A00%3A00%3A01 uuid%3A ip%3A127.0.0.1%3A49493 name%3AMusique%20Salon model%3Asqueezeslave isplayer%3A1 displaytype%3Asqueezeslave canpoweroff%3A1 connected%3A1 YOU ARE A KILLER :) TheD6Bel's Profile: http://forums.slimdevices.com/member.php?userid=58077 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
Hi, Could someone help me to modify the Power Switch plugin to control the gpio pins on the raspberry pi? I think this could be easier than using an USB-relay.. How do I start with this? I have no experience with squeezebox plugins.. Thanks in advance! RobbeD's Profile: http://forums.slimdevices.com/member.php?userid=56967 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
RobbeD wrote: Hi, Could someone help me to modify the Power Switch plugin to control the gpio pins on the raspberry pi? I think this could be easier than using an USB-relay.. How do I start with this? I have no experience with squeezebox plugins.. Thanks in advance!SBS/LMS Plugins are written in perl, and with this plugin, all the code resides in Plugin.pm which you can extract from the zip file and edit with any text editor. If you have programming experience, you needn't be shy about hacking away at the code. You'd start by modifying the commandCallback(), handlePowerOn() handlePowerOff() functions. You'll need to know how to twiddle the gpio pins from a script. If you can do it from a bash script, then you'll be able to do it from perl. gharris999's Profile: http://forums.slimdevices.com/member.php?userid=115 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
Hi! I know your post is almost three years old, but you never know.. I also would like to use a relay for this purpose! My idea is to let a script run in the background that checks the powerstate of the player (squeezeplay) on the server via CLI. If the powerstate of the player is on, the relax should turn on the amplifier, otherwise it should turn it off. I am building a raspberry pi with squeezeplay into an old radio. Because i am using a raspberry-pi, i need to use an USB relay. I am very interested in your schematics and the program to control the relay. Thanks in advance! Greetings, Robbe RobbeD's Profile: http://forums.slimdevices.com/member.php?userid=56967 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
Have a look at the Denon plugins or IR blaster. They do this and all you'd need to do is replace the code they use to switch devices on and off with the code you need. The Denon ones use http or at least TCp I believe so maybe they are easier to convert. pippin's Profile: http://forums.slimdevices.com/member.php?userid=13777 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss
Re: [slim] Squeezebox Server with Squeezeslave to turn on speakers when playing
You could look at the Power Switch plugin and modify it to talk to your usb relay. http://www.gwendesign.com/slimserver/dev_hard_and_software.htm#powerswitchii gharris999's Profile: http://forums.slimdevices.com/member.php?userid=115 View this thread: http://forums.slimdevices.com/showthread.php?t=71077 ___ discuss mailing list discuss@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/discuss