Smart Home Automation Forum
[Arduino demo source code for KC868-A4]-14 MQTT demo - Printable Version

+- Smart Home Automation Forum (https://www.kincony.com/forum)
+-- Forum: Technical Support (https://www.kincony.com/forum/forumdisplay.php?fid=20)
+--- Forum: KC868-A4 (https://www.kincony.com/forum/forumdisplay.php?fid=21)
+--- Thread: [Arduino demo source code for KC868-A4]-14 MQTT demo (/showthread.php?tid=1843)

Pages: 1 2


RE: [Arduino demo source code for KC868-A4]-14 MQTT demo - admin - 03-04-2023

your relay board connect to mqtt broker server, your home assistant also need connect to same server by mqtt.


RE: [Arduino demo source code for KC868-A4]-14 MQTT demo - ledouble33 - 03-06-2023

(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


RE: [Arduino demo source code for KC868-A4]-14 MQTT demo - admin - 03-06-2023

good, it's work now.


RE: [Arduino demo source code for KC868-A4]-14 MQTT demo - ledouble33 - 03-09-2023

(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-mqtt-publish-ds18b20-temperature-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));
  }



RE: [Arduino demo source code for KC868-A4]-14 MQTT demo - admin - 03-09-2023

check your code, whether read ds18b20 data is correctly. or issue is during your MQTT code.


RE: [Arduino demo source code for KC868-A4]-14 MQTT demo - ledouble33 - 03-09-2023

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


RE: [Arduino demo source code for KC868-A4]-14 MQTT demo - admin - 03-09-2023

you can use serial output ds18b20 value in different code position, test which section have issue.


RE: [Arduino demo source code for KC868-A4]-14 MQTT demo - ledouble33 - 03-10-2023

(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
  }
}



RE: [Arduino demo source code for KC868-A4]-14 MQTT demo - admin - 03-10-2023

ok