• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

main/11-Mar-2024-190139

CMakeLists.txtD11-Mar-2024462 118

MakefileD11-Mar-2024266 103

README.mdD11-Mar-20242.6 KiB6044

mqtt_tcp_example_test.pyD11-Mar-20243.6 KiB10181

sdkconfig.ciD11-Mar-2024405 1312

README.md

1# ESP-MQTT sample application
2(See the README.md file in the upper level 'examples' directory for more information about examples.)
3
4This example connects to the broker URI selected using `idf.py menuconfig` (using mqtt tcp transport) and as a demonstration subscribes/unsubscribes and send a message on certain topic.
5(Please note that the public broker is maintained by the community so may not be always available, for details please see this [disclaimer](https://iot.eclipse.org/getting-started/#sandboxes))
6
7Note: If the URI equals `FROM_STDIN` then the broker address is read from stdin upon application startup (used for testing)
8
9It uses ESP-MQTT library which implements mqtt client to connect to mqtt broker.
10
11## How to use example
12
13### Hardware Required
14
15This example can be executed on any ESP32 board, the only required interface is WiFi and connection to internet.
16
17### Configure the project
18
19* Open the project configuration menu (`idf.py menuconfig`)
20* Configure Wi-Fi or Ethernet under "Example Connection Configuration" menu. See "Establishing Wi-Fi or Ethernet Connection" section in [examples/protocols/README.md](../../README.md) for more details.
21* When using Make build system, set `Default serial port` under `Serial flasher config`.
22
23### Build and Flash
24
25Build the project and flash it to the board, then run monitor tool to view serial output:
26
27```
28idf.py -p PORT flash monitor
29```
30
31(To exit the serial monitor, type ``Ctrl-]``.)
32
33See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
34
35## Example Output
36
37```
38I (3714) event: sta ip: 192.168.0.139, mask: 255.255.255.0, gw: 192.168.0.2
39I (3714) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
40I (3964) MQTT_CLIENT: Sending MQTT CONNECT message, type: 1, id: 0000
41I (4164) MQTT_EXAMPLE: MQTT_EVENT_CONNECTED
42I (4174) MQTT_EXAMPLE: sent publish successful, msg_id=41464
43I (4174) MQTT_EXAMPLE: sent subscribe successful, msg_id=17886
44I (4174) MQTT_EXAMPLE: sent subscribe successful, msg_id=42970
45I (4184) MQTT_EXAMPLE: sent unsubscribe successful, msg_id=50241
46I (4314) MQTT_EXAMPLE: MQTT_EVENT_PUBLISHED, msg_id=41464
47I (4484) MQTT_EXAMPLE: MQTT_EVENT_SUBSCRIBED, msg_id=17886
48I (4484) MQTT_EXAMPLE: sent publish successful, msg_id=0
49I (4684) MQTT_EXAMPLE: MQTT_EVENT_SUBSCRIBED, msg_id=42970
50I (4684) MQTT_EXAMPLE: sent publish successful, msg_id=0
51I (4884) MQTT_CLIENT: deliver_publish, message_length_read=19, message_length=19
52I (4884) MQTT_EXAMPLE: MQTT_EVENT_DATA
53TOPIC=/topic/qos0
54DATA=data
55I (5194) MQTT_CLIENT: deliver_publish, message_length_read=19, message_length=19
56I (5194) MQTT_EXAMPLE: MQTT_EVENT_DATA
57TOPIC=/topic/qos0
58DATA=data
59```
60