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