STREGA a company specialized in industrial communication with experience in the Automation, and SCADA which offer solutions tested in real industrial environments to provide the a reliable product on the market.
To learn how to connect a STREGA LoRa wireless smart valve & wireless time-controlled emitter to Ubidots through The Things Network, refer to this guide.
In this guide, we are going to cover STREGA Schedulers management for Ubidots
In order to program automatic operation of the STREGA schedulers through Ubidots dashboard, you have to implement some add-ons in your Ubidots account. Follow the steps below careful to ensure the proper operation.
Requirements
1. Setup "Scheduler" variable
1. Login to your Ubidots account.
2. Go to Devices page and select the device (SV/SE) for which you want to assign the Schedulers.
Once you entered the device, you'll see a screen as below:
NOTE: If your STREGA device is already transmitting data to Ubidots, you will be able to visualize the device identified with its Serial number on the Device section. Otherwise, create a new device in your Ubidots account and assign its serial number as device label.
3. Create a new variable by clicking on the "Add Variable" option. Then, select "Raw":
4. Assign a name to the variable – user defined (recommended to keep it as “scheduler” since we are creating it for scheduler operations).
5. Select the variable created, then copy the variable ID and keep for later.
2. Dashboard Creation - HTML canvas Widget
1. Go to the Dashboard (Data > Dashboards) section of your Ubidots account.
2. Select the plus (+) icon located a the right-upper side of the page. Then select HTML canvas as widget type:
3. First, assign the desired name to the Widget. Then, open the editor and place the following codes in the respective section:
3.1. Copy and paste the following HTML script in the HTML section:
<div class="notification--container" id="notification">
<p>Value sent successfully</div>
</div>
<div class="container">
<div class="row">
<div class="two columns offset-by-one">
Select the day
</div>
<div class="four columns">
<select name="Day" class="form__input" size="1" id="day">
<option value="">--No day selected--</option>
<option value="14">Sunday</option>
<option value="15">Monday</option>
<option value="16">Tuesday</option>
<option value="17">Wednesday</option>
<option value="18">Thurdsay</option>
<option value="19">Friday</option>
<option value="20">Saturday</option>
</select>
</div>
</div>
<div class="row d-block">
<div class="four offset-by-three columns center">Start</div>
<div class="four columns center">End</div>
</div>
<div class="row">
<div class="two columns offset-by-one">
Scheduler 1
</div>
<div class="two columns">
<input type="number" step="1" placeholder="HRS" id="value1" class="form__input" />
</div>
<div class="two columns">
<input type="number" step="1" placeholder="MIN" id="value2" class="form__input" />
</div>
<div class="two columns">
<input type="number" step="1" placeholder="HRS" id="value3" class="form__input" />
</div>
<div class="two columns">
<input type="number" step="1" placeholder="MIN" id="value4" class="form__input" />
</div>
</div>
<div class="row">
<div class="two columns offset-by-one">
Scheduler 2
</div>
<div class="two columns">
<input type="number" step="1" placeholder="HRS" id="value5" class="form__input" />
</div>
<div class="two columns">
<input type="number" step="1" placeholder="MIN" id="value6" class="form__input" />
</div>
<div class="two columns">
<input type="number" step="1" placeholder="HRS" id="value7" class="form__input" />
</div>
<div class="two columns">
<input type="number" step="1" placeholder="MIN" id="value8" class="form__input" />
</div>
</div>
<div class="row">
<div class="two columns offset-by-one">
Scheduler 3
</div>
<div class="two columns">
<input type="number" step="1" placeholder="HRS" id="value9" class="form__input" />
</div>
<div class="two columns">
<input type="number" step="1" placeholder="MIN" id="value10" class="form__input" />
</div>
<div class="two columns">
<input type="number" step="1" placeholder="HRS" id="value11" class="form__input" />
</div>
<div class="two columns">
<input type="number" step="1" placeholder="MIN" id="value12" class="form__input" />
</div>
</div>
<div class="row">
<div class="two columns offset-by-one">
Scheduler 4
</div>
<div class="two columns">
<input type="number" step="1" placeholder="HRS" id="value13" class="form__input" />
</div>
<div class="two columns">
<input type="number" step="1" placeholder="MIN" id="value14" class="form__input" />
</div>
<div class="two columns">
<input type="number" step="1" placeholder="HRS" id="value15" class="form__input" />
</div>
<div class="two columns">
<input type="number" step="1" placeholder="MIN" id="value16" class="form__input" />
</div>
</div>
<div class="row">
<div class="eight offset-by-two columns">
<button button type="button" class="form__button button--submit" id="send-value">Set Schedulers</button>
</div>
</div>
</div>
3.2. Copy and paste the following CSS script in the CSS section:
@import url("https://fonts.googleapis.com/css?family=Open+Sans");
* {
box-sizing: border-box;
}
body {
font-family: "Open Sans", sans-serif;
font-size: 14px;
}
.d-block {
display: block !important;
}
.center {
text-align: center;
}
.container {
position: relative;
width: 100%;
max-width: 960px;
margin: 0 auto;
box-sizing: border-box;
}
.container .row {
align-items: center;
display: flex;
}
.column,
.columns {
width: 100%;
float: left;
box-sizing: border-box;
margin-left: 4%;
}
.column:first-child,
.columns:first-child {
margin-left: 0;
}
.one.column,
.one.columns {
width: 4.66666666667%;
}
.two.columns {
width: 13.3333333333%;
}
.three.columns {
width: 22%;
}
.four.columns {
width: 30.6666666667%;
}
.five.columns {
width: 39.3333333333%;
}
.six.columns {
width: 48%;
}
.seven.columns {
width: 56.6666666667%;
}
.eight.columns {
width: 65.3333333333%;
}
.nine.columns {
width: 74%;
}
.ten.columns {
width: 82.6666666667%;
}
.eleven.columns {
width: 91.3333333333%;
}
.twelve.columns {
width: 100%;
margin-left: 0;
}
.one-third.column {
width: 30.6666666667%;
}
.two-thirds.column {
width: 65.3333333333%;
}
.one-half.column {
width: 48%;
}
/* Offsets */
.offset-by-one.column,
.offset-by-one.columns {
margin-left: 8.66666666667%;
}
.offset-by-two.column,
.offset-by-two.columns {
margin-left: 17.3333333333%;
}
.offset-by-three.column,
.offset-by-three.columns {
margin-left: 26%;
}
.offset-by-four.column,
.offset-by-four.columns {
margin-left: 34.6666666667%;
}
.offset-by-five.column,
.offset-by-five.columns {
margin-left: 43.3333333333%;
}
.offset-by-six.column,
.offset-by-six.columns {
margin-left: 52%;
}
.offset-by-seven.column,
.offset-by-seven.columns {
margin-left: 60.6666666667%;
}
.offset-by-eight.column,
.offset-by-eight.columns {
margin-left: 69.3333333333%;
}
.offset-by-nine.column,
.offset-by-nine.columns {
margin-left: 78%;
}
.offset-by-ten.column,
.offset-by-ten.columns {
margin-left: 86.6666666667%;
}
.offset-by-eleven.column,
.offset-by-eleven.columns {
margin-left: 95.3333333333%;
}
.offset-by-one-third.column,
.offset-by-one-third.columns {
margin-left: 34.6666666667%;
}
.offset-by-two-thirds.column,
.offset-by-two-thirds.columns {
margin-left: 69.3333333333%;
}
.offset-by-one-half.column,
.offset-by-one-half.columns {
margin-left: 52%;
}
.container:after,
.row:after {
content: "";
display: table;
clear: both;
}
.row {
margin-top: 14px;
margin-bottom: 14px;
}
input {
width: 100%;
}
.form__input {
background: #ffffff;
border: 1px solid #ccc;
padding: 8px 4px;
outline: none;
width: 100%;
}
.form__button {
background: transparent;
cursor: pointer;
width: 100%;
}
.form__button.button--submit {
border: 1px solid #00bcd4;
border-radius: 50px;
color: #00bcd4;
font-weight: bold;
padding: 8px 0;
transition: background-color 300ms ease-in-out;
transition: color 300ms ease-out;
}
.form__button.button--submit:hover {
background-color: #00bcd4;
color: #ffffff;
}
.notification--container {
display: none;
}
3.3. Copy and paste the following JavaScript script in the JavaScript section:
var $sendValue = $('#send-value');
var $port = $('#day');
var $value1 = $('#value1');
var $value2 = $('#value2');
var $value3 = $('#value3');
var $value4 = $('#value4');
var $value5 = $('#value5');
var $value6 = $('#value6');
var $value7 = $('#value7');
var $value8 = $('#value8');
var $value9 = $('#value9');
var $value10 = $('#value10');
var $value11 = $('#value11');
var $value12 = $('#value12');
var $value13 = $('#value13');
var $value14 = $('#value14');
var $value15 = $('#value15');
var $value16 = $('#value16');
var TOKEN = 'ASSIGN_YOUR_UBIDOTS_TOKEN';
var VARIABLE_ID = 'ASSIGN_VARIABLE_ID';
var $notification = $('#notification');
function postValue(variable, token, callback) {
var url = 'https://industrial.api.ubidots.com/api/v1.6/variables/' + variable + '/values';
var headers = {
'Content-Type': 'application/json',
'X-Auth-Token': TOKEN
};
$notification.hide();
$.ajax({
data: JSON.stringify({
value: parseInt($port.val(), 10),
context:{"schl1h_on":parseInt($value1.val(), 10),"schl1m_on":parseInt($value2.val(),10),"schl1h_off":parseInt($value3.val(), 10),"schl1m_off":parseInt($value4.val(),10),"schl2h_on":parseInt($value5.val(), 10),"schl2m_on":parseInt($value6.val(),10),"schl2h_off":parseInt($value7.val(), 10),"schl2m_off":parseInt($value8.val(),10),
"schl3h_on":parseInt($value9.val(), 10),"schl3m_on":parseInt($value10.val(),10),"schl3h_off":parseInt($value11.val(), 10),"schl3m_off":parseInt($value12.val(),10),"schl4h_on":parseInt($value13.val(), 10),"schl4m_on":parseInt($value14.val(),10),"schl4h_off":parseInt($value15.val(), 10),"schl4m_off":parseInt($value16.val(),10)
}
}),
method: 'POST',
url: url,
headers: headers,
success: function (res) {
callback(res.value);
}
});
}
$sendValue.on('click', function () {
postValue(VARIABLE_ID, TOKEN, function (value) {
$notification.show();
});
});
Once the code is properly placed, assign your Ubidots TOKEN, and the variable ID of the variable created (previously copied) where is indicated in the code below.
3.4. Add the following library to the "3rd Party Library" section:
https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js
4. At this point, you'll be able to see the Schedulers widget created on your Dashboard.
3. Create an Event for Schedulers in Ubidots
TTN Setup
1. Login to your TTN account – click on Application – select Integration.
2. Create a HTTP Integration for Ubidots. Assign a Process ID, select the Access Key as Default, enter http://
in URL
Column and Method as POST and click on save.
3. Go to "Payload Formats" section, and assign the following code as encoder of your application.
function Encoder(object, port) {
function pad(num, len) {
return ("00" + num).substr(-len);}
function pad1(num, len) {
return ("000" + num).substr(-len);}
function pad2(num, len) {
return ("0000" + num).substr(-len);}
function dec_to_bho (n, base) {
if (n < 0) {
n = 0xFFFFFFFF + n + 1;}
switch (base){
case 'B':
return parseInt(n, 10).toString(2);
break;
case 'H':
return parseInt(n, 10).toString(16);
break;
case 'O':
return parseInt(n, 10).toString(8);
break;
default:
return("Wrong input.........");}}
var bytes = [];
var ports = port;
var Schl_on = 10;
var Schl_off = 00;
var Schl_m = 0;
// open and close command
if (port === 1) {
bytes[0] = object.payload;
return bytes;
}
// UL frequency time
if (port === 11){
if (object.unit1===1){
bytes[0] = 128;}
else{
bytes[0] = 0;}
bytes[1] = object.time1;
if (object.unit2===1){
bytes[2] = 128;}
else{
bytes[2] = 0;}
bytes[3] = object.time2;
return bytes;
}
// Schedulers status setting
if (port === 21){
bytes[0] = object.Schl_status;
return bytes;
}
// Synchronizing RTC
if (port === 13){
bytes[0] = object.Sync_RTC;
return bytes;
}
if (port === 12){
var t0 = object.Sync_RTC;
bytes[0] = parseInt(t0.substr(0,1));
bytes[1] = parseInt(t0.substr(1,1));
bytes[2] = parseInt(t0.substr(2,1));
bytes[3] = parseInt(t0.substr(3,1));
bytes[4] = parseInt(t0.substr(4,1));
bytes[5] = parseInt(t0.substr(5,1));
bytes[6] = parseInt(t0.substr(6,1));
bytes[7] = parseInt(t0.substr(7,1));
bytes[8] = parseInt(t0.substr(8,1));
bytes[9] = parseInt(t0.substr(9,1));
bytes[10] = parseInt(t0.substr(10,1));
bytes[11] = parseInt(t0.substr(11,1));
bytes[12] = parseInt(t0.substr(12,1));
bytes[13] = parseInt(t0.substr(13,1));
return bytes;
}
// Schedulers setting
if (port===14 || port===15 || port===16 || port===17 || port===18 || port===19 || port===20) {
bytes[0] = 255;
if (object.schl1h_on==="None" || object.schl1h_on===255){
bytes[1] = 255;}
else{
var a = parseInt(object.schl1h_on);
var b = pad(a,2);
var c = b.substr(0,1);
var d = b.substr(1,1);
var e = pad(dec_to_bho (c,'B'),2);
var f = pad2(dec_to_bho (d,'B'),4);
var g = parseInt((Schl_on+e+f),2);
bytes[1] = g;}
if (object.schl1m_on==="None" || object.schl1m_on===255){
bytes[2] = 255;}
else{
var a1 = parseInt(object.schl1m_on);
var b1 = pad(a1,2);
var c1 = b1.substr(0,1);
var d1 = b1.substr(1,1);
var e1 = pad1(dec_to_bho (c1,'B'),3);
var f1 = pad2(dec_to_bho (d1,'B'),4);
var g1 = parseInt((Schl_m+e1+f1),2);
bytes[2] = g1;}
bytes[3] = 255;
if (object.schl1h_off==="None" || object.schl1h_off===255){
bytes[4] = 255;}
else{
var a2 = parseInt(object.schl1h_off);
var b2 = pad(a2,2);
var c2 = b2.substr(0,1);
var d2 = b2.substr(1,1);
var e2 = pad(dec_to_bho (c2,'B'),2);
var f2 = pad2(dec_to_bho (d2,'B'),4);
var g2 = parseInt((Schl_off+e2+f2),2);
bytes[4] = g2;}
if (object.schl1m_off==="None" || object.schl1m_off===255){
bytes[5] = 255;}
else{
var a3 = parseInt(object.schl1m_off);
var b3 = pad(a3,2);
var c3 = b3.substr(0,1);
var d3 = b3.substr(1,1);
var e3 = pad1(dec_to_bho (c3,'B'),3);
var f3 = pad2(dec_to_bho (d3,'B'),4);
var g3 = parseInt((Schl_m+e3+f3),2);
bytes[5] = g3;}
bytes[6] = 255;
if (object.schl2h_on==="None" || object.schl2h_on===255){
bytes[7] = 255;}
else{
var a4 = parseInt(object.schl2h_on);
var b4 = pad(a4,2);
var c4 = b4.substr(0,1);
var d4 = b4.substr(1,1);
var e4 = pad(dec_to_bho (c4,'B'),2);
var f4 = pad2(dec_to_bho (d4,'B'),4);
var g4 = parseInt((Schl_on+e4+f4),2);
bytes[7] = g4;}
if (object.schl2m_on==="None" || object.schl2m_on===255){
bytes[8] = 255;}
else{
var a5 = parseInt(object.schl2m_on);
var b5 = pad(a5,2);
var c5 = b5.substr(0,1);
var d5 = b5.substr(1,1);
var e5 = pad1(dec_to_bho (c5,'B'),3);
var f5 = pad2(dec_to_bho (d5,'B'),4);
var g5 = parseInt((Schl_m+e5+f5),2);
bytes[8] = g5;}
bytes[9] = 255;
if (object.schl2h_off==="None" || object.schl2h_off===255){
bytes[10] = 255;}
else{
var a6 = parseInt(object.schl2h_off);
var b6 = pad(a6,2);
var c6 = b6.substr(0,1);
var d6 = b6.substr(1,1);
var e6 = pad(dec_to_bho (c6,'B'),2);
var f6 = pad2(dec_to_bho (d6,'B'),4);
var g6 = parseInt((Schl_off+e6+f6),2);
bytes[10] = g6;}
if (object.schl2m_off==="None" || object.schl2m_off===255){
bytes[11] = 255;}
else{
var a7 = parseInt(object.schl2m_off);
var b7 = pad(a7,2);
var c7 = b7.substr(0,1);
var d7 = b7.substr(1,1);
var e7 = pad1(dec_to_bho (c7,'B'),3);
var f7 = pad2(dec_to_bho (d7,'B'),4);
var g7 = parseInt((Schl_m+e7+f7),2);
bytes[11] = g7;}
bytes[12] = 255;
if (object.schl3h_on==="None" || object.schl3h_on===255){
bytes[13] = 255;}
else{
var a8 = parseInt(object.schl3h_on);
var b8 = pad(a8,2);
var c8 = b8.substr(0,1);
var d8 = b8.substr(1,1);
var e8 = pad(dec_to_bho (c8,'B'),2);
var f8 = pad2(dec_to_bho (d8,'B'),4);
var g8 = parseInt((Schl_on+e8+f8),2);
bytes[13] = g8;}
if (object.schl3m_on==="None" || object.schl3m_on===255){
bytes[14] = 255;}
else{
var a9 = parseInt(object.schl3m_on);
var b9 = pad(a9,2);
var c9 = b9.substr(0,1);
var d9 = b9.substr(1,1);
var e9 = pad1(dec_to_bho (c9,'B'),3);
var f9 = pad2(dec_to_bho (d9,'B'),4);
var g9 = parseInt((Schl_m+e9+f9),2);
bytes[14] = g9;}
bytes[15] = 255;
if (object.schl3h_off==="None" || object.schl3h_off===255){
bytes[16] = 255;}
else{
var a10 = parseInt(object.schl3h_off);
var b10 = pad(a10,2);
var c10 = b10.substr(0,1);
var d10 = b10.substr(1,1);
var e10 = pad(dec_to_bho (c10,'B'),2);
var f10 = pad2(dec_to_bho (d10,'B'),4);
var g10 = parseInt((Schl_off+e10+f10),2);
bytes[16] = g10;}
if (object.schl3m_off==="None" || object.schl3m_off===255){
bytes[17] = 255;}
else{
var a11 = parseInt(object.schl3m_off);
var b11 = pad(a11,2);
var c11 = b11.substr(0,1);
var d11 = b11.substr(1,1);
var e11 = pad1(dec_to_bho (c11,'B'),3);
var f11 = pad2(dec_to_bho (d11,'B'),4);
var g11 = parseInt((Schl_m+e11+f11),2);
bytes[17] = g11;}
bytes[18] = 255;
if (object.schl4h_on==="None" || object.schl4h_on===255){
bytes[19] = 255;}
else{
var a12 = parseInt(object.schl4h_on);
var b12 = pad(a12,2);
var c12 = b12.substr(0,1);
var d12 = b12.substr(1,1);
var e12 = pad(dec_to_bho (c12,'B'),2);
var f12 = pad2(dec_to_bho (d12,'B'),4);
var g12 = parseInt((Schl_on+e12+f12),2);
bytes[19] = g12;}
if (object.schl4m_on==="None" || object.schl4m_on===255){
bytes[20] = 255;}
else{
var a13 = parseInt(object.schl4m_on);
var b13 = pad(a13,2);
var c13 = b13.substr(0,1);
var d13 = b13.substr(1,1);
var e13 = pad1(dec_to_bho (c13,'B'),3);
var f13 = pad2(dec_to_bho (d13,'B'),4);
var g13 = parseInt((Schl_m+e13+f13),2);
bytes[20] = g13;}
bytes[21] = 255;
if (object.schl4h_off==="None" || object.schl4h_off===255){
bytes[22] = 255;}
else{
var a14 = parseInt(object.schl4h_off);
var b14 = pad(a14,2);
var c14 = b14.substr(0,1);
var d14 = b14.substr(1,1);
var e14 = pad(dec_to_bho (c14,'B'),2);
var f14 = pad2(dec_to_bho (d14,'B'),4);
var g14 = parseInt((Schl_off+e14+f14),2);
bytes[22] = g14;}
if (object.schl4m_off==="None" || object.schl4m_off===255){
bytes[23] = 255;}
else{
var a15 = parseInt(object.schl4m_off);
var b15 = pad(a15,2);
var c15 = b15.substr(0,1);
var d15 = b15.substr(1,1);
var e15 = pad1(dec_to_bho (c15,'B'),3);
var f15 = pad2(dec_to_bho (d15,'B'),4);
var g15 = parseInt((Schl_m+e15+f15),2);
bytes[23] = g15;}
return bytes;
}}
Make sure to press "Save payload functions" to save the changes made.
Ubidots Setup
1. Go the "Event" (Data > Event) section, and create a new event just by pressing the plus (+) icon located at the right upper side of the page.
2. Create an Event using the variable which you have created for schedulers (this is the variable created for your scheduler in the device page).
In the “If Triggers” page select the variable and set the value equal to 14 (=Sunday):
NOTE: 7 events must be created separately for reach day of the week since the port are different for every day in the STREGA schedulers mechanisms; so totally 7 events for 7 days.
For the remaining 6 events to be created, select the same variable which you have created for schedulers in the device:
For Sunday set the value equal to 14
For Monday set the value equal to 15
For Tuesday set the value equal to 16
For Wednesday set the value equal to 17
For Thursday set the value equal to 18
For Friday set the value equal to 19
For Saturday set the value equal to 20
3. Then click on the action – create a new action – select TTN Downlink.
3.1. Then, in the following page fill the parameters required:
Fill the Application ID of your TTN account, Process ID (Name given when creating the Http Integration), Application Access Key (The access key which you have given while creating the Http Integration “Default Key” it can be found in the TTN account. TTN – Application - Overview).
3.2. Type the Device ID of your SV/SE, in the Port column type 14 for Sunday Schedule.
For Monday set the value to 15
For Tuesday set the value to 16
For Wednesday set the value to 17
For Thursday set the value to 18
For Friday set the value to 19
For Saturday set the value to 20
3.3. Select the Payload Type as Payload fields. Then, create the below mentioned field by clicking on the Add Field:
schl1h_on
schl1m_on
schl1h_off
schl1m_off
schl2h_on
schl2m_on
schl2h_off
schl2m_off
schl3h_on
schl3m_on
schl3h_off
schl3m_off
schl4h_on
schl4m_on
schl4h_off
schl4m_off
3.4. Then assign the value for each payload_field. Select the “Context” from the drop down for the field. Then double click on the context and edit is as context.schl1h_on
. The same should be done for the remaining all the field variables. The content name should be same as the payload_field name. Refer the above point for the payload_field name.
4. To finish,click ok and name the schedulers respective to the day for easy identification.
IMPORTANT NOTE: The same procedure should be followed for creating the remaining 6 events
5. Go to same event. Click on the event which you have created for the Scheduler.
5.1. Go to the action block and click on the “+” icon.
5.2. Select the set variable
5.3. Select the variable of the Schedulers and set the value to zero.
5.4. To finish, press "ok".
4. Summary
Now you're able to program automatic operation of the STEGA schedulers through Ubidots Dashboard in just a few minutes!
Other readers have also found useful...