Added RTC offset calculation to return absolute time

This commit is contained in:
2022-04-24 22:06:06 +02:00
parent d1c052ac90
commit 3c53f94c1b
5 changed files with 27 additions and 22 deletions

View File

@@ -90,14 +90,15 @@ class MultiNode:
print(f"Hash doesn't match! Expected {hash_function.digest()} got {data_hash}")
return
if not rx_id in self.devices:
self.devices[rx_id] = {"last_message_id": msg_id}
self.decode_packet(self.devices[rx_id], data)
self.print_data()
# print(f"{tx_id} #{msg_id}: {decode_packet(data):.3f} V, {payload.rssi} dB(?) RSSI, {payload.snr} dB(?) SNR {(time.clock_gettime_ns(0)) / 1e9}")
if not tx_id in self.devices:
self.devices[tx_id] = {}
self.devices[tx_id]["last_message_id"] = msg_id
self.decode_packet(self.devices[tx_id], data)
# RSSI cahnges from -13 to -27 on change from +20 to +2 dBm TX setting
# print(f"{tx_id} #{msg_id}: {self.decode_packet(self.devices[rx_id], data)} V, {payload.rssi} dB(?) RSSI, {payload.snr} dB(?) SNR {(time.clock_gettime_ns(0)) / 1e9}")
# print(f"{tx_id} #{msg_id}: {data.hex()} {self.decode_packet(data)}, {payload.rssi} dB(?) RSSI, {payload.snr} dB(?) SNR {(time.clock_gettime_ns(0)) / 1e9}")
self.print_data()
def send_packet(self, target: int, data):
assert len(data) < 256
@@ -121,17 +122,19 @@ class MultiNode:
def print_data(self):
for device_id in self.devices:
device = self.devices[device_id]
print(f'{device_id}:')
print(f'Node {device_id} @ ID {device["last_message_id"]}:')
if "status" in device:
print(f'\t{device["status"]["battery"]} V {device["status"]["temperature"]} °C')
print(f'\t{device["status"]["battery"]:.3f} V {device["status"]["temperature"]:.1f} °C')
if "sensors" in device:
for sensor in device["sensors"]:
if sensor["value"] == math.nan:
print(f'\tCH {sensor["channel"]} on Pin {sensor["pin"]}: ERROR')
else:
print(f'\tCH {sensor["channel"]} on Pin {sensor["pin"]}: {sensor["value"]} {self.sensor_type_table[sensor["type"]]}')
print(f'\tCH {sensor["channel"]} on Pin {sensor["pin"]}: {sensor["value"]:.4f} {self.sensor_type_table[sensor["type"]]}')
print()
if __name__ == "__main__":