Difference between revisions of "XUELK-AN-005: Implementing an Industrial IoT gateway/supervisor"

From DAVE Developer's Wiki
Jump to: navigation, search
(Ubidots)
Line 36: Line 36:
 
[https://ubidots.com Ubidots] is ''a codeless IoT Platform designed to help you prototype and scale your IoT projects to production''.
 
[https://ubidots.com Ubidots] is ''a codeless IoT Platform designed to help you prototype and scale your IoT projects to production''.
  
This application notes consists of three step to connect SBC-LYNX to ubidots.
+
This example consists of three steps. The first shows
The first part describes how to connect the sbc-lynx to ubidots and send data to the platform (ubidots).
+
*How to connect the SBC Lynx to Ubidots
The second part describes how to visualize on the dash board of the ubidots
+
*How to upload data to the cloud.
The third part is how to setup events so as to get a notification
+
The second part describes how to visualize on the dashboard of Ubidots. That last shows how to set up events so as to get a notification.
====Sending data to Ubidots====
+
====Connecting and uploading data to Ubidots====
The SBC LYNX board used specification:
+
As stated before, it is assumed that the board runs a Debian distribution:
 
+
<pre class="board-terminal">
CPU: based on NXP/Freescale i.MX6UL
 
2xRS232-2xRS485 on Serial Multi Protocol
 
Operating Systems: Linux, Debian (Jessie)
 
IEC-61131 PLC runtime
 
 
 
Cross Checking the Sbc-lynx board distribution used and the command used to check the distribution is lsb_release –a and looks like the below one
 
 
 
 
root@arm:~# lsb_release -a
 
root@arm:~# lsb_release -a
 
No LSB modules are available.
 
No LSB modules are available.
Line 56: Line 49:
 
Release: 8.7
 
Release: 8.7
 
Codename: Jessie
 
Codename: Jessie
 +
</pre>
  
 
I) Connecting the SBC-LYNX devices to the Ubidots IoT cloud
 
I) Connecting the SBC-LYNX devices to the Ubidots IoT cloud
Line 72: Line 66:
 
pip install ubidots
 
pip install ubidots
  
Now we have installed to our target device (local gateway/device=sbc-lynx) the necessary library python api ubidots client
+
Now we have installed to our target device (local gateway/device=SBC Lynx) the necessary library python api ubidots client
  
 
II) To connect our SBC LYNX board to the ubidot IoT cloud we need to have user account on the ubidots cloud platform and get the API(a unique key for each account ) and token from the website, very simple.
 
II) To connect our SBC LYNX board to the ubidot IoT cloud we need to have user account on the ubidots cloud platform and get the API(a unique key for each account ) and token from the website, very simple.
Line 164: Line 158:
  
  
When we execute this python code from the sbc-lynx board, it will send random data to the ubidots (to each variable, in my case it is three variable)
+
When we execute this python code from the SBC Lynx board, it will send random data to the ubidots (to each variable, in my case it is three variable)
  
 
====Visualizing data on the cloud dashboards====
 
====Visualizing data on the cloud dashboards====
Line 228: Line 222:
  
  
In this way, we can connect our device (sbc-lynx) to the ubidots cloud with Ubidot’s python api client and send data to the cloud then visualize it on the cloud in way we configured and also get notification by means of different ways.
+
In this way, we can connect our device (SBC Lynx) to the ubidots cloud with Ubidot’s python api client and send data to the cloud then visualize it on the cloud in way we configured and also get notification by means of different ways.
  
 
==References==
 
==References==
 
===Not exhaustive list of IoT cloud platforms===
 
===Not exhaustive list of IoT cloud platforms===
 
TBD
 
TBD

Revision as of 16:18, 21 April 2017

Info Box
SBC Lynx-top.png Applies to SBC Lynx

History[edit | edit source]

Version Date Notes
0.5.0 April 2017 First draft

Introduction[edit | edit source]

SBC Lynx provides is extremely flexible in terms of communication interfaces and I/O ports. When used in combination with a Linux distribution such as Debian, it is an ideal solution to implement compact highly-integrated cost-effective gateways/controllers for Industrial Internet of Things applications (IIoT).

IIoT is a vast field that includes several disciplines. At field level, the typical IIoT system requires

  • collecting data from different in nature networks and fieldbuses (an RS485 bus, an Ethernet LAN, an IO-Link port, etc.)
  • uploading the data to the cloud over an Internet connection.

This application note provides some examples of hardware and software configurations that can be used for these purposes. Also, it shows how to harness the versatility of SBC Lynx to integrate on the same platform even processing and controlling functionalities. [1]

The examples were tested on an SBC Lynx board equipped with optional wireless module and that runs Debian distribution, as described XUELK-AN-002:_Running_Debian_distribution|here]].


[1] It is worth remembering that SBC Lynx supports IEC 61131-3 compliant soft-PLC engines as well, such as Axel LogicLab.

Cloud interfacing[edit | edit source]

At the time of this writing, tens of cloud platforms are available on the market addressing IoT and IIoT applications. Some of them provide free accounts for small projects or evaluation purposes.

The following sections describe how to interface an SBC Lynx-based gateway to such platforms.

Ubidots[edit | edit source]

Ubidots is a codeless IoT Platform designed to help you prototype and scale your IoT projects to production.

This example consists of three steps. The first shows

  • How to connect the SBC Lynx to Ubidots
  • How to upload data to the cloud.

