2025-12-0200 Störung MQTT !!
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
|
||||
#define SEALEVELPRESSURE_HPA (1013.25)
|
||||
|
||||
const float No_Val = 999.99;
|
||||
const float No_Val = -999.99;
|
||||
|
||||
|
||||
struct {
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
#include "Adafruit_HTU21DF.h"
|
||||
|
||||
const float No_Valhtu = 999.99;
|
||||
const float No_Valhtu = 0;
|
||||
|
||||
struct {
|
||||
char temperature[15] = {0};
|
||||
char humity[15] = {0};
|
||||
float Temp = No_Valhtu;
|
||||
float Feuchte = No_Valhtu;
|
||||
bool Status = true;
|
||||
} htu21Data;
|
||||
|
||||
Adafruit_HTU21DF htu = Adafruit_HTU21DF();
|
||||
@@ -15,7 +16,7 @@ Adafruit_HTU21DF htu = Adafruit_HTU21DF();
|
||||
void init_HTU21(){
|
||||
if (!htu.begin()) {
|
||||
Serial.println("Couldn't find sensor HUT21D!");
|
||||
while (1);
|
||||
htu21Data.Status = false;
|
||||
}
|
||||
Serial.println("HUT21D gefunden");
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
platform = espressif32
|
||||
board = nodemcu-32s
|
||||
framework = arduino
|
||||
;
|
||||
;monitor_port = /dev/ttyUSB0
|
||||
monitor_speed = 115200
|
||||
monitor_filters = time
|
||||
@@ -85,8 +86,10 @@ build_flags = ${env.build_flags}
|
||||
|
||||
[env:marcelDebug] ; Sulzfeld
|
||||
build_flags = ${env.build_flags}
|
||||
-DSTASSID=\"MagentaWLAN-RGDO\"
|
||||
-DSTAPSK=\"93329248424922704583\"
|
||||
;-DSTASSID=\"MagentaWLAN-RGDO\"
|
||||
;-DSTAPSK=\"93329248424922704583\"
|
||||
-DSTASSID=\"Redmi-Note-11\"
|
||||
-DSTAPSK=\"51Fische#\"
|
||||
-DGATEWAY=\"192.168.127.1\"
|
||||
-DDNS=\"192.168.127.1\"
|
||||
-DSECONDARDNS=\"8.8.8.8\"
|
||||
@@ -94,6 +97,8 @@ build_flags = ${env.build_flags}
|
||||
-DSUBNET=\"255.255.255.0\"
|
||||
-Dmqtt_server=\"hjkmqtt.dedyn.io\"
|
||||
-DMQTTPORT=61883
|
||||
;-Dmqtt_server=\"192.168.127.193\"
|
||||
;-DMQTTPORT=1883
|
||||
-DCO2Wert=\"hjk/devices/257923/telemetry/co2\"
|
||||
-DAKKU=\"hjk/devices/WETTERSTATIONMARCEL/telemetry/battery\"
|
||||
-DWETTER=\"hjk/devices/WETTERSTATIONMARCEL/telemetry/temperature_Htu_21\"
|
||||
|
||||
52
src/main.cpp
52
src/main.cpp
@@ -117,6 +117,8 @@ u_int16_t EndederAbdunklung = 7;
|
||||
|
||||
//------ Speicher für Sekunden ------
|
||||
uint8_t SekOld = 99;
|
||||
uint8_t SekError = 0;
|
||||
uint16_t ErrorOld = 0;
|
||||
|
||||
// Wifi
|
||||
// Wifi
|
||||
@@ -168,6 +170,7 @@ bool NOHTU = false;
|
||||
bool readHtuFlag = true;
|
||||
float akku = 5.00;
|
||||
int Helligkeit = 255;
|
||||
bool MQTT_Error_Flag = false;
|
||||
|
||||
|
||||
|
||||
@@ -191,7 +194,7 @@ const char* topic_Akku = AKKU;
|
||||
const char* topic_Helligkeit = HELL;
|
||||
|
||||
void callback(char* topic1, byte* payload, unsigned int length);
|
||||
//void ZeigeZeit(int xPos);
|
||||
void ZeigeZeit(tm localTime,int xPos, int yPos);
|
||||
void scroll_text(uint8_t ypos, unsigned long scroll_delay, String text, uint8_t colorR, uint8_t colorG, uint8_t colorB, boolean blink);
|
||||
void scroll_text2(uint8_t ypos, unsigned long scroll_delay, String text, uint8_t colorR, uint8_t colorG, uint8_t colorB, boolean blink);
|
||||
void scroll_Grad(uint8_t ypos, unsigned long scroll_delay, String text, uint8_t colorR, uint8_t colorG, uint8_t colorB, boolean blink);
|
||||
@@ -342,7 +345,7 @@ void callback(char* topic1, byte* payload, unsigned int length) {
|
||||
#endif
|
||||
}
|
||||
void reconnect() {
|
||||
sprintf(clientName, "%s%s", "Uhr", "_Zentrale" );
|
||||
sprintf(clientName, "%s%s", "TEST", "_DISPLAY" );
|
||||
// Loop until we're reconnected
|
||||
while (!client.connected()) {
|
||||
Serial.print("Attempting MQTT connection...");
|
||||
@@ -363,6 +366,7 @@ void reconnect() {
|
||||
Serial.print(client.state());
|
||||
Serial.println(" try again in 5 seconds");
|
||||
scroll_text(32-7,80, "MQTT Error", 127,82,0, true);
|
||||
ErrorOld ++;
|
||||
// Wait 5 seconds before retrying
|
||||
delay(5000);
|
||||
}
|
||||
@@ -622,13 +626,17 @@ void Test()
|
||||
void setup() {
|
||||
startTime = millis();
|
||||
Serial.begin(115200);
|
||||
if (!htu.begin()) {
|
||||
/* if (!htu.begin()) {
|
||||
Serial.println("Couldn't find sensor!");
|
||||
NOHTU = true;
|
||||
delay(500);
|
||||
|
||||
} */
|
||||
init_HTU21();
|
||||
if (htu21Data.Status == true){
|
||||
read_HTU21D();
|
||||
}
|
||||
read_HTU21D();
|
||||
|
||||
Init_BME280();
|
||||
#ifndef CO2Wert
|
||||
beginC02();
|
||||
@@ -656,14 +664,14 @@ void setup() {
|
||||
|
||||
|
||||
//------- TEST -----------
|
||||
/* display.fillRect(31, 5, 2, 6, myRED);
|
||||
display.fillRect(31, 5, 2, 6, myRED);
|
||||
delay(2000);
|
||||
display.fillRect(31, 5, 2, 6, myGREEN);
|
||||
delay(2000);
|
||||
display.fillRect(31, 5, 2, 6, myBLUE);
|
||||
delay(2000);
|
||||
display.fillRect(31, 5, 2, 6, myBLACK);
|
||||
delay(2000); */
|
||||
delay(2000);
|
||||
//----------------------
|
||||
print_wifi_status();
|
||||
configTime(0, 0, NTP_SERVER);
|
||||
@@ -795,7 +803,7 @@ static void setup_wifi() {
|
||||
|
||||
//WiFi.forceSleepWake();
|
||||
delay( 1 );
|
||||
WiFi.config( ip, gateway, subnet, dns, secondarDNS);
|
||||
//WiFi.config( ip, gateway, subnet, dns, secondarDNS);
|
||||
|
||||
WiFi.begin(ssid, pass);
|
||||
|
||||
@@ -818,12 +826,32 @@ static void setup_wifi() {
|
||||
|
||||
|
||||
void loop() {
|
||||
|
||||
/* if (MQTT_Error_Flag == true){
|
||||
if (ErrorOld != timeinfo.tm_sec){
|
||||
ErrorOld = timeinfo.tm_sec;
|
||||
if (SekError <= 10){
|
||||
SekError ++ ;
|
||||
Serial.printf("MQTT ERROR: %5d \n",SekError);
|
||||
}
|
||||
else{
|
||||
SekError = 0;
|
||||
MQTT_Error_Flag = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!client.connected()) {
|
||||
reconnect();
|
||||
}
|
||||
|
||||
if (MQTT_Error_Flag == false) {
|
||||
if (!client.connected()) {
|
||||
reconnect();
|
||||
}
|
||||
} */
|
||||
|
||||
if (!client.connected()) {
|
||||
reconnect();
|
||||
Serial.printf("\n\n\t\tBis jetzt konnte %3d mal kein Kontakt zum MQTT-Server hergestellt werden.\n\n", ErrorOld);
|
||||
}
|
||||
getNTPtime(10);
|
||||
client.loop();
|
||||
|
||||
@@ -856,7 +884,9 @@ void loop() {
|
||||
{
|
||||
if (readHtuFlag == true)
|
||||
{
|
||||
read_HTU21D();
|
||||
if (htu21Data.Status == true){
|
||||
read_HTU21D();
|
||||
}
|
||||
if (BME280Data.Status == true) {
|
||||
Read_BME280();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user