Fetching Data From ThingSpeak IoT Cloud

In this post we will see how to fetch data from ThingSpeak (an IoT Cloud plarform). The data can be fetched from any client device: A laptop, mobile or a micro-controller.

We will use a JQuery based web page on a laptop, to fetch the data logged into ThingSpeak. You may visit my other post on setting up a device channel in ThingSpeak for a tutorial on the pre-requisites.

The HTML/JQuery Code

The JQuery based web page has been coded in such a way that it will fetch the last logged data row every 10 seconds. The re-usable code has been provided below.



Steps to re-use the above code

Follow these steps to re-use the above code.
  1. Download the JQuery library. I have used "jquery-1.12.1.min.js". You are free to chose, but if you do, then make sure you update the HTML appropriately.
  2. Copy the code
  3. Create an HTML file in the same directory as the JQuery library
  4. Paste the code in the HTML file
  5. Make sure you change the channel ID in the GetData() function to fetch data from your device channel. However, I have left mine "as is" in the above code, so that it works out of the box for you.
  6. Save and close the HTML file
  7. Open the HTML file in a browser
  8. Every 10 seconds it should fetch data from ThingSpeak and display it on the screen

Running the HTML/JQuery App

Follow these steps outlined below.
  1. Just right click and open with a browser.
  2. This is what I see when I open the HTML file.
Fetching Data From ThingSpeak IoT Cloud

What Next?

Well, this is how you can fetch the logged data from your remote sensors or edge devices via an IoT Cloud such as ThingSpeak. Of course you may perform a lot of things hereafter: predictive analytics, machine learning and so on...

Cheers,
KBRC



8 comments:

  1. Thank you very much.
    It exactly the same what I need.
    And it's working fine and gives the correct out put
    .

    ReplyDelete
  2. Sir how can i display all.channel data and feed data in tabular format in html

    ReplyDelete
  3. Can you show how to post to thingspeak. Thank for the tutotrial.

    ReplyDelete
  4. How to fetch data from two fields at a time

    ReplyDelete
  5. Merkur 20C Open Comb - Classic Leather - TITanium
    A Merkur 20C Open Comb titanium easy flux 125 amp welder is a chrome plated safety razor that provides great control over skin exposure. titanium vs ceramic Ideal for beginners to shaving with the open thunder titanium lights comb $42.00 · man titanium bracelet ‎Out of stock edc titanium

    ReplyDelete