Add on off Widget | MATLAB IoT Analytics | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
Add on off Widget
No permission to create posts
June 28, 2019
2:37 am
Avatar
nazanin.89

Silver
Members
Forum Posts: 5
Member Since:
June 28, 2019
sp_UserOfflineSmall Offline

Hi I am trying to add on/off widget for my project I want to have an on off button which become off when I send 0 to field 1 and become on when I send 1 to field 1 please help me if you know the answer: These are the codes I have tried so far but didnt work

//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
//netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js

https://gitcdn.github.io/bootstrap-toggle/2.2.0/js/bootstrap-toggle.min.js

body { background-color: #fff; padding: 40px; }

// set your channel id here
var channel_id = 808470;
// set your channel's read api key here if necessary
var api_key = 'XDATZS4GKZ6ARSMM';
// http response that we're reacting to
$(document).ready(function() {
// perform the request
function getData() {
$.get('https://api.thingspeak.com/channels/' + channel_id + '/feed/last.json?api_key=' + api_key, function(data) {
updateButton(data.field1);
});
}

// change the UI on the button
function updateButton(field1) {
if (field1 === 1) {
$('#togglebutton').bootstrapToggle('on');
} else {
$('#togglebutton').bootstrapToggle('off');
}
});
});

June 28, 2019
3:23 am
Avatar
nazanin.89

Silver
Members
Forum Posts: 5
Member Since:
June 28, 2019
sp_UserOfflineSmall Offline

I also try another code which didnt work as well

//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
//netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js

https://gitcdn.github.io/bootstrap-toggle/2.2.0/js/bootstrap-toggle.min.js
https://www.gstatic.com/charts/loader.js

body { background-color: #fff; padding: 40px; }

// set your channel id here
var channel_id = 808470;
// set your channel's read api key here if necessary
var api_key = 'XDATZS4GKZ6ARSMM';

google.setOnLoadCallback(initChart);

// load the data
function loadData() {

// get the data from thingspeak
$.getJSON('https://api.thingspeak.com/channels/808470/feed/last.json?api_key=XDATZS4GKZ6ARSMM, function(data) {
// get the data point
updateButton(data.field1);
});
}
// change the UI on the button
function updateButton(field1) {
if (field1 === 1) {
$('#togglebutton').bootstrapToggle('on');
} else {
$('#togglebutton').bootstrapToggle('off');
}
}
});
}

// initialize the chart
function initChart() {
loadData();
// load new data every 15 seconds
setInterval('loadData()', 1000);
}

June 28, 2019
1:24 pm
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 730
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline
July 1, 2019
3:43 am
Avatar
nazanin.89

Silver
Members
Forum Posts: 5
Member Since:
June 28, 2019
sp_UserOfflineSmall Offline

Hi
Thank you for your reply, but I need more Widgets to have better visualization for my system ,cause I want to design a Home Automation System and want to use lamp indicator for for example lamp controls and cause I am going to write a paper I would prefer to have different Widgets for different tasks . Can you please help to have on off Widget .Thingspeak is really good but unfortunately suffers from the lack of text and button Widget.
Regards,

July 1, 2019
5:26 am
Avatar
nazanin.89

Silver
Members
Forum Posts: 5
Member Since:
June 28, 2019
sp_UserOfflineSmall Offline

What I am exactly interested is for example when I copy the following related channel link in my browser and change the field from 0 to 1
https://api.thingspeak.com/update?api_key=D4QG0HQUFVI850WS&field1=0
the button change to off or on I have tried different codes but I cant apply this function please help me in this case.

July 3, 2019
2:39 am
Avatar
nazanin.89

Silver
Members
Forum Posts: 5
Member Since:
June 28, 2019
sp_UserOfflineSmall Offline

Hi
I am still waiting for the answer please help me and if it is not possible to have such a functionality just mention it.
Thank you.

July 3, 2019
9:06 am
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 730
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

I do not understand your request. I was not clear why the lamp indicator does not work for you. Please consider upgrading to a paid license for additional support.

Forum Timezone: America/New_York

Most Users Ever Online: 166

Currently Online:
28 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 272

Vinod: 240

piajola: 95

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 8665

Moderators: 1

Admins: 2

Forum Stats:

Groups: 3

Forums: 14

Topics: 1600

Posts: 5760

Newest Members:

aaceitunog01, AlinaCutle, MARTO, simplicity1, jango6954, LDN001

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457