Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Arduino demo source code for KC868-A4]-14 MQTT demo
#11
your relay board connect to mqtt broker server, your home assistant also need connect to same server by mqtt.
Reply
#12
(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


Attached Files Image(s)
   
Reply
#13
good, it's work now.
Reply
#14
(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));
  }
Reply
#15
check your code, whether read ds18b20 data is correctly. or issue is during your MQTT code.
Reply
#16
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


Attached Files
.txt   mqtt.txt (Size: 9.68 KB / Downloads: 173)
Reply
#17
you can use serial output ds18b20 value in different code position, test which section have issue.
Reply
#18
(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
  }
}
Reply
#19
ok
Reply


Forum Jump:


Users browsing this thread:
1 Guest(s)