Squeezebox and Smarthings

Thanks Lee for the above and beyond help. I was able to get this working with the server being on a password after reading the example codes you linked. I couldn’t find the encrypted version on my pi anywhere like that robot example you posted had but I was able to get it to work with a plain text version. Here is the changes to the SBBridge.py. I basically added a variable to store the username and one for the password too. I added the time library so I could add a sleep in the code after the first connect to give it a second to connect before I shoot off the password. I then added the send string to send the username and password. All my additions are surrounded with ** obviously the stars have to be deleted for it to work but I couldn’t figure out how to make them bold on here to accentuate my changes. Now if I can figure out how the player syncs work in the app I’ll be set. Seems like one of my groups worked and another one said null for some reason in the slurper after I tried to activate a “group” maybe its cause I don’t have any playlists or something and that expected behavior? but Ill probably just have to play with it more to figure it all out. Would anyone else be interested in a next song previous song and play stop buttons? Seems it would be useful to add those features but at least most importantly as it is I can easily turn on and off players.

## Bridge program between smart things and the raspberry PI
##
##                       |  RASPBERRY PI INTERNAL
##                       |
##   S                   |                       S
##   T                   |  B                    B 
##       ---- HTTP --->  |  R  ---- TELNET --->  
##   S                   |  I                    S
##   E                   |  D                    E
##   R                   |  G                    R
##   V   <--- JSON ----  |  E  <--- TELNET ----  V
##   E                   |                       E
##   R                   |                       R
##                       |
##
## the Json will be sent via a line of shell code and TELNET treated as raw
## packets as far as possible

import socket
import threading
import subprocess
**import time**

myIP = ''

telnetPort = 9090 #these need numbers
telnetIP = '192.168.1.85'

httpPort = 39500
httpIP = '' #raspi ip

SmartHubIP = '192.168.1.119'
**username = 'usernamehere'**
**password = 'passwordhere'**

def sendJSON(message):
    ##complie and send a JSON msg by shell script
    subprocess.call('curl -H \"Content-Type: application/json\" -X POST -d \'{\"SBSResponse\":\"' + message + '\"}\' http://' + SmartHubIP + ':' + str(httpPort), shell = True)

    

def telnetHandler():
    ##recvs and deals with telnet msgs, will use sendJSON funct
    while True:       
        msg = telSocket.recv(1024)

##        with lock:
##            print('recved on telnet: ' + msg.decode().strip())
            
        sendJSON(msg.decode())


def httpHandler():
    ##recvs and deals with HTTP msgs, will use sendTEL funct
    while True:
 
        con, addr = httpSocket.accept()

        SmartHubIP = addr[0]
	SmartHubPort = addr[1]
        
        requ = con.recv(1024)
            
##        with lock:
##            print('recved on http: ' + requ.decode().strip())
##            print('resolved IP: ' + SmartHubIP + '\n resolved Port: ' + str(SmartHubPort))

        con.close()

        telSocket.send(requ)
        


lock = threading.Lock() #allows threads to print


httpSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)#creates the socket for recveing HTTP msgs (server type)
httpSocket.bind((httpIP, httpPort))
httpSocket.listen(3)


telSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)#creates the telnet socket (client type)
telSocket.connect((telnetIP, telnetPort))
**time.sleep(5)**
**telSocket.sendall("login "+username+" "+password+"\r\n" )**
        

telnetDaemon = threading.Thread(target = telnetHandler, args = ()) #creates threads
httpDaemon = threading.Thread(target = httpHandler, args = ())
telnetDaemon.isDaemon() #sets threads to daemons
httpDaemon.isDaemon()

telnetDaemon.start() #begins threads 
httpDaemon.start()


while True:
    pass

Just an update from my end. Had surgery, so am just now having a chance to work on my idea. This past week I’ve succeeded in getting server and player device handlers written and functioning with two players being controlled independently. I do get server responses back without a bridge, but only with polling, no lan aysnc yet that I know of. Need to do a bit more testing and clean up my code. Will try to share something soon. Glad thereis still interest in this.

I would love to see what you have

I have finally gotten my code posted. I’ve started a new topic so that I can attempt to keep the feedback about it findable and not continue to clutter up this conversation. Thanks for your interest.

Announcements from your Squeezebox players.

  • Generic Media Render (DLNA Speakers) reworked to work with Squeezebox.

  • Use Big Talker to make your announcements

If it is of use to anybody please consider donating to my favourite charity: https://www.nowdonate.com/checkout/pv0j03m4s1o1x60o6bh2

Its not perfect, but works, your welcome to feedback problems, but I’m not promising to fix it.

1 Like