Connecting Modbus devices to Azure IoT Hub
FATBOX G3 Quick Start Guide:
This quick start guide is for engineers to quickly get from the wire up, to collecting data and visualising their remote field equipment on Azure IoT Hub & Power BI using the dual SIM FATBOX G3 IIoT gateway.

What You'll Need To Get Started
-
1 FATBOX G3 Azure IOT Gateway Starter Kit
-
1pc FATBOX G3 – Dual SIM Industrial 3G Gateway with Azure IoT client and Modbus RTU & TCP server
-
1pc Digital input module – 4 x digital inputs (or switch contacts) Modbus RTU slave unit
-
1pc Analog input – 2 x analog input Modbus RTU slave unit
-
Wires to connect the FATBOX G3 to the Modbus slave units (0.3m)
-
2x 24VDC power supply 100-240VAC – 1 for FATBOX G3 and 1 for the 2 Modbus slave units
-
1x cellular antenna (2m wire length)
-
1x temperature sensor (0c - 400c) with 1m wire
-
Learn More: Click Here
You will also need the following
-
1 x micro SIM card with 3G/4G data enabled – please also get its APN setting from provider.
-
A Microsoft Azure account
-
optional: Test switches or load (max 230V 8A, e.g. a 12V indicator) if there is no field equipment ready.
Note: As per writing, you can get a one-month-free-or-USD200-credit for Microsoft Azure & Power BI to help with testing your concept. Click here to get your Free Azure Trial
The Temperature Sensor
You can get more information on the temperature sensor here.
You can also access its data sheet here.
Collecting non-Modbus interface devices
For collecting data from non-Modbus interface devices, LUA or BASH scripts can be easily written to poll any data that is accessible over Ethernet or RS-485/232 interfaces. The data can then be put into a JSON format that can be processed by Stream Analytics query in Azure.
Let's Get Started:
1. Design
It’s usually good practice to start by mapping out the devices you want to monitor, e.g. a switch or a sensor in a network diagram.
Later, you can move on to your own field devices like power meters or PLCs.
2. Wire Up
This section describes how to wire up the Modbus-485 I/O modules included in the starter kit to the FATBOX G3 and also to its 24VDC power supply. It will also show you how to wire up the temperature sensor to the analog Modbus module. The following are simplified wiring diagrams for the Novus Automation I/O modules but please refer to details in the instruction manual download links.
In your starter kit, a temperature sensor is pre-wired to to the Digirail-2A analog module to facilitate immediate testing of transmission of field data to your Ubidots platform.
Before you begin wiring, make sure to insert the an active SIM card into the FATBOX G3:
1. Dismantle the casing cover and slide out the PCB. Avoid touching the electronics, handle the board by the edges.

2. Insert your micro SIM card into the SIM card slot. Push the metal latch left/right to lock/unlock. Reassemble the metal casing.

Once the SIM card is in and the gateway is assembled you can proceed to wiring up the sensor and modules to it.


3. Setting Up The FATBOX G3
3A. Log into the FATBOX web console.
When you have connected up the FATBOX [ETH0 port], log into the web console [192.168.1.1].
By default the username is admin and password is fatbox12345
3B. Configure the cellular 3G settings
Enter in the APN details you got from your SIM card operator.
Then to confirm the settings, click the UPDATE button.
3C. Configure the Serial Port Settings
Got to <Port Settings>. Configure your serial port parameters as follows:
Remember to confirm the settings by clicking the UPDATE button.

3D. Enable SSH to be used for managing the FATBOX
Click on the <MANAGEMENT> tab and enable the SSH option. Remember to confirm the settings by clicking the UPDATE button.

3E. Ensure you have the iotasset.txt
The FATBOX G3 integrates a ‘device server’ that will poll all attached Modbus RTU and TCP slaves at a configure period. This server reads a configuration file ‘iotasset.txt’ that is a simple text file with each polled Modbus device register specified as following:
MBM_START
TYPE,R
ADDR,1
MBFC,3
REGS,8,1,UINT16HL
Key,4C_IN1
TYPE,R
ADDR,2
MBFC,3
REGS,14,1,UINT16HL
Key,2A_IN1
MBM_STOP
Please refer to our FAQ for more detailed write up for the iotasset device register.
To configure the iotasset.txt file to your device, please refer to our Modbus User Guide.
The iotasset.txt file comes pre-installed with your FATBOX G3. If for some reason it becomes overwritten, you have to do the following step to add the file to the FATBOX's /user directory. Note that the gateway HTTPS connected webconsole must be accessible (If you do not have an Internet connection, you can follow the alternative steps here).
Log into your web console and go to the <IOT Hardware> tab, click on 'Upload iotasset.txt File' button.

