Bevywise Networks | IoT Platform & IoT Solutions - IoT Solutions & Artificial Intelligence to make a better tomorrow.
  • sparkplug b mqtt simulation

Sparkplug B MQTT Simulation

By Ranjith Kumar Diraviyam




  • sparkplug b mqtt simulation

Sparkplug B MQTT Simulation

By |November 13th, 2018|


Sparkplug provides an open and freely available specification for how Edge of Network (EoN) gateways or native MQTT enabled end devices and MQTT Applications communicate bi-directionally within an MQTT Infrastructure. One of the unique aspects of MQTT is that it was originally designed for real time SCADA systems to help reduce data latency over bandwidth limited and often unreliable network infrastructure. The intent of the Sparkplug specification is to take full advantage of MQTT’s native Continuous Session Awareness capability as it applies to real time SCADA/IIoT solutions.

Specifications of Sparkplug

 Currently there are two Sparkplug defined encoding schemes that this specification supports.

  • The first one is the Sparkplug A encoding scheme based on the very popular Kura open source Google Protocol Buffer definition.
  • The second one is the Sparkplug B encoding scheme that provides a richer data model developed with the feedback of many system integrators and end user customers using MQTT.

Sparkplug MQTT Topics & Messages

This blog guide you to simulate the Sparkplug B encoding in Bevywise IoT Simulator. Before simulating you must know about the Sparkplug Topic Namespace Elements and Sparkplug MQTT Message Types. 

Sparkplug Topic Namespace Elements:

All Clients which use the Sparkplug spec will use this default UTF-8 Format Topic namespace.

namespace/group_id/message_type/edge_node_id/[device_id]

  • namespace: It is the root element that will define both the structure of the remaining namespace elements as well as the encoding used for the associated payload data. Format for namespace is UTF-8 string constant should be used. The current Sparkplug specification defines two namespaces:
      • Sparkplug payload definition A
        • namespace element should be “spAv1.0”
      • Sparkplug payload definition B
        • namespace element should be “spBv1.0”
  • group_id: This provides unique logical group ID of MQTT EoN nodes. For group_id the format should be  UTF-8 alphanumeric string, except for the reserved characters of ‘+’ (plus), ‘/’ (forward slash), and ‘#’ (number sign). Examples of where the [group_id] might be used include Cement industry where MQTT EoN nodes on different department have the different [group_id].
  • message_type Element: It provide the indication as to, how to handle the MQTT payload of the message. The following message_type elements are defined for the Sparkplug Topic Namespace:
  • NBIRTH – Birth certificate for MQTT EoN nodes.
  • NDEATH – Death certificate for MQTT EoN nodes.
  • DBIRTH – Birth certificate for Devices.
  • DDEATH  – Death certificate for Devices.
  • NDATA    – Node data message.
  • DDATA     – Device data message.
  • NCMD – Node command message.
  • DCMD      – Device command message.
  • STATE – Critical application state message.
  • edge_node_id: Unquie identification for the MQTT EoN nodes within the infrastructure. For edge_node_id the format should be UTF-8 alphanumeric string, except for the reserved characters of ‘+’ (plus), ‘/’ (forward slash), and ‘#’ (number sign). The edge_node_id travels with every message published, so it should be as short as possible
  • device_id: Unquie ID which used to identify the device attached to the MQTT EoN node. device_id is an optional element since some messages will be either originating or destined to the edge_node_id, in that place device_id would not be required. The format of the device_id is a valid UTF-8 alphanumeric String except for the reserved characters of ‘+’ (plus), ‘/’ (forward slash), and ‘#’ (number sign).The device_id travels with every message published, so it should be as short as possible.

Simulate Sparkplug MQTT Device & Network

  • Bevywise IoT Simulator is a simulation tool which help users to test and develop the MQTT/IoT Applications. For installation and setup of Bevywise IoT Simulator, please refer our help doc and video tutorial.
  • After starting the Simulator, create a new network.
  • In new network, create three MQTTEoN nodes by via device creation : spBv1.0, Node2, Node3.

Dashboard of the IoT Simulator

