Exploring Mainflux and Its Usage

0
4459
mainfulx featured image

Mainflux is a highly secure, open source and patent-free IoT cloud platform developed in the GO programming language. It is based on a set of microservices. It accepts connections over multiple network protocols like HTTP, MQTT, Websocket, CoAP, etc, making a seamless bridge between them. Mainflux is used as IoT middleware, on top of which advanced IoT solutions can be constructed.

Mainflux is used as the IoT middleware for constructing complex IoT solutions. It makes use of south bound API to connect devices and northbound API to connect applications, and then it permits message routing between them. The whole bottom-to-top system (device, Mainflux platform, and application) bundled together is called a ‘vertical solution’.
From Figure 1, we can understand that Mainflux works as middleware that does a lot of heavy lifting. The product designers have only to focus on connected devices (physical design, firmware, etc) and the end user application (GUI that controls the device), as the Mainflux block can be reused. Mainflux sends messages between connected devices and applications in a highly secure manner, also offering many other services needed for these devices and applications. It offers multi-protocol device-agnostic message relay with distributed time-series data storage, and multi-user, multi-tenant device and application management middleware.

Architecture
Mainflux works as middleware, which means it employs a set of servers that provide several functionalities and services used in developing IoT applications.

The features of Mainflux are:

  • Messaging bridge (HTTP Sender, MQTT and WS, CoAP)—relays messages between devices and applications
  • Systems manager (Manager)
  • Device manager (Device)—accepts device connections on southbound interface
  • Application manager (App)—accepts application connections on northbound interface
  • User manager (Mainflux UI, Mainflux CLI)—provides user management for the applications
    Time-series storage engine (Message Reader, Message Writer, Cassandra)—stores and queries measurement data points in the time-series format
  • Complex Event Processing (uses the system event bus NATS)—consumes the incoming time-series streams, and can automate triggers and actions based on a configurable set of rules.

Apart from messaging, Mainflux contains three main domains: user, thing and channel.

User represents the real user of the system. A user can access the platform through the access token, which can be obtained via an email id and password. Once logged, users can access or manage the resources (things and channels) by CRUD operations, and can define access control policies by connecting them.

Thing represents the applications or devices connected to Mainflux, which use the platform for message exchange with another device.

Channel represents the way through which a message is sent; simply put, we can say it is a communication channel.

Installation
Before installing Mainflux, install the prerequisites given below:

  • Docker
  • Docker Compose

Once the above components are installed successfully, the next step is to download the source code. You can do this in two ways — with or without the Git tool. I prefer to do it with the Git tool as it will download all the source code in the appropriate folder. But if you do this without the Git tool, you will have to download the Zip file from the GitHub repository, and extract the source code to the destination directory on your machine. Once it is done, you are ready for the next step.

Figure 1: Location of Mainflux inside the IoT system

We will now use the terminal to navigate to the folder where we have downloaded or extracted the Mainflux source code. For example, for my machine I used the /home/user/ directory. If the Git tool is used in the previous step, then there should be a
/home/user/mainflux directory as your path. Else, if you have used the Zip file and extracted it to your machine, then a folder might be created with the name as mainflux-master. Navigate to that source code directory. The next step is to start the Mainflux core services by executing the command:

docker-compose -f docker/docker-compose.yml up -d

Assuming that the above command is executed successfully, the Mainflux IoT platform should be up and running.

Figure 2: The key constituent elements of Mainflux

Some points to note

  • Docker composition is defined under your project root/docker/docker-compose.yml file. You can customise this file according to your specific needs.
  • The most likely problems to occur are port conflicts. If any of your applications is using a port that is needed to run Mainflux services, then you need to free that port or modify the default port from docker-compose.yml.
  • Another common problem faced is failure to allow all the ports in the firewall configuration.

Using Mainflux
Mainflux is basically about messages, for which it provides a simple UI client known as Dashflux. As said earlier, to login for the first time you need to register by providing a valid user name and password. Once logged into the system, you can manage resources with the help of CRUD (create, read, update and delete) operations, and can define the access control policies. After login, the user is redirected to the home page (Figure 3).

Figure 3: Dashflux home page

You can see three buttons on the top right corner in the Dashflux home page. The Things button will navigate to the things dashboard, Channels to the channels dashboard and Logout will log you out. Clicking on the plus symbol will open the dialogue for adding a new thing or channel. Once a channel is created, the user can edit it and connect or disconnect devices.

Remember one thing can be connected to more than one channel, and vice versa. Mainflux uses Rest API — all the operations can be done by using various command line tools or any HTTP API development tool.

Figure 3 can be divided into two parts: core platform components and optional ones. Core platform components are NATS, protocol adaptors and normalizer. Writer and database are optional. Here, ‘thing’ represents an application or device that uses Mainflux for message exchange. As the need to use Mainflux is different for every company, the protocol adaptor is used to support various types of protocols like MQTT, WebSocket and HTTP. For every protocol used, there is a corresponding protocol adaptor. The job of the adaptor is to transform a protocol-specific message to a suitable format, i.e., Mainflux message. Then comes NATS, which is an open source scalable messaging system Mainflux uses for message exchange within a platform. Once published to NATS, the message will be transferred to normaliser service. The job of normaliser is to convert the message to the SenML (Sensor Markup Language) format. Normaliser then forwards the converted message to NATS for further processing, to check whether it is in SenML or not. Only SenML formatted messages will be written in the database.

Security
Mainflux is a highly secured system. It has dedicated authentication and does not allow access to unauthorised devices and applications. All the messages and the network traffic are encrypted by the latest security standards such as TLS v1.3.

Mainflux is licensed under the Apache License 2.0. It is a lightweight and scalable platform. As all the services are deployed as a Docker container, the whole platform setup and installation takes only three steps. We can also customise whatever service or feature we like, and contribute to the Git repo if we wish to.

LEAVE A REPLY

Please enter your comment!
Please enter your name here