In the new window, click on 'CHOOSE FILE' and select from your local folder the updated iotasset.txt file then click on 'UPLOAD FIRMWARE FILE'. After the upload is successful you will need to close the page and log in again for security purpose.
3F. Set up the FATBOX G3 Azure Hub IoT Client
Click the <IOT Client> tab in your web configuration menu and create a DeviceID for this FATBOX.
How you name this ID is up to you but make it distinct so you can identify it easily later.
Select the ENABLE option and confirm your settings by clicking the UPDATE button.

Save your settings by going to the <MANAGEMENT> tab to reboot the G3.
Technical :: we suggest doing an ‘interim’ test at this point to ensure that your Modbus master, network and I/O modules are working before interacting with the Azure system.
For MAC users, open a session on Terminal and log into the box using the command: 'ssh root@192.168.1.1'
For Windows, use PUTTY or a similar software, open a session to host: 192.168.1.1, port: 22; and log into the box as: root.
When you are prompted for the password:
> Enter the password as: fatbox12345
> Enter the command 'cd /tmp' to the console
> Enter the command 'cat dataq.txt' to the console.
(Note: For firmware 2.4.17 or later, you should use the following commands instead)
> Enter the password as: fatbox12345
> Enter the command 'cat /data/dataout' to the console.
If you see an output similar to the following, CONGRATULATIONS! Your site level devices are properly configured and now we can proceed to the Azure settings.

