def on_message_device_cb(client, msg): device_cb_msg = str(msg.payload) if g.BOKEH_DEV: print(device_cb_msg) new_conn_status = None if device_cb_msg in ['successfully_connected', 'already_connected']: new_conn_status = True elif device_cb_msg == 'ok_to_unsubscribe': new_conn_status = False client.unsubscribe([g.t_calibration, g.t_device_ctrl_cb]) util.doc_next_tick(doc, util.add_subscription, client, 'calibration') elif device_cb_msg in [ 'successfully_disconnected', 'no_control_allowed', 'esp_init', 'esp_interrupted' ]: new_conn_status = False if new_conn_status is not None: util.doc_next_tick(doc, util.conn_status_update, conn_status, new_conn_status)
def on_disconnect(client, userdata, rc): if rc != 0: client.loop_stop() if g.BOKEH_DEV: print("\nMqtt: Unexpected disconnection.\n") util.doc_next_tick(doc, util.conn_status_update, conn_status, False)
def device_slc_callback(attr, old, new): g.device_id = new g.d_idx = DEVICES['code'].index(g.device_id) if conn_status.value: util.doc_next_tick(doc, util.device_control, client, "unsub") else: client.unsubscribe([g.t_calibration, g.t_device_ctrl_cb]) util.doc_next_tick(doc, util.add_subscription, client, 'calibration')
def periodic_stream(): global new_data if new_data: util.doc_next_tick(doc, util.stream_update, source=source1, new_data=new_data) new_data = dict()
def device_slc_callback(attr, old, new): g.device_id = new g.d_idx = CALIBRATIONS['d_code'].index(g.device_id) g.c_ang = float(CALIBRATIONS['c_data'][g.d_idx]['angular']) g.c_lin = float(CALIBRATIONS['c_data'][g.d_idx]['linear']) if conn_status.value: disable_stream() util.doc_next_tick(doc, util.device_control, client, "unsub") else: client.unsubscribe([g.t_measure, g.t_device_ctrl_cb]) util.doc_next_tick(doc, util.add_subscription, client, 'measure')
def on_message_device_cb(client, msg): """Callback function that handles messages from 't_device_ctrl_cb' topic which is used as a callback topic to return the results of the control commands sent to the device. msg.payload = string with the result """ device_cb_msg = str(msg.payload) if g.BOKEH_DEV: print(device_cb_msg) new_conn_status = None if device_cb_msg == 'successfully_connected': new_conn_status = True device_frequency(data_freq_sld.value) # ''' FOR TESTING/DEBUG if g.BOKEH_DEV: if os.path.isfile(FILE_PATH): os.remove(FILE_PATH) # ''' elif device_cb_msg == 'already_connected': new_conn_status = True elif device_cb_msg == 'ok_to_unsubscribe': new_conn_status = False client.unsubscribe([g.t_measure, g.t_device_ctrl_cb]) util.doc_next_tick(doc, util.add_subscription, client, 'measure') elif device_cb_msg in [ 'successfully_disconnected', 'no_control_allowed', 'esp_init', 'esp_interrupted' ]: new_conn_status = False if not stream_data_btn.active: util.doc_next_tick(doc, disable_stream) if new_conn_status is not None: util.doc_next_tick(doc, util.conn_status_update, conn_status, new_conn_status)