Sign Up with Ubidots to Power Your IoT App

Ubidots is a hosted IoT plat­form in the cloud that can help to jump­start your IoT ap­pli­ca­tion. It was cre­ated in a startup ac­cel­er­a­tor, and has since pow­ered hun­dreds of IoT ap­pli­ca­tions across mul­ti­ple sec­tors like health­care, en­ergy, etc, in more than 4

OpenSource For You - - Contents - By: Romin Irani The au­thor has been work­ing in the soft­ware in­dus­try for 20+ years. His pas­sion is to read, write and teach about tech­nol­ogy and make de­vel­op­ers suc­cess­ful. He blogs at www.ro­mini­rani.com.

In this ar­ti­cle, we will take a look at the Ubidots plat­form and un­der­stand the process of sign­ing up, in­gest­ing our sen­sor data into the plat­form and vi­su­al­is­ing it.

Fea­tures

The plat­form is avail­able as a ser­vice and of­fers the fol­low­ing fea­tures:

APIs to in­gest your sen­sor data from any de­vice. Sup­port for both HTTP and MQTT pro­to­cols for data in­ges­tion.

Dash­boards to help you vi­su­alise your IoT data.

Alerts for your users/ap­pli­ca­tions based on your sen­sor data.

In­te­gra­tion with more than 20 de­vices (Adafruit, Ar­duino, Par­ti­cle, Tes­sel and oth­ers) to help jump­start mov­ing your IoT data to the Ubidots plat­form.

Free to get started with ed­u­ca­tion and busi­ness pric­ing plans, based on your re­quire­ments.

Get­ting started

The first step in us­ing the Ubidot plat­form is to sign up for its ser­vice. Sign­ing up is free and pro­vides you with the ‘Ed­u­ca­tion plan’, which is suf­fi­cient to get started on small projects or proof-of-con­cept ap­pli­ca­tions.

The signup page is lo­cated at https://app.ubidots.com/ ac­counts/signup/ and af­ter suc­cess­fully sign­ing up, you will head to the Ubidots home page, where you can see that you have been pro­vided 5000 cred­its to use. We will re­fer to this home page as the Web por­tal.

Ob­tain­ing the Ubidots API To­ken

One of the im­por­tant things to do up­front is to note down your API to­ken. This will be re­quired later in the ar­ti­cle when we use the HTTP API as a pri­mary mech­a­nism to in­gest our sen­sor data into the Ubidots plat­form. The API to­ken is avail­able when you click on your ac­count name on the top right cor­ner of the Web por­tal and then on the API

cre­den­tials, as shown in Fig­ure 1.

This will lead to a page where you will be shown an API key and a de­fault API to­ken. Care­fully note down the API to­ken and store it. From now, we will re­fer to this as the API_TOKEN.

Set­ting up the de­vice

The first thing that we should do is to set up our de­vices in Ubidots. The ‘Free Plan’ comes with sup­port for 20 de­vices. Think of these de­vices as those that col­lect sen­sor data like tem­per­a­ture. So let’s as­sume that we have de­ployed a de­vice named

D1, from which we are cap­tur­ing tem­per­a­ture data via a stan­dard tem­per­a­ture sen­sor. You can have up to 20 de­vices uniquely con­fig­ured, which will help you fil­ter, track and mea­sure the data that is com­ing from var­i­ous de­vices, by iden­ti­fy­ing them via the de­vice’s la­bel.

So let’s go ahead and set up a de­vice named D1. Fol­low the steps given be­low.

1. From the Web por­tal, visit the De­vices link at the top. By de­fault, when you go to the De­vices page, it will show that a de­fault de­vice has been con­fig­ured. I sug­gest that you delete it, so that we can start with a clean slate as shown in Fig­ure 2.

2. Click on the Add De­vice icon. Name the de­vice D1, as shown in Fig­ure 3.

3. Click on de­vice D1. This will lead you to a de­tailed page, as shown in Fig­ure 4.

4. Now, we need to add a vari­able.

This vari­able can be the sen­sor data that we are track­ing — for ex­am­ple, tem­per­a­ture. We can cap­ture more than one vari­able or sen­sor data com­ing from a sin­gle de­vice. Click on the Add Vari­able icon shown in Fig­ure 4. Se­lect De­fault and then name the vari­able as Tem­per­a­ture, as shown in Fig­ure 5.

