Skip to content

Instantly share code, notes, and snippets.

@exocode
Forked from jdevoo/notes.md
Last active February 22, 2019 12:17
Show Gist options
  • Save exocode/2c8e232ebd14f94b8e415b0da35cace6 to your computer and use it in GitHub Desktop.
Save exocode/2c8e232ebd14f94b8e415b0da35cace6 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

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

create things

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

discover

mainflux-cli things get ID %usertok%
mainflux-cli things get all %usertok%

create channel to allow thing and app communication

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

associate app and device over channel

mainflux-cli things connect
mainflux-cli things connect THINGID CHANNELID %usertok%
mainflux-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   |
                +----------+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment