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/
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.
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,
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