03-09-2023, 10:40 AM
(This post was last modified: 03-09-2023, 12:08 PM by ledouble33.)
(03-06-2023, 08:11 AM)administrateur Wrote: Bon, ça marche maintenant.I try to integrate ds18b20 I was inspired by the following tutorial (https://randomnerdtutorials.com/esp32-mq...e-arduino/)
in the serial monitor the temperature changes well but when I listen in home assistant the temperature value does not change it is always 21.94 C
I have a doubt about the following code part
Code:
unsigned long currentMillis = millis();
// Every X number of seconds (interval = 10 seconds)
// it publishes a new MQTT message
if (currentMillis - previousMillis >= interval) {
// Save the last time a new reading was published
previousMillis = currentMillis;
// New temperature readings
sensors.requestTemperatures();
// Temperature in Celsius degrees
temperature1 = sensors.getTempCByIndex(0);
// Temperature in Fahrenheit degrees
//temp = sensors.getTempFByIndex(0);
// Publish an MQTT message on topic esp32/ds18b20/temperature
uint16_t packetIdPub1 = mqttClient.publish(MQTT_PUB_TEMP, 1, true, String(temperature1).c_str());
Serial.printf("Publishing on topic %s at QoS 1, packetId: ", MQTT_PUB_TEMP);
Serial.println(packetIdPub1);
Serial.printf("Message: %.2f /n", sensors.getTempCByIndex(0));
}