PDA

View Full Version : Squeezebox Server with Squeezeslave to turn on speakers when playing



Lister
2009-11-07, 04:43
Hi there,


After setting up Squeezebox Server on a 24/7 server running Ubuntu, connecting a SQ3 and a SQ boom to it, I use SqueezeboxSlave as a daemon on the server itself.
All works perfectly, so I'm up to the next step: turning on the powered speakers connected to the server automatically when squeezeslave starts to play anything.
So far I've managed to connect a 220v relay to the com port of the server using salvaged electronics parts and I can successfully switch the speakers on and off from the commandline by starting and stopping a program.

What I want to do is to monitor the state of Squeezeslave, preferably with a bash script, and switch the speakers on when it is playing anything, and switch them off when it stops. With the Boom in use as an alarmclock, and synced with SQslave, I can then have music throughout my house when drinking my morning coffee. :) (and maybe let the relay turn the lights on or something...)

How can I poll the play/stop state of Squeezeslave?
Can I poll SB Server directly? The m3u playlist in /var/lib/squeezeboxserver/prefs/ tells me the playlist update date/time and therefore the moment it starts playing, but how do I know when it stops?
Or can I catch a signal from the lcdproc option?

I'll be very happy to hear anyones thoughts on this.


Cheers,
Lister

Btw, is someone interested in the schematics and program for the comport relay?

RobbeD
2012-08-29, 03:46
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

pippin
2012-08-29, 04:13
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.

gharris999
2012-08-29, 06:55
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

RobbeD
2012-10-22, 05:12
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!

gharris999
2012-10-22, 07:35
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.

TheD6Bel
2012-11-11, 07:39
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
2012-11-11, 07:39
it is possible to know the status of squeezebox go to

IPSQUEEZEBOX:9000/status.txt

to control the switching on and off I buy it
http://www.ebay.com/itm/ws/eBayISAPI.dll?ViewItem&item=300749445346

the post with script (in french)
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=65&t=17048

or if you have found the file needs to be changed, I want the good solution because I did not understand what to change and how

thank's

epoch1970
2012-11-11, 10:34
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.
You can use something like netcat or telnet to communicate w/ LMS, or use a JSON client.

Here is an idea of what you can get w/ the CLI (power, mode, volume are probably interesting to you):
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
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 search the forums there are many example scripts available.

EDIT: Or use/modify one of the above mentioned plugins (srvPowerControl, PowerSave…)

TheD6Bel
2012-11-11, 13:28
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

:(

epoch1970
2012-11-11, 14:15
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:

lsof -n |grep squeeze|grep LISTEN
squeezebo 4732 squeezeboxserver 9u IPv4 497337 0t0 TCP *:3483 (LISTEN)
squeezebo 4732 squeezeboxserver 18u IPv4 497353 0t0 TCP *:9090 (LISTEN)
squeezebo 4732 squeezeboxserver 28u IPv4 497365 0t0 TCP *:9000 (LISTEN)

TheD6Bel
2012-11-11, 14:27
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 squeezeboxserver 9u 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)

epoch1970
2012-11-11, 15:11
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 --I edited my own example before posting to make it more readable.
The server url-encodes special characters. %3A is ":", %20 is " " (space) 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.

TheD6Bel
2012-11-11, 15:47
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
2012-11-18, 05:07
Hello,

the best is instal python for LMS: pylms
http://pypi.python.org/packages/source/p/pylms/pylms-1.0.tar.gz

after:
root@squeezeplug:~# pylms -i
INFO: Server Version: 7.7.2
INFO: Player: 00:00:00:00:00:01 | Musique Salon | V: 61 | M: pause | T: 16.2112755013 | C: True | W: 0
WARNING: No arguments provided

or

root@squeezeplug:~# pylms -i
INFO: Server Version: 7.7.2
INFO: Player: 00:00:00:00:00:01 | Musique Salon | V: 61 | M: play | T: 14.875410223 | C: True | W: 0
WARNING: No arguments provided

or

root@squeezeplug:~# pylms -i
INFO: Server Version: 7.7.2
INFO: Player: 00:00:00:00:00:01 | Musique Salon | V: 61 | M: stop | T: 0.0 | C: True | W: 0
WARNING: No arguments provided

for the script is easy now :)

TheD6Bel
2012-11-18, 05:24
Hello,

the best is instal python for LMS: pylms
http://pypi.python.org/packages/source/p/pylms/pylms-1.0.tar.gz

and with pylms -i

root@squeezeplug:~# pylms -i
INFO: Server Version: 7.7.2
INFO: Player: 00:00:00:00:00:01 | Musique Salon | V: 61 | M: pause | T: 16.2112755013 | C: True | W: 0
WARNING: No arguments provided

or

