def broadcast_post(): if not request.json: return _error('json required') if not 'data' in request.json: return _error('missing data') data = request.json['data'] byte = bytes(data.encode()) msg_id = str(uuid4())[1:5].upper() if 'msg_id' in request.json: msg_id = request.json['msg_id'] if len(byte) > 250: return _error("data too large") NC.default().post_notification('queue_broadcast', threaded=True, data=data, msg_id=msg_id) return jsonify({ "ok": True, "node": device_id, "bytes": len(byte), "data": data, "msg_id": msg_id })
def receive(): global sent while True: line = str(ser.readline()) if line and strip(line) != sent and line != "b''" and strip( line) != "": sent = strip(line) NC.default().post_notification('queue_broadcast', data=sent, msg_id=None)
def receive_nrf(): global sent_nrf global ser_nrf while True: line = str(ser_nrf.readline()) if line and strip(line) != sent_nrf and line != "b''" and strip( line) != "": sent = strip(line) NC.default().post_notification('queue_broadcast', data=sent, msg_id=None) NC.default().post_notification('queue_broadcast', data="G:42.429371,-88.607452", msg_id=None)
def queue_broadcast(data, msg_id=None): myre = re.compile('^(.{4}):.*$') if myre.match(data): msg_id = myre.findall(data) data = data[5:] if not msg_id: msg_id = str(uuid4())[1:5].upper() if msg_id in id_queue: return id_queue.append(msg_id) NC.default().post_notification('broadcast', data=data, msg_id=msg_id)
def request_refill(self, medicine): data = self.to_json() data['medicine'] = medicine.to_json() NC.default().post_notification('refill', medicine=medicine, patient=self)
def dispense(self, medicine): data = self.to_json() data['medicine'] = medicine.to_json() NC.default().post_notification('dispense', medicine=medicine, patient=self)
def on_broadcast(self, data): NC.default().post_notification('queue_broadcast', threaded=True, data=data['data'], msg_id=data['msg_id'])
def handle_data(data): NC.default().post_notification('queue_broadcast', data=data, msg_id=None)