command lamp_lounge: UDP -> TCP

This commit is contained in:
Markus Schmidl 2017-01-11 21:29:01 +01:00
parent 296de07e14
commit 827c5c73e8
1 changed files with 8 additions and 8 deletions

View File

@ -17,19 +17,19 @@ def run_ecmd(cmd):
req = requests.get("%s%s" % (baseuri, cmds)) req = requests.get("%s%s" % (baseuri, cmds))
return req.text.strip() return req.text.strip()
def run_udp(cmd): def run_tcp(cmd):
ip="172.23.92.247" ip="172.23.92.15"
port=49152 port=49152
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# 10 ms timeout # 100 ms timeout
s.settimeout(0.1) s.settimeout(0.1)
s.sendto(cmd, (ip, port)) s.connect((ip, port))
s.send(cmd)
try: try:
rec = s.recvfrom(1024)[0] rec = s.recv(1024)
except: except:
rec = "" rec = ""
s.close() s.close()
print(rec)
return rec return rec
# lamp_lounge handling # lamp_lounge handling
@ -47,7 +47,7 @@ def cmd_lamp_lounge(inp, reply=None):
c = "a\x00\x03" + struct.pack('BBB', int(args[0][2:4], 16), int(args[0][0:2], 16), int(args[0][4:6], 16)) c = "a\x00\x03" + struct.pack('BBB', int(args[0][2:4], 16), int(args[0][0:2], 16), int(args[0][4:6], 16))
rep = run_udp(c) rep = run_tcp(c)
if len(rep) < 3: if len(rep) < 3:
reply("Error: no reply") reply("Error: no reply")