diff --git a/tasmota/language/bg-BG.h b/tasmota/language/bg-BG.h index be2fceb3c..8acbff8e1 100644 --- a/tasmota/language/bg-BG.h +++ b/tasmota/language/bg-BG.h @@ -504,8 +504,10 @@ //xsns_35_tx20.ino #define D_TX20_WIND_DIRECTION "Посока на вятъра" +#define D_TX20_WIND_DEGREES "Степени на вятъра" #define D_TX20_WIND_SPEED "Скорост на вятъра" #define D_TX20_WIND_SPEED_AVG "Средна скорост на вятъра" +#define D_TX20_WIND_SPEED_MIN "Мини. скорост на вятъра" #define D_TX20_WIND_SPEED_MAX "Макс. скорост на вятъра" #define D_TX20_NORTH "С" #define D_TX20_EAST "И" diff --git a/tasmota/language/cs-CZ.h b/tasmota/language/cs-CZ.h index 6ef51f27d..2d15ac443 100644 --- a/tasmota/language/cs-CZ.h +++ b/tasmota/language/cs-CZ.h @@ -504,8 +504,10 @@ //xsns_35_tx20.ino #define D_TX20_WIND_DIRECTION "Směr větru" +#define D_TX20_WIND_DEGREES "Úhel větru" #define D_TX20_WIND_SPEED "Rychlost větru" #define D_TX20_WIND_SPEED_AVG "Průměrná rychlost větru" +#define D_TX20_WIND_SPEED_MIN "Minimální rychlost větru" #define D_TX20_WIND_SPEED_MAX "Maximální rychlost větru" #define D_TX20_NORTH "S" #define D_TX20_EAST "V" diff --git a/tasmota/language/de-DE.h b/tasmota/language/de-DE.h index cf2aa258b..e87624bfa 100644 --- a/tasmota/language/de-DE.h +++ b/tasmota/language/de-DE.h @@ -503,10 +503,12 @@ #define D_CALIBRATION "Kalibrierung" //xsns_35_tx20.ino -#define D_TX20_WIND_DIRECTION "Wind Richtung" +#define D_TX20_WIND_DIRECTION "Windrichtung" +#define D_TX20_WIND_DEGREES "Windrichtung Grad" #define D_TX20_WIND_SPEED "Windgeschwindigkeit" -#define D_TX20_WIND_SPEED_AVG "Ø Windgeschwindigkeit" -#define D_TX20_WIND_SPEED_MAX "max Windgeschwindigkeit" +#define D_TX20_WIND_SPEED_AVG "Windgeschwindigkeit Ø" +#define D_TX20_WIND_SPEED_MIN "Windgeschwindigkeit Min" +#define D_TX20_WIND_SPEED_MAX "Windgeschwindigkeit Max" #define D_TX20_NORTH "N" #define D_TX20_EAST "O" #define D_TX20_SOUTH "S" diff --git a/tasmota/language/el-GR.h b/tasmota/language/el-GR.h index b3608bb7b..dbeb71a68 100644 --- a/tasmota/language/el-GR.h +++ b/tasmota/language/el-GR.h @@ -504,8 +504,10 @@ //xsns_35_tx20.ino #define D_TX20_WIND_DIRECTION "Κατεύθυνση ανέμου" +#define D_TX20_WIND_DEGREES "Βαθμός ανέμου" #define D_TX20_WIND_SPEED "Ταχύτητα ανέμου" #define D_TX20_WIND_SPEED_AVG "Μέση ταχύτητα ανέμου" +#define D_TX20_WIND_SPEED_MIN "Ελάχιστη ταχύτητα ανέμου" #define D_TX20_WIND_SPEED_MAX "Μέγιστη ταχύτητα ανέμου" #define D_TX20_NORTH "Β" #define D_TX20_EAST "Α" diff --git a/tasmota/language/en-GB.h b/tasmota/language/en-GB.h index 66a6e0243..792c2b597 100644 --- a/tasmota/language/en-GB.h +++ b/tasmota/language/en-GB.h @@ -504,8 +504,10 @@ //xsns_35_tx20.ino #define D_TX20_WIND_DIRECTION "Wind Direction" +#define D_TX20_WIND_DEGREES "Wind Degrees" #define D_TX20_WIND_SPEED "Wind Speed" #define D_TX20_WIND_SPEED_AVG "Wind Speed Avg" +#define D_TX20_WIND_SPEED_MIN "Wind Speed Min" #define D_TX20_WIND_SPEED_MAX "Wind Speed Max" #define D_TX20_NORTH "N" #define D_TX20_EAST "E" diff --git a/tasmota/language/es-ES.h b/tasmota/language/es-ES.h index 59916f487..77e7c6047 100644 --- a/tasmota/language/es-ES.h +++ b/tasmota/language/es-ES.h @@ -504,8 +504,10 @@ //xsns_35_tx20.ino #define D_TX20_WIND_DIRECTION "Dirección del Viento" +#define D_TX20_WIND_DEGREES "Ángulo del Viento" #define D_TX20_WIND_SPEED "Vel. del Viento" #define D_TX20_WIND_SPEED_AVG "Vel. Prom. del Viento" +#define D_TX20_WIND_SPEED_MIN "Vel. Min. del Viento" #define D_TX20_WIND_SPEED_MAX "Vel. Max. del Viento" #define D_TX20_NORTH "N" #define D_TX20_EAST "E" diff --git a/tasmota/language/fr-FR.h b/tasmota/language/fr-FR.h index 5356848d8..a63955ab7 100644 --- a/tasmota/language/fr-FR.h +++ b/tasmota/language/fr-FR.h @@ -504,8 +504,10 @@ //xsns_35_TX20.ino #define D_TX20_WIND_DIRECTION "Direction du vent" +#define D_TX20_WIND_DEGREES "Degré de vent" #define D_TX20_WIND_SPEED "Vitesse du vent" #define D_TX20_WIND_SPEED_AVG "Vitesse Moy." +#define D_TX20_WIND_SPEED_MIN "Vitesse Min" #define D_TX20_WIND_SPEED_MAX "Vitesse Max" #define D_TX20_NORTH "N" #define D_TX20_EAST "E" diff --git a/tasmota/language/he-HE.h b/tasmota/language/he-HE.h index fa3b07a31..86af3c35a 100644 --- a/tasmota/language/he-HE.h +++ b/tasmota/language/he-HE.h @@ -504,8 +504,10 @@ //xsns_35_tx20.ino #define D_TX20_WIND_DIRECTION "כיוון הרוח" +#define D_TX20_WIND_DEGREES "זווית הרוח" #define D_TX20_WIND_SPEED "מהירות הרוח" #define D_TX20_WIND_SPEED_AVG "מהירות הרוח ממוצעת" +#define D_TX20_WIND_SPEED_MIN "מהירות הרוח היא מינימלית" #define D_TX20_WIND_SPEED_MAX "מהירות הרוח מקסימלית" #define D_TX20_NORTH "N" #define D_TX20_EAST "E" diff --git a/tasmota/language/hu-HU.h b/tasmota/language/hu-HU.h index 541d0c783..d9348dde1 100644 --- a/tasmota/language/hu-HU.h +++ b/tasmota/language/hu-HU.h @@ -504,8 +504,10 @@ //xsns_35_tx20.ino #define D_TX20_WIND_DIRECTION "Szélirány" +#define D_TX20_WIND_DEGREES "Szél mértéke" #define D_TX20_WIND_SPEED "Szélsebesség" #define D_TX20_WIND_SPEED_AVG "Átlag szélsebesség" +#define D_TX20_WIND_SPEED_MIN "Min. szélsebesség" #define D_TX20_WIND_SPEED_MAX "Max. szélsebesség" #define D_TX20_NORTH "É" #define D_TX20_EAST "K" diff --git a/tasmota/language/it-IT.h b/tasmota/language/it-IT.h index 62127ef24..e5ee2f1aa 100644 --- a/tasmota/language/it-IT.h +++ b/tasmota/language/it-IT.h @@ -504,8 +504,10 @@ //xsns_35_tx20.ino #define D_TX20_WIND_DIRECTION "Direzione Vento" +#define D_TX20_WIND_DEGREES "Angolo Vento" #define D_TX20_WIND_SPEED "Velocità Vento" #define D_TX20_WIND_SPEED_AVG "Velocità Media Vento" +#define D_TX20_WIND_SPEED_MIN "Velocità Minima Vento" #define D_TX20_WIND_SPEED_MAX "Velocità Massima Vento" #define D_TX20_NORTH "N" #define D_TX20_EAST "E" diff --git a/tasmota/language/ko-KO.h b/tasmota/language/ko-KO.h index 2a20ce2d0..f8cd83e99 100644 --- a/tasmota/language/ko-KO.h +++ b/tasmota/language/ko-KO.h @@ -504,9 +504,11 @@ //xsns_35_tx20.ino #define D_TX20_WIND_DIRECTION "풍향" +#define D_TX20_WIND_DEGREES "바람 정도" #define D_TX20_WIND_SPEED "풍속" #define D_TX20_WIND_SPEED_AVG "평균 풍속" -#define D_TX20_WIND_SPEED_MAX "최대 풍속" +#define D_TX20_WIND_SPEED_MIN "풍속 최소" +#define D_TX20_WIND_SPEED_MAX "풍속 최대" #define D_TX20_NORTH "N" #define D_TX20_EAST "E" #define D_TX20_SOUTH "S" diff --git a/tasmota/language/nl-NL.h b/tasmota/language/nl-NL.h index 658f18547..bc9b1876e 100644 --- a/tasmota/language/nl-NL.h +++ b/tasmota/language/nl-NL.h @@ -504,8 +504,10 @@ //xsns_35_tx20.ino #define D_TX20_WIND_DIRECTION "Windrichting" +#define D_TX20_WIND_DEGREES "Wind graad" #define D_TX20_WIND_SPEED "Windsnelheid" #define D_TX20_WIND_SPEED_AVG "Windsnelheid gemiddeld" +#define D_TX20_WIND_SPEED_MIN "Windsnelhied minimum" #define D_TX20_WIND_SPEED_MAX "Windsnelhied maximaal" #define D_TX20_NORTH "N" #define D_TX20_EAST "E" diff --git a/tasmota/language/pl-PL.h b/tasmota/language/pl-PL.h index e2d59a2dc..9cc522fa7 100644 --- a/tasmota/language/pl-PL.h +++ b/tasmota/language/pl-PL.h @@ -504,8 +504,10 @@ //xsns_35_tx20.ino #define D_TX20_WIND_DIRECTION "Kierunek" +#define D_TX20_WIND_DEGREES "Grad" #define D_TX20_WIND_SPEED "Prędkość" #define D_TX20_WIND_SPEED_AVG "Średnia prędkość" +#define D_TX20_WIND_SPEED_MIN "Minimalna prędkość" #define D_TX20_WIND_SPEED_MAX "Maksymalna prędkość" #define D_TX20_NORTH "N" #define D_TX20_EAST "E" diff --git a/tasmota/language/pt-BR.h b/tasmota/language/pt-BR.h index da386917c..4909fc08c 100644 --- a/tasmota/language/pt-BR.h +++ b/tasmota/language/pt-BR.h @@ -504,8 +504,10 @@ //xsns_35_tx20.ino #define D_TX20_WIND_DIRECTION "Direção do vento" +#define D_TX20_WIND_DEGREES "Ângulo do vento" #define D_TX20_WIND_SPEED "Velocidade do vento" #define D_TX20_WIND_SPEED_AVG "Velocidade média do vento" +#define D_TX20_WIND_SPEED_MIN "Velocidade do vento Mínima" #define D_TX20_WIND_SPEED_MAX "Velocidade do vento Máxima" #define D_TX20_NORTH "N" #define D_TX20_EAST "L" diff --git a/tasmota/language/pt-PT.h b/tasmota/language/pt-PT.h index 1f9c36a6b..1e49c449c 100644 --- a/tasmota/language/pt-PT.h +++ b/tasmota/language/pt-PT.h @@ -504,8 +504,10 @@ //xsns_35_tx20.ino #define D_TX20_WIND_DIRECTION "Direção do vento" +#define D_TX20_WIND_DEGREES "Ângulo do vento" #define D_TX20_WIND_SPEED "Velocidade do vento" #define D_TX20_WIND_SPEED_AVG "Velocidade média do vento" +#define D_TX20_WIND_SPEED_MIN "Velocidade mínima do vento" #define D_TX20_WIND_SPEED_MAX "Velocidade máxima do vento" #define D_TX20_NORTH "N" #define D_TX20_EAST "E" diff --git a/tasmota/language/ru-RU.h b/tasmota/language/ru-RU.h index 846a653ac..a312000b7 100644 --- a/tasmota/language/ru-RU.h +++ b/tasmota/language/ru-RU.h @@ -504,8 +504,10 @@ //xsns_35_tx20.ino #define D_TX20_WIND_DIRECTION "Wind Direction" +#define D_TX20_WIND_DEGREES "Wind Degrees" #define D_TX20_WIND_SPEED "Wind Speed" #define D_TX20_WIND_SPEED_AVG "Wind Speed Avg" +#define D_TX20_WIND_SPEED_MIN "Wind Speed Min" #define D_TX20_WIND_SPEED_MAX "Wind Speed Max" #define D_TX20_NORTH "N" #define D_TX20_EAST "E" diff --git a/tasmota/language/sk-SK.h b/tasmota/language/sk-SK.h index f335ca42d..f5041901a 100644 --- a/tasmota/language/sk-SK.h +++ b/tasmota/language/sk-SK.h @@ -504,8 +504,10 @@ //xsns_35_tx20.ino #define D_TX20_WIND_DIRECTION "Smer vetra" +#define D_TX20_WIND_DEGREES "Uhol vetra" #define D_TX20_WIND_SPEED "Rýchlosť vetra" #define D_TX20_WIND_SPEED_AVG "Priemerná rýchlosť vetra" +#define D_TX20_WIND_SPEED_MIN "Minimálna rýchlosť vetra" #define D_TX20_WIND_SPEED_MAX "Maximálna rýchlosť vetra" #define D_TX20_NORTH "S" #define D_TX20_EAST "V" diff --git a/tasmota/language/sv-SE.h b/tasmota/language/sv-SE.h index 9485c1f4e..7741c8937 100644 --- a/tasmota/language/sv-SE.h +++ b/tasmota/language/sv-SE.h @@ -504,8 +504,10 @@ //xsns_35_tx20.ino #define D_TX20_WIND_DIRECTION "Vindriktning" +#define D_TX20_WIND_DEGREES "Vindvinkel" #define D_TX20_WIND_SPEED "Vindstyrka" #define D_TX20_WIND_SPEED_AVG "Vindstyrka medel" +#define D_TX20_WIND_SPEED_MIN "Vindstyrka min" #define D_TX20_WIND_SPEED_MAX "Vindstyrka max" #define D_TX20_NORTH "N" #define D_TX20_EAST "Ö" diff --git a/tasmota/language/tr-TR.h b/tasmota/language/tr-TR.h index ee2a548ae..51f0a3ddb 100644 --- a/tasmota/language/tr-TR.h +++ b/tasmota/language/tr-TR.h @@ -504,8 +504,10 @@ //xsns_35_tx20.ino #define D_TX20_WIND_DIRECTION "Wind Direction" +#define D_TX20_WIND_DEGREES "Wind Degrees" #define D_TX20_WIND_SPEED "Wind Speed" #define D_TX20_WIND_SPEED_AVG "Wind Speed Avg" +#define D_TX20_WIND_SPEED_MIN "Wind Speed Min" #define D_TX20_WIND_SPEED_MAX "Wind Speed Max" #define D_TX20_NORTH "N" #define D_TX20_EAST "E" diff --git a/tasmota/language/uk-UA.h b/tasmota/language/uk-UA.h index 98a352ea7..a7bcfa5da 100644 --- a/tasmota/language/uk-UA.h +++ b/tasmota/language/uk-UA.h @@ -504,8 +504,10 @@ //xsns_35_tx20.ino #define D_TX20_WIND_DIRECTION "Напрям вітру" +#define D_TX20_WIND_DEGREES "Кут вітру" #define D_TX20_WIND_SPEED "Швидкість вітру" #define D_TX20_WIND_SPEED_AVG "Середня швидкість вітру" +#define D_TX20_WIND_SPEED_MIN "Мінімальна швидкість вітру" #define D_TX20_WIND_SPEED_MAX "Максимальна швидкість вітру" #define D_TX20_NORTH "Пн" #define D_TX20_EAST "Сх" diff --git a/tasmota/language/zh-CN.h b/tasmota/language/zh-CN.h index c46d353ea..53e05b1f4 100644 --- a/tasmota/language/zh-CN.h +++ b/tasmota/language/zh-CN.h @@ -504,8 +504,10 @@ //xsns_35_tx20.ino #define D_TX20_WIND_DIRECTION "风向" +#define D_TX20_WIND_DEGREES "风度" #define D_TX20_WIND_SPEED "风速" #define D_TX20_WIND_SPEED_AVG "平均风速" +#define D_TX20_WIND_SPEED_MIN "最低风速" #define D_TX20_WIND_SPEED_MAX "最高风速" #define D_TX20_NORTH "北" #define D_TX20_EAST "东" diff --git a/tasmota/language/zh-TW.h b/tasmota/language/zh-TW.h index 118aeb501..2e9994046 100644 --- a/tasmota/language/zh-TW.h +++ b/tasmota/language/zh-TW.h @@ -504,8 +504,10 @@ //xsns_35_tx20.ino #define D_TX20_WIND_DIRECTION "Wind Direction" +#define D_TX20_WIND_DEGREES "Wind Degrees" #define D_TX20_WIND_SPEED "Wind Speed" #define D_TX20_WIND_SPEED_AVG "Wind Speed Avg" +#define D_TX20_WIND_SPEED_MIN "Wind Speed Min" #define D_TX20_WIND_SPEED_MAX "Wind Speed Max" #define D_TX20_NORTH "N" #define D_TX20_EAST "E" diff --git a/tasmota/xsns_35_tx20.ino b/tasmota/xsns_35_tx20.ino index 850c7deda..14fd5c9f9 100644 --- a/tasmota/xsns_35_tx20.ino +++ b/tasmota/xsns_35_tx20.ino @@ -41,7 +41,8 @@ #define XSNS_35 35 #define TX2X_BIT_TIME 1220 // microseconds -#define TX2X_RESET_VALUES 60 // seconds +#define TX2X_WEIGHT_AVG_SAMPLE 150 // seconds +#define TX23_READ_INTERVAL 4 // seconds (don't use less than 3) // The Arduino standard GPIO routines are not enough, // must use some from the Espressif SDK as well @@ -59,8 +60,9 @@ extern "C" { const char HTTP_SNS_TX2X[] PROGMEM = "{s}" D_TX2x_NAME " " D_TX20_WIND_SPEED "{m}%s " D_UNIT_KILOMETER_PER_HOUR "{e}" "{s}" D_TX2x_NAME " " D_TX20_WIND_SPEED_AVG "{m}%s " D_UNIT_KILOMETER_PER_HOUR "{e}" + "{s}" D_TX2x_NAME " " D_TX20_WIND_SPEED_MIN "{m}%s " D_UNIT_KILOMETER_PER_HOUR "{e}" "{s}" D_TX2x_NAME " " D_TX20_WIND_SPEED_MAX "{m}%s " D_UNIT_KILOMETER_PER_HOUR "{e}" - "{s}" D_TX2x_NAME " " D_TX20_WIND_DIRECTION "{m}%s (%s°){e}"; + "{s}" D_TX2x_NAME " " D_TX20_WIND_DIRECTION "{m}%s %s°{e}"; #endif // USE_WEBSERVER const char kTx2xDirections[] PROGMEM = D_TX20_NORTH "|" @@ -88,11 +90,12 @@ uint16_t tx2x_sc = 0; uint16_t tx2x_sf = 0; float tx2x_wind_speed_kmh = 0; +float tx2x_wind_speed_min = 200.0; float tx2x_wind_speed_max = 0; float tx2x_wind_speed_avg = 0; -float tx2x_wind_sum = 0; -int tx2x_count = 0; uint8_t tx2x_wind_direction = 0; +int tx2x_count = 0; +uint16_t tx2x_avg_samples; bool tx2x_available = false; @@ -121,7 +124,6 @@ void TX2xStartRead(void) * La Crosse TX23 Anemometer datagram after setting TxD to low/high * 1-1 0 1 0-0 11011 0011 111010101111 0101 1100 000101010000 1-1 - Received pin data at 1200 uSec per bit * t s c sa sb sc sd se sf - * 1 0 1-1 00100 1100 000101010000 1010 1100 000101010000 - sa to sd inverted user data, LSB first * t - host pulls TxD low - signals TX23 to sent measurement * s - TxD released - TxD is pulled high due to pullup * c - TX23U pulls TxD low - calculation in progress @@ -152,26 +154,8 @@ void TX2xStartRead(void) for (int32_t bitcount = 41; bitcount > 0; bitcount--) { uint8_t dpin = (digitalRead(pin[GPIO_TX2X_TXD_BLACK])); #ifdef USE_TX23_WIND_SENSOR - if (bitcount > 41 - 5) { - // start - tx2x_sa = (tx2x_sa << 1) | (dpin); - } else if (bitcount > 41 - 5 - 4) { - // wind dir - tx2x_sb = tx2x_sb >> 1 | ((dpin) << 3); - } else if (bitcount > 41 - 5 - 4 - 12) { - // windspeed - tx2x_sc = tx2x_sc >> 1 | ((dpin) << 11); - } else if (bitcount > 41 - 5 - 4 - 12 - 4) { - // checksum - tx2x_sd = tx2x_sd >> 1 | ((dpin) << 3); - } else if (bitcount > 41 - 5 - 4 - 12 - 4 - 4) { - // wind dir (invert) - tx2x_se = tx2x_se >> 1 | ((dpin ^ 1) << 3); - } else { - // windspeed (invert) - tx2x_sf = tx2x_sf >> 1 | ((dpin ^ 1) << 11); - } -#else + dpin ^= 1; +#endif if (bitcount > 41 - 5) { // start frame (invert) tx2x_sa = (tx2x_sa << 1) | (dpin ^ 1); @@ -191,23 +175,14 @@ void TX2xStartRead(void) // windspeed tx2x_sf = tx2x_sf >> 1 | (dpin << 11); } -#endif delayMicroseconds(TX2X_BIT_TIME); } uint8_t chk = (tx2x_sb + (tx2x_sc & 0xf) + ((tx2x_sc >> 4) & 0xf) + ((tx2x_sc >> 8) & 0xf)); chk &= 0xf; -#ifdef USE_TX23_WIND_SENSOR // check checksum, non-inverted with inverted values and max. speed - if ((chk == tx2x_sd) && (tx2x_sb==tx2x_se) && (tx2x_sc==tx2x_sf) && (tx2x_sc < 511)) { - tx2x_available = true; - } -#else - if ((chk == tx2x_sd) && (tx2x_sc < 511)) { // if checksum seems to be ok and wind speed below 51.1 m/s - tx2x_available = true; - } -#endif + tx2x_available = ((chk == tx2x_sd) && (tx2x_sb==tx2x_se) && (tx2x_sc==tx2x_sf) && (tx2x_sc < 511)); #ifdef USE_TX23_WIND_SENSOR } tx23_stage++; @@ -219,49 +194,82 @@ void TX2xStartRead(void) GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, 1 << pin[GPIO_TX2X_TXD_BLACK]); } -void Tx2xReset(void) +void Tx2xResetStat(void) { + tx2x_wind_speed_min = tx2x_wind_speed_kmh; + tx2x_wind_speed_max = tx2x_wind_speed_kmh; + uint16_t tx2x_prev_avg_samples = tx2x_avg_samples; + if (Settings.tele_period) { + // number for avg samples = teleperiod value if set + tx2x_avg_samples = Settings.tele_period; + } else { + // otherwise use default number of samples for this driver + tx2x_avg_samples = TX2X_WEIGHT_AVG_SAMPLE; + } + if (tx2x_prev_avg_samples != tx2x_avg_samples) { + tx2x_wind_speed_avg = tx2x_wind_speed_kmh; tx2x_count = 0; - tx2x_wind_sum = 0; - tx2x_wind_speed_max = 0; + } } void Tx2xRead(void) { #ifdef USE_TX23_WIND_SENSOR + // TX23 needs to trigger start transmission - TxD Line + // ___________ _ ___ ___ + // |____| |___________| |_| |__XXXXXXXXXX + // trigger start conv Startframe Data + // // note: TX23 speed calculation is unstable when conversion starts // less than 2 seconds after last request - if ((uptime % 3)==0) { + if ((uptime % TX23_READ_INTERVAL)==0) { // TX23 start transmission by pulling down TxD line for at minimum 500ms // so we pull TxD signal to low every 3 seconds tx23_stage = 0; pinMode(pin[GPIO_TX2X_TXD_BLACK], OUTPUT); digitalWrite(pin[GPIO_TX2X_TXD_BLACK], LOW); - } else if ((uptime % 3)==1) { - // after pulling down TxD every 3 second we pull-up TxD every 3+1 seconds - // to trigger start transmission + } else if ((uptime % TX23_READ_INTERVAL)==1) { + // after pulling down TxD: pull-up TxD every x+1 seconds + // to trigger TX23 start transmission tx23_stage = 1; // first rising signal is invalid pinMode(pin[GPIO_TX2X_TXD_BLACK], INPUT_PULLUP); } #endif - if (0==Settings.tele_period && !(uptime % TX2X_RESET_VALUES)) { - Tx2xReset(); + if (0!=Settings.tele_period && Settings.tele_period!=tx2x_avg_samples) { + // new teleperiod value + Tx2xResetStat(); } - else if (tx2x_available) { + if (tx2x_available) { // Wind speed spec: 0 to 180 km/h (0 to 50 m/s) tx2x_wind_speed_kmh = float(tx2x_sc) * 0.36; + if (tx2x_wind_speed_kmh < tx2x_wind_speed_min) { + tx2x_wind_speed_min = tx2x_wind_speed_kmh; + } if (tx2x_wind_speed_kmh > tx2x_wind_speed_max) { tx2x_wind_speed_max = tx2x_wind_speed_kmh; } - tx2x_count++; - tx2x_wind_sum += tx2x_wind_speed_kmh; - tx2x_wind_speed_avg = tx2x_wind_sum / tx2x_count; + // exponentially weighted average is not quite as smooth as the arithmetic average + // but close enough to the moving average and does not require the regular reset + // of the divider with the associated jump in avg values after period is over + if (tx2x_count <= tx2x_avg_samples) { + tx2x_count++; + } + tx2x_wind_speed_avg -= tx2x_wind_speed_avg / tx2x_count; + tx2x_wind_speed_avg += tx2x_wind_speed_kmh / tx2x_count; + tx2x_wind_direction = tx2x_sb; + + if (!(uptime % tx2x_avg_samples)) { + tx2x_wind_speed_min = tx2x_wind_speed_kmh; + tx2x_wind_speed_max = tx2x_wind_speed_kmh; + + } } } void Tx2xInit(void) { + Tx2xResetStat(); #ifdef USE_TX23_WIND_SENSOR tx23_stage = 0; pinMode(pin[GPIO_TX2X_TXD_BLACK], OUTPUT); @@ -276,22 +284,46 @@ void Tx2xShow(bool json) { char wind_speed_string[33]; dtostrfd(tx2x_wind_speed_kmh, 1, wind_speed_string); + char wind_speed_min_string[33]; + dtostrfd(tx2x_wind_speed_min, 1, wind_speed_min_string); char wind_speed_max_string[33]; dtostrfd(tx2x_wind_speed_max, 1, wind_speed_max_string); char wind_speed_avg_string[33]; dtostrfd(tx2x_wind_speed_avg, 1, wind_speed_avg_string); + char wind_direction_degree_string[33]; + dtostrfd(tx2x_wind_direction*22.5, 1, wind_direction_degree_string); char wind_direction_string[4]; GetTextIndexed(wind_direction_string, sizeof(wind_direction_string), tx2x_wind_direction, kTx2xDirections); - char wind_direction_degree[33]; - dtostrfd(tx2x_wind_direction*22.5, 1, wind_direction_degree); if (json) { +#ifdef USE_TX2x_LEGACY_JSON ResponseAppend_P(PSTR(",\"" D_TX2x_NAME "\":{\"Speed\":%s,\"SpeedAvg\":%s,\"SpeedMax\":%s,\"Direction\":\"%s\",\"Degree\":%s}"), wind_speed_string, wind_speed_avg_string, wind_speed_max_string, wind_direction_string, wind_direction_degree); - Tx2xReset(); +#else + // new format grouped by Speed and Dir(ection) + // Card = cardianal (N../O../S../W..) + // Deg = Degree + ResponseAppend_P( + PSTR(",\"" D_TX2x_NAME "\":{\"Speed\":{\"Act\":%s,\"Avg\":%s,\"Min\":%s,\"Max\":%s},\"Direction\":{\"Cardinal\":\"%s\",\"Degree\":%s}}"), + wind_speed_string, + wind_speed_avg_string, + wind_speed_min_string, + wind_speed_max_string, + wind_direction_string, + wind_direction_degree_string + ); +#endif #ifdef USE_WEBSERVER } else { - WSContentSend_PD(HTTP_SNS_TX2X, wind_speed_string, wind_speed_avg_string, wind_speed_max_string, wind_direction_string, wind_direction_degree); + WSContentSend_PD( + HTTP_SNS_TX2X, + wind_speed_string, + wind_speed_avg_string, + wind_speed_min_string, + wind_speed_max_string, + wind_direction_string, + wind_direction_degree_string + ); #endif // USE_WEBSERVER } } @@ -313,11 +345,11 @@ bool Xsns35(uint8_t function) Tx2xRead(); break; case FUNC_JSON_APPEND: - Tx2xShow(1); + Tx2xShow(true); break; #ifdef USE_WEBSERVER case FUNC_WEB_SENSOR: - Tx2xShow(0); + Tx2xShow(false); break; #endif // USE_WEBSERVER }