Sparkplug MQTT Message Types

Sparkplug defines the Topic Namespace for set of MQTT messages that are used to manage connection state as well as bidirectional metric information exchange that would apply to many typical real-time SCADA/IIoT, monitoring, and data collection system use cases. The defined message types include:

  • NBIRTH – Birth certificate for MQTT EoN nodes.
  • NDEATH – Death certificate for MQTT EoN nodes.
  • DBIRTH – Birth certificate for Devices.
  • DDEATH  – Death certificate for Devices.
  • NDATA    – Node data message.
  • DDATA     – Device data message.
  • NCMD – Node command message.
  • DCMD      – Device command message.
  • STATE – Critical application state message.

Advantage of using these defined messages:

Using these defined messages the SCADA/IIOT Application can:

  • Discover all metadata and monitor state of any EoN/Device connected to the MQTT infrastructure.
  • Discover all metrics which include all diagnostics, properties, metadata, and current state values.
  • Issue write/command messages to any EoN/Device metric.

Creating Sparkplug MQTT Message types in IoT Simulator

  1. MQTT EoN NBIRTH and NDeath Certificate: The first MQTT message that an EoN node MUST publish upon the successful establishment of an MQTT Session is an EoN BIRTH Certificate.
  • Creating NBIRTH: [namespace/group_id/NBIRTH/edge_node_id]
    • Click spBv1.0 and
    • Create a event with “Whole day” configuration with every 5 sec time interval.
    • In that give the topic namespace as

                                 spBv1.0/kiln/NBIRTH/1

  • Select QoS as 1 and retain as 1
  • Give message as “NBIRTH” and save it

NBIRTH simulation for Sparkplug

  • Creating NDEATH: [namespace/group_id/NDEATH/edge_node_id]
    • Click spBv1.0 and
    • Create a event with “On Disconnect” configuration.
    • In that give the topic as

                                spBv1.0/kiln/NDEATH/1

    • Select QoS as 1 and retain as 1
    • Give message as “NDEATH” and save it.

NDEATH simulation for Sparkplug

  1. MQTT EoN Node Data (NDATA)
  • Once an MQTT EoN node is online with a proper NBIRTH, the NDATA will published.
  • This enables the advantages of the native Continuous Session Awareness of MQTT to monitor the STATE of all connected MQTT EoN node and to rely on Report by Exception (RBE) messages for metric state changes over the MQTT session connection.
  • The payload of NDATA messages will contain any RBE or time based metric EoN node values that need to be reported to any subscribing MQTT clients.
  • Creating NDATA:[namespace/group_id/NDATA/edge_node_id]
    • Click spBv1.0 and
    • Click the + icon and select Behaviour
    • In that, give command topic as “NBIRTH topic namespace” and command “NBIRTH”.
    • Next give the NDATA topic namespace in Event and give Event Data as current time and click save.

                         spBv1.0/Kiln/NDATA/1

    • Now NDATA will published to subscriber once they subscribe the NDATA topic namespace.

MQTT simulator NDATA Sparkplug

  1. Device Birth Certificate[DBRITH]
  • The MQTT EoN node is responsible for the management of all attached physical and/or logical devices. Once the EoN node has published its NBIRTH, the customers application ensure that EoN Node is ONLINE
  • But each physical and/or logical device connected to this node will still need to provide this DBIRTH before consumer applications create/update the metric structure (if this is the first time this device has been seen) and set any associated metrics in the application to a “GOOD” state.
  • Creating the DBRITH:[namespace/group_id/DBIRTH/edge_node_id]
    • Click spBv1.0 and
    • Click the + icon and select Behaviour
    • In that, give command topic as “NBIRTH topic namespace” and command “NBIRTH”.
    • Next give the DBIRTH topic namespace in Event and give Event Data as DBIRTH and click save.

                                   spBv1.0/Kiln/DBIRTH/1

    • Now DBIRTH will published to subscriber once they subscribe the DBIRTH topic namespace.

