Skip to content

Commit bb2a483

Browse files
author
xlyric
committed
correction bug reco MQTT
1 parent b3263c5 commit bb2a483

File tree

5 files changed

+29
-17
lines changed

5 files changed

+29
-17
lines changed

src/config/config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ constexpr size_t NTP_UPDATE_INTERVAL_MS = 3600000; /// synch de l'heure toute le
154154
// #define ARDUINO_RUNNING_CORE 1
155155
#endif
156156

157-
#define RELEASE "Version 20250418"
157+
#define RELEASE "Version 20250422"
158158
constexpr const int FS_RELEASE = 20250324;
159159

160160
#ifdef LIGHT_FIRMWARE

src/config/enums.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
//***********************************
2828
//************* Constantes
2929
//***********************************
30-
#define TABLEAU_SIZE 16 // NOSONAR
30+
#define TABLEAU_SIZE 7 // NOSONAR
3131
#define SECURITEPASS "MyPassword" // NOSONAR
3232
#if DEBUG == true
3333
#define serial_print(x) Serial.print (x)
@@ -40,7 +40,7 @@
4040
//***********************************
4141
//************* Variable locales
4242
//***********************************
43-
int tableaudemo[TABLEAU_SIZE] = {180, 180, 0, 0, -150, -150, 4, 4 ,180, 180, 5,5, -150 ,-150, 2,2 }; // NOSONAR
43+
int tableaudemo[TABLEAU_SIZE] = {180, 3, -150, 4, 150, 5, -180}; // NOSONAR
4444

4545
//***********************************
4646
//************* class DEVICE_STATE

src/functions/Mqtt_http_Functions.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,13 @@ WiFiClient espClient;
8787
} else {
8888
Serial.print("MQTT failed, retcode=");
8989
Serial.print(client.state());
90-
Serial.println(" try again in 2 seconds");
90+
Serial.println(" try again in 5 seconds");
9191
///dans le doute si le mode AP est actif on le coupe
9292
Serial.println(WiFi.status());
9393

9494
// Wait 2 seconds before retrying
95-
delay(2000); // 24/01/2023 passage de 5 à 2s
95+
yield(); // permet de libérer le CPU pour d'autres tâches
96+
delay(5000); // 24/01/2023 passage de 5 à 2s
9697
} // else
9798
} // while
9899
}
@@ -230,14 +231,12 @@ WiFiClient espClient;
230231
client.subscribe(("memory/"+compteur_grid.topic+"#").c_str());
231232
client.loop();
232233

233-
if (xSemaphoreTake(mutex, portMAX_DELAY)) { // Prend le mutex
234234
if (config.IDXdimmer != 0 ) {
235235
Mqtt_send(String(config.IDXdimmer),"0","","Dimmer");
236236
}
237237
if (strcmp(config.topic_Shelly,"none") != 0)
238238
client.subscribe(config.topic_Shelly);
239-
xSemaphoreGive(mutex); // Libère le mutex
240-
}
239+
241240
}
242241
#endif //ifndef LIGHT_FIRMWARE
243242
#endif //ifndef MQTT_FUNCTIONS

src/main.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -767,10 +767,10 @@ void loop() {
767767

768768

769769

770-
771-
int retry_wifi = 0;
772-
773770
#ifdef DEBUGLEVEL1
771+
// test de la connexion client mqtt
772+
Serial.print("client connected ? :");
773+
Serial.println(client.connected());
774774
//// test de synchro pour debug
775775
if (dimmer1.getsync()) {
776776
Serial.println("sync ok");
@@ -806,6 +806,18 @@ void loop() {
806806
printTaskStack(myTaskwatchdogmemory, "myTaskwatchdogmemory");
807807
#endif
808808

809+
//**** Loop - vérification de la connexion au serveur MQTT ****
810+
#ifndef LIGHT_FIRMWARE
811+
if (config.mqtt) {
812+
if (!client.connected()) {
813+
reconnect();
814+
}
815+
client.loop(); // Keep the MQTT connection alive
816+
}
817+
#endif // not LIGHT_FIRMWARE
818+
819+
int retry_wifi = 0;
820+
809821
//***********************************
810822
//************* Loop - web socket loop
811823
//***********************************
@@ -884,13 +896,13 @@ void loop() {
884896
strcpy(programme_marche_forcee.heure_demarrage, "00:00"); // NOSONAR
885897
strcpy(programme_marche_forcee.heure_arret, "00:00"); // NOSONAR
886898
/// remonté MQTT
887-
#ifndef LIGHT_FIRMWARE
899+
/* #ifndef LIGHT_FIRMWARE
888900
Mqtt_send(String(config.IDX), String(unified_dimmer.get_power()),"pourcent"); // remonté MQTT de la commande réelle
889901
if (configmqtt.HA) {
890902
int instant_power = unified_dimmer.get_power();
891903
device_dimmer.send(String(instant_power * config.charge/100));
892904
}
893-
#endif // not LIGHT_FIRMWARE
905+
#endif */ // not LIGHT_FIRMWARE
894906
} // if (programme.stop_progr() || programme_marche_forcee.stop_progr() )
895907
} // if (programme.run || programme_marche_forcee.run)
896908

@@ -910,7 +922,7 @@ void loop() {
910922
//demarrage du ventilateur
911923
digitalWrite(COOLER, HIGH);
912924
/// remonté MQTT
913-
#ifndef LIGHT_FIRMWARE
925+
/* #ifndef LIGHT_FIRMWARE
914926
915927
Mqtt_send(String(config.IDX), String(unified_dimmer.get_power()),"pourcent"); // remonté MQTT de la commande réelle
916928
if (configmqtt.HA) {
@@ -921,6 +933,7 @@ void loop() {
921933
}
922934
}
923935
#endif // not LIGHT_FIRMWARE
936+
*/
924937
} // if (programme.start_progr() || programme_marche_forcee.start_progr() )
925938
} // else
926939
} // if (config.dimmerlocal)

src/tasks/send-mqtt.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void send_to_mqtt(void * parameter) { // NOSONAR
8181
long timemesure = start-beforetime;
8282
float wattheure = (timemesure * abs(gDisplayValues.watt) / timemilli);
8383
#ifndef LIGHT_FIRMWARE
84-
if (xSemaphoreTake(mutex, portMAX_DELAY)) {
84+
8585
// domoticz et jeedom
8686
if (config.IDX != 0 ) {
8787
Mqtt_send(String(config.IDX), String(int(gDisplayValues.watt)),"","watt");
@@ -138,13 +138,13 @@ void send_to_mqtt(void * parameter) { // NOSONAR
138138
}
139139
}
140140
//maj 202030209
141-
xSemaphoreGive(mutex); // Libère le mutex
141+
142142
#endif // not LIGHT_FIRMWARE
143143

144144
beforetime = start;
145145
Pow_mqtt_send = 0 ;
146146

147-
}
147+
148148
#endif
149149
}
150150

0 commit comments

Comments
 (0)