Added non wifimanager wifi connection support.

This commit is contained in:
Kai Lauterbach 2022-10-31 11:56:44 +01:00
parent 17fdbe6155
commit 93114b0f49
3 changed files with 58 additions and 3 deletions

View file

@ -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) <add link here>
//#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

View file

@ -7,13 +7,16 @@
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h> // WiFiClient
#include <WiFiManager.h> // WiFiManager from bib manager
// Project includes
#include "constants.h"
#include "config.h"
#include "config_user.h"
#ifndef DISABLE_WIFIMANAGER
#include <WiFiManager.h> // 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,12 +263,25 @@ 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
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);
}
}

View file

@ -1,6 +1,8 @@
#include "config_user.h"
//*************************************************************************//
#if INFLUXDB_VERSION == 1
#include <ESP8266Influxdb.h> // 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 <InfluxDbClient.h> // from bib manager
@ -210,3 +214,5 @@ void _writePoint()
}
#endif // influxdb version 2 check
//*************************************************************************//