iot simualtor device birth sparkplug

  1. Device Data Messages (DDATA):
  • Once an MQTT EoN node and associated devices are all online with proper Birth Certificates it is in a mode of quiescent Report by Exception (RBE) reporting of any metric that changes.
  • It take advantage to monitor the STATE of all connected devices and can rely on Report by Exception (RBE) messages for any metric value change over the MQTT session connection.
  • Creating DDATA: [namespace/group_id/DDATA/edge_node_id/device_id]
    • Click spBv1.0 and
    • Click event with “Specific Duration” for 20 min duration with 10 sec interval.
    • In that give the topic as

                                spBv1.0/kiln/DDATA/1/LSM213

    • Select QoS as 1 and retain as 1
    • Give Random message as “ON|OFF” and click save.

Iot Simulator specific duration events

  1. Device Death Certificate[DDEATH]
  • If the device becomes unavailable for any reason (no response, CRC error, etc.) it is the responsibility of the EoN node to publish a DDEATH on behalf of the end device.
  • Once the DDEATH certificate published, any MQTT client subscribed to this device should set the data quality of all metrics to “STALE”.
  • Creating DDEATH:

                  [namespace/group_id/DDEATH/edge_node_id/device_id]

  • Click spBv1.0 and
  • Click the + icon and select Behaviour
  • In that, give command topic as “DDATA topic namespace” and command “OFF”.
  • Next give the DBIRTH topic namespace in Event and give Event Data as DDEATH and click save.

spBv1.0/Kiln/DDEATH/1

  • Now DDEATH will published to subscriber once they subscribe the DBIRTH topic namespace based on the DDATA.

Sparkplug device death MQTT messages

  1.  SCADA/IIoT Host Birth and Death Certificates
  • The SCADA/IIoT Host Node is any MQTT Client application that subscribes to and publishes messages.
  • In an infrastructure, mulitple MQTT Servers provide redundancy and scalability, for that MQTT EoN nodes need to be aware of the “state” of the primary SCADA/IIoT Host application(s).
  • The “state” can be acheived by the unique set of Birth/Death Certificates that the SCADA/IIoT Host MQTT Client MUST publish when a new MQTT session is established.
  • Topic namespace for SCADA/IIOT Host : STATE/scada_host_id
  • It uses an aspect of the MQTT transport called a “RETAINED” publish to maintain the current state of the Primary Host MQTT Client session state to all available MQTT Servers.
  • The format of the scada_host_id can be valid String with the exception of the reserved characters of ‘+’ (plus), ‘/’ (forward slash), and ‘#’ (number sign).
  • Creating SCADA/IIoT Birth Certificate Payload (STATE):
    • Click the SCADA/IIOT and
    • Create events with “On Connect” configuration.
    • In that give topic as SCADA/IIOT Host topic namespace[STATE/scada_host_id]: STATE/SCADABIRTH
    • Set WILL Retain flag as “1” and QoS as “1”
    • Select message type as “Text” and variant as “Constant”.
    • Give Payload or message as “ONLINE“.

IoT Simualtor SCADA Birth command

  • SCADA/IIoT Host Death Certificate Payload (STATE):
  • When the SCADA/IIoT Host MQTT client establishes an MQTT session to the MQTT Server(s), the Death Certificate will be part of the Will Topic and Will Payload registered in the MQTT CONNECT transaction.
  • The Will Topic should be: STATE/scada_host_id
    • Creating SCADA/IIoT DEATHCertificate Payload (STATE):
      • Click the SCADA/IIOT and
      • Click the switch button straight to WILL
      • In that give topic as : STATE/SCADADEATH
      • Give message or payload as “OFFLINE”
      • Set WILL Retain flag as “1” and QoS as “1”

IoT Simulator Will for Sparkplug

  1. MQTT EoN Node Command (NCMD) 
  • The NCMD command topic provides the Topic Namespace used to send commands to any connected EoN nodes.
  • This means sending an updated metric value to an associated metric included in the NBIRTH metric list.
  • Topic namespace: namespace/group_id/NCMD/edge_node_id
  • Creating MQTT EoN Node Command (NCMD)
    • Click spBv1.0 and
    • Create event withInstant command
    • In that give topic as

                           spBv1.0/Kiln/NCMD/1

  • Set QoS to “1” and Retain to “1”
  • Select message type as JSON and click + button.
  • In that add NBIRTH metric like:

