Replace Wemos D1 mini with Wemos D1 mini ESP32
This commit is contained in:
28
src/wlan.cpp
28
src/wlan.cpp
@@ -1,10 +1,6 @@
|
||||
#include "wlan.h"
|
||||
|
||||
void initialize_wlan() {
|
||||
connection_handler = WiFi.onStationModeGotIP(on_wlan_connection);
|
||||
disconnection_handler =
|
||||
WiFi.onStationModeDisconnected(on_wlan_disconnection);
|
||||
}
|
||||
void initialize_wlan() { WiFi.onEvent(wlan_connection_handler); }
|
||||
|
||||
void initialize_mqtt() {
|
||||
mqtt_client.onConnect(on_mqtt_connection);
|
||||
@@ -21,15 +17,19 @@ void connect_mqtt() {
|
||||
mqtt_client.connect();
|
||||
}
|
||||
|
||||
void on_wlan_connection(const WiFiEventStationModeGotIP &event) {
|
||||
Serial.println("WiFi connected");
|
||||
connect_mqtt();
|
||||
}
|
||||
|
||||
void on_wlan_disconnection(const WiFiEventStationModeDisconnected &event) {
|
||||
Serial.println("WiFi disconnected");
|
||||
mqtt_connection_timer.detach();
|
||||
wlan_connection_timer.once(2, connect_wlan);
|
||||
void wlan_connection_handler(WiFiEvent_t event) {
|
||||
Serial.printf("[WiFi-event] event: %d\n", event);
|
||||
switch (event) {
|
||||
case SYSTEM_EVENT_STA_GOT_IP:
|
||||
Serial.println("WiFi connected");
|
||||
connect_mqtt();
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_DISCONNECTED:
|
||||
Serial.println("WiFi disconnected");
|
||||
mqtt_connection_timer.detach();
|
||||
wlan_connection_timer.once(2, connect_wlan);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void on_mqtt_connection(bool session) {
|
||||
|
||||
Reference in New Issue
Block a user