def ohb_listen_thread(): oh.set_poll_listener(listener) oh.set_host(cfg.get('host')) oh.set_port(cfg.get('port')) while True: oh.get_status("/rest/sitemaps/" + sitemap) #oh.get_status("/rest/sitemaps/default") time.sleep(1) # not more than once a second
sys.path.append('..') #sys.path.append('../mqttudp') import threading #import re import mqttudp.engine as me import mqttudp.interlock import mqttudp.config as cfg import paho.mqtt.client as broker cfg.set_group('mqtt-gate') log = cfg.log blackList = cfg.get('blacklist') SUBSCRIBE_TOPIC = cfg.config.get('mqtt-gate', 'subscribe') MQTT_BROKER_HOST = cfg.config.get('mqtt-gate', 'host') MQTT_BROKER_PORT = cfg.config.getint('mqtt-gate', 'port') #SUBSCRIBE_TOPIC="#" #MQTT_BROKER_HOST="smart." #MQTT_BROKER_HOST="iot.eclipse.org" ilock = mqttudp.interlock.Bidirectional(5) def broker_on_connect(client, userdata, rc, unkn): # @UnusedVariable #print("Connected with result code "+str(rc)) log.info("Connected with result code " + str(rc)) client.subscribe(SUBSCRIBE_TOPIC)
#sys.path.append('../mqttudp') #import threading import time #import re import mqttudp.engine import mqttudp.interlock import mqttudp.openhab as openhab import mqttudp.config as cfg cfg.set_group('openhab-gate') log = cfg.log blackList = cfg.get('blacklist') verbose = cfg.getboolean('verbose') dc = openhab.Decoder() # do not repeat item in 10 seconds if value is the same it = mqttudp.interlock.Timer(10) def listener(msg): #global new_items dc.new_items = {} #print("msg="+str(msg)) #print("") dc.extract_content(msg)
sys.path.append('..') #sys.path.append('../mqttudp') import threading import time import mqttudp.engine import mqttudp.interlock import mqttudp.openhab as openhab import mqttudp.config as cfg cfg.set_group('openhab-gate') log = cfg.log blackList = cfg.get('blacklist') sitemap = cfg.get('sitemap') verbose = cfg.getboolean('verbose') oh = openhab.RestIO() dc = openhab.Decoder() # back/forth loop lock ilock = mqttudp.interlock.Bidirectional(5) # do not repeat item in 60 seconds if value is the same it_to_udp = mqttudp.interlock.Timer(60) it_to_ohb = mqttudp.interlock.Timer(20)
import sys sys.path.append('..') #sys.path.append('../mqttudp') #import requests import mqttudp.engine import mqttudp.config as cfg import mqttudp.openhab as openhab cfg.set_group('openhab-gate') log = cfg.log oh = openhab.RestIO() oh.set_host(cfg.get('host')) oh.set_port(cfg.get('port')) last = {} def recv_packet_from_udp(pkt): if pkt.ptype != mqttudp.engine.PacketType.Publish: return if last.__contains__(pkt.topic) and last[pkt.topic] == pkt.value: return last[pkt.topic] = pkt.value #print( topic+"="+value ) log.info("To OpenHAB " + pkt.topic + "=" + pkt.value) #put_status(topic, value) oh.post_command(pkt.topic, pkt.value)