Unable to data to Esp32

Hello Everyone I am working on a project in which i have to take user input(numeric value) and send it to esp32 using mosquitto mqtt broker. can anyone guide me how to do that and how to parse the data in esp32? i have done receiving part and its working perfectly but unable to send the data., kindly guide me..

have you tried a google search 'esp32 mqtt tutorial'?

1 Like

You might want to share what you have done so far as well.

1 Like

Yes i have checked almost all tutorials but no one is sending user input to esp32 they are just doing the receiving part

There are hundreds of examples - search Google for mqtt esp32

Check out the function named messageReceived in this one...
"ESP32 MQTT Tutorial - valvers.com" ESP32 MQTT Tutorial - valvers.com

1 Like

You don't send data from one mqtt client to another. You send it to the broker from one client, and the other client subscribes to the topic in order that the broker sends it the data. What you need to google for is how to subscribe to an mqtt broker from an esp32.

1 Like

I'm using ESP8266 devices which are very similar to the ESP32, and there are several MQTT libraries available. I found @knolleary's "pubsubclient" (GitHub - knolleary/pubsubclient: A client library for the Arduino Ethernet Shield that provides support for MQTT.) very easy to work with, and have had no problems sending and receiving packets using it.

For parsing packets that will depend on your message format, but in my case I use JSON for all messages and include cJSON (GitHub - DaveGamble/cJSON: Ultralightweight JSON parser in ANSI C) in my ESP8266 build. It's small, fast and handles all the basic JSON structures I need.

1 Like

Another very useful library is... ArduinoJson especially if you need to serialise or deserialise MQTT data.
Make sure you get the latest version (6.18.0) as it makes dealing with data a 'breeze'.

1 Like

Thank you Everyone for your kind response, I have successfully received the data in esp32.. data is in json format need to parse only i will look in for json libraries. thankyou anyways

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.