Wednesday, December 09, 2015

Android Tasker: Automatically Storing Local Barometric Pressure Data

One of Shira's headache triggers is the weather, specifically barometric pressure. I was wondering how hard it would be to grab the current barometric pressure and store it all based on the phone's current geolocation.

Turns out, not that hard. One HTTP Request to openweathermap.org is all it takes to get the raw data. And parsing the JSON results turns out to be downright trivial thanks to this awesome Javascriptlet hack. JSON saves the day again!

Running this task appends the location, atmospheric pressure and timestamp to a text file.

Next up: using this text file. Stay tuned for more weather hacking fun.

Here's the Tasker Task described above. It's almost too easy to do!

Store Pressure Data (68)
    A1: Get Location [ Source:GPS Timeout (Seconds):100 Continue Task Immediately:Off Keep Tracking:Off ] 
    A2: Variable Split [ Name:%LOC Splitter:, Delete Base:Off ] 
    A3: HTTP Get [ Server:Port:api.openweathermap.org Path:/data/2.5/weather Attributes:lat=%LOC1
lon=%LOC2
appid=API_KEY Cookies: User Agent: Timeout:10 Mime Type: Output File: Trust Any Certificate:Off ] 
    A4: JavaScriptlet [ Code:var data = JSON.parse(global("HTTPD"));
var wloc = data.name;
var wpressure = data.main.pressure; Libraries: Auto Exit:On Timeout (Seconds):45 ] 
    A5: Write File [ File:Download/pressure.txt Text:%wloc: %wpressure | %DATE %TIME Append:On Add Newline:On ] 

1 comment: