Add more informations about sensor

Add wlan info and signal
This commit is contained in:
Pierrick C 2020-03-24 23:50:44 +01:00
parent c0da9e2204
commit 1bbfad291a

View File

@ -52,19 +52,33 @@ client = MQTTClient(client_id=config.CLIENT_ID,
client.connect() client.connect()
client.publish("test/bme280/humidity/unit", "%", retain=True, qos=0) 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) time.sleep_ms(100)
client.publish("test/bme280/pressure/unit", "hPa", retain=True, qos=0) 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) 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) 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: while 1:
bme_data = bme.get_measurement() bme_data = bme.get_measurement()
print(bme_data) print(bme_data)
client.publish("test/bme280/humidity/value",
"{:.0f}".format(bme_data["humidity"])) for nature, param in topics.items():
client.publish("test/bme280/pressure/value", client.publish(param[0], param[1].format(bme_data[nature]*param[2]))
"{:.2f}".format(bme_data["pressure"]/100))
client.publish("test/bme280/temperature/value", client.publish("test/esp8266_0/wifi/rssi", "{:.0f}".format(wlan.status('rssi')))
"{:.1f}".format(bme_data["temperature"]))
time.sleep_ms(1000) time.sleep_ms(1000)