Esempio n. 1
0
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
    })
Esempio n. 2
0
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)
Esempio n. 3
0
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)
Esempio n. 4
0
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)
Esempio n. 5
0
 def request_refill(self, medicine):
     data = self.to_json()
     data['medicine'] = medicine.to_json()
     NC.default().post_notification('refill',
                                    medicine=medicine,
                                    patient=self)
Esempio n. 6
0
 def dispense(self, medicine):
     data = self.to_json()
     data['medicine'] = medicine.to_json()
     NC.default().post_notification('dispense',
                                    medicine=medicine,
                                    patient=self)
Esempio n. 7
0
 def on_broadcast(self, data):
     NC.default().post_notification('queue_broadcast',
                                    threaded=True,
                                    data=data['data'],
                                    msg_id=data['msg_id'])
Esempio n. 8
0
def handle_data(data):
    NC.default().post_notification('queue_broadcast', data=data, msg_id=None)