diff --git a/main.py b/main.py index 29d7256..3ebc1a0 100644 --- a/main.py +++ b/main.py @@ -11,6 +11,10 @@ import yaml from amqtt.client import MQTTClient, ClientException from amqtt.mqtt.constants import QOS_1, QOS_2 import json +import base64 +import numpy as np +import cv2 as cv + sublist = [] @@ -38,7 +42,18 @@ async def uptime_coro(): packet = message.publish_packet dictout = decoder(packet.payload.data) print("%d: %s => %s" % (count, packet.variable_header.topic_name, dictout)) - publishData(str(dictout["data"]), str(dictout["sensorID"]), str(packet.variable_header.topic_name.split("/")[-1]), dictout["timestamp"]) + if packet.variable_header.topic_name.split("/")[-1] == "camera": # trigger image loading + print(len(dictout["data"])) + img = np.frombuffer(base64.b64decode(dictout["data"]), np.uint8) + #height, width = img.shape[:2] + #print(height, width) + + #cv.imshow('frame', img) + cv.imwrite('./output.jpg', img) + #if cv.waitKey(1) == ord('q'): + # break + else: + publishData(str(dictout["data"]), str(dictout["sensorID"]), str(packet.variable_header.topic_name.split("/")[-1]), dictout["timestamp"]) #await C.unsubscribe(['a/b']) #await C.disconnect() except ClientException as ce: @@ -57,10 +72,11 @@ def publishData(data, sensorID, sensorType, dataTimestamp): print("DONE") def subdict(d, header): + # coordinate mqtt topic names and waggle topics / sensor names for k,v in d.items(): if isinstance(v, dict): if header is not None: - subdict(v, header + k + "/") + subdict(v, header + k + "/") # recurse further else: subdict(v, k + "/") else: diff --git a/requirements.txt b/requirements.txt index 65395c4..9091cf6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ pywaggle[all] -amqtt==0.11.0b1 -pyyaml -alive-progress \ No newline at end of file +amqtt==0.10.0a3 +pyyaml \ No newline at end of file diff --git a/run.sh b/run.sh index 27d3a29..07dafb5 100755 --- a/run.sh +++ b/run.sh @@ -1,9 +1,9 @@ #!/bin/bash -#export PYWAGGLE_LOG_DIR=test-run -python main.py & -sleep 1 -python client.py #2&>/dev/null > /dev/null -sleep 5 -jobs -p -kill $(jobs -p) \ No newline at end of file +export PYWAGGLE_LOG_DIR=test-run +python main.py +#sleep 1 +#python client.py #2&>/dev/null > /dev/null +#sleep 5 +#jobs -p +#kill $(jobs -p) diff --git a/subscribe.yaml b/subscribe.yaml index 432edc7..b1d64df 100644 --- a/subscribe.yaml +++ b/subscribe.yaml @@ -7,5 +7,5 @@ sensors: - "1" - "2" pi1: - - "humidity" - - "camera" \ No newline at end of file + - "camera" + - "uptime" \ No newline at end of file diff --git a/test-run/data.ndjson b/test-run/data.ndjson index cbd87eb..e7babf6 100644 --- a/test-run/data.ndjson +++ b/test-run/data.ndjson @@ -1,38 +1,21 @@ -{"meta":{"sensorID":"0","sensorType":"microphone"},"name":"network.bridge.sensor.microphone","timestamp":"2023-03-21T14:46:25.762401149","value":1} -{"meta":{"sensorID":"0","sensorType":"microphone"},"name":"network.bridge.sensor.microphone","timestamp":"2023-03-21T14:49:11.913989882","value":1} -{"meta":{"sensorID":"0","sensorType":"microphone"},"name":"network.bridge.sensor.microphone","timestamp":"2023-03-21T14:52:40.885835367","value":1} -{"meta":{"sensorID":"0","sensorType":"microphone"},"name":"network.bridge.sensor.microphone","timestamp":"2023-03-21T14:53:10.464592551","value":1} -{"meta":{"sensorID":"0","sensorType":"microphone"},"name":"network.bridge.sensor.microphone","timestamp":"2023-03-21T14:53:17.921731597","value":1} -{"meta":{"sensorID":"0","sensorType":"distance"},"name":"network.bridge.sensor.distance","timestamp":"2023-03-23T16:25:51.990142198","value":23.0} -{"meta":{"sensorID":"0","sensorType":"distance"},"name":"network.bridge.sensor.distance","timestamp":"2023-03-23T16:27:40.431504756","value":23.0} -{"meta":{"sensorID":"0","sensorType":"distance"},"name":"network.bridge.sensor.distance","timestamp":"2023-03-23T16:28:15.329268361","value":23.0} -{"meta":{"sensorID":"0","sensorType":"distance"},"name":"network.bridge.sensor.distance","timestamp":"2023-04-25T02:41:20.991421576","value":23.0} -{"meta":{"sensorID":"0","sensorType":"distance"},"name":"network.bridge.sensor.distance","timestamp":"2023-04-25T02:42:12.652135412","value":"23.0"} -{"meta":{"sensorID":"0","sensorType":"distance"},"name":"network.bridge.sensor.distance","timestamp":"2023-04-25T02:42:53.066840228","value":"23.0"} -{"meta":{"sensorID":"0","sensorType":"distance"},"name":"network.bridge.sensor.distance","timestamp":"2023-04-25T02:45:23.283790094","value":"23.0"} -{"meta":{"sensorID":"0","sensorType":"distance"},"name":"network.bridge.sensor.distance","timestamp":"2023-04-25T02:47:35.919512434","value":"23.0"} -{"meta":{"sensorID":"0","sensorType":"distance"},"name":"network.bridge.sensor.distance","timestamp":"2023-04-25T02:48:33.712925528","value":"23.0"} -{"meta":{"sensorID":"0","sensorType":"distance"},"name":"network.bridge.sensor.distance","timestamp":"2023-04-25T02:49:00.403114061","value":"23.0"} -{"meta":{"sensorID":"0","sensorType":"distance"},"name":"network.bridge.sensor.distance","timestamp":"2023-04-25T02:50:08.021896061","value":"23.0"} -{"meta":{"sensorID":"0","sensorType":"uptime"},"name":"network.bridge.sensor.uptime","timestamp":"2023-04-25T02:50:08.022049430","value":"100246.73"} -{"meta":{"sensorID":"0","sensorType":"distance"},"name":"network.bridge.sensor.distance","timestamp":"2023-04-25T02:51:32.596627385","value":"23.0"} -{"meta":{"sensorID":"0","sensorType":"uptime"},"name":"network.bridge.sensor.uptime","timestamp":"2023-04-25T02:51:32.596818320","value":"100331.3"} -{"meta":{"sensorID":"0","sensorType":"distance"},"name":"network.bridge.sensor.distance","timestamp":"2023-04-25T02:51:37.597553087","value":"23.0"} -{"meta":{"sensorID":"0","sensorType":"uptime"},"name":"network.bridge.sensor.uptime","timestamp":"2023-04-25T02:51:37.597775545","value":"100336.3"} -{"meta":{"sensorID":"0","sensorType":"distance"},"name":"network.bridge.sensor.distance","timestamp":"2023-04-25T02:51:47.594756583","value":"23.0"} -{"meta":{"sensorID":"0","sensorType":"uptime"},"name":"network.bridge.sensor.uptime","timestamp":"2023-04-25T02:51:47.594964505","value":"100346.3"} -{"meta":{"sensorID":"0","sensorType":"distance"},"name":"network.bridge.sensor.distance","timestamp":"2023-04-25T02:51:57.595145358","value":"23.0"} -{"meta":{"sensorID":"0","sensorType":"uptime"},"name":"network.bridge.sensor.uptime","timestamp":"2023-04-25T02:51:57.595314756","value":"100356.3"} -{"meta":{"sensorID":"0","sensorType":"distance"},"name":"network.bridge.sensor.distance","timestamp":"2023-04-25T02:52:07.595837006","value":"23.0"} -{"meta":{"sensorID":"0","sensorType":"uptime"},"name":"network.bridge.sensor.uptime","timestamp":"2023-04-25T02:52:07.596042910","value":"100366.3"} -{"meta":{"sensorID":"0","sensorType":"distance"},"name":"network.bridge.sensor.distance","timestamp":"2023-04-25T02:52:17.594484939","value":"23.0"} -{"meta":{"sensorID":"0","sensorType":"uptime"},"name":"network.bridge.sensor.uptime","timestamp":"2023-04-25T02:52:17.594742543","value":"100376.3"} -{"meta":{"sensorID":"0","sensorType":"distance"},"name":"network.bridge.sensor.distance","timestamp":"2023-04-25T02:52:22.609991681","value":"23.0"} -{"meta":{"sensorID":"0","sensorType":"distance"},"name":"network.bridge.sensor.distance","timestamp":"2023-04-25T02:52:42.357291413","value":"23.0"} -{"meta":{"sensorID":"0","sensorType":"uptime"},"name":"network.bridge.sensor.uptime","timestamp":"2023-04-25T02:52:42.357447243","value":"100401.06"} -{"meta":{"sensorID":"0","sensorType":"distance"},"name":"network.bridge.sensor.distance","timestamp":"2023-04-25T02:52:54.065078655","value":"23.0"} -{"meta":{"sensorID":"0","sensorType":"distance"},"name":"network.bridge.sensor.distance","timestamp":"2023-04-25T02:54:26.859578466","value":"23.0"} -{"meta":{"sensorID":"0","sensorType":"uptime"},"name":"network.bridge.sensor.uptime","timestamp":"2023-04-25T02:54:26.859743183","value":"100505.57"} -{"meta":{"sensorID":"0","sensorType":"distance"},"name":"network.bridge.sensor.distance","timestamp":"2023-04-25T02:54:31.847342612","value":"23.0"} -{"meta":{"sensorID":"0","sensorType":"uptime"},"name":"network.bridge.sensor.uptime","timestamp":"2023-04-25T02:54:31.847538395","value":"100510.55"} -{"meta":{"sensorID":"0","sensorType":"distance"},"name":"network.bridge.sensor.distance","timestamp":"2023-04-25T02:54:41.845631157","value":"23.0"} +{"meta":{"sensorID":"0","sensorType":"uptime"},"name":"network.bridge.sensor.uptime","timestamp":"2023-05-02T15:28:38.566622257","value":"814.3"} +{"meta":{"sensorID":"0","sensorType":"uptime"},"name":"network.bridge.sensor.uptime","timestamp":"2023-05-02T15:28:46.089594575","value":"821.82"} +{"meta":{"sensorID":"0","sensorType":"uptime"},"name":"network.bridge.sensor.uptime","timestamp":"2023-05-02T15:28:54.142512597","value":"829.88"} +{"meta":{"sensorID":"0","sensorType":"uptime"},"name":"network.bridge.sensor.uptime","timestamp":"2023-05-02T15:29:22.331154146","value":"858.07"} +{"meta":{"sensorID":"0","sensorType":"uptime"},"name":"network.bridge.sensor.uptime","timestamp":"2023-05-02T15:29:30.350679756","value":"866.09"} +{"meta":{"sensorID":"0","sensorType":"uptime"},"name":"network.bridge.sensor.uptime","timestamp":"2023-05-02T15:29:38.496613416","value":"874.23"} +{"meta":{"sensorID":"0","sensorType":"uptime"},"name":"network.bridge.sensor.uptime","timestamp":"2023-05-02T15:29:46.628002400","value":"882.36"} +{"meta":{"sensorID":"0","sensorType":"uptime"},"name":"network.bridge.sensor.uptime","timestamp":"2023-05-02T15:29:54.670600106","value":"890.41"} +{"meta":{"sensorID":"0","sensorType":"uptime"},"name":"network.bridge.sensor.uptime","timestamp":"2023-05-02T15:31:30.891024825","value":"986.63"} +{"meta":{"sensorID":"0","sensorType":"uptime"},"name":"network.bridge.sensor.uptime","timestamp":"2023-05-02T15:31:38.936544837","value":"994.67"} +{"meta":{"sensorID":"0","sensorType":"uptime"},"name":"network.bridge.sensor.uptime","timestamp":"2023-05-02T15:31:46.946380771","value":"1002.68"} +{"meta":{"sensorID":"0","sensorType":"uptime"},"name":"network.bridge.sensor.uptime","timestamp":"2023-05-02T15:31:54.825962183","value":"1010.56"} +{"meta":{"sensorID":"0","sensorType":"uptime"},"name":"network.bridge.sensor.uptime","timestamp":"2023-05-02T15:32:02.891364497","value":"1018.63"} +{"meta":{"sensorID":"0","sensorType":"uptime"},"name":"network.bridge.sensor.uptime","timestamp":"2023-05-02T15:32:15.762933582","value":"1031.5"} +{"meta":{"sensorID":"0","sensorType":"uptime"},"name":"network.bridge.sensor.uptime","timestamp":"2023-05-02T15:32:23.869455957","value":"1039.6"} +{"meta":{"sensorID":"0","sensorType":"uptime"},"name":"network.bridge.sensor.uptime","timestamp":"2023-05-02T15:32:31.657693104","value":"1047.39"} +{"meta":{"sensorID":"0","sensorType":"uptime"},"name":"network.bridge.sensor.uptime","timestamp":"2023-05-02T15:32:39.596944900","value":"1055.33"} +{"meta":{"sensorID":"0","sensorType":"uptime"},"name":"network.bridge.sensor.uptime","timestamp":"2023-05-02T15:32:47.846902748","value":"1063.58"} +{"meta":{"sensorID":"0","sensorType":"uptime"},"name":"network.bridge.sensor.uptime","timestamp":"2023-05-02T15:33:23.011959212","value":"1098.75"} +{"meta":{"sensorID":"0","sensorType":"uptime"},"name":"network.bridge.sensor.uptime","timestamp":"2023-05-02T15:34:44.917333986","value":"1180.65"} +{"meta":{"sensorID":"0","sensorType":"uptime"},"name":"network.bridge.sensor.uptime","timestamp":"2023-05-02T15:34:53.142359741","value":"1188.88"}