From 0c1d7ab026c0b295cd8875f1c168f9da7631428b Mon Sep 17 00:00:00 2001 From: Pierrick C Date: Thu, 26 Mar 2020 23:11:51 +0100 Subject: [PATCH] Add pressure at sea level Some code fact. --- code/config_template.py | 2 ++ code/main.py | 30 +++++++++++++++++++----------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/code/config_template.py b/code/config_template.py index 5f2bfc8..0ef83e8 100644 --- a/code/config_template.py +++ b/code/config_template.py @@ -11,3 +11,5 @@ MQTT_PASSWD = "passwd" WIFI_SSID = "my_wifi_ssid" WIFI_PSK = "my_wifi_wpa_key" + +ALTITUDE = 150 diff --git a/code/main.py b/code/main.py index 9cc1c32..14431b4 100644 --- a/code/main.py +++ b/code/main.py @@ -1,4 +1,4 @@ -"""Station météo connectée au service Adafruit IO +"""Station météo connectée vers MQTT via wifi """ import time @@ -45,6 +45,9 @@ bme.set_measurement_settings({ # Start the sensor automatically sensing bme.set_power_mode(bme280_i2c.BME280_NORMAL_MODE) +# Conversion coeff. between measured pressure and Seau Mean-level pressure +# Source: https://fr.wikipedia.org/wiki/Pression-altitude +SMLP_coef=pow(1.0-((0.0065*config.ALTITUDE)/288.15), 5.255) # PT100 (via max81865 module) sensor setup spi=machine.SPI(-1, sck=machine.Pin(14, machine.Pin.OUT), mosi=machine.Pin(13, machine.Pin.OUT), miso=machine.Pin(12, machine.Pin.OUT)) @@ -84,6 +87,8 @@ MqttPublish(client, "humidity/unit", "%", retain=True) MqttPublish(client, "humidity/desc", "Capteur Bosch BME280", retain=True, qos=0) MqttPublish(client, "pressure/unit", "hPa", retain=True, qos=0) MqttPublish(client, "pressure/desc", "Capteur Bosch BME280", retain=True, qos=0) +MqttPublish(client, "pressure2/unit", "hPa", retain=True, qos=0) +MqttPublish(client, "pressure2/desc", "Capteur Bosch BME280 revenu au niveau de la mer", retain=True, qos=0) MqttPublish(client, "temperature/unit", "degC", retain=True, qos=0) MqttPublish(client, "temperature/desc", "Capteur Bosch BME280", retain=True, qos=0) MqttPublish(client, "temperature2/unit", "degC", retain=True, qos=0) @@ -100,25 +105,28 @@ time.sleep_ms(1000) # - string format # - factor (multiplier) # - qos -topics = {"humidity" : ["humidity/value", "{:.0f}", 1, 1], +topics = {"time" : ["time/last_values", "{}", 1, 1], + "humidity" : ["humidity/value", "{:.0f}", 1, 1], "pressure" : ["pressure/value", "{:.2f}", 0.01, 1], - "temperature" : ["temperature/value", "{:.1f}", 1, 1]} + "pressure2" : ["pressure2/value", "{:.2f}", 0.01, 1], + "temperature" : ["temperature/value", "{:.1f}", 1, 1], + "temperature2" : ["temperature/value2", "{:.1f}", 1, 1], + "wifi_rssi" : ["wifi/rssi", "{:.0f}", 1, 1], + } while 1: bme_data = bme.get_measurement() - meas_time = now() - print(meas_time, ":", bme_data) - print("Pt100:", max31865.temperature, "degC") + bme_data['time'] = now() + bme_data['pressure2'] = bme_data['pressure']/SMLP_coef + bme_data['temperature2'] = max31865.temperature + bme_data['wifi_rssi'] = wlan.status('rssi') + print(bme_data) for nature, param in topics.items(): MqttPublish(client, param[0], param[1].format(bme_data[nature]*param[2]), qos=param[3], - sleep=50) - - MqttPublish(client, "temperature2/value", "{:.2f}".format(max31865.temperature)) - MqttPublish(client, "wifi/rssi", "{:.0f}".format(wlan.status('rssi'))) - MqttPublish(client, "time/last_values", meas_time, retain=True) + sleep=20) time.sleep_ms(1000)