Comments (6)
@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.
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.
@ 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.
@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.
@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.
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)
- Is it safe to use 'strlen'? (IDFGH-8733) HOT 2
- Feature request: Add menuconfig option to prefer PSRAM when allocating outbox buffers. (IDFGH-8993) HOT 6
- MQTT5 "flow control" gets out of sync, prevents message sending (IDFGH-9028) HOT 3
- Bug: esp_mqtt_client_publish deadlock (IDFGH-9038) HOT 4
- Make `MQTT_POLL_READ_TIMEOUT_MS` configurable through `menuconfig/sdkconfig` (IDFGH-9196) HOT 2
- printf nano formatting and using "%zu" in debug log messages (IDFGH-9208) HOT 1
- Publish data leaking to topic (IDFGH-9290) HOT 5
- Not compatible with CPP, IDF 5.0 (IDFGH-9334) HOT 5
- How can I detect Expired certificates (IDFGH-9420) HOT 3
- ESP-IDF won't connect to MQTT broker local gateway IP (IDFGH-9465) HOT 4
- Init multiple network components in separate network interfaces (IDFGH-9466) HOT 2
- MQTT 5 Bug - Checks packet header but there is none (IDFGH-9603) HOT 1
- esp_mqtt_client_publish() does not return -1 for QOS0 when disconnect (IDFGH-10129) HOT 1
- Possible bug on mqtt5 client when QoS>0 (IDFGH-10436) HOT 3
- MQTT QOS2 not resend PUBREC ACKNOWLEDGED message (IDFGH-10609)
- Qos 2 wrong implementation (IDFGH-10613) HOT 5
- Last Will Message pushed when I reconnect (IDFGH-10970) HOT 1
- esp_mqtt_set_config ignores buffer_size (IDFGH-11058) HOT 2
- AUTH command not supported (IDFGH-11745)
- MQTT data persistence (QOS 1 and 2) (IDFGH-12616) HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from esp-mqtt.