From 7a689034b44ef69697178bcae8b28855d354d2cb Mon Sep 17 00:00:00 2001 From: Kai Lauterbach Date: Sun, 22 May 2022 08:51:24 +0200 Subject: [PATCH] Added windspeed exceed functionality, it calls an url if max windspeed is exceeded --- firmware/config.h | 4 ++++ firmware/firmware.ino | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/firmware/config.h b/firmware/config.h index 3a02556..352a019 100644 --- a/firmware/config.h +++ b/firmware/config.h @@ -37,6 +37,10 @@ #define COUNT_TO_MPS (TWO_PI * ROTOR_LENGTH_M / WIND_SENSOR_MEAS_TIME_S) #define WINDSPEED_FACTOR (COUNT_TO_MPS * MPS_CORRECT_FACT) +#define HTTP_CALL_ON_WINDSPEED_EXCEED_MPS 5.0 // 5.0 m/s == 18 km/h +#define HTTP_CALL_ON_WINDSPEED_INTERVAL_S 60 // it's required to be bigger than WIND_SENSOR_MEAS_TIME_S +#define HTTP_CALL_ON_WINDSPEED_URL "http://192.168.0.250:3001/button-windspeedexceed?event=click" + #define BAT_LOW_VOLTAGE 3.6 #define BAT_EMERGENCY_DEEPSLEEP_VOLTAGE 3.5 diff --git a/firmware/firmware.ino b/firmware/firmware.ino index dc26f0d..24ce7dd 100644 --- a/firmware/firmware.ino +++ b/firmware/firmware.ino @@ -4,6 +4,7 @@ #include #include #include +#include #include // WiFiClient #include // WiFiManager from bib manager @@ -11,6 +12,12 @@ // Project includes #include "config.h" +#ifdef HTTP_CALL_ON_WINDSPEED_EXCEED +#if (HTTP_CALL_ON_WINDSPEED_INTERVAL_S < HTTP_CALL_ON_WINDSPEED_EXCEED_MPS) +#error "HTTP_CALL_ON_WINDSPEED_INTERVAL_S < WIND_SENSOR_MEAS_TIME_S" +#endif +#endif + #include "config_user.h" //*************************************************************************// @@ -19,8 +26,9 @@ const uint8_t VALUES = 8; float currentSensorData[VALUES] = {nanf("no value"), nanf("no value"), nanf("no value"), nanf("no value"), nanf("no value"), nanf("no value"), nanf("no value"), nanf("no value")}; float (*sensors[VALUES])() = {}; -uint16_t update_sensor_cnt = 0; -uint16_t update_webserver_cnt = 0; +uint16_t update_sensor_cnt = 0; +uint16_t update_webserver_cnt = 0; +uint16_t update_windspeed_exceed_cnt = 0; WiFiManager wifiManager; @@ -206,10 +214,36 @@ void loop() #ifdef WEBUPDATER_FEATURE update_webserver_cnt++; #endif + +#ifdef HTTP_CALL_ON_WINDSPEED_EXCEED + update_windspeed_exceed_cnt++; +#endif } void _loop() { +#ifdef HTTP_CALL_ON_WINDSPEED_EXCEED + if (HTTP_CALL_ON_WINDSPEED_INTERVAL_S * 1000 / DELAY_LOOP_MS > update_windspeed_exceed_cnt) { + if (sensors[SENSOR_WINDSPEED]) { + currentSensorData[SENSOR_WINDSPEED] = sensors[SENSOR_WINDSPEED](); + + if (currentSensorData[SENSOR_WINDSPEED] >= HTTP_CALL_ON_WINDSPEED_EXCEED_MPS) + { + // call the url HTTP_CALL_ON_WINDSPEED_URL + WiFiClient client; + HTTPClient http; + http.begin(client, String(HTTP_CALL_ON_WINDSPEED_URL).c_str()); + http.end(); + // Send HTTP GET request + int httpResponseCode = http.GET(); + } + } else { + currentSensorData[SENSOR_WINDSPEED] = nan("no value"); + } + update_windspeed_exceed_cnt = 0; + } +#endif + #ifndef BATTERY_POWERED if (UPDATE_SENSOR_INTERVAL_S * 1000 / DELAY_LOOP_MS > update_sensor_cnt) { return;