diff --git a/get_data.py b/get_data.py index 844cc3c..3b3f804 100644 --- a/get_data.py +++ b/get_data.py @@ -7,9 +7,13 @@ from datetime import datetime import bluetooth._bluetooth as bluez import paho.mqtt.publish as publish -from bluetooth_utils.bluetooth_utils import (disable_le_scan, enable_le_scan, - parse_le_advertising_events, - raw_packet_to_str, toggle_device) +from bluetooth_utils.bluetooth_utils import ( + disable_le_scan, + enable_le_scan, + parse_le_advertising_events, + raw_packet_to_str, + toggle_device, +) def send_to_mqtt(data: dict): @@ -43,15 +47,16 @@ def le_advertise_packet_handler(mac: str, _, data: bytes, __): temp = int(data_str[22:26], 16) / 10 hum = int(data_str[26:28], 16) batt = int(data_str[28:30], 16) - send_to_mqtt( - { - 'timestamp': datetime.now().strftime("%Y-%m-%d %H:%M:%S"), - 'mac': mac, - 'temperature': temp, - 'humidity': hum, - 'battery': batt, - } - ) + mqtt_data = { + 'timestamp': datetime.now().strftime("%Y-%m-%d %H:%M:%S"), + 'mac': mac, + 'temperature': temp, + 'humidity': hum, + 'battery': batt, + } + send_to_mqtt(mqtt_data) + print('Sending to MQTT:') + print(mqtt_data) if __name__ == '__main__':