Code Monkey home page Code Monkey logo

Comments (6)

AmrutaCh avatar AmrutaCh commented on August 15, 2024 1

@souxx and @wdouglas1999
Declare mqttClient as global variable and use it

// global declaration
esp_mqtt_client_handle_t mqttClient;

// initialize
esp_mqtt_client_config_t mqtt_cfg = {
...
...
...};

mqttClient = esp_mqtt_client_init(&mqtt_cfg);
esp_mqtt_client_start(mqttClient);

// subscribe
esp_mqtt_client_subscribe(mqttClient, topic, qos);

// publish
esp_mqtt_client_publish(mqttClient, topic, data, dataLength, qos, retain);

Hope this is helpful

from esp-mqtt.

DarioB92 avatar DarioB92 commented on August 15, 2024 1

Hello, thanks for your work, however I still cannot understand how to to receive a message from a subscribed topic. Do I have to set a callback function? A commented exemple of publishing and receiving a message could be real helpful. Thanks!

from esp-mqtt.

wdouglas1999 avatar wdouglas1999 commented on August 15, 2024 1

@ DarioB92,

I ended up using the example following example code on github.

https://github.com/jessebraham/esp32-mqtt-client/blob/master/main/esp32-mqtt-client.c

I hope it will help you.

from esp-mqtt.

AmrutaCh avatar AmrutaCh commented on August 15, 2024 1

@DarioB92 mqtt_event_handler is the required call back you are talking about and it is already set up. Whenever any message is available for subscribed topic MQTT_EVENT_DATA event will occur.

case MQTT_EVENT_DATA:
ESP_LOGI(TAG, "MQTT_EVENT_DATA");
printf("TOPIC=%.*s\r\n", event->topic_len, event->topic);
printf("DATA=%.*s\r\n", event->data_len, event->data);
break;

This will give you all required data regarding the received message. If you have basic knowledge of mqtt protocol, I think, the examples given in the repo are self-explanatory. You just need to try them.

from esp-mqtt.

wdouglas1999 avatar wdouglas1999 commented on August 15, 2024

@souxx,
Good day,
Have you managed to figure out how to subscribe and publish massages yet? I would also like a basic example of how to do this.

from esp-mqtt.

david-cermak avatar david-cermak commented on August 15, 2024

Closing this older issue, as it seems it has been answered. Please feel free to reopen or raise a new one if it's not the case.

from esp-mqtt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.