Thingspeak
About ,Account and Channel Creation
ThingSpeak is a webservice, open source Internet of Things (IoT) application and API to store and retrieve data from things.
The service is free and offers a very basic http based service for starters.The platform is very limited but suits the context, for now, since its extremely easy to setup. Lets start
- Sign Up for an account in thingspeak
- Create a new channel.
- Go to the channel setting and copy the API Write key.
You can select enable/select more fields in a channel to view/capture multiple data streams.Also you may enable public view to publish the channel to anyone with access to your channel id
The API key should be kept secure since it forms the one and only layer of authentication.
Configuration
Raspberry Pi will work as a gateway to publish data from sensors interfaced via its GPIO or sensors connected via external devices such as Arduino.To proceed make sure that you have a working internet connection on Raspberry Pi that can connect to Thingspeak servers.
We will use an RPi and Arduino to better understand the concepts.
- Setup Arduino to send serial data over USB.You may use LDR experiment as an example.
- Connect Arduino to RPi via USB.Try
dmesg | grep tty
to check and identify the device. - Change permissions to ensure read access to the device
sudo chmod 777 /dev/ttyACM0
The device address should be as obtained from previous line of code.It can be ACM0 ACM1 (ACMx series ) or USB0 USB1 (USBx series)
Code
The code for RPi can be cloned from my github repo. Try in terminal
git clone https://github.com/akshaim/thingspeak
The code can also be downloaded from here
- Go to the cloned/downloaded repository and edit thingspeaktest.py. Try
nano thingspeaktest.py
- Enter you write api key in the field provided and save the file.
Press Ctrl + O and then enter to save.Press Ctrl + X to exit from nano
- Execute the code.Try
python thingspeaktest.py
- If you get status code as 200 ,you should see an entry (value 12)in your thingspeak channel webview (private/public depending on your channel settings)
- Now edit thingspeaktestloop.py and add the write API key as in the previous case.
- Run the code. Try
python thingspeaktestloop.py
- Now edit thingspeaktestserial.py as in the previous case.The python code sends a dynamic value from Arduino to thingspeak server
Change the field value to observe change in webview (fieldchart).
The code sends a static value(default 12) to thingspeak server in a 16 second interval and updates the status to user
Ensure that the device address(arduino) is same as one you observed. Default value is /dev/ttyACMO