MQTT client examples based emqtt
- Connecting via TCP/TLS/WS/WSS examples.
- Publish/Subscribe examples.
- Async publish examples.
- Receiving messages example.
- Compile it first
rebar3 compile
- Start application
rebar3 shell
- Run the TCP examples, i.e:
1> mqttex:run(tcp).
publish msg[1] success!
publish msg[2] success!
publish msg[3] success!
async publish msg[1] success
async publish msg[2] success
async publish msg[3] success
subscribe/unsubscribe success
publisher publish success
received message topic: <<"testtopic/1">>, payload: <<"123456">>
ok
2>
Of course, you can also run example programs based on other communication layers by executing mqttex:run(tls)
or mqttex:run(ws)
or mqttex:run(wss)
.