I created an alert on my phone to tell me when the temperature outside drops below freezing. Since I don't have my own network accessible thermometer, I am using the wunderground api to query the closest weather station, a couple of miles away. It should be close enough.
I used this blog post as a guide for accessing the wunderground api: http://www.pocketables.com/2012/07/tasker-task-that-speaks-the-weather-forecast-download.html
I set up a wunderground developer account here: http://www.wunderground.com/weather/api/
In Tasker:
The profile runs every hour.
The task is as follows:
A1: HTTP Get [ Server:Port:api.wunderground.com Path:/api/[mykey]/conditions/q/[my state abbrev]/[the town or neigborhood with the station I wanted to query].xml Attributes: Cookies: Timeout:10 Mime Type:text/plain Output File: ]
A2: Variable Set [ Name:%wunderresults To:%HTTPD Do Maths:Off Append:Off ]
A3: Variable Search Replace [ Variable:%wunderresults Search:\<temp\_f\>\d\d.\d\<\/temp\_f\> Ignore Case:Off Multi-Line:Off One Match Only:Off Store Matches In:%matchedtemp Replace Matches:Off Replace With:a ]
A4: Variable Search Replace [ Variable:%matchedtemp1 Search:\d\d.\d Ignore Case:Off Multi-Line:Off One Match Only:Off Store Matches In:%matchedtemptwo Replace Matches:Off Replace With: ]
A5: Variable Set [ Name:%oakbrookTemp To:%matchedtemptwo1 Do Maths:Off Append:Off ]
A6: Flash [ Text:%myTemp Long:Off ]
A7: If [ %myTemp < 33 ]
A8: Notify [ Title:Temperature Warning Text:%myTemp Icon:hd_alerts_and_states_warning Number:0 Permanent:Off Priority:3 ]
I had to do some parsing gymnastics to get the temperature out of the xml returned from wunderground (actions 3 and 4).
I also have the temp display on a MimialistText widget so I can see the temp anytime, not just when it's freezing.
Saturday, December 28, 2013
RPi - Python and Blinking LED
I successfully created a python script to blink an LED attached to the RPi/Pi Cobbler.
The circuit attaches to the 3.3V output, routes through the LED, a 470R, and back to GPIO pin 18.
I wrote it using IDLE on the RPi GUI.
I used this blog post as my guide: http://www.thirdeyevis.com/pi-page-2.php
I also referred to this one and even started to set up the WebIDE: http://www.akeric.com/blog/?tag=pi-cobbler
The code:
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
def Blink(numTimes,speed):
for i in range(0,numTimes):
print "Iteration " + str(i+1)
GPIO.output(18,True)
time.sleep(speed)
GPIO.output(18,False)
time.sleep(speed)
print "Done"
GPIO.cleanup()
iterations = raw_input("Enter total number of times to blink: ")
speed = raw_input("Enter length of each blink(seconds): ")
Blink(int(iterations),float(speed))
The circuit attaches to the 3.3V output, routes through the LED, a 470R, and back to GPIO pin 18.
I wrote it using IDLE on the RPi GUI.
I used this blog post as my guide: http://www.thirdeyevis.com/pi-page-2.php
I also referred to this one and even started to set up the WebIDE: http://www.akeric.com/blog/?tag=pi-cobbler
The code:
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
def Blink(numTimes,speed):
for i in range(0,numTimes):
print "Iteration " + str(i+1)
GPIO.output(18,True)
time.sleep(speed)
GPIO.output(18,False)
time.sleep(speed)
print "Done"
GPIO.cleanup()
iterations = raw_input("Enter total number of times to blink: ")
speed = raw_input("Enter length of each blink(seconds): ")
Blink(int(iterations),float(speed))
Tuesday, December 24, 2013
Simple LED Circuit
My Pi Cobbler arrived the other day and finally got around to playing. Created a simple LED circuit using the 3.3 V and ground pins on the cobbler. No Pi functionality was used other than as a source of power.
I used this blog post as a guide.
https://projects.drogon.net/raspberry-pi/gpio-examples/tux-crossing/gpio-examples-1-a-single-led/
Next, I'll control the LED via gpio on the pi.
Circuit:
I used this blog post as a guide.
https://projects.drogon.net/raspberry-pi/gpio-examples/tux-crossing/gpio-examples-1-a-single-led/
Next, I'll control the LED via gpio on the pi.
Circuit:
Google Location Data
Using this blog post as my guide, I downloaded the location data that Google stores about me and plotted it via R: http://seasci.wordpress.com/2013/12/20/it-knows-where-i-live/
The json file downloaded from Google Takeout was 123 MBs, over 780k location records. It takes several minutes for the script to parse all those records.
The blog author is from UK so I needed to adjust map parameters to my relevant locations.
This script uses get_map() a lot. Here's the documentation for get_map(): http://www.inside-r.org/packages/cran/ggmap/docs/get_map
I also tried to convert the json file to a csv prior to importing into R using this py script: https://github.com/Scarygami/location-history-json-converter/blob/master/location_history_json_converter.py
I modified the csv output format a bit to include accuracy data and to add a comma between lat and lon. I think because there were some records without accuracy, I was getting errors so applied a Catch KeyError function to the accuracy line. This helped me: http://stackoverflow.com/questions/16154032/catch-keyerror-in-python
Next I need to modify my R script to read in csv instead of json.
I also tried to convert the json file to a csv prior to importing into R using this py script: https://github.com/Scarygami/location-history-json-converter/blob/master/location_history_json_converter.py
I modified the csv output format a bit to include accuracy data and to add a comma between lat and lon. I think because there were some records without accuracy, I was getting errors so applied a Catch KeyError function to the accuracy line. This helped me: http://stackoverflow.com/questions/16154032/catch-keyerror-in-python
Next I need to modify my R script to read in csv instead of json.
Tuesday, December 17, 2013
R - POSIXct vs. POSIXlt
As I continue to learn about managing date and time data, I'm working to understand the difference between
POSIXct and POSIXlt
POSIXct is a date-time data object that stores the number of seconds since a certain point in time in the past.
POSIXlt stores a list of day, month, year, hour, minute, second, etc.
I'm still learning when best to use each type in different contexts. More to come on that.
R - strftime() vs. strptime()
I'm learning how to handle date and time data in R.
There are two functions that are similar when converting date/time related data.
strptime() takes a character vector (string) and converts to a POSIXlt or POSIXct data object.
strftime() takes a a POSIXlt or POSIXct data object and converts to a character vector (string).
Here is documentation on use including formatting characters: http://www.inside-r.org/r-doc/base/strftime
There are two functions that are similar when converting date/time related data.
strptime() takes a character vector (string) and converts to a POSIXlt or POSIXct data object.
strftime() takes a a POSIXlt or POSIXct data object and converts to a character vector (string).
Here is documentation on use including formatting characters: http://www.inside-r.org/r-doc/base/strftime
Sunday, December 15, 2013
R - Comment Lines in Data File
Today I learned that you can have comments lines in data files. You need to include comment.char="#" as an argument to read.csv() and use whatever symbol you want, though a # (octothorpe) would be consistent with commenting in Rscript.
Example:
data <- read.csv("../datasets/heatmaps_in_r.csv", comment.char="#")
Subscribe to:
Posts (Atom)