Merge pull request #3 from marenz2569/ChaosChemnitz
Fensterbogenbeleuchtungssteuerung
This commit is contained in:
commit
11687a9ad0
|
@ -6,6 +6,8 @@ import requests
|
|||
import urllib
|
||||
from subprocess import check_output
|
||||
import json
|
||||
import socket
|
||||
import struct
|
||||
|
||||
def run_ecmd(cmd):
|
||||
# baseuri = "http://netio.chch.lan.ffc/ecmd?"
|
||||
|
@ -15,6 +17,49 @@ def run_ecmd(cmd):
|
|||
req = requests.get("%s%s" % (baseuri, cmds))
|
||||
return req.text.strip()
|
||||
|
||||
def run_udp(cmd):
|
||||
ip="172.23.92.247"
|
||||
port=49152
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
# 10 ms timeout
|
||||
s.settimeout(0.1)
|
||||
s.sendto(cmd, (ip, port))
|
||||
try:
|
||||
rec = s.recvfrom(1024)[0]
|
||||
except:
|
||||
rec = ""
|
||||
s.close()
|
||||
print(rec)
|
||||
return rec
|
||||
|
||||
# lamp_lounge handling
|
||||
@hook.command("lamp_lounge", autohelp=True)
|
||||
def cmd_lamp_lounge(inp, reply=None):
|
||||
"""lamp_lounge color - set the lamp color"""
|
||||
args = inp.split(" ")
|
||||
if len(args) < 1:
|
||||
reply("lamp_lounge color - set the lamp color")
|
||||
return
|
||||
|
||||
if len(args[0]) != 6:
|
||||
reply("lamp_lounge color - set the lamp color")
|
||||
return
|
||||
|
||||
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)
|
||||
|
||||
if len(rep) < 3:
|
||||
reply("Error: no reply")
|
||||
return
|
||||
|
||||
if rep[0] == 'a':
|
||||
reply("OK")
|
||||
elif rep[0] == 'e':
|
||||
reply("error: " + rep[3:])
|
||||
else:
|
||||
reply("fatal error")
|
||||
|
||||
# Lamp handling
|
||||
@hook.command("lamp", autohelp=True)
|
||||
def cmd_lamp(inp, reply=None):
|
||||
|
|
Reference in New Issue