root@squeezeplug:~# pylms -i
INFO: Server Version: 7.7.2
INFO: Player: 00:00:00:00:00:01 | Musique Salon | V: 61 | M: play | T: 14.875410223 | C: True | W: 0
WARNING: No arguments provided

or

root@squeezeplug:~# pylms -i
INFO: Server Version: 7.7.2
INFO: Player: 00:00:00:00:00:01 | Musique Salon | V: 61 | M: stop | T: 0.0 | C: True | W: 0
WARNING: No arguments provided

for the script is easy now :)

TheD6Bel
2012-11-18, 13:28
Hello i instal a python for LMS and is very easy to have status of server

PYLMS https://github.com/jingleman/PyLMS

root@squeezeplug:~# pylms -i
INFO: Server Version: 7.7.2
INFO: Player: 00:00:00:00:00:01 | Musique Salon | V: 41 | M: stop | T: 0.0 | C: True | W: 0
WARNING: No arguments provided

my problem is to create a python script with the status of every player :(

epoch1970
2012-11-19, 10:50
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… ) 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-Mondays&p=700283&viewfull=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 are relevant python scripts around here. Did you search on the forums ?

TheD6Bel
2012-11-19, 12:19
hello,

I did a search but I have not found a script to manage GPIO over RPi

epoch1970
2012-11-19, 15:04
Wha??

Have you tried "gpio raspberry pi python" on google ?

TheD6Bel
2012-11-20, 03:30
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=65&t=17048&sid=b081c7bdc97882d2bca4bc66807eda87&start=25

If MPD playing music, GPIO is opens, if in pause/stop GPIO closes.




#!/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()

epoch1970
2012-11-20, 16:34
did you see this one : http://forums.slimdevices.com/showthread.php?88269-Sample-code-JSON-API-in-your-language&p=636134&viewfull=1#post636134

TheD6Bel
2012-11-29, 11:13
did you see this one : http://forums.slimdevices.com/showthread.php?88269-Sample-code-JSON-API-in-your-language&p=636134&viewfull=1#post636134

i see, but isn't for manage GPIO, is for have inforamtions over serveurs/player

but thanks :)

RobbeD
2013-04-30, 01:51
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! :-)



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)

TheD6Bel
2013-04-30, 02:28
Thanks, i test now ;)

RobbeD
2013-04-30, 05:18
Ok! :-) Let me know if it works or not..

TheD6Bel
2013-05-01, 06:52
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

EDIT I tested withe a tester and pin 12 (gpio18) out continuous 3.3V with LMS on or off

TheD6Bel
2013-05-01, 07:27
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

RobbeD
2013-05-01, 08:18
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..

TheD6Bel
2013-05-02, 11:41
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
^
TabError: inconsistent use of tabs and spaces in indentation

TheD6Bel
2013-05-02, 12:05
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

Julf
2013-05-02, 12:24
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.

<edit> I had a look at your script. Are you aware that python syntax is indentation-sensitive? Your indentation seems to be all over the place.

RobbeD
2013-05-03, 01:44
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

Julf
2013-05-03, 02:26
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.

TheD6Bel
2013-05-03, 10:10
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

RobbeD
2013-05-08, 06:09
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

TheD6Bel
2013-05-08, 10:51
hello,

your file is the same script :)

but thanks for you work ;)

palmerx
2014-11-18, 13:41
This looks amazing, would that work on the PiCorePlayer also to turn on my Amp??

https://sites.google.com/site/picoreplayer/home

TheD6Bel
2014-11-18, 14:07
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 ;)

RobbeD
2014-11-18, 14:56
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

TheD6Bel
2014-11-18, 15:31
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
2014-11-19, 01:35
Hello RobbeD,

don't work for me :


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?

RobbeD
2014-11-20, 05:24
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?

TheD6Bel
2014-11-20, 05:35
Sorry my mistake!

for run script i make ./rxpl.py

i'am on work now, i tried tonight

TheD6Bel
2014-11-20, 12:20
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 ;)

palmerx
2014-11-20, 13:12
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!!

TheD6Bel
2014-11-20, 14:21
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 :


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 :


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


chmod 755 relay.py

and for run your script and test it


python relay.py

now for run your script on boot, (i don't tried yet, only with first script)


nano /etc/rc.local

before "exit 0"

you put
/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

EDIT : i forget

for boot every boot is


python /yourpath/relay.py &

palmerx
2014-11-22, 13:34
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

TheD6Bel
2014-11-22, 15:13
hello, your script like this


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{\ninterva l=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 = 50000

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
2014-11-23, 08:10
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

palmerx
2014-11-23, 09:56
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
2014-11-23, 10:01
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

TheD6Bel
2014-11-23, 14:36
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 &

;)

RobbeD
2014-11-25, 01:04
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.

TheD6Bel
2014-11-25, 13:52
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 ;)

RobbeD
2014-11-25, 14:21
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?

ashwin.isaac
2015-02-18, 03:45
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?