reworked WiFi-Stuff
This commit is contained in:
		| @@ -52,6 +52,10 @@ | ||||
| #ifndef WIFI_SSID | ||||
| #error "You must define an WIFI_SSID for OTA-Update" | ||||
| #endif | ||||
| #ifndef WIFI_AP_SSID | ||||
| #warning "No WIFI_AP_SSID defined. Using DeviceName" | ||||
| #define WIFI_AP_SSID DEVICE_NAME | ||||
| #endif | ||||
| #ifndef WIFI_AP_PASSWORD | ||||
| #error "You must define an WIFI_AP_PASSWORD for Standalone AP-Mode" | ||||
| #endif | ||||
|   | ||||
| @@ -22,11 +22,14 @@ | ||||
| #ifdef WIFI_CLIENT | ||||
| #include <WiFiMulti.h> | ||||
|  | ||||
| const char *ssid = QUOTE(WIFI_SSID); | ||||
| const char *password = QUOTE(WIFI_PASSWORD); | ||||
| #ifdef FEATURE_ENABLE_WIFI_CLIENT | ||||
| #include <ESP8266WiFiMulti.h> | ||||
|  | ||||
| const char *ssid = QUOTE(WIFI_SSID_CLIENT); | ||||
| const char *password = QUOTE(WIFI_PASSWORD_CLIENT); | ||||
| const uint32_t connectTimeoutMs = 5000; | ||||
|  | ||||
| WiFiMulti wifiMulti; | ||||
| ESP8266WiFiMulti wifiMulti; | ||||
| #endif | ||||
|  | ||||
| PCF8574 i2c_io(I2C_IO_ADDRESS); | ||||
| @@ -56,7 +59,7 @@ Ticker tmrInputGetter(tmrCallback_InputGetter, 250, 0, MILLIS); | ||||
| void tmrCallback_EEPROMCyclicPDS(); | ||||
| Ticker tmrEEPROMCyclicPDS(tmrCallback_EEPROMCyclicPDS, 60000, 0, MILLIS); | ||||
|  | ||||
| #ifdef WIFI_CLIENT | ||||
| #ifdef FEATURE_ENABLE_WIFI_CLIENT | ||||
| void tmrCallback_WiFiMaintainConnection(); | ||||
| Ticker tmrWiFiMaintainConnection(tmrCallback_WiFiMaintainConnection, 1000, 0, MILLIS); | ||||
| #endif | ||||
| @@ -120,14 +123,12 @@ void setup() | ||||
| 	InitLoRa(&setMPins_Helper); | ||||
| 	tmrStatusSender.start(); | ||||
|  | ||||
| #ifdef WIFI_CLIENT | ||||
| #ifdef FEATURE_ENABLE_WIFI_CLIENT | ||||
| 	WiFi.mode(WIFI_STA); | ||||
| 	WiFi.setHostname(globals.DeviceName_ID); | ||||
| 	wifiMulti.addAP(QUOTE(WIFI_SSID), QUOTE(WIFI_PASSWORD)); | ||||
| 	tmrWiFiMaintainConnection.start(); | ||||
| 	WiFi.setHostname(globals.DeviceName); | ||||
| 	wifiMulti.addAP(QUOTE(WIFI_SSID_CLIENT), QUOTE(WIFI_PASSWORD_CLIENT)); | ||||
| 	WiFiMaintainConnectionTicker.start(); | ||||
| #else | ||||
| 	WiFi.mode(WIFI_AP); | ||||
| 	WiFi.begin(QUOTE(DEVICE_NAME), QUOTE(WIFI_AP_PASSWORD)); | ||||
| 	WiFi.mode(WIFI_OFF); | ||||
| #endif | ||||
|  | ||||
| @@ -420,29 +421,38 @@ void tmrCallback_WiFiMaintainConnection() | ||||
| 	else | ||||
| 	{ | ||||
| 		if (WiFiFailCount < WiFiFailMax) | ||||
| 		{ | ||||
| 			WiFiFailCount++; | ||||
| 		} | ||||
| 		else | ||||
| 			toggleWiFiAP(false); | ||||
| 		{ | ||||
| 			debugV("WiFi not connected! - Start AP"); | ||||
| 			toggleWiFiAP(); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| #endif | ||||
|  | ||||
| void toggleWiFiAP(boolean shutdown) | ||||
| { | ||||
| 	if (WiFi.getMode() != WIFI_OFF && shutdown == true) | ||||
| 	if (WiFi.getMode() != WIFI_OFF) | ||||
| 	{ | ||||
| 		WiFi.mode(WIFI_OFF); | ||||
| #ifdef WIFI_CLIENT | ||||
| 		tmrWiFiMaintainConnection.stop(); | ||||
| 		debugV("WiFi turned off"); | ||||
| #ifdef FEATURE_ENABLE_WIFI_CLIENT | ||||
| 		WiFiMaintainConnectionTicker.stop(); | ||||
| #endif | ||||
| 	} | ||||
| 	else if (shutdown == false) | ||||
| 	else | ||||
| 	{ | ||||
| 		WiFi.mode(WIFI_AP); | ||||
| 		WiFi.softAPConfig(IPAddress(WIFI_AP_IP_GW), IPAddress(WIFI_AP_IP_GW), IPAddress(255, 255, 255, 0)); | ||||
| 		WiFi.softAP(globals.DeviceName_ID, QUOTE(WIFI_AP_PASSWORD)); | ||||
| #ifdef WIFI_CLIENT | ||||
| 		tmrWiFiMaintainConnection.stop(); | ||||
| 		WiFi.softAP(QUOTE(WIFI_AP_SSID), QUOTE(WIFI_AP_PASSWORD)); | ||||
| #ifdef FEATURE_ENABLE_WIFI_CLIENT | ||||
| 		WiFiMaintainConnectionTicker.stop(); | ||||
| 		debugV("WiFi AP started, stopped Maintain-Timer"); | ||||
| #else | ||||
| 		debugV("WiFi AP started"); | ||||
| #endif | ||||
| 	} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user