From b79b6c36710e7205094b77633216fc0c425d2735 Mon Sep 17 00:00:00 2001 From: coolneng Date: Tue, 10 Mar 2026 15:44:37 +0100 Subject: [PATCH] Replace Wemos D1 mini with Wemos D1 mini ESP32 --- README.org | 2 +- include/wlan.h | 7 ++----- platformio.ini | 6 +++--- src/wlan.cpp | 28 ++++++++++++++-------------- 4 files changed, 20 insertions(+), 23 deletions(-) diff --git a/README.org b/README.org index f00ca91..d7cb015 100644 --- a/README.org +++ b/README.org @@ -1,6 +1,6 @@ * Muraqib -CO2 sensor that collects and sends its data via MQTT to a server. The board of the sensor is the Wemos D1 mini and the sensor is a SCD41. +CO2 sensor that collects and sends its data via MQTT to a server. The board of the sensor is the Wemos D1 mini ESP32 and the sensor is a SCD41. ** Pinout of the board diff --git a/include/wlan.h b/include/wlan.h index cfb553e..1197945 100644 --- a/include/wlan.h +++ b/include/wlan.h @@ -3,12 +3,11 @@ #include "config.h" #include -#include #include +#include static AsyncMqttClient mqtt_client; static Ticker mqtt_connection_timer, wlan_connection_timer; -static WiFiEventHandler connection_handler, disconnection_handler; extern Config *config; void initialize_wlan(); @@ -19,9 +18,7 @@ void connect_wlan(); void connect_mqtt(); -void on_wlan_connection(const WiFiEventStationModeGotIP &event); - -void on_wlan_disconnection(const WiFiEventStationModeDisconnected &event); +void wlan_connection_handler(WiFiEvent_t event); void on_mqtt_connection(bool session); diff --git a/platformio.ini b/platformio.ini index e828ba4..5929278 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,11 +9,11 @@ ; https://docs.platformio.org/page/projectconf.html [env:d1_mini] -platform = espressif8266 -board = d1_mini +platform = espressif32 +board = wemos_d1_mini32 board_build.filesystem = littlefs framework = arduino -monitor_filters = esp8266_exception_decoder +monitor_filters = esp32_exception_decoder lib_deps = sensirion/Sensirion I2C SCD4x@^1.1.0 marvinroger/AsyncMqttClient@^0.9.0 diff --git a/src/wlan.cpp b/src/wlan.cpp index a8afcc6..3fa7579 100644 --- a/src/wlan.cpp +++ b/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) {