Kleine verandering
This commit is contained in:
@@ -20,6 +20,7 @@ Zorg dat je in de hoofdmap "GoodGarden" zit. Kijk in je path: "../GoodGarden". A
|
|||||||
|
|
||||||
- pip install mysql-connector-python
|
- pip install mysql-connector-python
|
||||||
- pip install requests
|
- pip install requests
|
||||||
|
- pip install paho-mqtt
|
||||||
|
|
||||||
## Gebruik
|
## Gebruik
|
||||||
|
|
||||||
|
|||||||
@@ -7,18 +7,29 @@ def on_message(client, userdata, message):
|
|||||||
data = json.loads(payload_str)
|
data = json.loads(payload_str)
|
||||||
|
|
||||||
device_256 = 0
|
device_256 = 0
|
||||||
|
last_seen = None
|
||||||
|
last_battery_voltage = None
|
||||||
|
|
||||||
device_322 = 0
|
device_322 = 0
|
||||||
|
last_seen = None
|
||||||
|
last_battery_voltage = None
|
||||||
|
|
||||||
for key in data["results"]:
|
for key in data["results"]:
|
||||||
if int(key["id"]) == 256:
|
if int(key["id"]) == 256:
|
||||||
device_256 = int(key["id"])
|
device_256 = int(key["id"])
|
||||||
print(f"{device_256}")
|
last_seen = int(key["last_seen"])
|
||||||
|
last_battery_voltage = float(key["last_battery_voltage"])
|
||||||
|
# print(f"{device_256}")
|
||||||
|
print(f"Het device {device_256} is voor het laatst geien op: {last_seen} met de voltage als {last_battery_voltage}")
|
||||||
|
|
||||||
elif int(key["id"]) == 322:
|
elif int(key["id"]) == 322:
|
||||||
device_322 = int(key["id"])
|
device_322 = int(key["id"])
|
||||||
print(f"{device_322}")
|
last_seen = int(key["last_seen"])
|
||||||
|
last_battery_voltage = float(key["last_battery_voltage"])
|
||||||
|
# print(f"{device_256}")
|
||||||
|
print(f"Het device {device_322} is voor het laatst gezien op: {last_seen} met de voltage als {last_battery_voltage}")
|
||||||
|
|
||||||
print(f"Message received on topic {message.topic}: {data}")
|
print(f"\033[92mMessage received on topic\033[0m {message.topic}: {data}")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
topic = "goodgarden/devices"
|
topic = "goodgarden/devices"
|
||||||
|
|||||||
Reference in New Issue
Block a user