Kefalovryso Master
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
.pio
|
||||
.vscode/.browse.c_cpp.db*
|
||||
.vscode/c_cpp_properties.json
|
||||
.vscode/launch.json
|
||||
.vscode/ipch
|
||||
.vscode/extensions.json
|
||||
@@ -0,0 +1,24 @@
|
||||
; PlatformIO Project Configuration File
|
||||
;
|
||||
; Build options: build flags, source filter
|
||||
; Upload options: custom upload port, speed and extra flags
|
||||
; Library options: dependencies, extra library storages
|
||||
; Advanced options: extra scripting
|
||||
;
|
||||
; Temperatur messen und an MQTT senden
|
||||
|
||||
[env:dfrobot_firebeetle2_esp32e]
|
||||
platform = espressif32
|
||||
board = dfrobot_firebeetle2_esp32e
|
||||
framework = arduino
|
||||
monitor_speed = 115200
|
||||
monitor_filters =
|
||||
default
|
||||
time
|
||||
lib_deps =
|
||||
bblanchon/ArduinoJson@^7.2.0
|
||||
ropg/ezTime@^0.8.3
|
||||
hasenradball/AM2302-Sensor@^1.4.0
|
||||
symlink:///home/kouros/work/workspace/micro/libraries/LocalNetworkManager
|
||||
tzapu/WiFiManager@^2.0.17
|
||||
256dpi/MQTT@^2.5.2
|
||||
@@ -0,0 +1,82 @@
|
||||
#include <WiFi.h>
|
||||
#include <AM2302-Sensor.h>
|
||||
#include "LocalNetworkManager.h"
|
||||
|
||||
#define uS_TO_S_FACTOR 1000000ULL /* Conversion factor for micro seconds to seconds */
|
||||
#define SLEEP 300 // Sleep time in seconds
|
||||
|
||||
constexpr unsigned int SENSOR_PIN{ D3 };
|
||||
AM2302::AM2302_Sensor am2302{ SENSOR_PIN };
|
||||
|
||||
typedef struct {
|
||||
char dateTime[9];
|
||||
int humidity;
|
||||
float temperature;
|
||||
float voltage;
|
||||
} sensor_data_t;
|
||||
|
||||
sensor_data_t sensorData;
|
||||
|
||||
WiFiClient wifi;
|
||||
|
||||
LocalNetworkManager nm;
|
||||
|
||||
|
||||
void prepareMqtt() {
|
||||
nm.connectMqtt();
|
||||
}
|
||||
|
||||
void initAM2302() {
|
||||
if (!am2302.begin()) {
|
||||
Serial.println("Could not find a valid AM2302 sensor, check wiring!");
|
||||
while (100);
|
||||
}
|
||||
}
|
||||
|
||||
void readSensor() {
|
||||
am2302.read();
|
||||
// Read temperature as Celsius (the default)
|
||||
float temp = am2302.get_Temperature();
|
||||
// Read humidity
|
||||
float hum = am2302.get_Humidity();
|
||||
Serial.printf("Sensor: Temperature: %.1f Humidity: %.1f", temp, hum);
|
||||
Serial.println();
|
||||
sensorData.temperature = temp;
|
||||
sensorData.humidity = hum;
|
||||
if (temp > 0) {
|
||||
char tempString[8];
|
||||
dtostrf(sensorData.temperature, 1, 1, tempString);
|
||||
nm.publishMessage("kefalovryso/temperature", tempString);
|
||||
dtostrf(sensorData.humidity, 1, 1, tempString);
|
||||
nm.publishMessage("kefalovryso/humidity", tempString);
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200); // Initialize the serial port
|
||||
|
||||
Serial.println("");
|
||||
|
||||
// Init AM3202 Sensor
|
||||
initAM2302();
|
||||
|
||||
//Set device in AP_STA mode
|
||||
WiFi.mode(WIFI_AP_STA);
|
||||
if (nm.LocalNetworkManagerInit()) {
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
nm.initNTPTime("CET");
|
||||
prepareMqtt();
|
||||
}
|
||||
}
|
||||
readSensor();
|
||||
delay(200);
|
||||
Serial.printf("Deep Sleep for %d seconds", SLEEP);
|
||||
esp_sleep_enable_timer_wakeup((uint64_t)SLEEP * uS_TO_S_FACTOR);
|
||||
esp_deep_sleep_start();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user