ONLINE_STATE and ONLINE TIME.

  • Give the Key as ONLINE_STATE, select “constant”, give value as TRUE and click ADD
  • Next click + button and
  • Give Key as ONLINE_TIME, select “System variable” and select “$Current_time from list
  • next click ADD and save the JSON.

 

IoT Simualtor Device NCMD Command

  • Once the NBIRTH occurred, publish the NCMD by clicking the action icon
  • on the left side, now the NCMD will send commands to connected EoN nodes.
  • Next the subscribe the NCMD topic in SCADA/IIOT to get the Update metric from spBv1.0.
  1. Device Command (DCMD)
  • The DCMD topic provides the Topic Namespace used to publish metrics to any connected device.
  • This means sending a new metric value to an associated metric included in the DBIRTH metric list.
  • Topic namespace: namespace/group_id/DCMD/edge_node_id/device_id
  • Creating Device Command (DCMD)
    • Click spBv1.0 and
    • Create event with “Instant command
    • In that give topic as

                             spBv1.0/Kiln/DCMD/1/LSM213

    • Set QoS to “1” and Retain to “1”
    • Select message type as JSON and click + button.
    • In that add NBIRTH metric like:
    • ONLINE_STATE and ONLINE TIME.
    • Give the Key as ONLINE_STATE, select “constant”, give value as TRUE and click ADD
    • Next click + button and
    • Give Key as ONLINE_TIME, select “System variable” and select “$Current_time from list
    • next click ADD and save the JSON.

IoT Simualtor Device DCMD Command

  • Once the DBIRTH occurred, publish the DCMD by clicking the action icon
  • on the left side, now the NCMD will send commands to connected EoN nodes.
  • Next the subscribe the DCMD topic in SCADA/IIOT to get the Update metric from spBv1.0.

These are the Sparkplug set of MQTT Message Types that are used to manage connection state. Next connect the Bevywise IoT Simulator to built-in MQTTBroker or connect to any other MQTTBroker to start the Spatkplug Simulation. Likewise create Sparkplug message type for other Nodes.

You can get started by downloading the IoT Simulator now.

Download IoT Simulator

Feel free to write to support for any questions.

  • High Availability MQTT Cluster

High availability MQTT Cluster

By |October 24th, 2018|


High availably MQTT Cluster is very important for any production IoT deployments. Failures can happen due to Software failures, Disk errors, network connectivity, Hardware component failures, etc.,  To ensure that your services are up and running always to your customers, the services need to be functionally and physically redundant. This article helps you to set up a high availability MQTT Cluster with the MQTTRoute, the fastest MQTT Broker. Our IoT Platform  which is a complete SaaS based Framework targeting large scale multi tenancy has High availability built inside it. You need at 5 machines ( or VMs) to set up each and every component as shown in the Image above. We recommend all the machines to be Ubuntu 14 or 16.

Database Cluster High Availability

Data Storage is a crucial component for any production application. It is mandatory to have a Master/ Slave set up for your database storage. You can refer to the Digital Ocean document for setting up the same. Alternatively you can use Amazon RDS or Azure Data Store which by default provides the redundancy of the Data storage and much more features like time based snapshots for recovery.

Dockerize the MQTT Broker

You can either run the MQTT broker using our scripts or dockerize it if needed. A Complete article on how to dockerize the MQTT Broker is available here. Dockerizing will provide you some assistance in service manageability like auto restart and more. You can get your copy of the MQTT Broker from the download page.

Set up High Availability MQTT Cluster

You need to run the dockerized MQTT Broker in two machines in parallel to set up a cluster. Even though both the brokers are fully functional, only the MQTT Broker will be marked as Active Broker which will serve all the requests from the devices and from the Web UI. The second broker will be a hot standby which will start working when the main broker is down.

Enabling High Availability with Load Balancer

Set up the nginx in one of the machines as the load balancer. Following are the steps to configure the same.

Update and Install Nginx.

