Google Gauge Plugin Trying to display Daily Sum instead of Last Entry | ThingSpeak Plugins | 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
Google Gauge Plugin Trying to display Daily Sum instead of Last Entry
No permission to create posts
December 20, 2015
12:12 am
Avatar
Veramacor
New Member
Members
Forum Posts: 2
Member Since:
December 20, 2015
sp_UserOfflineSmall Offline

Hello All,

This is what I'd like to do. I would like to retrieve the sum of all my datapoints for a field for the current day and display the result
in a gauge control The call works in a browser
no problem:

http://api.thingspeak.com/channels/70495/field/5.json?days=1&sum=daily

So I replaced this JSON Call:

$.getJSON('https://api.thingspeak.com/channels/' + channel_id + '/feed/last.json?api_key=' + api_key, function(data) {

with this:

$.getJSON('https://api.thingspeak.com/channels/' + channel_id + '/fields/5.json?days=1&sum=daily&api_key=' + api_key, function(data) {

Here is the code I think it fails on. I don't thing p = data.field5 is valid the first JSON call returns extra JSON.

// load the data
function loadData() {
// variable for the data point
var p;

// get the data from thingspeak
$.getJSON('https://api.thingspeak.com/channels/' + channel_id + '/fields/5.json?days=1&sum=daily&api_key=' + api_key, function(data) {

// get the data point
p = data.field5; //Thingspeak

if (p) {
p = (p/1);
displayData(p);
}

});
}

Any help would be appreciated!

Thanks,

Jeff

December 22, 2015
7:49 am
Avatar
Veramacor
New Member
Members
Forum Posts: 2
Member Since:
December 20, 2015
sp_UserOfflineSmall Offline

I found the answer.

I just needed a little education on how javascript parses the data:

$.getJSON('https://api.thingspeak.com/channels/' + channel_id + '/feed.json?days=1&sum=daily&api_key=' + api_key, function(data) {

// get the data point
var p = data.feeds[0].field5; //Thingspeak

The $.getJSON with the function(data) does the parsing for you. I just had to learn about how the data is referenced :

data.feeds[0].field5 references "field5":"46.90999999999999" in the return JSON:

{"channel":{"id":70495,"name":"Whatameter_52_1","field1":"Count","field2":"Duration","field3":"AverageReading","field4":"Battery Voltage","field5":"Volume","created_at":"2015-12-06T16:13:09Z","updated_at":"2015-12-22T12:47:07Z","last_entry_id":278},"feeds":[{"created_at":"2015-12-22T00:00:00Z","field1":"2825.0","field2":"1004.0","field3":"3788.0","field4":"88.54867","field5":"46.90999999999999"}]}

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online: Hans, agrisensezm
37 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 261

Vinod: 196

piajola: 85

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

Newest Members:

Archieter, JamesExedo, IrbosHich, brodi, kasko, franklin castro

Administrators: Hans: 387, lee: 457