Have you tried reconfiguring the MQTT integration in Gladys?
Simply, change the password then click ‹ Save ›.
Then check the container status…
OK thanks for the info
[quote="GBoulvin, post:121, topic:6272
You’ve got one for zigbee2mqtt, so that’s normal ![]()
You should say a bit more.
Yes zigbee2mqtt but also MQTT(Mosquitto)

According to my friend I had also installed Mosquitto a second time. That was the problem.
By removing one of the two Mosquitto instances, no more issues!
So is it working or not? Are you seeing the information come through?
Yes, it’s working
Thank you all
![]()
Hello everyone,
I got started but after several attempts I still get this in the serial monitor :
ets Jan 8 2013,rst cause:4, boot mode:(3,6)
12:58:34.798 -\u003e
12:58:34.798 -\u003e wdt reset
12:58:34.798 -\u003e load 0x4010f000, len 3424, room 16
12:58:34.798 -\u003e tail 0
12:58:34.798 -\u003e chksum 0x2e
12:58:34.798 -\u003e load 0x3fff20b8, len 40, room 8
12:58:34.798 -\u003e tail 0
12:58:34.798 -\u003e chksum 0x2b
12:58:34.798 -\u003e csum 0x2b
12:58:34.798 -\u003e v000456d0
12:58:34.798 -\u003e ~ld
12:58:34.892 -\u003e ⸮\u001c\u000
Hi @Tornes
What kind of board do you have? A D1 mini?
yes, that’s right, I just got a result by modifying the code as follows :
only the returned value is always 100 regardless of the sensor’s distance
I have checked the pins are in the right place (D6 and D7)
PS: if I used the code given in the first post it didn’t work ![]()
Where do you see a result of 100?
Your serial monitor screenshot doesn’t show anything. Did you flash your board properly? I have the impression it’s not being recognized.
I can see the result in MQTT Explorer.
I suppose so since the monitor shows WiFi/MQTT OK and I’m getting MQTT messages on the correct topic.
EDIT: I tried different types of boards without success with the code given on the first page; however with Doudy’s code it works — I just always have the same value ![]()
Can you copy the entire code using the tags, please, so I can take a look?
Here:
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
/* WIFI */
#define wifi_ssid "XXX" // your wifi ssid
#define wifi_password "XXX" // your wifi password
/* MQTT */
#define mqtt_server "XXXXX"
#define mqtt_user nullptr // username
#define mqtt_password nullptr // MQTT password
#define gladys_topic "gladys/master/device/mqtt:jardin:capteur-ultrason/feature/mqtt: jardin:capteur-ultrason:quantite/state"
#define mqtt_cuve "mqtt:jardin:capteur-ultrason" // Tank sensor topic
/* Buffer qui permet de décoder les messages MQTT reçus */
char message_buff[100];
long lastMsg = 0; // Timestamp of the last message published to MQTT
long lastRecu = 0;
bool debug = false; // Displays on the console if True
/* Constantes pour les broches */
const byte TRIGGER_PIN = 7; // TRIGGER pin
const byte ECHO_PIN = 6; // ECHO pin
/* Constantes pour le timeout */
const unsigned long MEASURE_TIMEOUT = 25000UL; // 25ms = ~8m at 340m/s
/* Vitesse du son dans l'air en mm/us */
const float SOUND_SPEED = 340.0 / 1000;
// Création des objets
WiFiClient espClient;
PubSubClient mqttclient(espClient);
void setup() {
/* Initialise le port serie */
Serial.begin(115200); //Facultatif pour le debug
while (! Serial){
delay(1);
/* Initialise les broches */
pinMode(TRIGGER_PIN, OUTPUT);
digitalWrite(TRIGGER_PIN, LOW); // The TRIGGER pin must be LOW at rest
pinMode(ECHO_PIN, INPUT);
}
setup_wifi(); //We connect to the wifi network
mqttclient.setServer(mqtt_server, 1883); // Configure MQTT server connection
}
void setup_wifi() {
delay(10);
Serial.println("\\r\\n\\r\\nxxxxxxxxxxx START xxxxxxxxxxxxxxx");
Serial.print("Connexion à ");
Serial.println(wifi_ssid);
//WiFi.disconnect();
//WiFi.mode(WIFI_STA);
WiFi.begin(wifi_ssid, wifi_password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println(".");
Serial.print("Connexion WiFi établie ");
Serial.print("=> Adresse IP : ");
Serial.println(WiFi.localIP());
}
//Reconnexion
void reconnect() {
Serial.print("Test MQTT : ");
Serial.print("=> Adresse IP : ");
Serial.println(mqtt_server);
// Loop until reconnected
while (!mqttclient.connected()) {
Serial.print("Connexion au serveur MQTT...");
if (mqttclient.connect("ESP8266Client", mqtt_user, mqtt_password)) {
Serial.println("OK");
} else {
Serial.print("KO, erreur : ");
Serial.print(mqttclient.state());
Serial.println(" On attend 5 secondes avant de recommencer");
delay(5000);
}
}
}
void loop() {
if (!mqttclient.connected()) {
reconnect();
}
mqttclient.loop();
long now = millis();
/* Send a message every minute*/
if (now - lastMsg > 1000 * 60) {
lastMsg = now;
/* 1. Start a distance measurement by sending a 10µs HIGH pulse on the TRIGGER pin */
digitalWrite(TRIGGER_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIGGER_PIN, LOW);
/* 2. Measure the time between sending the ultrasonic pulse and its echo (if it exists) */
long measure = pulseIn(ECHO_PIN, HIGH, MEASURE_TIMEOUT);
/* 3. Calculate the distance from the measured time */
int distance_mm = measure / 2.0 * SOUND_SPEED;
float c = 2600 - distance_mm; // VERY IMPORTANT Replace 2000 with the height of your tank
c = c / 2600;
c = c * 100;
// No need to go further if the sensor returns nothing
if ( isnan(c)) {
Serial.println("Echec de lecture ! Verifiez votre capteur HRC-04");
return;
}
if ( debug ) {
Serial.print("Cuve : ");
Serial.print(c);
}
mqttclient.publish(gladys_topic, String(c).c_str(), true); // Publish the % of the tank on the topic in gladys
}
}
That looks good to me.
Have you already tested your ultrasonic sensor with another code, for example for a measurement or something, to see if it’s working properly?
No, that’s what I’m going to do then to validate that it works.
Thanks in any case for checking the code; however, how can I explain that I had to modify it compared to yours?
Indeed, that’s not logical. I should test it again on a fresh install to check, because I had tinkered with it quite a bit back then.
Can you confirm that in the serial monitor the connection is properly established but that afterward it displays « tank: 100 » in a loop every minute?
On the monitor it shows « WiFi connection established, MQTT OK » but that’s all. I can see the 100 in the MQTT messages it sends.
You should then have « tank: … » with the value reported by your sensor. That’s not normal.
Ah ok … is your code identical to the one posted in the first post?