Changes

Jump to: navigation, search
Ubidots
===Ubidots===
[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.
The first part describes how to connect the sbc-lynx to ubidots and send data to the platform (ubidots).
The second part describes how to visualize on the dash board of the ubidots
The third part is how to setup events so as to get a notification
====Sending data to Ubidots====
The SBC LYNX board used specification:
 
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
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
[[File:XUELK-AN-IIoT-1.png|thumb|center|600px|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
[[File:XUELK-AN-IIoT-2.png|thumb|center|600px|caption]]
 
 
Click the API Credentials
[[File:XUELK-AN-IIoT-3.png|thumb|center|600px|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
[[File:XUELK-AN-IIoT-4.png|thumb|center|600px|caption]]
 
 
Click the device option, then we will get the following
[[File:XUELK-AN-IIoT-5.png|thumb|center|600px|caption]]
 
 
Click the device and add variable (equivalent to sensors)
[[File:XUELK-AN-IIoT-6.png|thumb|center|600px|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
[[File:XUELK-AN-IIoT-7.png|thumb|center|600px|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====
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
[[File:XUELK-AN-IIoT-8.png|thumb|center|600px|caption]]
 
 
In my case, I have selected the first option chart, in this case there are several option to use
[[File:XUELK-AN-IIoT-9.png|thumb|center|600px|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
[[File:XUELK-AN-IIoT-10.png|thumb|center|600px|caption]]
 
 
====Notification setting (event scheduling setting)====
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.
[[File:XUELK-AN-IIoT-11.png|thumb|center|600px|caption]]
 
 
When we click the “Even option “, we will get the following
[[File:XUELK-AN-IIoT-12.png|thumb|center|600px|caption]]
 
 
Then click the device (with the name already created, in this case mine device name = my_device_1) and select the variable.
[[File:XUELK-AN-IIoT-13.png|thumb|center|600px|caption]]
 
 
After selecting the variable, we will put the if then statement
[[File:XUELK-AN-IIoT-14.png|thumb|center|600px|caption]]
 
 
After putting a value to the if – then statement, we will select a means to get notification
[[File:XUELK-AN-IIoT-15.png|thumb|center|600px|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
[[File:XUELK-AN-IIoT-16.png|thumb|center|600px|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.
4,650
edits

Navigation menu