Press "Enter" to skip to content

Weekend Enthusiast Posts

Collecting and Handling 911 Event Data

Seattle has a pretty awesome approach to data availability and transparency through data.Seattle.gov.  The city has thousands of data sets available (from in-car police video records to land zoning to real-time emergency feeds) and Socrata, a Seattle-based company, has worked with the city (and many other cities) to allow developers to engage this data however they like.  I spent some time playing around with some of the data sets and decided it’d be nice to know when police and fire events occurred near my apartment. I setup a script to pull the fire and police calls for events occurring within 500 meters of my apartment and started storing them into a local database (Socrata makes it so simple – amazing work by that team).  While reading it from the API, I check the proximity of the event to my address and also the type of event (burglary, suspicious person, traffic stop, etc) and trigger emails for the ones I really want to know about (such as a near by rape, burglary, shooting, vehicle theft, etc).  I decided to store all events, even traffic stops, just because.  I may find a use for it later – who knows… After I’ve scrubbed through and sent…

Location to HTTP – Send GPS data to remote script

I wanted to capture my phone’s location information and store it remotely (on my server) so I could do with it as I please.  Most of the apps I found were severely limited in that they only mapped within the app, were riddled with ads, crashed frequently, or were untrustworthy (they’re storing my location, after all).  So, I decided to build my own app that did what I wanted. Location to HTTP Location to HTTP is an app I’m working on which allows users to input a remote script URL to capture a device’s location information via POST. How it works Create a remote script to capture the variables $lat and $lon via POST (example below). Download the app and enter the URL of that script. The app will automatically send the location information every 5-10 minutes to the script. Possible Uses Track your phone’s location so you can retrace your steps if you lose it. Store your location history for displaying in custom interfaces. Share your location with friends/family when travelling or hiking. Trigger home automation events based on your location (turn on the heat, turn on the lights, unlock the doors, feed the pets, water the plants, etc.).…

Webcam Captures Text and Stores in MySQL Database

