Wednesday 16 September 2015

Android data to Thinkspeak with Tasker HTTP Post

I wanted to study how to exchange data between Android and Internet-of-Things cloud storage. If you have used Tasker, then you know that it is very powerful tool and that was number one choice to the Android end. I have connected my Arduino system to Xively Internet-of-Things cloud storage, but I find out that Mathworks has similar (and maybe better) service called Thingspeak.

As proof of consept I created a Thingspeak data channel for Android battery level (https://thingspeak.com/channels/55432). 
Thingspeak channel settings. 
From Thingspeak 'Data Import / Export' tab you will find an example how data channels are updated. That information will be needed for Tasker task. 

In Tasker create new Task that we can call "Thingspeak Batt Mon". 


Tasker task for Thingspeak data update. 
On this task I use %LOCATION variable that is updated in other task. That variable is same as %LOC, so it contains the latitude and longitude information separated by comma. If you want to include the location to the data then lat and long need to be stored to separate variables that I have done in first action 'Variable Split'. That will split the "lat, long" coordinates to two separate variables %LOCATION1 and %LOCATION2. 

Second action on this task is IF loop where I compare battery level to the battery level that is stored to %BATT_old variable. This way we do not update the data if value has not been changed. 

Then we get to the main part of the task, the HTTP Post action. 
HTTP Post action. 
In this action we define the Thingspeak server address and update path. This information you can find from the Thingspeak channel help. Then on the Data / File field we define the data that we send to the server. Key is your own API-key and then we define the data that we send to the server, each parameter on separate row. First parameter I have field1 where I want to store the %BATT Tasker variable. Then I have two coordinate parameters where I store the %LOCATION1 and %LOCATION2 variables that were created by the first split action. Rest of the fields can be left untouched. 

If you look the task next I have the variable set action that store the current battery level to variable #BATT_old that was used in IF statement.

Next is 15 seconds delay that is there to make sure that update interval to Thingspeak server s minimum 15 seconds. Thinkspeak has the update rate limitation of 15 seconds. 

Below IF loop I have the ELSE brach. That is needed for #BATT_old variable update in case IF branch is not executed.

Tasker task need to run by the profile. For profile I created simple Time profile that will run the task every 15 minutes.


Then data should start to appear on Thingspeak server. 

Thingspeak channel.

The location will not be visible on channel page, but can be seen on channel feed (Data Export). Note that you need to add "location=true" parameter like this: http://api.thingspeak.com/channels/55432/field/1.json?location=true (I have removed location from my public feed).



Tasker - Thingspeak combo will allow all kind of data transfer between Android and Internet, but also allows easy data transfer between Android and Arduinio or RaspberryPI. With Tasker it is possible to create all kind of user interfaces (example with speech) or location based events that can be used to trigger your controller. Data can be also read with Tasker from the feed and any kind of alarms and notifications can be created.

Following article was great help with Tasker: Controlling Your Home Automation Controller with Tasker

1 comment:

oscar said...

great! i was lookiing por these to monitor the batteries from various celphones i have. is a shame i cant find any simple app that just do that, monitor and uploar my bateri level to the cloud. but thank to you it is some kind solved.
https://thingspeak.com/channels/88440