Add more informations about sensor
Add wlan info and signal
This commit is contained in:
parent
c0da9e2204
commit
1bbfad291a
28
code/main.py
28
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)
|
||||
|
Loading…
Reference in New Issue
Block a user