While visiting my family recently, I saw my dad entering numbers from each of the 5-8 ticket receipts he receives daily to keep track of the work he’s done, report for payroll, etc.  I knew there had to be an easier way to collect this information without having to key each ticket manually or without using a clunky, slow scanner.  After a bit of research, I found an API for OCR from Haven OnDemand and I wrote a simple script to use the camera on his laptop to snap pictures of the tickets, scrape the text and position of the text from the tickets, store it all in a MySQL database, and retain the image of the tickets in a digital archive. Demo: Snapping image via webcam and storing text The script itself is actually very simple: <?php $con=mysqli_connect(localhost,<user>,<pw>,<db>); $name = date(‘Y-m-d_H:i:s’); $newname=”images/”.$name.”.jpg”; $file = file_put_contents( $newname, file_get_contents(‘php://input’) ); if (!$file) { print “Unable to write image to directory.”; exit(); } else { $filePath = ‘http://’ . $_SERVER[‘HTTP_HOST’] . dirname($_SERVER[‘REQUEST_URI’]) . ‘/’ . $newname; $result_json = file_get_contents(“https://api.idolondemand.com/1/api/sync/ocrdocument/v1?apikey=<dedacted>&url=$filePath&mode=scene_photo”); $json_a=json_decode($result_json,true); $result_left=0; $result_top=0; $result_widht=0; $result_height=0; foreach($json_a[text_block] as $p){ $result_text=htmlspecialchars($p[text]); $result_left=$p[left]; $result_top=$p[top]; $result_width=$p[width]; $result_height=$p[height]; $sql=”insert into image (name,pxleft,pxtop,pxwidth,pxheight,result) values (‘$name’,’$result_left’,’$result_top’,’$result_width’,’$result_height’,’$result_text’)”; $result=mysqli_query($con,$sql); $value=mysqli_insert_id($con); } }…

Data Visualization and Demo

As mentioned previously, my goal wasn’t to just create a home controller/dashboard but to also collect as much data as possible while doing so.  So tonight, I started playing around with a few different visualizations of the data I’ve collected thus far.  It took a few hours but I’m satisfied with the current state. I’m doing simple dumps of the most recent music played by my Amazon Echo; most recent programming watched via DirecTv; visualizing the daily average, minimum, and maximum temperature and humidity levels in my apartment; visualizing by hour of day the average, min, and max temperature for the current month vs the previous month; breaking down the amount of time I spend at home by day of week (and telling on myself that I like to leave work early on Fridays :)); and visualizing my TV watching habits by hour of day and day of week. I recorded a video of this all and also included the DirecTv control demo at the end.

Home Automation and NFC Tags

NFC has proven to be a pretty useless technology for cell phones (unless you’re one of the people who use you Google Wallet/Apple Pay).  Nevertheless, I decided to buy some tags and play with them because they’re so damn cheap (just over a dollar each, depending on the type). One useful application of NFC tags is setting “scenes” using my existing home automation setup.  By setting a tag where I usually place my phone at night, I can trigger several events all at once.  When I play my phone on my nightstand, the following events are triggered: If it’s a weekday, set my alarm for 7:00 AM. If an alarm was set, the phone will adjust its volume and say “Alarm set to 7 AM”. Using the same text to speech, the phone will say “Goodnight, Kevin.” After pausing for a few seconds, it’ll POST to a simple script I wrote  and turn all the lights in the apartment off before setting it’s volume to mute for the remainder of the night. It’s a simple way of automating my night time routine and is likely the most practical use of NFC tags with home automation (and it’s not super practical, at that).  If you…

Expanding the Home Dashboard

In the previous post, I outlined the Home Dashboard touchscreen for controlling lights, temperature/humidity, displaying Amazon Echo information, displaying who’s home (via bluetooth sniffing), and displaying what was being watched on DirecTv.  As this dashboard is intended to be a sudo remote control for my home, I thought it made sense to be able to actually control the TV with it. After a bit of tweaking and some UI work, the end result is a super-quick (HTTP response is ~30 milliseconds which feels nearly as quick as the standard DirecTv remote) interaction between device and DirecTv receiver. From my home dashboard/touchscreen controller, I can select the title that’s currently playing to launch the remove control (pictured above).  You’ll notice that the touchscreen controller can do everything the standard remote can do, including guide browsing, DVR browsing, etc.

Home Dashboard using a Raspberry Pi

After creating a desktop home automation dashboard and, later, a live stream “digital picture frame”, I got the idea to combine the two into an always-on control panel that condenses everything I care about into a single kiosk which can sit on my end table or nightstand. What it does It’s essentially a condensed UI of the desktop version linked above which uses the same databases and processes. Current indoor temperature and humidity (via DHT11 sensor) If my Amazon Echo is playing music, it’ll display the artist, song, and album If I’m watching TV, it’ll show the title, channel, and image/movie poster Display unique icons for each person in the house (by sniffing for their phone’s bluetooth signal) It’ll show the status of my lights (on/off) and update if that status changes (using the Wink API) Through touch screen, allow me to control my lights in near real-time. Materials Used A Pi3 Pi display A case Indirectly, I also engage my Wink Hub, Amazon Echo, and DirecTv receiver. How it works Much of this (temperature, humidty, DirecTv and Wink control) is covered in “The Foundation” post.  Specific to collecting information from the Amazon Echo, I use IfTTT and the Maker channel.  Each time my…

Using a Pi to measure TV habits

As noted here, I’m using the the DirecTV SHEF API and a Raspberry Pi to poll my DirecTV receivers every minute and store what they’re doing into a MySQL database. After ~6 months of storing that data, I thought it’d be interesting to analyze some of it.  After all, do I really watch enough HBO and Starz to warrant paying for them every month? Channel Preferences 25,900 minutes of TV watched (~2.25 hours per day…eek; still less than the national average!). 2,612 minutes of that was recorded (10%). NBC is our favorite channel (3,869 minutes watched, 15%). E! is our second favorite channel (1,911 minutes watched, 7.37%). Gotta keep up with those Kardashians. Premium movie channels (HBO, Starz, Encore, Cinemax, etc) were watched 6,870 minutes (26.52%) – apparently worth the money. Premium movie channels were recorded only 571 minutes (lots of ad hoc movie watching, I guess). NBC is our most recorded channel (479 minutes) followed by HGTV (391 minutes) and ABC (330). Time Habits Sunday is the most watched day (no surprise here) with 7,157 minutes watched (28%) Saturday is the second with 5,385 (21%) Wednesday is the least watch with 1,144 (4.4%) April was our biggest TV month with 6,413 minutes…

Webcam Stream as Digital Picture Frame

I don’t have a quality window view in my office building and found myself checking the local news’ weather cams throughout the day so I thought it’d be cool to have a live outdoor view streaming to my desk.  Using a Pi 3, Pi Display, a case, and camera, I built a digital picture frame which streams a live video feed from my apartment window to my desk at work.  While going through the process, I hit a few hiccups and a ton of outdated resources online so I thought I’d share my learnings and provide documentation for anyone wishing to recreate. The following will setup a Pi to run Chromium in Kiosk mode on startup while silencing errors and hiding your cursor.  The assumptions made before beginning are that you’re able to SSH into both of the Pis and your Pis are connected to WiFi.  The guide I followed to setup my cam stream is solid so no need to re-invent the wheel – use this guide to setup your first Pi to stream your cam image.  The obvious callout is to make sure your stream resolution matches your display’s resolution.  The steps below will be for your picture frame Pi…

A month of tinkering

New Design The original design wasn’t “clean” feeling and didn’t function too well on mobile or even tablet displays.  I changed that up a bit and the new design has a lot of transparent divs, bokeh background images, and some jquery to make actions a bit smoother. Wink Integration Improvements The initial integration of the Wink API wasn’t that great.  I was using PHP to trigger shell scripts which would then make the API call – quite messy and had several opportunities for failure.  This method also made a new request for a bearer token each time an action was taken so if I turned on three lights, I requested three unique tokens from the API.  I’ve since cleaned that up and now use a single token per session and the API calls are all made in a single PHP file.  This still isn’t the cleanest or safest way to do this but it works for my usecase. While doing this, I also added the ability to dim some lights (such as the kitchen light which we leave on during the night).  The next step is to fetch the current state of the lights so that we can eliminate the…