def heartbeat_jingyi(): # global sockLocal # sockLocal = doConnect(host, port) # send_data(procSensor()) while True: try: global devCache result = engine.execute("select * from sensor_geomagnetism") tmpCache = {} for row in result: key = str(row['dev_eui']).replace("-", "").lower() tmpCache[key] = row devCache = tmpCache logger.debug("begin send heartbeat") header['host_code_machine_id'] = 667 thr = Greenlet(send_data, procHeartbeat()) thr.run() time.sleep(3) header['host_code_machine_id'] = 666 thr = Greenlet(send_data, procHeartbeat()) thr.run() # send_data(procHeartbeat()) except Exception as error: error_msg = error logger.error(str(error_msg)) time.sleep(300)
def listen_join_request(): ps = db1.pubsub() ps.subscribe(Channel1.join_req_alarm) while True: for item in ps.listen(): logger.info(ConstLog.join_req + 'LISTEN MSG ' + str(item)) if item['type'] == 'message': data = item['data'].decode() data = json.loads(data) thr = Greenlet(process_join_request, data) thr.run()
def heartbeat_jingyi(): # global sockLocal # sockLocal = doConnect(host, port) # send_data(procSensor()) while True: logger.debug("begin send heartbeat") header['host_code_machine_id'] = 667 thr = Greenlet(send_data, procHeartbeat()) thr.run() time.sleep(3) header['host_code_machine_id'] = 666 thr = Greenlet(send_data, procHeartbeat()) thr.run() # send_data(procHeartbeat()) time.sleep(300)
def listen_jingyi_request(): # sockLocal = doConnect(host, port) ps = db2.pubsub() ps.subscribe("up_alarm:9999939a00000000") # ps.subscribe("up_alarm:1020304050607080") while True: for item in ps.listen(): try: logger.debug(str(item)) if item['type'] == 'message': thr = Greenlet(proc_message, item) thr.run() except Exception as error: error_msg = error logger.error(str(error_msg))
def loop_sensor_jingyi(): # global sockLocal # sockLocal = doConnect(host, port) # send_data(procSensor()) while True: time.sleep(1) ctime = time.time() try: for dev in dataPositionGlobal.keys(): if dataPositionGlobal[dev]['need_send'] == True and ctime - dataPositionGlobal[dev]['last_receive_time'] > 18: logger.debug("begin send sensor:%s,dev:%s", dev, dataPositionGlobal[dev]['last_sensor_info']['position_id']) if dataPositionGlobal[dev]['last_send_state'] == 1 and dataPositionGlobal[dev]['last_sensor_info']['state'] == 1: sensor = dataPositionGlobal[ dev]['last_sensor_info'].copy() sensor['state'] = 0 thr = Greenlet(send_data, procSensor(sensor)) thr.run() thr1 = Greenlet(send_data_delay, procSensor(dataPositionGlobal[ dev]['last_sensor_info'])) thr1.run() else: thr = Greenlet(send_data, procSensor(dataPositionGlobal[ dev]['last_sensor_info'])) thr.run() # send_data(procSensor(dataPositionGlobal[ # dev]['last_sensor_info'])) dataPositionGlobal[dev]['last_send_state'] = dataPositionGlobal[ dev]['last_sensor_info']['state'] dataPositionGlobal[dev]['need_send'] = False except Exception as error: error_msg = error logger.error(str(error_msg))