windows["state"][row_id][col_id] = "?" def updateWindows(): global windows windows_old = windows.copy() for row_id, row in enumerate(config.windows): for col_id, window in enumerate(row): if (window != "x" and window != "?") : if (window[0].lower() in io_ports) : windows["state"][row_id][col_id] = io_ports[window[0].lower()][int(window[1])] else : windows["state"][row_id][col_id] = "!" hausbus3.update_group("windows", windows, False) hausbus3.publish("windows", retain = True) hausbus3.start("heizungssteuerung", http_port=80, mqtt_broker = config.mqtt_broker) io_ports = {} windows = {} initWindows() try: thread.start_new_thread( outputThread, () ) thread.start_new_thread( serialThread, () ) except: print >> sys.stderr, "Error: unable to start threads" try: while 1: time.sleep(10) # Ctrl-C interupts our server magic
#!/usr/bin/python # Import the Hausbus3 module import hausbus3 import os, time base_path = os.path.dirname(os.path.realpath(os.path.abspath(__file__))) # start the Hausbus2 server on port 8080 hausbus3.start("example", http_port=8080, https_port=4443, keyfile=base_path + '/example.key', certfile=base_path + '/example.crt', mqtt_broker = "127.0.0.1") # Set variables to be served via the Hausbs3 Server hausbus3.update("temperature","olymp", 23.70, False) hausbus3.update("temperature", "kueche", 25.20, False) hausbus3.update("temperature", "eecke", 23.40) hausbus3.update("io_ports", "A", "11001101", False) hausbus3.update("io_ports", "B", "10001110", False) hausbus3.update("io_ports", "C", "01010100") hausbus3.update("pinpad", "door", "locked", False) hausbus3.update("pinpad", "lastsync", 1321819942, False) hausbus3.update("pinpad", "wrongpins", 3, False) hausbus3.update("pinpad", "msg", "Willkommen im RZL") hausbus3.update("windows","state", [["x", "1", "x", "x", "0", "x", "x", "?", "x", "x", "?", "x"], ["x", "0", "0", "?", "0", "x", "x", "0", "?", "0", "0", "x"]]) try: while 1: time.sleep(10) # Ctrl-C interupts our server magic except KeyboardInterrupt:
import hausbus3 from urllib2 import urlopen import socket socket._fileobject.default_bufsize = 0 def ohai(people): for person in people: print "OHAI " + person def kthxbye(people): for person in people: print "KTHXBYE " + person # start the Hausbus3 server on port 8080 hausbus3.start("raumstatus-proxy", http_port=8080, mqtt_broker = "127.0.0.1") laboranten = [] laboranten_old = [] try: f = urlopen("http://status.raumzeitlabor.de/api/stream/full.json") for line in f: if line == "\r\n": # KeepAlive-Package only continue data = json.loads(line) hausbus2.update("raumstatus","tuer",data["details"]["tuer"], False) hausbus2.update("raumstatus","geraete",data["details"]["geraete"], False) hausbus2.update("raumstatus","laboranten",data["details"]["laboranten"])
global windows windows_old = windows.copy() for row_id, row in enumerate(config.windows): for col_id, window in enumerate(row): if (window != "x" and window != "?"): if (window[0].lower() in io_ports): windows["state"][row_id][col_id] = io_ports[ window[0].lower()][int(window[1])] else: windows["state"][row_id][col_id] = "!" hausbus3.update_group("windows", windows, False) hausbus3.publish("windows", retain=True) hausbus3.start("heizungssteuerung", http_port=80, mqtt_broker=config.mqtt_broker) io_ports = {} windows = {} initWindows() try: thread.start_new_thread(outputThread, ()) thread.start_new_thread(serialThread, ()) except: print >> sys.stderr, "Error: unable to start threads" try: while 1: time.sleep(10)