Skip to content

Instantly share code, notes, and snippets.

@jdevoo
Created December 21, 2018 13:21
Show Gist options
  • Save jdevoo/ca6e4646cdef12e2fb7e48db851193b6 to your computer and use it in GitHub Desktop.
Save jdevoo/ca6e4646cdef12e2fb7e48db851193b6 to your computer and use it in GitHub Desktop.
Mainflux Demo

Mainflux Demo

intro

The Mainflux domain model is based around 3 entities: users, things and channels

user represents the real (human) user of the system

things represents devices and applications connected to Mainflux. There are two types of "things" supported at the moment: device and app. Device is used to represent any physical device connected to the platform. App represents any 3rd party service that uses the platform for message exchange with things.

channel represents a communication channel and serves as message topic that can be consumed by things connected to it

  • I will create a user, 2 things and a channel
  • then connect things to channels via cli
  • and show mqtt (using mosquitto client) and http examples

minor changes

added depends_on to nginx in docker-compose.yaml

launch cmder with 3 panels

docker-compose up

create users

cli users
cli users create john.doe@acme.org password
cli users token john.doe@acme.org password
set USERTOK=ID

create things

cli things create
cli things create "{\"type\": \"device\", \"name\": \"arduino http\"}" %usertok%
cli things create "{\"type\": \"device\", \"name\": \"beaglebone mqtt\"}" %usertok%
cli things create "{\"type\": \"app\", \"name\": \"mosquitto_sub\"}" %usertok%

discover

cli things get ID %usertok%
cli things get all %usertok%

create channel to allow thing and app communication

cli channels create "{\"name\":\"testchan\"}" %usertok%
cli channels get ID %usertok%
cli channels get all %usertok%

associate app and device over channel

cli things connect
cli things connect THINGID CHANNELID %usertok%
cli things connect APPID CHANNELID %usertok%

use mosquitto

prepared a clihelper image which includes mosquitto-clients and curl

switch to third cmder panel and show app subscribing to things via mqtt clihelper mosquitto_sub -u APPID -P THINGKEY -t channels/CHANNELID/messages

switch to cli cmder panel and show things sending un-normalized message via mqtt clihelper mosquitto_pub -u MQTTTHINGID -P APPKEY -t channels/CHANNELID/messages -m "test"

normalizer

expects messages in SenML format e.g. message with 2 readings (see rfc8428 for details)

[{"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}]

show thing sending senml message via https clihelper curl --cacert shared/mainflux-server.crt --insecure -X POST -H "Authorization: HTTPTHINGKEY" https://localhost/http/channels/CHANNELID/messages -d "@/root/senml/ex1.json"

diagram

Not shown: LoRa adapter or influxdb with reader and writer

                +----------+
                |          |-------------------------------------------+
+----------+    |          |    +----------+    +----------+           |
| dashflux | ---|          |    |normalizer| ---|          |     +----------+
+----------+    |          |    +----------+    |          |  +--|  things  |--+
                |          |                    |          |  |  +----------+  |
+----------+    |          |    +----------+    |          |  |  +----------+  |
|   cli    | ---|          |--- |   http   | ---|          |  +--|  pgsql   |  |
+----------+    |          |    +----------+    |          |     +----------+  |
                |   nginx  |    +----------+    |          |                   |
+----------+    |          |--- | mqtt/ws  | ---|   nats   |                   |
|   app    |<---|          |    +----------+    |          |     +----------+  |
+----------+    |          |    +----------+    |          |  +--|  pgsql   |  |
                |          |--- |    ws    | ---|          |  |  +----------+  |
+----------+    |          |    +----------+    |          |  |  +----------+  |
|  thing   |>---|          |    +----------+    |          |  +--|  users   |--+
+----------+    |          |--- |   coap   | ---|          |     +----------+
                |          |    +----------+    +----------+           |
                |          |-------------------------------------------+
                +----------+
                      |
                +----------+
                |  redis   |
                +----------+
@tawanda
Copy link

tawanda commented Nov 5, 2019

Thanks for the guide, how do you draw this ASCII diagram, from scratch or are there some tools out there

@jdevoo
Copy link
Author

jdevoo commented Nov 5, 2019

sadly from scratch

@tawanda
Copy link

tawanda commented Nov 5, 2019

Wow then good work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment