Add pressure at sea level

Some code fact.
This commit is contained in:
Pierrick C 2020-03-26 23:11:51 +01:00
parent 05b98fc1f7
commit 0c1d7ab026
2 changed files with 21 additions and 11 deletions

View File

@ -11,3 +11,5 @@ MQTT_PASSWD = "passwd"
WIFI_SSID = "my_wifi_ssid"
WIFI_PSK = "my_wifi_wpa_key"
ALTITUDE = 150

View File

@ -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)