We have suc­cess­fully cre­ated a de­vice D1 that will pro­vide us tem­per­a­ture val­ues, which we will track via the tem­per­a­ture vari­able that we cre­ated and as­so­ciate with this de­vice. Let us now look at how we can get our sen­sor val­ues into the sys­tem.

The HTTP API

Ubidots sup­ports both the HTTP and MQTT pro­to­cols as a way to in­gest data into the sys­tem. In this ar­ti­cle, we will fo­cus on the HTTP API, and demon­strate how you can in­gest data into your ap­pli­ca­tion. In our case, we will as­sume that the sen­sor data is be­ing gen­er­ated by de­vice D1 and the sen­sor data is a tem­per­a­ture that is be­ing recorded.

The API end­point is avail­able at https://things.ubidots.com/api/ v1.6/ and we will need to use the API_TOKEN as well as our de­vice and vari­able that we have cre­ated to push data into the sys­tem.

To send val­ues into the sys­tem for a spe­cific de­vice and vari­able, we need to do a HTTP POST to the HTTPs URL, the for­mat of which is given be­low: http://things.ubidots.com/api/ v1.6/de­vices/{LABEL_DEVICE}/ {VARIABLE_LABEL}/val­ues

So for our de­vice D1, the {LABEL_DEVICE} will have the value ‘D1’ and for the {VARIABLE_ LA­BEL}, we shall use the value ‘tem­per­a­ture’. In ad­di­tion, we will need to ap­pend the API_TOKEN value to the URL as a re­quest pa­ram­e­ter.

The vari­able name to be used for the API_TOKEN is to­ken.

Sam­ple re­quest

For ex­am­ple, if we wish to push the value of 29.5 as the tem­per­a­ture value for de­vice D1, we will need to do a HTTP POST, as fol­lows: https:// things.ubidots.com/api/v1.6/de­vices/ D1/tem­per­a­ture/val­ues/?to­ken =API_ TO­KEN

…with the POST body as fol­lows:

{“value”:”29.5”}

We can also pro­vide the con­text and time­stamp vari­ables that are op­tional but can be use­ful for track­ing the lo­ca­tion of the de­vice, and also the time­stamp at which the sen­sor value was recorded. The data that will be passed in the HTTP POST re­quest body will then be as fol­lows:

{“value”:29.5”,”time­stamp”:146466136900 0,”con­text”:{“lat”:19.07,”lon”:72.87}}.

When you send the con­text, the Ubidots dash­board that we saw ear­lier will recog­nise it as a GeoPoint and will plot it on the map.

Sam­ple trans­ac­tions

We can use the curl utility to do a few sam­ple HTTP POST re­quests to our end­point, so that we can see how we can then vi­su­alise the data in the Ubidots dash­board.

Here is a sam­ple curl re­quest for in­sert­ing tem­per­a­ture sen­sor data read at de­vice D1:

$ curl -X POST -H “Con­tent-Type: ap­pli­ca­tion/json” -d ‘{“value”:29.7, “con­text

“:{“lat”:19.07, “lng”:72.87}, “time­stamp”:1493817120}’ http://things. ubidots.com/api/v1.6/de­vices/D1/ tem­per­a­ture/val­ues?to­ken= u31S5yB1GaKnD64DwOJsKWYEc­je9nv

