ioTracks MQTT client version 0.2 (beta-release)

The MQTT adapter microservice has been created to make MQTT-related development easier. This microservice allows you to convert MQTT-messages to ioMessage format and vice versa.

You can use it as a subscriber or as a publisher - or even both as a publisher and a subscriber at the same time.

It is capable of working both with remote MQTT brokers and a local one that runs in the Docker container.


Whenever you wish to publish message to broker, send ioMessage to MQTT client using the following format:

"infotype" : "mqtt/message"

"infoformat" : "application/json"

"contextdata" : json containing "topic" and "qos", e.g. {"topic" : "home/water/sensor", "qos": 2}

"contentdata" : your message payload (any useful data)


There are three possible schemes of usage:

1) Usage as a message publisher.

This MQTT client will convert messages received from the generator from ioMessage format to MQTT format; it will then send converted messages to the public MQTT broker located at test.mosquitto.org.

In this case, you have to attach a message publisher. In this example we've used "sashayakovtseva/iotracks:generator-with-infotype" image with hardcoded payload, but you'll likely want to use some other message generator.

MQTT-01-publisher.png


JSON config for message generator:

{
	"frequency" : 3000, 
	"infotype" : "mqtt/message",
	"infoformat" : "application/json",
	"topic" : "home/water/sensor",
	"qos": 2
}

JSON config for MQTT client:

{
	"broker" : {"host": "test.mosquitto.org", "port" : 8883},
	"ca_cert" : "MIIC8DCCAlmgAwIBAgIJAOD63PlXjJi8MA0GCSqGSIb3DQEBBQUAMIGQMQswCQYDVQQGEwJHQjEXMBUGA1UECAwOVW5pdGVkIEtpbmdkb20x
	DjAMBgNVBAcMBURlcmJ5MRIwEAYDVQQKDAlNb3NxdWl0dG8xCzAJBgNVBAsMAkNBMRYwFAYDVQQDDA1tb3NxdWl0dG8ub3JnMR8wHQYJKoZIhvcNAQkBFhByb
	2dlckBhdGNob28ub3JnMB4XDTEyMDYyOTIyMTE1OVoXDTIyMDYyNzIyMTE1OVowgZAxCzAJBgNVBAYTAkdCMRcwFQYDVQQIDA5Vbml0ZWQgS2luZ2RvbTEOMA
	wGA1UEBwwFRGVyYnkxEjAQBgNVBAoMCU1vc3F1aXR0bzELMAkGA1UECwwCQ0ExFjAUBgNVBAMMDW1vc3F1aXR0by5vcmcxHzAdBgkqhkiG9w0BCQEWEHJvZ2V
	yQGF0Y2hvby5vcmcwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMYkLmX7SqOT/jJCZoQ1NWdCrr/pq47m3xxyXcI+FLEmwbE3R9vMrE6sRbP2S89pfrCt
	7iuITXPKycpUcIU0mtcT1OqxGBV2lb6RaOT2gC5pxyGaFJ+hA+GIbdYKO3JprPxSBoRponZJvDGEZuM3N7p3S/lRoi7G5wG5mvUmaE5RAgMBAAGjUDBOMB0GA
	1UdDgQWBBTad2QneVztIPQzRRGj6ZHKqJTv5jAfBgNVHSMEGDAWgBTad2QneVztIPQzRRGj6ZHKqJTv5jAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA4
	GBAAqw1rK4NlRUCUBLhEFUQasjP7xfFqlVbE2cRy0Rs4o3KS0JwzQVBwG85xgeREyPOFdGdhBY2P1FNRy0MDr6xr+D2ZOwxs63dG1nnAnWZg7qwoLgpZ4fESP
	D3PkA1ZgKJc2zbSQ9fCPxt2W3mdVav66c6fsb7els2W2Iz7gERJSX"
}


2) Usage as a subscriber.

