Image for post
Image for post

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
Jan 25, 2019 · 2 min read

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!

Drasko DRASKOVIC

Written by

Mainflux IoT Platform

Mainflux is highly secure, scalable, open-source IoT platform written in Go and deployed in Docker. It serves as software infrastructure and set of microservices for development of the Internet of Things Solutions and deployment of Intelligent products.

Drasko DRASKOVIC

Written by

Mainflux IoT Platform

Mainflux is highly secure, scalable, open-source IoT platform written in Go and deployed in Docker. It serves as software infrastructure and set of microservices for development of the Internet of Things Solutions and deployment of Intelligent products.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store