From c30441a9f61b887ad17288e0d705dce1adbcf76d Mon Sep 17 00:00:00 2001 From: Terra Date: Sun, 24 Apr 2022 03:41:28 +0200 Subject: [PATCH] more init --- .gitignore | 1 + PyRH | 1 - RasPi | 1 - RasPi/Config.toml | 7 +++++ RasPi/MultiNode.py | 71 ++++++++++++++++++++++++++++++++++++++++++++++ RasPi/RXTest.py | 55 +++++++++++++++++++++++++++++++++++ 6 files changed, 134 insertions(+), 2 deletions(-) create mode 100644 .gitignore delete mode 120000 PyRH delete mode 120000 RasPi create mode 100644 RasPi/Config.toml create mode 100644 RasPi/MultiNode.py create mode 100644 RasPi/RXTest.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c18dd8d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__/ diff --git a/PyRH b/PyRH deleted file mode 120000 index c13d270..0000000 --- a/PyRH +++ /dev/null @@ -1 +0,0 @@ -/mnt/ssh/multinode/PyRH \ No newline at end of file diff --git a/RasPi b/RasPi deleted file mode 120000 index 5785649..0000000 --- a/RasPi +++ /dev/null @@ -1 +0,0 @@ -/mnt/ssh/multinode/RasPi \ No newline at end of file diff --git a/RasPi/Config.toml b/RasPi/Config.toml new file mode 100644 index 0000000..f7aead3 --- /dev/null +++ b/RasPi/Config.toml @@ -0,0 +1,7 @@ +[server] +address = 0x0001 +secret_key = 0x2e29b257521dc792 + +[node] +address = 0x1FFF +secret_key = 0x7ed64cce5b5d8e85 \ No newline at end of file diff --git a/RasPi/MultiNode.py b/RasPi/MultiNode.py new file mode 100644 index 0000000..53f2523 --- /dev/null +++ b/RasPi/MultiNode.py @@ -0,0 +1,71 @@ +from enum import IntEnum +import struct +from pyblake2 import blake2s +import time +import toml + +HASH_LENGTH = 8 + +with open("Config.toml", "r") as config_file: + config = toml.loads(config_file.read()) + +print(config) +devices = {} + + +class MessageType(IntEnum): + DeviceStatus = 1 + SensorStatus = 2 + + +def decode_packet(data): + packet_type = data[0] + + # match packet_type: + # case MessageType.DeviceStatus: + + if packet_type == MessageType.DeviceStatus: + return {"Battery voltage": struct.unpack('> i) & 1: + channels.append(i) + + sensor_data = [] + for i in range(len(channels)): + offset = i * 6 + sensor_data.append({ + "channel": channels[i], + "type": data[3 + offset], + "pin": data[4 + offset], + "value": struct.unpack('