Added pressure compensation against altitude

This commit is contained in:
2020-12-15 17:42:04 +01:00
parent 07d8a53f58
commit 981a83c80f

View File

@ -63,6 +63,9 @@ const char* dom_in = "domoticz/in";
char msgToPublish[MQTT_MAX_PACKET_SIZE + 1];
// Defines
#define OTAPASSWORD "123" // Password for OTA upload thru Arduino IDE
// Debug
#define DEBUG 1
#ifdef DEBUG
@ -97,6 +100,10 @@ char msgToPublish[MQTT_MAX_PACKET_SIZE + 1];
// if we have a correct dataline
#define DONT_CHKSUM 1
// Define ALTITUDE if you need to get pression corrected
// Set this to 0 if you don't care
#define ALTITUDE 340 // Longwy is at 340m
// Place holder for the packet received
String pkt_str = "";
@ -177,7 +184,7 @@ void setup_ota() {
// No auth per default
// XXX: Change this
ArduinoOTA.setPassword((const char *)"123");
ArduinoOTA.setPassword((const char *)OTAPASSWORD);
ArduinoOTA.onStart([]() {
Serial.println("Start");
@ -213,28 +220,6 @@ void setup() {
Serial.println("Weather Station 3 Adapter by Kiwi");
Serial.println(ESP.getFullVersion());
// WiFi.hostname("ESP-Weather-Station");
// WiFi.mode(WIFI_STA);
// WiFi.begin(ssid, password);
// Use this loop instead to wait for an IPv6 routable address
// addr->isLocal() (meaning "not routable on internet") is true with:
// - IPV4 DHCP autoconfigured address 169.254.x.x
// (false for any other including 192.168./16 and 10./24 since NAT may be in the equation)
// - IPV6 link-local addresses (fe80::/64)
// for (bool configured = false; !configured;) {
// for (auto addr : addrList)
// if ((configured = !addr.isLocal()
// // && addr.isV6() // uncomment when IPv6 is mandatory
// // && addr.ifnumber() == STATION_IF
// )) {
// break;
// }
// Serial.print('.');
// delay(500);
// }
WiFiManager wm;
wm.setSaveConfigCallback(saveConfigCallback);
@ -555,8 +540,9 @@ void print_weather(WS3Packet* p){
// Print the data over MQTT
void push_weather(WS3Packet* p) {
String MQPayload;
byte humidity_status = 0; // Domoticz humdity status
byte bar_forecast = 0; // Domoticz baro forcast
byte humidity_status = 0; // Domoticz humdity status
byte bar_forecast = 0; // Domoticz baro forcast
float pression = 0.0; // Pression
// Rain is mm x 100 -> Have to compute this.
// MQPayload = "{ \"idx\" : "+ String(domoticz_rain) +",\"nvalue\" : 0, \"svalue\" : \"" + String(p->rain_1m) + ";" + String(p->rain_1m) + "\"}";
MQPayload = "{ \"idx\" : "+ String(idx_rain) +",\"nvalue\" : 0, \"svalue\" :\"" + String(p->rain_1h) + ";" + String(p->rain_1m) + "\"}";
@ -580,7 +566,9 @@ void push_weather(WS3Packet* p) {
humidity_status = 0; // Normal
}
}
// TODO : prediction
// Correct the pression according to altitude
pression = p->air_pressure + (ALTITUDE / 8.3);
// Prediction
// 0 : No info
// 1 : Sunny
// 2 : Partly cloudy
@ -588,11 +576,11 @@ void push_weather(WS3Packet* p) {
// 4 : Rain
// Maybe have to store values for last 3 hours?
// XXX: fix value with altitude
if (p->air_pressure < 1000) {
if (pression < 1000) {
bar_forecast = 4; // Rain
} else if (p->air_pressure < 1020) {
} else if (pression < 1020) {
bar_forecast = 3; // Cloudy
} else if (p->air_pressure < 1030) {
} else if (pression < 1030) {
bar_forecast = 2; // Partly cloudy
} else {
bar_forecast = 1; // Sunny
@ -602,7 +590,7 @@ void push_weather(WS3Packet* p) {
//SLpressure_mB = p->air_pressure;
// MQPayload = "{ \"idx\" : "+ String(domoticz_temp) +",\"nvalue\" : 0, \"svalue\": \"" + String(p->temp_f) + ";" + String(p->humidity) + ";0;" + String(SLpressure_mB) +";0\"}";
// MQPayload = "{ \"idx\" : "+ String(idx_temp) +",\"nvalue\" : 0, \"svalue\": \"" + String(p->temp_f) + ";" + String(p->humidity) + ";"+String(humidity_status)+ ";" + String(p->air_pressure) +";0\"}";
MQPayload = "{ \"idx\" : "+ String(idx_temp) +",\"nvalue\" : 0, \"svalue\": \"" + String(p->temp_f) + ";" + String(p->humidity) + ";"+String(humidity_status)+ ";" + String(p->air_pressure) +";"+String(bar_forecast)+"\"}";
MQPayload = "{ \"idx\" : "+ String(idx_temp) +",\"nvalue\" : 0, \"svalue\": \"" + String(p->temp_f) + ";" + String(p->humidity) + ";"+String(humidity_status)+ ";" + String(pression) +";"+String(bar_forecast)+"\"}";
sendMQTTPayload(MQPayload);
// Wind