ThingSpeak is an IoT platform with built-in MATLAB® analytics, which allows preprocessing, analyzing and visualizing data sent by IoT devices, as well as creating actions such as alerts based on your channel data.
Prerequisites
- A user account on ThingSpeak.
Setup ThingSpeak
Log in to your ThingSpeak user account and navigate to the Channels section. To create a new channel, click the New Channel button.
Enter a Name for your channel, give labels to the data fields and enable them by checking the boxes next to them.
When done, scroll down and click the Save Channel button.
You should enable a field for each metric from the decoded_payload
object of the uplink message.
For implementing the webhook integration on The Things Stack, you will need the following information from your channel’s page on ThingSpeak:
-
Channel ID, which can be found on the Channel Settings tab after channel creation, or under your channel’s name on top of the channel page;
-
Write API Key, which can be found on the API Keys tab.
Configure The Things Stack
Before implementing the Webhook integration, you need to create an uplink payload formatter in order to decode the uplink payload and set fields in the decoded_payload
object of the uplink message. The example uplink payload formatter is shown below.
function decodeUplink(input) {
return {
data: {
field1: input.bytes[0],
field2: input.bytes[1]
},
warnings: [],
errors: []
};
}
The last step is to instantiate the ThingSpeak Webhook template to create a Webhook integration.
Give a name to your integration by filling in the Webhook ID field.
Fill in the Channel ID field with the ThingSpeak channel ID value, and paste the Write API Key from ThingSpeak in the API Key field.
Finish by clicking the Create thingspeak webhook button.
To see the values of all parameters of the ThingSpeak integration, click on the integration after you created it with the Webhook template.
At this point, you can go back to your channels page on ThingSpeak and select the private or public view of your channel to check out the field charts under Channel Stats. You can now also write and automate MATLAB® code to analyze and further visualize your data.