The second part describes how to visualize on the dashboard of Ubidots. That last shows how to set up events so as to get a notification.

Connecting and uploading data to Ubidots[edit | edit source]

As stated before, it is assumed that the board runs a Debian distribution:

root@arm:~# lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 8.7 (jessie)
Release: 8.7
Codename: Jessie

I) Connecting the SBC-LYNX devices to the Ubidots IoT cloud by means of ubidot python api client

To connect our SBC LYNX board to the ubidots using ubidot’s api client library, the first step is to install the “Python ubidots python API client” that is available on the PyPal as ubidots https://pypi.python.org/pypi/ubidots/ (First we need to have a python installed on our board.)

The command to install the API client to the sbcl-ynx board is as follows:

First Login to Sbc-lynx board with root privileges (sudo) and excute these commands: apt-get update apt-get upgrade apt-get install python-setuptools easy_install pip pip install ubidots

Now we have installed to our target device (local gateway/device=SBC Lynx) the necessary library python api ubidots client

II) To connect our SBC LYNX board to the ubidot IoT cloud we need to have user account on the ubidots cloud platform and get the API(a unique key for each account ) and token from the website, very simple.


Go to the website of the ubidots cloud, https://ubidots.com/ and click the sign up option on the right upper corner of the website and create the account I have created for my activity and here I put it in below username =zerihun pass = Zeri@204920


caption


To get the Api key for the created account, go to the right upper corner of the home page of the ubidots and click on the user name then you will see four options which are My Profile, API Credentials, Docs and Log Out


caption


Click the API Credentials


caption


Here in below I wrote mine API key and token as an example which will be needed when we generate an instance to communicate with the target device (Sbc-lynx board)

API KEY = 4435dd4dd5454114fc2e5425b3dd9361de0f2ffa Token = fwSetosAgIG3d128YdzP5fi4hADzWU


III) Now, after creating the user profile on the ubidots cloud side, we can be connected to it by creating an Api-Client instance from the Lynx board.

To create an instance, the code is:

from ubidots import ApiClient api = ApiClient(token=' fwSetosAgIG3d128YdzP5fi4hADzWU ')

After establishing the instance with the cloud, we will retrieve the variable. The variable is where we want to save the value that we will send to the Cloud.

But before sending data to the cloud side, we first go to the device option and define our own device and create the variables (equivalent to sensors) To create variables, there are three option in the upper center of the home page of the ubidots shown below


caption


Click the device option, then we will get the following


caption


Click the device and add variable (equivalent to sensors)


caption


After adding the variables, we need their id therefore to find their id put the cursor on bottom side of each variable box then, you will see “I”option then click it you will get the id of the variable that is used to establish an instance to this variable with the target device(sbc -lynx)

In my case (for example), I have added to my device three different variables named as Fall_sensor, Temp_sensor and Flood_sensor

To create an instance, use the following format my_variable_lynx = api.get_variable('id _variable form the ubidots')

Having instantiating variable, we can save a new value with the following line: new_value = my_variable.save_value({'value': xxxxxxxxxxx}) Here is my simple python script to send random data to the ubidots


caption


from ubidots import ApiClient import random api = ApiClient(token='fwSetosAgIG3d128YdzP5fi4hADzWU') my_variable_1 = api.get_variable('58cfe99b7625427aeab8a5e8') test_value_1 = random.uniform(0,1) test_value_1 = my_variable_1.save_value({'value':test_value_1}) my_variable_2 = api.get_variable('58d0df2f7625427ae8065765') test_value_2 = random.randint(1,10) test_value_2 = my_variable_2.save_value({'value':test_value_2}) my_variable_3 = api.get_variable('58d0f2d77625427ae6d4847f') test_value_3 = random.randint(1,10) test_value_3 = my_variable_3.save_value({'value':test_value_3})


When we execute this python code from the SBC Lynx board, it will send random data to the ubidots (to each variable, in my case it is three variable)

Visualizing data on the cloud dashboards[edit | edit source]

To visualize the data sent to the ubodots, we have an option called Dash board on the ubidots cloud side, we have three steps to adjust the dashboard that is the place where we will select the way we want to visualize the data.

Click the Dash board Click the “+ “symbol on the right upper corner Then you will get “How would you like to see your data?” and different option below this question like Chart, metric, map, indicator, controller etc


caption


In my case, I have selected the first option chart, in this case there are several option to use


caption


In my case, I have selected the first option (Line chart) then confirm and I have done the same for all my three variables and the dash board after sending data looks the below one


caption


Notification setting (event scheduling setting)[edit | edit source]

Sending sms or email to authorized user based on the event configured on the cloud. In the Event section, we can set a trigger, sms or an email to get notification based our interest.


caption


When we click the “Even option “, we will get the following


caption


Then click the device (with the name already created, in this case mine device name = my_device_1) and select the variable.


caption


After selecting the variable, we will put the if then statement


caption


After putting a value to the if – then statement, we will select a means to get notification


caption


Then, we will put a statement (message) to get as a notification either for sms (cell phone number) or email for email notification. Here in below I put snap shot of the final step of the event setting


caption


In this way, we can connect our device (SBC Lynx) to the ubidots cloud with Ubidot’s python api client and send data to the cloud then visualize it on the cloud in way we configured and also get notification by means of different ways.

References[edit | edit source]

Not exhaustive list of IoT cloud platforms[edit | edit source]

TBD