MQTT
Using the MQTT-client sample bundle
The MQTT-client sample bundle in samples/mqtt-client shows how to connect to
an MQTT server. This client is based on the
MQTT.js package.
Prerequisites
You will need a working nodecg-io installation. If you have non yet take a
look at installation guide. You may need to
install this bundle, so take a look at the
“Try an included sample”-Guide. It
will also tell you how to log in and how to use the GUI.
You also need:
- MQTT-server
Configure the MQTT-client sample bundle
-
In NodeCG, create a new mqtt-client service instance.
-
Enter the connection parameters of the mqtt server. The URL should be in following the pattern
<protocol>://<address>:<port>. Allowed protocols are:mqtt,mqtts,tcp,tls,ws,wss.In case your server needs authentication, set the
usernameandpasswordfields otherwise remove them from the configuration:{ "address": "mqtt://localhost", "topics": ["sample/topic", "diffrent/topic2"], "username": "yourUser", "password": "yourPassword" }After entering it, click save.
-
Set the sample's (
mqtt-client) dependency to be the newly created service instance (of typemqtt-client). - The console should display if the connection was successfully established and should show inbound messages on the subscribed topic.