In many IoT applications, the storage of sensor values in the cloud is of particular interest, because this data can then be retrieved from anywhere via the Internet.
We use the cloud server ThingSpeak, which is available free of charge for small data amounts. In addition, this cloud service offers Mathworks (MatLab distribution), which data makes it easy to graphically display data as part of an website.
To use the services, you must create a personal account with ThingSpeak (www.thingspeak.com). The data is organized in tables called channels. First you define a new channel by selecting a name (e.g. Sensor Data) and a field descriptor (column name, e.g. Temperature (degC)). Under Channel Sharing Setting, select Share channel with everyone. Under API Keys note the the Write and Read API Keys.
Under API Request you get the information how to enter a new value (Update a Channel Feed) using a HTTP or HTTPS GET request, e.g.
You may copy this line to the browser URL and see the result under My Channels.
The following program connects to na access point and sends a new temperature value every 20 s (for a free account the maximum data rate is 1 sample every 15 s). The temperature is also shown on the display of the micro:bit's and written into the console. The HTTP response received from the cloud server is shown in the console. It is the total number of channel values.
const char* key = "TJH7REA0WQD0QC5P";
connectAP("raspilink", "aabbaabbaabb", reply);
dtostrf(temp, 4, 1, temp_s);
strcpy(buf, "New temperature: ");
strcat(buf, " C");
dtostrf(temp, 4, 2, buf);
You can retrieve the channel data of a public channel with a HTTP GET request, e.g. the last 100 entries with
where the number is the Channel ID coming from your ThinkSpeak account. The data is json-formattet and will display well in a browser if you use the above URL. (Don't forget that your channel must have the Share option view with everyone enabled).
Clicking the small window icon in the Field 1 Chart opens a link that displays the graph the browser. You can copy this link to any browser in the world to see your channel data.