{“url”: “http://things.ubidots.com/ api/v1.6/val­ues/5909899e7625421b6 8f86883”, “value”: 29.7, “time­stamp”: 1493817120, “con­text”: {“lat”: 19.07, “lng”: 72.87}, “cre­at­ed_at”: “2017-0503T07:41:18.226”}

Sim­i­larly, cre­ate a few more val­ues with dif­fer­ent time­stamps and tem­per­a­ture val­ues to sim­u­late data be­ing re­ceived from the sen­sor.

If you visit the Web por­tal and click on De­vices, you will find the value has got recorded, as shown in Fig­ure 6.

You can even click on the vari­able, i.e., tem­per­a­ture, to see the de­tails in the graph (Fig­ure 7).

Dash­board

The Ubidots dash­board al­lows you to cre­ate dash­boards where you can add graph­i­cal wid­gets to vi­su­alise your sen­sor data from var­i­ous de­vices. To cre­ate a dash­board, you can go to the Web por­tal and then click on Dash­board. Sim­ply add a new dash­board, se­lect a chart type from one of the many op­tions of­fered (for ex­am­ple LineChart), and then se­lect the de­vice and the vari­able. In our case, it is de­vice D1 and the vari­able Tem­per­a­ture.

Once you have added that to the dash­board, you can see it as shown in Fig­ure 8.

Events

A pow­er­ful fea­ture of the Ubidots plat­form is to set alerts on your sen­sor data. For ex­am­ple, we can raise an alert in case the tem­per­a­ture goes over 30°C. If that con­di­tion is met, we can de­liver the alert via email or SMS, in­voke a Web­hook, etc.

To con­fig­ure a sam­ple event, you can go to the Web por­tal and click on Events. Then add a new event, se­lect the de­vice and vari­able, and de­fine the con­di­tion as shown in Fig­ure 9.

For ex­am­ple, we have se­lected the tem­per­a­ture vari­able for de­vice D1 and set a con­di­tion of > 30°C (greater than 30 de­grees Centi­grade). The graph­i­cal con­fig­u­ra­tion is shown in Fig­ure 9.

Click on Con­tinue and you will be asked to se­lect the medium via which the alert can be sent. The list of de­liv­ery chan­nels is shown in Fig­ure 10.

Click on Fin­ish to cre­ate the event, and then the alert will be raised on any sen­sor value for a tem­per­a­ture that is above 30°C from de­vice D1.

Client li­braries

You can in­te­grate the API calls for in­gest­ing data into the sys­tem via var­i­ous client li­braries that are made avail­able in Ubidots. Client li­braries are avail­able for mul­ti­ple pop­u­lar lan­guages like Python, Java, Node.js, Ruby, An­droid and oth­ers. This makes the task of col­lect­ing any sen­sor data from an ap­pli­ca­tion straight­for­ward, re­mov­ing the bur­den of deal­ing di­rectly with HTTP re­quest/re­sponse han­dling in your code.

The API meth­ods are not just to save val­ues but also for cre­at­ing data sources (de­vices), cre­at­ing vari­ables, get­ting val­ues of vari­ables and for the bulk im­port of vari­able val­ues.

A sam­ple code in Python for in­gest­ing val­ues is given be­low:

from ubidots im­port ApiClient api = ApiClient(to­ken=’<API_TOKEN>’)

# Get Tem­per­a­ture Vari­able my_­vari­able = api.get_ vari­able(‘<VARIABLE_ID’)

# Save Tem­per­a­ture Vari­able new_­value = my_­vari­able.save_ value({‘value’: 29.5})

Ubidots’ pric­ing

Ubidots has flex­i­ble pric­ing. There are two plans avail­able: Ed­u­ca­tion and Busi­ness. The Ed­u­ca­tion plan is free and lets you connect up to a max­i­mum of 20 de­vices, al­lows data re­ten­tion for 30 days and a max­i­mum sen­sor data in­ges­tion rate of 60 per minute.

This should be suf­fi­cient for most hob­by­ists and en­thu­si­asts who want to get started with the plat­form. The Busi­ness plan caters to a greater num­ber of de­vices, an on-de­mand in­ges­tion rate and a man­age­ment suite. The pric­ing is avail­able on call. You can find out more about the dif­fer­ences be­tween the Ed­u­ca­tion and Busi­ness plans on the pric­ing page.

Ubidots is a pow­er­ful hosted IoT plat­form that pro­vides fea­tures to in­gest, process and vi­su­alise your IoT ap­pli­ca­tion data. It is quick to get started with, and pro­vides easy-to-use REST APIs to help you de­cou­ple your sen­sor in­fras­truc­ture and fo­cus on push­ing the data out to the plat­form, where you can trans­form it to a higher level ap­pli­ca­tion do­main. It is an excellent plat­form to build your IoT proof-of-con­cept ap­pli­ca­tion and take your idea to a wider au­di­ence.

Fig­ure 4: Add a vari­able for the de­vice

Fig­ure 2: Adding a new de­vice

Fig­ure 5: Tem­per­a­ture vari­able

Fig­ure 3: De­tails about the de­vice

Fig­ure 1: API cre­den­tials

Fig­ure 8: Tem­per­a­ture dash­board

Fig­ure 7: Tem­per­a­ture data

Fig­ure 6: Sam­ple tem­per­a­ture value

Fig­ure 9: Event con­di­tion con­fig­u­ra­tion

Fig­ure 10: Event no­ti­fi­ca­tion chan­nel con­fig­u­ra­tion

Newspapers in English

Newspapers from India

© PressReader. All rights reserved.