element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • Product Groups
  • Store
    Store
    • Visit Your Store
    • Choose Another Store
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
Personal Blogs
  • Members
  • More
Personal Blogs
Legacy Personal Blogs K64F Weather Part 3 -Interface to thingsNext click on the API
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: colin_meikle@mentor.com
  • Date Created: 27 Mar 2015 9:39 PM Date Created
  • Views 221 views
  • Likes 0 likes
  • Comments 0 comments
Related
Recommended

K64F Weather Part 3 -Interface to thingsNext click on the API

colin_meikle@mentor.com
colin_meikle@mentor.com
27 Mar 2015

Using A Web Service to Display Results

 

This is a follow on from K64F MBED Part 2 Weather Station

Often you want to record, store or display the results you collect over time. You can do this yourself, either by storing the results locally e.g. we do this in this application by storing the results on the sdcard. However if you have web connectivity as we do, using cloud based services is probably the best solution. There are numerouss ervices you can use, some free some and some subscription based. Which you chose will based on your actual needs and usage. For this application we will use thingspeak.org, you can sign up for a free account and using the service is very easy.

 

Setting up Thingspeak

 

First sign in then create a new channel https://thingspeak.com/

image

 

This will give you a form which you can fill in. The important part is the field sections. These fields are the variables that you will use for your data, so you simply label them with the names for your variables.

image

 

next click on the API Keys tab. Take note of the Write  API key

In the Mbed compiler open the main.cpp and look for this section

//sent to thingsspeak

    if(cnt==10){ //don't update as often

      cnt=0;

      memset(resp, '\0', sizeof(resp));

    //POST data

      if(temperature!=-100){ //just check we have a valid temp

        map.put("api_key","YOUR KEY HERE");

 

Replace where is says YOUR KEY HERE with your write key

We then build up out post request with the data to match the fields we set up in thingsspeak. Finally we use http.post to send the data to https://api.thingspeak.com/update

sprintf(val[0],"%4.1f",temperature);

        map.put("field1", val[0]);

        sprintf(val[1],"%4.1f",humidity);

        map.put("field2", val[1]);

        sprintf(val[2],"%4.1f",forcastTemp);

        map.put("field3", val[2]);

        sprintf(val[3],"%4.1f",forcastPressure);

        map.put("field4", val[3]);

        pc.printf("\nTrying to post data...\n");

        ret = http.post("https://api.thingspeak.com/update", map, &inText);

 

The code sends the data once per minute, you need to take care you don't send it too often as there are limits on  how often you can update.

That's all that is required, once you've sent some results you can view the graphs,

image

The icons on the top right of the graphs, allow you to customize the graph and give you the code snippets for embedding the graphs in your webpage

 

 

Getting everything running

 

complete tomorrow

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2023 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • Facebook
  • Twitter
  • linkedin
  • YouTube