(Don't remove the previous elements so that you can see how you can receive the messages using another client.)

This MQTT client will convert messages received from the public MQTT broker in MQTT format to ioMessage format, and then send the converted messages to the REST API element.

To visualize the received messages, you will have to attach a REST API element and open a public port for it (you can use your own microservice or use the one provided by ioTracks - it is present in the catalog on the Build screen in ioAuthoring).

Then, just browse to the ComSat URL obtained upon port creation. See how to open a port here: https://iotracks.com/build-sample (see demo 1, point 4).

MQTT-02-subscriber.png


JSON config for MQTT client:

{
	"subscriptions":[{"topic": "home/water/sensor", "qos": 1}],
	"broker" : {"host": "test.mosquitto.org", "port" : 8883},
	"ca_cert" : "MIIC8DCCAlmgAwIBAgIJAOD63PlXjJi8MA0GCSqGSIb3DQEBBQUAMIGQMQswCQYDVQQGEwJHQjEXMBUGA1UECAwOVW5pdGVkIEtpbmdkb20x
	DjAMBgNVBAcMBURlcmJ5MRIwEAYDVQQKDAlNb3NxdWl0dG8xCzAJBgNVBAsMAkNBMRYwFAYDVQQDDA1tb3NxdWl0dG8ub3JnMR8wHQYJKoZIhvcNAQkBFhByb
	2dlckBhdGNob28ub3JnMB4XDTEyMDYyOTIyMTE1OVoXDTIyMDYyNzIyMTE1OVowgZAxCzAJBgNVBAYTAkdCMRcwFQYDVQQIDA5Vbml0ZWQgS2luZ2RvbTEOMA
	wGA1UEBwwFRGVyYnkxEjAQBgNVBAoMCU1vc3F1aXR0bzELMAkGA1UECwwCQ0ExFjAUBgNVBAMMDW1vc3F1aXR0by5vcmcxHzAdBgkqhkiG9w0BCQEWEHJvZ2V
	yQGF0Y2hvby5vcmcwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMYkLmX7SqOT/jJCZoQ1NWdCrr/pq47m3xxyXcI+FLEmwbE3R9vMrE6sRbP2S89pfrCt
	7iuITXPKycpUcIU0mtcT1OqxGBV2lb6RaOT2gC5pxyGaFJ+hA+GIbdYKO3JprPxSBoRponZJvDGEZuM3N7p3S/lRoi7G5wG5mvUmaE5RAgMBAAGjUDBOMB0GA
	1UdDgQWBBTad2QneVztIPQzRRGj6ZHKqJTv5jAfBgNVHSMEGDAWgBTad2QneVztIPQzRRGj6ZHKqJTv5jAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA4
	GBAAqw1rK4NlRUCUBLhEFUQasjP7xfFqlVbE2cRy0Rs4o3KS0JwzQVBwG85xgeREyPOFdGdhBY2P1FNRy0MDr6xr+D2ZOwxs63dG1nnAnWZg7qwoLgpZ4fESP
	D3PkA1ZgKJc2zbSQ9fCPxt2W3mdVav66c6fsb7els2W2Iz7gERJSX"
}

JSON config for the REST API element:

{
	"buffersize":15,
	"contentdataencoding":"utf8",
	"contextdataencoding":"utf8",
	"outputfields":
	{
		"publisher":"source",
		"contentdata":"contentdata",
		"timestamp":"time",
		"contextdata": "contextdata",
		"infotype": "infotype",
		"infoformat": "infoformat"
	}
}


Your output should look like this:

MQTT-03-messages.png

3) Usage both as a subscriber and a publisher.

The following scheme is valid too!

Note that the REST API element has nothing to do with topics of the message generator if the MQTT client is not subscribed to any topics. REST API will get messages of only subscribed topics.

MQTT-04-pub-and-sub.png

Config explanation:

"subscriptions":[{"topic": "home/water/sensor", "qos": 1}] - an optional key, contains a list of topics and related "qos" (quality of service). You cannot subscribe to a topic without "qos" - it is required key for subscription;
"broker" : {"host": "test.mosquitto.org", "port" : 8883} - a required key that points to particular broker. "host" and "port" keys are required too;
"ca_cert" - an optional key, use it if your broker requires a certificate to connect;
"user" : {"username" : "TestUser","password" : "blabla"} - an optional key, use it if your broker requires a user to connect; "username" and "password" keys are required if you use a "user" field.