$ sudo apt-get update

$ sudo apt-get install nginx

Configure the Nginx proxy

$ sudo vim /etc/nginx/nginx.conf

The routing needs to be done for both the Web UI and the MQTT over TCP and MQTT over Web Socket connectivity.

http {

     include mime.types;

     default_type application/octet-stream;

     proxy_connect_timeout 2s;

     proxy_read_timeout 2s;

      sendfile on;

  keepalive_timeout 65;

upstream Brokerui {

  #server 127.0.0.1:8080;

        server (Standby MQTTRoute ip):8080 fail_timeout=1s max_fails=1;

         server (Standby MQTTRoute ip):8080 backup;

     }

  server {

  listen 80;

         location / {

             proxy_pass http://Brokerui;

}

error_page 500502503504 /50x.html;

         location = /50x.html {

         root html;

}
}
}

stream {

upstream broker {

server (Active MQTTRoute IP ):1883 fail_timeout=1s max_fails=1;

server (Standby MQTTRoute ip);1883 backup;

}

upstream websocket {

server (Active MQTTRoute IP ):10443 fail_timeout=1s max_fails=1;

server (Standby MQTTRoute ip):10443 backup;

}

server {

listen 1883;

proxy_pass broker ;

proxy_connect_timeout 1s;

}

server {

listen 10443;

proxy_pass websocket;

proxy_connect_timeout 2s;

}
}

Now your high availability MQTT cluster is ready for production

Validate the High Availability MQTT Cluster

The production ready MQTT Client should have the necessary code to reconnect whenever there is a disconnection issues. Refer to best practices for building  MQTT Client.

  1. Connect a MQTT client that has reconnection support and connect to your Public IP of your Load Balancer machine.
  2. You can see the device on the User Interface of the MQTTRoute and also you will start seeing the MQTT messages.
  3. Once the complete setting up is running, stop the Active MQTT Broker using the sh stop broker.sh or the docker command.
  4. You can see your edge client disconnect, reconnected again and start continue with its messaging and you will start seeing it seamlessly on the MQTT Broker User Interface.
  5. The Standby MQTT Broker has now become active and started serving the requests.

Failure & Update the set up

If the active MQTTRoute fails, the Hot Standby MQTT Broker will become the active broker. This makes it mandatory to set up another MQTT Broker for the hot standby. So set up another instance of Ubuntu and set up the MQTT Broker in it. Go back to the Nginx configuration and change the IP Addresses of the MQTTRoute accordingly and run the following command

Check the correctness of the syntax

$ sudo nginx -t

Reload the configuration.

$sudo nginx -s reload

MQTTRoute is the fastest MQTT Broker that will be helpful if you are planning to run an IoT deployment of tens of thousands of devices for a single business or a few business that falls under a single use case.

Download MQTTRoute now to get started with your High availability MQTT Cluster.

High Availability MQTT Cluster

Feel free to write to support for any queries or suggestions.

For large scale deployments, try the IoT Platform which is hosted at Devicemanager.bevywise.com All our products can be white labelled and used on private cloud or in premise.

  • MQTT Broker enhanced

MQTT Broker – Manage devices better

By |October 16th, 2018|


Today we are happy to announce an enhanced version of the MQTT Broker.

MQTT Broker manage devices better

You will be able to initiate a command to any particular device from the User Interface of the MQTT Broker. This has been previously supported via REST API built over the broker. The REST APIs were used by customers to initiate a command from their application.

When you do a real time project, IP Address of the edge device helps you get more information & exact location of the device. The new update shows your the client IP Address on the UI. Going forward we will be adding alerts based on the changes in the client IPs to inform suspicious activity.

MQTT Client Error Monitoring

There is no ideal system in the world. But it is very important we know the issues and mitigate them. All Edge devices will not behave perfectly as per the Protocol. Any Edge device can be disconnected from the MQTT Broker for various reasons. In a similar way, any packet that is not as per the standard can be dropped as well. We have added support for highlight the actual cause. It helps you identify and clear the alarm easily. The following scenarios will show you a warning on the User Interface :

  1. Reuse of the Client identifier.
  2. Usage of wrong MQTT credentials.
  3. Inconsistency in connectivity & Timeout issues.
  4. Usage of invalid Certificates for SSL / TLS connections.
  5. Not supported characters in Client Identifier.
  6. Missing of required Client Details.
  7. Atypical disconnection.
  8. Error in the MQTT Packet formation.
  9. Server not able to handle new request.