4. Add the FATBOX G3 to your Azure IOT Hub
We worked hard and closely to integrate AZURE IoT Hub client. You can securely collect data from remote industrial devices like MODBUS RTU and TCP power meters, PLCs or sensors. The FATBOX G3 with serial RS-485/232, Ethernet and CAN Bus is a flexible and robust LTE and 3G I(IoT) field gateway for your Azure remote monitoring and analytics solution.
4A. Log into Azure IOT Hub
Log into your Azure Portal (https://portal.azure.com) using your account settings & open up Device Explorer.
4B. Create a new Resource
In the dashboard select -> Create a Resource -> Internet of Things -> IoT Hub -> CREATE.
Create a distinct name for your Resource Group (i.e. you can call this the name of your project or application) and IoT Hub Name (i.e. you can call this the location of your device, we called ours "resourcegrp" in this example). Click the 'Review + Create' tab to create.


4C. Obtain your Primary Key Connection String
To register the FATBOX G3 as a new device in AZURE we first need a Shared Access Key known as the Primary Key Connection String.
Go to the IoTHub you just created.

Scroll down to -> IOT devices
On the top panel click "+New".
Create a name for your device (Device ID). In this example, we called our device "newsite".
Then click "Save"


In your IoT Hub, select the Device ID you just created.
You should see a section with the heading 'Connection String-Primary Key' under this menu. Click on the 'clipboard' icon to copy or select the entire string and copy it using the 'Ctrl-C' keyboard shortcut.


Save it into a text file and name it "connstr.txt."
Upload this into the FATBOX G3 using the following steps:
Go to your web configuration menu -> IOT Hardware -> upload connstr.txt

Save your settings by going to the <MANAGEMENT> tab to reboot the G3.
4E. Test that your Azure account is receiving data
At this point it is good to check if everything is connected well and ensure that your AZURE account has started to receive the data from your NOVUS modules.
To do this open Powershell by clicking this icon on Azure.

Run the following commands:
az extension add --name azure-iot
az iot hub monitor-events --output table --hub-name {YourIoTHubName}
Replace {YourIoTHubName} with the name of your iothub name which you have created earlier. If you were following the same names used in this demo, the command would be:
az iot hub monitor-events --output table --hub-name newsite
You should be able to see the same strings as above in the device explorer [image below is a sample].

5. Set Up Stream Analytics
5A. Create a new Stream Analytics Job
Log into Azure using your account settings.
In the search bar, search for "Stream Analytics Job"
Add a new job.


You can use the following settings to get you started.
NAME: newsite
SUBSCRIPTION: Free trial/Pay as you go
RESOURCEGRP: [select the name you created in step 4B from the drop down menu] in our example, the name was 'resourcegrp'
Create the new job.

5B. Create the Job Topology
We will designate the input and output for the job.
Click on the <Go To Resource> button.
Go to -> Inputs->add stream input -> IOT Hub
You can use the following settings
INPUT ALIAS: inputbi
IOT HUB: newsite [from the drop down menu]
SUBSCRIPTION: Pay as you go

Next on the <OUTPUTS> field, select > Add.
Choose PowerBI from the scroll down list & authorize it.

You can use the following settings to start off.
OUTPUT ALIAS: outputbi
DATASET NAME: newdataset
TABLE NAME: newtable
Click on SAVE.

Next select <EDIT QUERY> at the top right of Query field in the Job Topology table.
Replace [Input] and [Output]with the name of the input and the name of the output you created in the past few steps.
Then enter the following into the empty field given:
Under 'SELECT'
deviceId,RecOn as TIMESTAMP,[Key],
CAST (Val AS bigint) as VAL
Under 'INTO'
outputbi #The output alias you have created.
Under 'FROM'
inputbi #The input alias you have created.
Click <SAVE>. This should give you a set up similar to the following:

5C. Test your settings
Let's test is everything is going well so far and that the Stream Analytics has started receiving data for its job.
Go to your Stream Analytics Dashboard and click on the START THE JOB button.
If everything is set up well you should see a RUNNING status notification.
Congratulations! You are a successful device to cloud solution. Next is decide on how to ingest and make economic benefit from all that data.
If however, the above fails please check the following possibilities.
-
Ensure FATBOX G3 is connected to the internet – it’s obvious but you never know.
-
Make sure /user/iotasset.txt is correctly configure and data is being correctly polled from slave devices and sent to /tmp/dataq.txt buffer file
-
Make sure that IoT device connection string is correct in /user/connstr.txt
Please contact Amplified Engineering at support@amplified.com.au for further assistance.
6. Visualise on Power BI
6A. Create a report in PowerBI
Log into PowerBI using your account settings. Please also ensure Stream Analytics is running and your G3 and Novus IO modules are switched on.
Once logged in to your account, go to <MY WORKSPACE> and create a new dashboard using the <+ Create> tab & give your new dashboard a name.

Once the dashboard is created, go to <Datasets> and select the dataset which you have created earlier in step 5B.
Then check on the pencil icon to edit the Date & Time to your required time zone.

Go back to <My Workspace> and click the <+Create> again to create a new report. Choose the dataset that you have just created.
Play around with the different graph settings to create the report that you will like. You can reference our sample below for the checkbox settings we use to create our graphs. (We used an area graph to plot the value of 2A_CH1 against Time.)

Once done save your report with the <SAVE> tab and pin a live page on the dashboard you have created.

You can continue adding for various keys to your dashboard. To view your report go to <Workspaces> & select your Dashboard.


Congratulations! You have successfully set up the data reporting from your device, streamed it through AZURE IoT Hub and visualized it onto PowerBI.
7. Create Cloud-to-Device controls
The FATBOX G3 industrial IoT gateway can be configured to receive control messages from Azure IoT Hub (or other cloud back-ends) to control Modbus or CAN bus connected field devices like PLCs, motor inverters or EV chargers.
This demo application explains the sending of a control string from Azure CLI to simulate a cloud application or dash board widget.
The data is sent over 4G/3G/Ethernet, securely received by the gateway and written to Modbus/CAN Bus registers of connected devices.
7A. Send Modbus or CAN Bus control message from Azure IoT Hub to the G3 Gateway
From your Azure console, start the CLI PowerShell.
Run the az extension add command to add the Microsoft Azure IoT Extension for Azure CLI to your CLI shell.
az extension add --name azure-iot
Then you can configure your cloud to devices send command string
az iot device c2d-message send -d simDevice --data "device_tag" --props "key0=value0;key1=value1" -n{YourIoTHubName}

At your FATBOX G3 gateway, if the C2D Azure function has been enabled the following process would be executed and in this case, Modbus register(s) in PLC.2 written.

Congratulations! You have successfully set up the data reporting from your device, streamed it through AZURE IoT Hub and visualized it onto PowerBI & created bi-directional message controls to your device from your cloud solution.
Thank you and we look forward to working with your team!
Other articles that may interest you
A linux MQTT Gateway
Reduce the 3 costs associated with cloud data
Feedback & Control IoT applications
Cross compile your C codes
Got a question for us?
Contacts:
Tech Support : support@amplified.com.au
Sales : sales@amplified.com.au
Amplified Engineering