03-04-2023, 11:04 PM
Pages: 1 2
03-06-2023, 03:53 AM
(03-04-2023, 11:04 PM)admin Wrote: [ -> ]your relay board connect to mqtt broker server, your home assistant also need connect to same server by mqtt.
thank you, I have a connection of the card, I can listen to the topic and order the relays
03-06-2023, 08:11 AM
good, it's work now.
03-09-2023, 10:40 AM
(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));
}03-09-2023, 12:25 PM
check your code, whether read ds18b20 data is correctly. or issue is during your MQTT code.
03-09-2023, 12:43 PM
the ds18b20 data read is correct in the serial monitor, I do not understand where my error comes from, I have little knowledge of coding
03-09-2023, 02:17 PM
you can use serial output ds18b20 value in different code position, test which section have issue.
03-10-2023, 09:17 AM
(03-09-2023, 02:17 PM)admin Wrote: [ -> ]you can use serial output ds18b20 value in different code position, test which section have issue.
I found
I created a read function of 2 probes and send by mqtt
tank you
Code:
void lecturePublication()
{
long now = millis();
//Envoi d'un message par minute
if (now - lastMsg > 1000 * 10) {
lastMsg = now;
sensors.requestTemperatures();
float temp_depart = sensors.getTempC(sensor1);
float temp_retour = sensors.getTempC(sensor2);
if ( debug ) {
Serial.print("Temperature : ");
Serial.print("Sensor 1(*C): ");
Serial.print(sensors.getTempC(sensor1));
Serial.print("Sensor 2(*C): ");
Serial.print(sensors.getTempC(sensor2));
}
client.publish(temperature_topic_depart, String(temp_depart).c_str(), true); //Publie la température sur le topic temperature_topic_depart
client.publish(temperature_topic_retour, String(temp_retour).c_str(), true); //Publie la température sur le topic temperature_topic_retour
}
}03-10-2023, 09:38 AM
ok
Pages: 1 2