Dynamic MQTT Authentication

You can now configure your MQTT Broker parameters from the User Interface. When the authentication is enabled, you will be able to add new MQTT Username and password and also delete authentication keys dynamically. This helps you in take actions swiftly when you find some wrong usage of authentication keys.

Further You will be able to enable / disable TLS and authentication from the User Interface. Also enable Custom Store option from the UI. But these setting changes need a restart of the broker from the terminal. We working on making these changes dynamic as possible.

The new version of the MQTTRoute can be hosted on AWS Securely. We would always recommend you to use Monit to run the MQTT Broker as a service and control over the web also.

Download the MQTT Broker now.

Download FREE MQTT Broker

We would be happy to answer your question and hear your feedback. Feel free to write your queries to support.

  • mqtt broker iot home security system

IoT Home Security System using Bevywise MQTT Broker

By |October 15th, 2018|


There is an increasing need for the Home security system in the today’s world. IoT home security system with camera is the gaining more adoption as it can create instant alerts to users anywhere over the internet. The system also helps you control your appliance in home remotely. An article in A Secure life outlines the top 10 reasons why you should have a IoT Home security system. We are happy to see the MQTTRoute adoption for the Home Security. Here is how our customer in Taiwan built the home security solution over Bevywise MQTT Broker.

IoT Home Security System – Design

The IoT Home Security system was built to serve multiple customers. Each individual user will have their own configurable threshold values for the various values monitored. A dashboard for each user that can alarm and alert based on their own threshold value.

MQTT Broker is the middle ware that helps connect sensors and gateways to collect data and store it in any database or Big Data engine.

The eFon Technology, Taiwan has developed the edge product with all the sensors needed for monitoring the Temperature, Humidity, Co2, Smoke and a few more critical information. They build actuators to control Door & Windows. These sensors were connected to a gateway and from which the data is sent to the MQTTRoute. The Custom Store options of the MQTTRoute has been used to push the data to the Social application hosted separately. The Social application stores the mapping between the User gateway and the customer login to provide the corresponding alerts.

The configuration screen and the alarm screens are as show in the figures below.

IoT Home Security Implementation with MQTT Broker

Figure 1 – Configuring the Alarms for an Individual

IoT Home Security Implementation with MQTT Broker

Figure 2 – Live Data view for a particular individual.

The User dashboard also has support for the streaming of the camera data from the individual customers home. The widget has an option to configure the IP Address of the Camera by the individual user.

Bevywise Networks customized the Social Web premium edition to store the Customer values and also provided an option on MQTT Broker to pull the list of sensors of the particular customer based on the data pushed from the edge devices.

“ The team at Bevywise Networks is IoT domain and technology experts. Their expertise helped us converge on our implementation much easier and faster. We would be happy to recommend Bevywise for any IoT Implementation.”

– Shan Lin Chin, Efon Technology, Taiwan.

 You can download the complete case study from here.

Download the MQTTRoute now to set up your own IOT Home security system

Download FREE MQTT Broker

Feel free to write to support for any questions or suggestions.

  • Free IoT Products

Free IoT Products for your Non Commercial Projects

By |September 26th, 2018|


During  College / research time, everyone cannot afford premium products for non commercial projects.  Free IoT Products will help students, researchers, professors today help do research to innovate new  things. It also helps them better to challenge the future world.  IoT , AI , ML  & Edge Computing are few of the fast growing technologies in the world today.

We at Bevywise Networks would like to take this opportunity to encourage the students, teachers and researchers community with a free complimentary license.  These products can help them do their research much easier and in a cost effective way.  We provide edge clients for the various operating System , MQTT Broker , IoT Simulator tools and an IoT Platform. The hosted IoT Platform (Bevywise Device Manager ) is always free and can be used for your testing.  How can you utilise these tools for your projects.

