Replace Wemos D1 mini with Wemos D1 mini ESP32
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -3,12 +3,11 @@
|
||||
|
||||
#include "config.h"
|
||||
#include <AsyncMqttClient.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <Ticker.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
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);
|
||||
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[env:d1_mini]
|
||||
platform = espressif8266
|
||||
board = d1_mini
|
||||
[env:s2_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
|
||||
|
||||
18
src/wlan.cpp
18
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) {
|
||||
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();
|
||||
}
|
||||
|
||||
void on_wlan_disconnection(const WiFiEventStationModeDisconnected &event) {
|
||||
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