2:37 am


Silver
June 28, 2019

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');
}
});
});
3:23 am


Silver
June 28, 2019

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);
}
1:24 pm


Moderators
March 7, 2017

Does the lamp indicator widget work for you?
https://www.mathworks.com/help/thingspeak/channel_display_widgets.html#lamp-widget
3:43 am


Silver
June 28, 2019

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,
5:26 am


Silver
June 28, 2019

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.
Most Users Ever Online: 166
Currently Online:
22 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:
estebanmateo93, mikewrite, onlinebusiness, winzy99, Zark_zeugan, StefanWiModerators: cstapels: 460
Administrators: Hans: 405, lee: 457