Building Edge Devices with Free IoT Products

MQTT is one of most widely adopted protocols for industrial and general purpose IoT Implementation. If you are building any edge device as part of your project, then you can utilise the MQTTRoute as your Message broker for your implementation. This will help you collect messages (events) from your edge devices, send commands to your edge devices as well using APIs.

Building Application for a Vertical

MQTTRoute is a perfect middleware which can collect the information from your edge device and then hand it over to your backend application or data store as required. You will be able to build an application for a Small and medium business use case with the MQTT Broker. We already have some integration done for MongoDB , ElasticSearch, Redis, etc.

With custom storage option

  • Do data analysis over these big data engines
  • Connect to your Big Data Engine
  • Integrate it with any IoT Application

If you are looking for a large scale project which needs an IoT Platform kind of framework, we can also work out a model to make it available for researchers and students.  Our simulation tool can help you test your application using different variations of data.

To start with you can always download all our products for a FREE evaluation.

Grab your complimentary license now

If you feel our tool would help us achieve your goal, feel free to check if you can choose our  FREE perpetual license.

  • MQTT Broker in Alibaba cloud

MQTT Broker in Alibaba Cloud – Secure hosting

By |September 19th, 2018|


Alibaba is the most used cloud hosting provider in China.  This article provides a step by step procedure to set up the MQTT Broker in Alibaba cloud.  Bevywise MQTT Broker just needed a Ubuntu instance to host the broker.

