Parse the Max/Min value from 1 day to HTMLpage, JSON question. | ThingSpeak API | Forum

Avatar

Please consider registering
Guest

Search

— Forum Scope —






— Match —





— Forum Options —





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

Register Lost password?
sp_Feed sp_TopicIcon
Parse the Max/Min value from 1 day to HTMLpage, JSON question.
Avatar
popunonkok

Silver
Forum Posts: 8
sp_UserOfflineSmall Offline
1
January 14, 2017 - 3:47 am
sp_Permalink sp_Print

This script works. It prints the 1st value of Field1 in my Channel. The code prints it in the Div class "Column-center".

<script>
$(document).ready(function(){
            $.getJSON("https://api.thingspeak.com/channels/XXXXXX/feeds.json?days=1", function(result){
            $(".column-center").prepend(result.feeds[1].field1);
        });
});
</script>

How can I change this so that I insted of the first value get the Max value of the entire 24 hours that I have "getJSON"???

Would love something like:

MAX(result.feeds.field1)

But I guess its not that simple.

 

Can anyone help me?

Avatar
Vinod

Forum Posts: 164
sp_UserOfflineSmall Offline
2
February 26, 2017 - 4:52 pm
sp_Permalink sp_Print

You could do this in Javascript.

data = $.getJSON("https://api.thingspeak.com/channels/XXXXXX/feeds.json?days=1");

var maxVal = -Infinity;
for (var i = 0; i < data.feeds.length; i++) {
   if (data.feeds[i].field1 > maxVal) {maxVal = data.feeds[i].field1;}
}

maxVal should have the maximum value of field1 in the last day (assuming you have accumulated <8000 points) in the last day.

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
13 Guest(s)

Currently Browsing this Page:
2 Guest(s)

Top Posters:

rw950431: 252

Vinod: 164

cstapels: 96

piajola: 75

vespapierre: 63

Adarsh_Murthy: 59

Newest Members:

donj51

trilee

Bfletche

stuartWAI

shivmkatiyar

AidanThing

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

 

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Administrators: Hans, lee