Replace Wemos D1 mini with Wemos D1 mini ESP32
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
* Muraqib
|
* 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
|
** Pinout of the board
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,11 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <AsyncMqttClient.h>
|
#include <AsyncMqttClient.h>
|
||||||
#include <ESP8266WiFi.h>
|
|
||||||
#include <Ticker.h>
|
#include <Ticker.h>
|
||||||
|
#include <WiFi.h>
|
||||||
|
|
||||||
static AsyncMqttClient mqtt_client;
|
static AsyncMqttClient mqtt_client;
|
||||||
static Ticker mqtt_connection_timer, wlan_connection_timer;
|
static Ticker mqtt_connection_timer, wlan_connection_timer;
|
||||||
static WiFiEventHandler connection_handler, disconnection_handler;
|
|
||||||
extern Config *config;
|
extern Config *config;
|
||||||
|
|
||||||
void initialize_wlan();
|
void initialize_wlan();
|
||||||
@@ -19,9 +18,7 @@ void connect_wlan();
|
|||||||
|
|
||||||
void connect_mqtt();
|
void connect_mqtt();
|
||||||
|
|
||||||
void on_wlan_connection(const WiFiEventStationModeGotIP &event);
|
void wlan_connection_handler(WiFiEvent_t event);
|
||||||
|
|
||||||
void on_wlan_disconnection(const WiFiEventStationModeDisconnected &event);
|
|
||||||
|
|
||||||
void on_mqtt_connection(bool session);
|
void on_mqtt_connection(bool session);
|
||||||
|
|
||||||
|
|||||||
@@ -9,11 +9,11 @@
|
|||||||
; https://docs.platformio.org/page/projectconf.html
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
[env:d1_mini]
|
[env:d1_mini]
|
||||||
platform = espressif8266
|
platform = espressif32
|
||||||
board = d1_mini
|
board = wemos_d1_mini32
|
||||||
board_build.filesystem = littlefs
|
board_build.filesystem = littlefs
|
||||||
framework = arduino
|
framework = arduino
|
||||||
monitor_filters = esp8266_exception_decoder
|
monitor_filters = esp32_exception_decoder
|
||||||
lib_deps =
|
lib_deps =
|
||||||
sensirion/Sensirion I2C SCD4x@^1.1.0
|
sensirion/Sensirion I2C SCD4x@^1.1.0
|
||||||
marvinroger/AsyncMqttClient@^0.9.0
|
marvinroger/AsyncMqttClient@^0.9.0
|
||||||
|
|||||||
28
src/wlan.cpp
28
src/wlan.cpp
@@ -1,10 +1,6 @@
|
|||||||
#include "wlan.h"
|
#include "wlan.h"
|
||||||
|
|
||||||
void initialize_wlan() {
|
void initialize_wlan() { WiFi.onEvent(wlan_connection_handler); }
|
||||||
connection_handler = WiFi.onStationModeGotIP(on_wlan_connection);
|
|
||||||
disconnection_handler =
|
|
||||||
WiFi.onStationModeDisconnected(on_wlan_disconnection);
|
|
||||||
}
|
|
||||||
|
|
||||||
void initialize_mqtt() {
|
void initialize_mqtt() {
|
||||||
mqtt_client.onConnect(on_mqtt_connection);
|
mqtt_client.onConnect(on_mqtt_connection);
|
||||||
@@ -21,15 +17,19 @@ void connect_mqtt() {
|
|||||||
mqtt_client.connect();
|
mqtt_client.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_wlan_connection(const WiFiEventStationModeGotIP &event) {
|
void wlan_connection_handler(WiFiEvent_t event) {
|
||||||
Serial.println("WiFi connected");
|
Serial.printf("[WiFi-event] event: %d\n", event);
|
||||||
connect_mqtt();
|
switch (event) {
|
||||||
}
|
case SYSTEM_EVENT_STA_GOT_IP:
|
||||||
|
Serial.println("WiFi connected");
|
||||||
void on_wlan_disconnection(const WiFiEventStationModeDisconnected &event) {
|
connect_mqtt();
|
||||||
Serial.println("WiFi disconnected");
|
break;
|
||||||
mqtt_connection_timer.detach();
|
case SYSTEM_EVENT_STA_DISCONNECTED:
|
||||||
wlan_connection_timer.once(2, connect_wlan);
|
Serial.println("WiFi disconnected");
|
||||||
|
mqtt_connection_timer.detach();
|
||||||
|
wlan_connection_timer.once(2, connect_wlan);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_mqtt_connection(bool session) {
|
void on_mqtt_connection(bool session) {
|
||||||
|
|||||||
Reference in New Issue
Block a user