Setting up the Alibaba Cloud for MQTT Broker:

  1. Select the Elastic Compute Service and create Ubuntu instance with minimum 1 CPU, 2GB RAM, 40 GB Disk with  Intel Xeon processor.
  2. After creating the instance, reset the password for ssh login.
  3. Create a inbound and outbound rule to ssh
    • To create outbound and inbound rule, expand “Network and  Security” and select “Security Group”.
    • In that page select “Add Rule”, it lead to Ingress and Outbound  page.
    • Click “Add Security Button” on the top right corner, it lead  to “Add Security Group Rule“.
    • In that Window select “Protocol type” as SSH and  “Authorization Objects” as 0.0.0.0/0 for access the Port  from any where or give specific IP address from which you  access SSH.
    • Do allow inbound flow of traffic for the following ports as well – 1883, 8080, 8081, 443 & 8883 
  4. Alibaba instance can be easily used via a remote connection from Windows, Ubuntu and MAC.
  5. Remote Connection from Windows:
    1. Download PuTTY fromhttp://www.chiark.greenend.org.uk/~sgtatham/putty/ or from other PuTTY download source. The “putty.exe” download is good for basic SSH.
    2. Save the download to your C:\WINDOWS folder.
    3. If you want to make a link to PuTTY on your desktop:
      1. Open the C:\WINDOWS folder in Windows Explorer.
      2. Right click on the putty.exe file and select Send To > Desktop
    4. Double-click on the putty.exe program or the desktop shortcut to  launch the application.
    5. Enter your connection settings:
      MQTT Broker Upload Putty settings

      Host Name: <Alibaba Public IP address>

      1. Port: 22 (leave as default
      2. Connection Type: SSH (leave as default)
    6. Click Open to start the SSH session.
    7. If this is your first time connecting to the server from this computer, you will see the following output. Accept the connection by clicking Yes.
      Login confirmation
    8. Once the SSH Connection is open, you should see a terminal prompt  asking for your username:
      login as: Connect with your SSH user of choice.Next, enter your  password.
    9. Please note that you will NOT see your cursor moving, or any  characters typed (such as ******), when typing your password. This is     a standard PuTTY security feature. Hit enter.
      Using keyboard-interactive authentication.
      Password:
    10. You are now logged into your server with SSH.
  6. Remote login from Liunx and MAC:
    • Open terminal and type [email protected]<public Alibaba IP>” and hit enter.
    • Type the password which you have reset in Step2.
    • You are now logged into your server with SSH.

You must have created an Ubuntu server by now and might have tested access to the server from Windows or  Linux or MAC. The next step is to transfer MQTT Broker to Alibaba.

Download the MQTT Broker

The MQTT Broker can be downloaded using the following button. The MQTT Broker has a 30 day trial version which supports upto 100 devices. You have to download the Ubuntu Version

FREE MQTT Broker

Transfer MQTT Broker to Alibaba

For Windows:

  1. Download the PSCP utility from PuTTy.org by clicking the file  name link and saving it to your computer.
  2. The PuTTY SCP (PSCP) client does not require installation in  Windows, but runs directly from a Command Promptwindow.  Move the download PSCP.exe file to the any location and note  the location
  3. Set the Environment Path for the PSCP.exe file.
  4. Open the Command Prompt window.
  5. Type “pscp <BevywiseMQTTRoute zip path> [email protected]<serverpublicIP>:/home/” and hit enter. The zip file will be automatically copy to the /home  location of Alibaba ubunut instance

For Linux & Mac:

  1. 1. Open terminal and type below command .
    scp <BevywiseMQTTRoute zip path> [email protected]<serverpublicIP>:/home/”
  2.  Zip file will be saved in the /home location of Alibaba Ubuntu  instance.

Starting MQTT Broker in Alibaba Cloud

It is very easy to set up MQTT Broker in Alibaba cloud. You can simply follow these steps to achieve it.

  1. Login to the Alibaba Ubuntu server via SSH and go to /home location via           “cd /home” command
  2. Type “unzip Bevywise_MQTT_Route_Linux.zip” and hit enter. Now MQTTBroker file will be extract in /home location under the Bevywise folder.
  3. Go to the file Bevywise by below command and hit enter.
    “cd Bevywise/MQTTRoute/bin”
  4. Open the data_store.conf file which is inside the conf folder.

    “vim /home/Bevywise/MQTTRoute/conf/data_store.conf”

    In that file change follow conf and save the file:

    DB_SERVER = MYSQL and give MySQL username and password 

    MYSQL_USER = <username>

    MYSQL_PASSWORD = <password>

  5. Run the Bevywise MQTT broker using the following command. It is advisible to run the Broker in the background mode to make sure the broker runs even after you close the terminal.
    “sh runbroker.sh”

Run MQTT Broker in Alibaba as a Service

If you don’t run MQTT Broker in Alibaba cloud as a service, then it will quit when you close your ssh session. So make sure you run the MQTT Broker as a service.

To run the MQTTBroker as service we need the Monit version 5.25 and it cannot be installed using the apt-get. The procedure to set up the monit is as follows. This application will ensure that the service will be started again when the server gets restarted.

  • Download the Monit for linux X64 or X86 based on your servers.
  • Extract the archive using tar -xzf < downloaded file >
  • Go to monit-5.25.2/bin
  • copy monit to /usr/bin folder – sudo cp monit /usr/bin
  • Go to monit-5.25.2/conf
  • copy the monitrc file to “/etc/” using below command – sudo cp monitrc /etc/
  • Modify the monit conf file. Uncomment the following lines in /etc/monitrc file.  use sudo vi /etc/monitrc. Change the username and password as per your  need.
    set httpd port 2812 and
           use address localhost # only accept connection from localhost  (drop if you use M/Monit)
           allow localhost # allow localhost to connect to the server and
           allow admin:monit # require user ‘admin’ with password ‘monit’ 
  • Add the following at the end of the /etc/monitrc file
    check process MQTTRoute with pidfile < path to Bevywise/MQTTRoute  >/Broker.pid
         start program = “< path to Bevywise/MQTTRoute >/bin/runbroker.sh”  with timeout 2 seconds
        stop program = “< path to Bevywise/MQTTRoute >/bin/stopbroker.sh”  with timeout 2 seconds
  • To reload the confirmation changes, run sudo monit reload
  • Add MQTTRoute process to monitoring sudo monit start MQTTRoute

We have hosted a Chinese version of MQTT Broker here.  Do give it a try and let us know your feedback. We would be always ready to help you with setting up the MQTT Broker in Alibaba. Feel free to post your queries and support requirement to our support.