Fix Rain stuff and data pushed to Domoticz

This commit is contained in:
2020-12-16 20:01:20 +01:00
parent 781a1dfcdb
commit cd48c76c0e

View File

@ -138,11 +138,11 @@ struct WS3Packet {
// The 8th field is "H0000" - Number of rain bucket in the last minute, (0-9999) // The 8th field is "H0000" - Number of rain bucket in the last minute, (0-9999)
int rt_rain_bucket; int rt_rain_bucket;
// The 9th field is "I0000" - Rain fall in 1 minute, unit: 0.1mm // The 9th field is "I0000" - Rain fall in 1 minute, unit: 0.1mm
float rain_1m; unsigned int rain_1m;
// The 10th field is "J0000" - the previous hour's rainfall ( 0.1 mm) // The 10th field is "J0000" - the previous hour's rainfall ( 0.1 mm)
float rain_1h; unsigned int rain_1h;
// The 11th field is "K0000" - rainfall during the first 24 hours ( 0.1 mm) // The 11th field is "K0000" - rainfall during the first 24 hours ( 0.1 mm)
float rain_24h; unsigned int rain_24h;
// The 12th field is "L0000" - temperature, unit: degree C (unit 0.1 Degree) // The 12th field is "L0000" - temperature, unit: degree C (unit 0.1 Degree)
float temp_f; float temp_f;
// The 13th field is "M000" - humidity ( 00 % - 99 %), unit 0.1% // The 13th field is "M000" - humidity ( 00 % - 99 %), unit 0.1%
@ -410,15 +410,15 @@ void parse_packet(String payload, WS3Packet* p) {
// Then move on to I0000 - rain last minute (0.1mm) // Then move on to I0000 - rain last minute (0.1mm)
int rain1m_idx = payload.indexOf('I'); int rain1m_idx = payload.indexOf('I');
p->rain_1m = payload.substring(rain1m_idx+1, rain1m_idx+5).toInt() *.1; p->rain_1m = payload.substring(rain1m_idx+1, rain1m_idx+5).toInt();
// Then move on to J0000 - rain last hour (0.1mm) // Then move on to J0000 - rain last hour (0.1mm)
int rain1h_idx = payload.indexOf('J'); int rain1h_idx = payload.indexOf('J');
p->rain_1h = payload.substring(rain1h_idx+1, rain1h_idx+5).toInt() *.1; p->rain_1h = payload.substring(rain1h_idx+1, rain1h_idx+5).toInt();
// Then move on to K0000 - rain last 24h (0.1mm) // Then move on to K0000 - rain last 24h (0.1mm)
int rain24h_idx = payload.indexOf('K'); int rain24h_idx = payload.indexOf('K');
p->rain_24h = payload.substring(rain24h_idx+1, rain24h_idx+5).toInt()*.1; p->rain_24h = payload.substring(rain24h_idx+1, rain24h_idx+5).toInt();
// Then move on to L0200 - temp (0.1°C) // Then move on to L0200 - temp (0.1°C)
// XXX: Check with minus zero temperatures // XXX: Check with minus zero temperatures
@ -439,6 +439,7 @@ void parse_packet(String payload, WS3Packet* p) {
WindGust = p->wind_speed; WindGust = p->wind_speed;
debugln("Update WindGust"); debugln("Update WindGust");
} }
if(loopcount >= 300) { if(loopcount >= 300) {
loopcount = 0; loopcount = 0;
WindGust = p->wind_speed; WindGust = p->wind_speed;
@ -498,11 +499,11 @@ void print_weather(WS3Packet* p){
Serial.println(p->rt_rain_bucket, DEC); Serial.println(p->rt_rain_bucket, DEC);
Serial.print("Rain 1m / 1H / 24H: "); Serial.print("Rain 1m / 1H / 24H: ");
Serial.print(p->rain_1m, DEC); Serial.print(p->rain_1m*0.1, DEC);
Serial.print(" / "); Serial.print(" / ");
Serial.print(p->rain_1h, DEC); Serial.print(p->rain_1h*0.1, DEC);
Serial.print(" / "); Serial.print(" / ");
Serial.print(p->rain_24h, DEC); Serial.print(p->rain_24h*.1, DEC);
Serial.println(" mm"); Serial.println(" mm");
Serial.print("humidity: "); Serial.print("humidity: ");
@ -524,8 +525,8 @@ void push_weather(WS3Packet* p) {
float pression = 0.0; // Pression float pression = 0.0; // Pression
float wct = 0.0; // Windchill temperature float wct = 0.0; // Windchill temperature
// Rain is mm x 100 -> Have to compute this. // Rain
MQPayload = "{ \"idx\" : "+ String(idx_rain) +",\"nvalue\" : 0, \"svalue\" :\"" + String(p->rain_1h) + ";" + String(p->rain_1m) + "\"}"; MQPayload = "{ \"idx\" : "+ String(idx_rain) +",\"nvalue\" : 0, \"svalue\": \"" + String(p->rain_1h*10) + ";" + String(p->rain_1m*0.1) + "\"}";
sendMQTTPayload(MQPayload); sendMQTTPayload(MQPayload);
// Temperature / Humidity / Baro // Temperature / Humidity / Baro
@ -634,6 +635,7 @@ void loop() {
if (!client.connected()) { if (!client.connected()) {
reconnect(); reconnect();
} }
// While data comes in and we don't have a pending packet to process... // While data comes in and we don't have a pending packet to process...
while (WS3.available() && pkt_ok !=true) { while (WS3.available() && pkt_ok !=true) {