def __init__(self): """ Create global bridge, initialize the bridge client and the lock for synchronization. """ # initialize bridge self.bridge = BridgeClient() # initialize synchronization lock self.lock = Lock()
def custom_callback_accepted(client, userdata, message): """ Callback to handle passing a custom message to the other processor via the bridge """ print('Callback', message.payload) msg = json.loads(message.payload) brightness = msg['state']['desired']['brightness'] color = msg['state']['desired']['color'] power = msg['state']['desired']['power'] code = 'NOOP' if brightness != '*': code = 'B' + str(brightness) if color != '*': code = 'C' + color if power != '*': code = 'P' + power client = BridgeClient() client.mailbox(code) print("Sent Message:", code)
@staticmethod def forODF(odf_name, data): os.system(r'echo "default-on" > /sys/class/leds/ds:green:wlan/trigger') global ODFcache if ODFcache[odf_name].qsize(): ODFcache[odf_name].get() ODFcache[odf_name].put(data) else: ODFcache[odf_name].put(data) os.system(r'echo "none" > /sys/class/leds/ds:green:wlan/trigger') BClient = BridgeClient() def Bridge2Arduino(): global incomming, ODFcache, IDFcache, timestamp, IDFsignal while True: for ODF in ODFcache: if ODFcache[ODF].qsize(): data = ODFcache[ODF].get() if data == None: continue for dimension in odf2Bridge[ODF]: if data[dimension[0]] is None:
# udpBridge.py import socket import time from bridgeclient import BridgeClient serverAddress = "192.168.1.2" serverPort = 8888 bridge = BridgeClient() inSocket = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) inSocket.bind(("",8888)) while True: try: incoming = inSocket.recv(255) bridge.put("in", incoming) except KeyboardInterrupt: break except Exception as err: print err pass
if key in self.bridge_var: r = self.bridge_var[key] else: r = None return r def getall(self): return self.bridge_var def put(self, key, value): self.bridge_var.update({key: value}) # run httpd server here # end of abstraction bridge_client = BridgeClient() # required values, if any error in bridge then defaults is used [1] # format codeword: ["codeword in bridge", default value, literal processing, variable] cw = { "mode": ["mode", "auto", True, "var.mode"], # valve position in % to start heating "valve": ["valve_pos", 35, True, "setup.valve_pos"], # start heating if single valve position in %, no matter how many valves are needed to start to heating "svpnmw": ["svpnmw", 75, True, "setup.svpnmw"], # how many valves must be in position stated above "valves": ["valves", 2, True, "setup.valves"], # if in total mode, sum of valves position to start heating "total": ["total_switch", 150, True, "setup.total_switch"], # preference, "per" = per valve, "total" to total mode "pref": ["preference", "per", True, "setup.preference"],
odf_list = custom.odf() idf_list = custom.idf() DAN.profile['df_list'] = [t[0] for t in idf_list] for t in odf_list: if t[0] not in DAN.profile['df_list']: DAN.profile['df_list'].append(t[0]) print('Detected features:') for f_name in DAN.profile['df_list']: print(' {}'.format(f_name)) DAN.device_registration_with_retry(custom.ServerIP) BridgeClient().put('Reg_done', '1') incomming = {} previous_outcomming = {} for f_name in [t[0] for t in odf_list]: incomming[f_name] = 0 for f_name in [t[0] for t in idf_list]: previous_outcomming[f_name] = '' while True: try: cache = {} check_list = [t[0] for t in odf_list] for f_name, index, pin_name in odf_list:
time.sleep(5) count += 1 def numberOfSteps(previous, current): diff = current - previous if abs(diff) > 180: steps = (360 - max(previous, current)) + min(previous, current) if current > previous: steps = steps - (2 * steps) else: steps = diff steps = int(steps * (512.0 / 360.0)) return (steps) if resp == 200: weatherData = json.loads(urlobj.read()) windDir = weatherData['wind']['deg'] steps = numberOfSteps(prev_windDir, windDir) else: windDir = prev_windDir steps = -1 #creates a bridge object bricli = BridgeClient() #Pass variables to the bridge memory bricli.put('steps', str(steps)) bricli.put('windDir', str(int(windDir)))
"no_oww": "no_oww"} stp.statMsg = { "idle": "idle", "heat": "heating", "start": "starting", "dead": "dead" } var = variables() # heat times; total: [totalheattime, time.time()] var.ht = {"total": [0, 0.0]} var.dev_log = {} var.msgQ = [] # initialize bridge var.value = BridgeClient() if path.ismount("/mnt/sda1"): stp.place = "/mnt/sda1/" elif path.ismount("/mnt/sdb1"): stp.place = "/mnt/sdb1/" else: err_str = "Error: can't find mounted storage device! Please mount SD card or USB key and run program again." llError(err_str) var.value.put(stp.cw["msg"], "Q") exit() try: stp.myip = socket.gethostbyname(socket.gethostname()) except Exception, e: err_str = "Error getting IP address from hostname, please check resolv.conf or hosts or both!\r\n"