From 93114b0f49c32c7f8ff8d46d66e1934fecf2344d Mon Sep 17 00:00:00 2001 From: Kai Lauterbach Date: Mon, 31 Oct 2022 11:56:44 +0100 Subject: [PATCH] Added non wifimanager wifi connection support. --- firmware/config_user.h.example | 16 ++++++++++++++ firmware/firmware.ino | 39 +++++++++++++++++++++++++++++++--- firmware/influxdb.ino | 6 ++++++ 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/firmware/config_user.h.example b/firmware/config_user.h.example index 712addb..c3f8547 100755 --- a/firmware/config_user.h.example +++ b/firmware/config_user.h.example @@ -38,6 +38,7 @@ String DEVICE_NAME = "weatherstation"; // not available or recommended for battery mode /********************************************************************************/ +//#define DISABLE_WIFIMANAGER // Restarts the firmware every n seconds //#define RESET_ESP_TIME_INTERVAL //#define ENABLE_WATCHDOG @@ -90,5 +91,20 @@ const char *INFLUXDB_TOKEN = "your api token"; // china aliexpress anemometer settings (calculation unknown) //#define WINDSPEED_FACTOR 2.4 +/********************************************************************************/ + +#ifdef DISABLE_WIFIMANAGER + // Set your Static IP address + IPAddress local_IP(192, 168, 178, 123); + // Set your Gateway IP address + IPAddress gateway(192, 168, 178, 1); + // Set subnet mask + IPAddress subnet(255, 255, 255, 0); + + #define WIFI_SSID "myWifi" // WLAN Netzwerk + #define WIFI_PASSWD "myPass" // WLAN Passwort #endif +/********************************************************************************/ + +#endif diff --git a/firmware/firmware.ino b/firmware/firmware.ino index 07cfc9c..70b3b8c 100644 --- a/firmware/firmware.ino +++ b/firmware/firmware.ino @@ -7,13 +7,16 @@ #include #include // WiFiClient -#include // WiFiManager from bib manager // Project includes #include "constants.h" #include "config.h" #include "config_user.h" +#ifndef DISABLE_WIFIMANAGER +#include // WiFiManager from bib manager +#endif + //*************************************************************************// // check if some settings are correct @@ -38,7 +41,9 @@ uint32_t wifi_check_interval_counter = 0; const String wifiName = "oko-weather-" + DEVICE_NAME; +#ifndef DISABLE_WIFIMANAGER WiFiManager wifiManager; +#endif uint8_t fsm_state = FSM_STATE_1; @@ -258,11 +263,24 @@ void wifiConnectionCheck() debug("no wifi connection, try to reconnect " + String(wifi_reconnect_cnt)); + WiFi.disconnect(); + WiFi.mode(WIFI_OFF); + WiFi.mode(WIFI_STA); + #ifdef WEBUPDATER_FEATURE setWifiReconnectCnt(wifi_reconnect_cnt); #endif - wifiConnect(); + if (wifi_reconnect_cnt >= 5) + { + debug("\nReboot"); + ESP.restart(); + } else { + + wifiConnect(); + + //initWifiBasedSW(); + } } @@ -273,6 +291,8 @@ void wifiConnect() // Establish WiFi connection if not already applied +#ifndef DISABLE_WIFIMANAGER + wifiManager.setMinimumSignalQuality(WIFI_MINIMUM_SIGNAL_QUALITY); // the time in seconds to wait for the known wifi connection wifiManager.setConnectTimeout(WIFI_AUTOCONNECT_TIMEOUT_S); @@ -296,6 +316,19 @@ void wifiConnect() } +#else // DISABLE_WIFIMANAGER + + WiFi.begin(WIFI_SSID, WIFI_PASSWD); + + debug("Connecting to WLAN"); + + while (WiFi.status() != WL_CONNECTED) + { + delay(100); + } + +#endif // DISABLE_WIFIMANAGER + } //*************************************************************************// @@ -309,7 +342,7 @@ void criticalBatCheck() debug("Bat Voltage: " + String(volt) + " V"); debug("Low battery, going into deep sleep."); // Casting to an unsigned int, so it fits into the integer range - ESP.deepSleep(1U * EMERGENCY_SLEEP_S * 1000000); // battery low, shutting down + ESP.deepSleep(1U * EMERGENCY_SLEEP_S * 1000000u); // battery low, shutting down delay(100); } } diff --git a/firmware/influxdb.ino b/firmware/influxdb.ino index 754e8c9..a3d2174 100644 --- a/firmware/influxdb.ino +++ b/firmware/influxdb.ino @@ -1,6 +1,8 @@ #include "config_user.h" +//*************************************************************************// + #if INFLUXDB_VERSION == 1 #include // https://github.com/hwwong/ESP8266Influxdb @@ -87,6 +89,8 @@ void pushToInfluxDB(String device, float sensorValues[]) { } while (_influxdb.response() != DB_SUCCESS and tries < 5); } +//*************************************************************************// + #elif INFLUXDB_VERSION == 2 #include // from bib manager @@ -210,3 +214,5 @@ void _writePoint() } #endif // influxdb version 2 check + +//*************************************************************************//