Hi
I need to publish some data on MQTT server.
I have done it using PubSubClient but it stop to work if web client is turn on ( this line in particular ESP32_Client = server.available(); )
I would ask if exist an arduino example that use IDF core library or some other good MQTT client
Thanks
MQTT example for Arduino
Re: MQTT example for Arduino
I have the Webserver and PubSubClient working together without any problems. I checked my code and didn't use server.available() anywhere so can't answer if that function is a problem for me. Why do you need it? I use the server.handleClient() method as it takes care of all the client gorp on its own.
Here are my web object declarations:
and my initialization calls:
and my handler loop (in a core 0 task):
Here are my web object declarations:
Code: Select all
WebServer server(80);
WiFiClient espClient;
PubSubClient mqttClient(espClient);
Code: Select all
server.begin();
MDNS.addService("http", "tcp", 80);
//=======================================================================================
// set up MQTT connection
//=======================================================================================
mqttClient.setServer(mqtt_server, 1883);
mqttClient.setCallback(callback);
Code: Select all
// finally, create a loop to monitor the web & MQTT interfaces
//===========================================================================
// 'LOOP' (Core 0)
//===========================================================================
while (1) {
ArduinoOTA.handle();
server.handleClient();
// now take care of MQTT client...
if (!mqttClient.connected()) {
reconnect();
} else
{
mqttClient.loop();
// manage publications...
if (bGotPublication) {
char topic[80];
sprintf(topic,"%s_out/%s",clientID,pubTopic);
mqttClient.publish(topic,pubMsg);
bGotPublication = false; // signal sent
}
}
delay(10); // add delay so task yields...
}
Re: MQTT example for Arduino
Hi TomWS1
Now I use ESPmDNS class and it work well
Thanks
Now I use ESPmDNS class and it work well
Thanks
Who is online
Users browsing this forum: No registered users and 54 guests