From 1bbfad291aa3d4d0ad6e0e9eb799656235dfe895 Mon Sep 17 00:00:00 2001 From: Pierrick C Date: Tue, 24 Mar 2020 23:50:44 +0100 Subject: [PATCH] Add more informations about sensor Add wlan info and signal --- code/main.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/code/main.py b/code/main.py index f331505..15bd1bd 100644 --- a/code/main.py +++ b/code/main.py @@ -52,19 +52,33 @@ client = MQTTClient(client_id=config.CLIENT_ID, client.connect() client.publish("test/bme280/humidity/unit", "%", retain=True, qos=0) +client.publish("test/bme280/humidity/desc", "Capteur Bosch BME280", retain=True, qos=0) time.sleep_ms(100) client.publish("test/bme280/pressure/unit", "hPa", retain=True, qos=0) +client.publish("test/bme280/pressure/desc", "Capteur Bosch BME280", retain=True, qos=0) time.sleep_ms(100) -client.publish("test/bme280/temperature/unit", "oC", retain=True, qos=0) +client.publish("test/bme280/temperature/unit", "degC", retain=True, qos=0) +client.publish("test/bme280/temperature/desc", "Capteur Bosch BME280", retain=True, qos=0) +time.sleep_ms(100) +client.publish("test/esp8266_0/wifi/ssid", config.WIFI_SSID, retain=True, qos=0) +client.publish("test/esp8266_0/wifi/ip", wlan.ifconfig()[0], retain=True, qos=0) time.sleep_ms(1000) +# For each nature, a list describe: +# - mqtt topic +# - string format +# - factor (multiplier) +topics = {"humidity" : ["test/esp8266_0/humidity/value", "{:.0f}", 1], + "pressure" : ["test/esp8266_0/pressure/value", "{:.2f}", 0.01], + "temperature" : ["test/esp8266_0/temperature/value", "{:.1f}", 1]} + while 1: bme_data = bme.get_measurement() print(bme_data) - client.publish("test/bme280/humidity/value", - "{:.0f}".format(bme_data["humidity"])) - client.publish("test/bme280/pressure/value", - "{:.2f}".format(bme_data["pressure"]/100)) - client.publish("test/bme280/temperature/value", - "{:.1f}".format(bme_data["temperature"])) + + for nature, param in topics.items(): + client.publish(param[0], param[1].format(bme_data[nature]*param[2])) + + client.publish("test/esp8266_0/wifi/rssi", "{:.0f}".format(wlan.status('rssi'))) + time.sleep_ms(1000)