2025-11-1900
This commit is contained in:
73
src/main.cpp
73
src/main.cpp
@@ -21,6 +21,9 @@
|
||||
|
||||
#include <mess_BME280.h>
|
||||
#include <mess_HTU21D.h>
|
||||
#ifndef CO2Wert
|
||||
#include <CO2.h>
|
||||
#endif
|
||||
|
||||
// Pins for LED MATRIX
|
||||
#ifdef ESP32
|
||||
@@ -72,7 +75,7 @@ unsigned long endTime;
|
||||
#include <Wire.h>
|
||||
#include <WiFi.h>
|
||||
#include <PubSubClient.h>
|
||||
#define mqtt_port 61883
|
||||
#define mqtt_port MQTTPORT
|
||||
WiFiClient espClient;
|
||||
PubSubClient client(espClient);
|
||||
|
||||
@@ -116,13 +119,15 @@ u_int16_t EndederAbdunklung = 7;
|
||||
uint8_t SekOld = 99;
|
||||
|
||||
// Wifi
|
||||
char ssid[] = "MagentaWLAN-RGDO"; // your network SSID (name)
|
||||
char pass[] = "93329248424922704583"; // your network password
|
||||
IPAddress ip( 192, 168, 127, 52);
|
||||
IPAddress gateway( 192, 168, 127, 1 );
|
||||
IPAddress subnet( 255, 255, 255, 0 );
|
||||
IPAddress dns1(192, 168, 127, 1); // DNS-Server 1
|
||||
IPAddress dns2(192, 168, 127, 1); // DNS-Server 2
|
||||
// Wifi
|
||||
char ssid[] = STASSID; // your network SSID (name)
|
||||
char pass[] = STAPSK; // your network password
|
||||
IPAddress ip;
|
||||
IPAddress gateway;
|
||||
IPAddress subnet;
|
||||
IPAddress dns; // DNS-Server
|
||||
IPAddress secondarDNS;
|
||||
|
||||
|
||||
/* char ssid[] = "EasyBox-838169"; // your network SSID (name)
|
||||
char pass[] = "RcZmua6Xv4R4V5Kf"; // your network password
|
||||
@@ -170,17 +175,21 @@ const char* const PROGMEM DAY_NAMES[] = {"Sonntag", "Montag", "Dienstag", "Mittw
|
||||
const char* const PROGMEM DAY_SHORT[] = {"So", "Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"};
|
||||
|
||||
//MQTT
|
||||
#define mqtt_port 61883
|
||||
const char* mqtt_server = "hjkmqtt.dedyn.io";
|
||||
/* #define mqtt_port 61883
|
||||
const char* mqtt_server = "hjkmqtt.dedyn.io"; */
|
||||
char topic_0[50];
|
||||
char msg[20];
|
||||
char clientName[30];
|
||||
#ifdef Covid
|
||||
const char* topic_Covid = "hjk/devices/Covid19/telemetry/Covid19";
|
||||
#endif
|
||||
const char* topic_Wetter = WETTER;
|
||||
const char* topic_Pressure = LUFTDRUCK;
|
||||
const char* topic_Luftfeuchtigkeit = FEUCHTIGKEIT;
|
||||
const char* topic_Akku = AKKU;
|
||||
const char* topic_Co2 = CO2Wert;
|
||||
#ifdef CO2Wert
|
||||
const char* topic_Co2 = CO2Wert;
|
||||
#endif
|
||||
|
||||
const char* topic_Helligkeit = HELL;
|
||||
|
||||
@@ -343,8 +352,10 @@ void reconnect() {
|
||||
if (client.connect(clientName)) {
|
||||
/* MQTTStatus.setPic(3); */
|
||||
Serial.println("connected");
|
||||
client.subscribe(topic_Co2);
|
||||
client.subscribe(topic_Covid);
|
||||
#ifdef CO2Wert
|
||||
client.subscribe(topic_Co2);
|
||||
#endif
|
||||
//client.subscribe(topic_Covid);
|
||||
client.subscribe(topic_Wetter);
|
||||
client.subscribe(topic_Pressure);
|
||||
client.subscribe(topic_Luftfeuchtigkeit);
|
||||
@@ -669,6 +680,9 @@ void setup() {
|
||||
}
|
||||
read_HTU21D();
|
||||
Init_BME280();
|
||||
#ifndef CO2Wert
|
||||
beginC02();
|
||||
#endif
|
||||
delay(5000);
|
||||
WiFi.mode( WIFI_OFF );
|
||||
// WiFi.forceSleepBegin();
|
||||
@@ -794,6 +808,23 @@ static void setup_wifi() {
|
||||
|
||||
long ErrCount = 0;
|
||||
|
||||
if (!ip.fromString(MYIP)) { // try to parse into the IPAddress
|
||||
Serial.println("UnParsable IP");
|
||||
}
|
||||
if (!dns.fromString(DNS)) { // try to parse into the IPAddress
|
||||
Serial.println("UnParsable DNS");
|
||||
}
|
||||
if (!gateway.fromString(GATEWAY)) { // try to parse into the IPAddress
|
||||
Serial.println("UnParsable GATEWAY");
|
||||
}
|
||||
if (!secondarDNS.fromString(SECONDARDNS)) { // try to parse into the IPAddress
|
||||
Serial.println("UnParsable GATEWAY");
|
||||
}
|
||||
if (!subnet.fromString(SUBNET)) { // try to parse into the IPAddress
|
||||
Serial.println("UnParsable GATEWAY");
|
||||
}
|
||||
|
||||
|
||||
delay(10);
|
||||
// We start by connecting to a WiFi network
|
||||
Serial.println();
|
||||
@@ -803,7 +834,7 @@ static void setup_wifi() {
|
||||
|
||||
//WiFi.forceSleepWake();
|
||||
delay( 1 );
|
||||
WiFi.config( ip, gateway, subnet, dns1, dns2);
|
||||
WiFi.config( ip, gateway, subnet, dns, secondarDNS);
|
||||
|
||||
WiFi.begin(ssid, pass);
|
||||
|
||||
@@ -846,6 +877,20 @@ void loop() {
|
||||
AkkuAlarm();
|
||||
}
|
||||
|
||||
#ifndef CO2Wert
|
||||
if ((timeinfo.tm_sec % 30) == 0)
|
||||
{
|
||||
if (readCo2Flag == true) //eadCo2Flag
|
||||
{
|
||||
CO2Wert = readCO2();
|
||||
Serial.print("CO = \t"); Serial.println(CO2Wert);
|
||||
readCo2Flag = false;
|
||||
}
|
||||
}else{
|
||||
readCo2Flag = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((timeinfo.tm_min % 2) == 0)
|
||||
{
|
||||
if (readHtuFlag == true)
|
||||
|
||||
Reference in New Issue
Block a user