Authentication and Topic Generation (MQTT) - Ravi-Pansuriya/Geeky GitHub Wiki
Authentication
Authentication is required to authenticate the MQTT client while connecting to the server. This way it helps server to keep only clients connected which are genuine.
To authenticate you need your registered email as username and Auth key as password. (you can find auth key at dashboard of web panel)
If you are using GeekyMQTT
you just have to simply pass username and password along with WiFiClient
while creating class object.
// Publisher
MQTTPublisher publisher(client, Username, AuthKey);
// Subscriber
MQTTSubscriber subscriber(client, Username, AuthKey);
Or if you are using PubSubClient
client.connect(clientId, Username, Password));
Check here for more detail about connect
method.
Same way you can authenticate your MQTT client if you are using any other client for your development board.
Topic
In MQTT, the word topic refers to an UTF-8 string that the broker uses to filter messages for each connected client. The topic consists of one or more topic levels. Each topic level is separated by a forward slash (topic level separator).
In comparison to a message queue, MQTT topics are very lightweight.
GeekyMQTT has multilevel and very specific topic structure for different devices/sensors listed under same controller. You can choose to subscribe either specific device/sensor or all devices/sensor of specified controller. To publish message you have to specify topic till 3rd level.
Don't understand? let's look at format below:
Example:
String topic;
topic = controllerId + "/devices/" + deviceId;
and if you wish to subscribe for multiple devices you can use # (wildcard) at topic level 3. It will listen all the messages published for devices/sensors for specified controller.
Example:
topic = controllerId + "/devices/#"; // for all devices
topic = controllerId + "/sensors/#"; // for all sensors
and of course you can use wild card (#) at topic level 2 to listen all the messages of devices and sensors all together.
topic = controllerId + "/#"; // for all devices and sensors