Quicktest Mainflux MQTT Messaging

This tutorial lists a few quick steps in order to quicktest Mainflux installation, quickly provision test environment and send some MQTT messages.

Drasko DRASKOVIC
Mainflux IoT Platform
2 min readJan 25, 2019

--

In the Mainflux dir execute:

make run

This will run docker composition.

Using Mainflux CLI:

mainflux-cli provision test

Expected response should be something like:

{
"email": "practical_beaver@email.com",
"password": "123"
}
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1NDg0OTM3MDAsImlhdCI6MTU0ODQ1NzcwMCwiaXNzIjoibWFpbmZsdXgiLCJzdWIiOiJwcmFjdGljYWxfYmVhdmVyQGVtYWlsLmNvbSJ9.bGuMdhHMD-LHONgm9eG28k5GQ-ijuhvcdO8v5w2oTNY"[
{
"id": "40816461-a2d6-402e-8d95-5a2cd2646735",
"key": "235f56fc-7f67-4749-aa94-5c9e172b0657",
"name": "d0",
"type": "device"
},
{
"id": "fcd4c722-b77a-45f0-a6d8-696245bee30a",
"key": "f1d812ca-d826-48c6-a10c-488ed79f5fb4",
"name": "d1",
"type": "app"
}
]
[
{
"id": "8206bc37-0882-48dd-beec-3c276fc16d24",
"name": "c0"
},
{
"id": "82f9131e-dc40-4bfe-8ab4-9ff52207ca9b",
"name": "c1"
}
]

CLI provisioning test actually creates one users, logs it in and then with his creadential it creates two things and two channels. Then it goes and connects first thing to first channel, and both things to second channel (so you can test that you are refused when trying to publish from second thing on a first channel).

From there on you can MQTT publish:

mosquitto_pub -u 40816461-a2d6-402e-8d95-5a2cd2646735 -P 235f56fc-7f67-4749-aa94-5c9e172b0657 -t channels/82f9131e-dc40-4bfe-8ab4-9ff52207ca9b/messages -h localhost -m '[{"bn":"some-base-name:","bt":1.276020076001e+09, "bu":"A","bver":5, "n":"voltage","u":"V","v":120.1}, {"n":"current","t":-5,"v":1.2}, {"n":"current","t":-4,"v":1.3}]'

Normalizer service log (in docker logs) should be somthing like this:

mainflux-normalizer | {"level":"info","message":"Method normalize took 33.241µs to complete without errors.","ts":"2019-01-25T23:13:54.029956981Z"}

This means that message passed through NATS and then into Normalizer, and SenML was correctly parsed and republished on NATS topics.

To test further you can connect MQTT subscriber in anouther terminal:

mosquitto_sub -u fcd4c722-b77a-45f0-a6d8-696245bee30a -P f1d812ca-d826-48c6-a10c-488ed79f5fb4 -t channels/82f9131e-dc40-4bfe-8ab4-9ff52207ca9b/messages -h localhost

It should recieve the messages like this:

[{"bn":"some-base-name:","bt":1.276020076001e+09, "bu":"A","bver":5, "n":"voltage","u":"V","v":120.1}, {"n":"current","t":-5,"v":1.2}, {"n":"current","t":-4,"v":1.3}]

To learn more about Mainflux and how we’re building the world’s most sophisticated open-source Industrial IoT cloud, visit our website and follow us on Twitter!

--

--