Hidden API Commands
When you are retrieving data from a ThingSpeak channel you have many options and formats to choose from. We wanted to highlight a few options that are easily overlooked.
Last.txt
Let’s say you have an Arduino and you want to get the last value in a channel. You could get your feed and then write some parsing code to extract the data that you are looking for. It’s a waste of code space and also fills your finite buffers on your microcontroller. Let the cloud do the work and give you just the value you are looking for.
Here’s how you would get our light levels: Live Demo
[cce]http://api.thingspeak.com/channels/9/field/1/last.txt[/cce]
Modifying the response
You can even add data to the response. Maybe you have Twilio reading back your temperature. It would not be much fun if Twillio says to you, “80”. Sensor data without context is noise!
Here are two optional parameters when returning the last data on a ThingSpeak Channel:
- prepend=[text to add before the API response]
- append=[text to add after the API response]
[cce]http://api.thingspeak.com/channels/9/field/1/last.txt?prepend=Your%20light%20level%20is%20&append=.%20Is%20someone%20in%20your%20room?[/cce]
Check out the ThingSpeak Documentation for more information.
Comments
To leave a comment, please click here to sign in to your MathWorks Account or create a new one.