Showing posts with label Internet of Things. Show all posts
Showing posts with label Internet of Things. Show all posts

Friday, January 2, 2015

2014: a Christmas Tree

WebLights Revisited


As a sort of follow up to one of my first posts I thought I'd describe some of the updates to a Rasberry Pi IOT lighting project I put together last year.

Christmas 2014


Built from the WebLamp example in the RPi MakeProjects book and using code posted at Matt Richardson's site I was able to reboot the project this year by simply re-establishing the /etc/init.d wrapper program I wrote to initialize the webserver and partner python program.  By connecting the lights to my PowerSwitch Tail the setup worked exactly as last year, with only about 10 minuntes of set up required.


New Connections

One enhancement I made this year was to add a better pair of connectors for the power switch connections.  For this I used my favourite method of connector for relatively portable projects; stereo 3.5mm audio jacks.  One of these, plus some pre-cut solid core wiring, gives a more stable connection which can be easily removed.  Since the plugs are cheap and the breakouts built they can be reused for other projects.



Design

Not wanting to stop at hardware I also included some soft enhancements this year.  First, I decorated the site a little more with some simple HTML formatting.  Since the python Flask webserver includes a main page and CSS I just inserted some additional text and format tags as well as a button object to make a prettier webpage:



Data

This year I've also added a data gathering element to the project, making it a two way IOT project.  To do this I first created a shell table on a MySQL server running on my network, SENSORS.Tree. This table keeps a log of the webpage status and timestamp captured from the weblamp.py webserver program.  To do this I added a MySQL connection using the MySQLdb package to my existing program and added a pair of update statements to the existing If structure based on the toggle of the HTML button for the lights:
      cur.execute("Insert into sensors.tree values ('on', sysdate());")
      cur.execute("Insert into sensors.tree values ('off', sysdate());")

These statements (and the MySQLdb connection string) update the SENSORS.Tree table with the status and timestamp at the time the switch was triggered.

After collecting some data I wrote a quick R program to ggplot the statuses for the following chart:

A 5PM On and 2AM Off timer is set

The code I used for the above was:
library(ggplot2)
library(RMySQL)
con <- dbConnect(MySQL(), user="user1", password="pass1", dbname="sensors", host="localhost")
rs <- dbSendQuery(con, "select * from sensors.tree;")
xmas <- fetch(rs)
huh <- dbHasCompleted(rs)
dbClearResult(rs)
dbDisconnect(con)
 
xmas$updated <- as.POSIXct(xmas$updated)
xmas$status <- as.factor(xmas$status)
ggplot(data=xmas, aes(x=updated, y=status, group=1, colour=status)) + geom_line()
Created by Pretty R at inside-R.org

Monday, January 27, 2014

Favorite Tools: NDBC and the Chesapeake Bay Interpretive Buoy System

This one is not really a tool I use at work, just a favorite public data source of mine.  I really love the combination of physical computing and data.  The NOAA Buoy system might be considered one of the most widespread internet of things installations.

The NOAA Buoy System, consists of a network of buoys from different programs all tracked by NOAA.  Many of these are not under the direct supervision of NOAA, some are academic, others are state or local government installations.

The National Data Buoy Center website and database provides instant access to the status of many of these buoys.  Also included within the network are the observations from volunteer ships outfitted with sensors and telemetry equipment.  Individual buoys can be found via a map applet or within a mobile optimized site.


The Chesapeake Bay Interpretive Buoy System is part of the NDBC network and was designed to track the health of the bay using a network smartBuoys installed around the Chesapeake Bay watershed.  The smart buoys include a suite of sensorsDIY Arduino weather station might dream of.  The program supplements this environmental data with a parallel historic lesson, combining the bay health with the history of development in the watershed area, including the connection of the buoy locations with the historic journeys of a favorite historical figure of mine, Captain John Smith.

The CBIBS includes some cool data visualization features, like a graphing applet and csv downloads.  It also has a mobile app, which I've added to my wonkApp collection along with the FRED app.


While this data is used more urgently by mariners and scientists I love checking this data to consider the environment at some of my favorite places in the area; in the lower Potomac near where I grew up, Jamestown Island (visible from the fort site), and in the Upper Potomac (visible from my apartment).


I've even written some shell commands which I use to check on the Alexandria Buoy for real-time weather stats 200 yards from my apartment building while at work:

alias bTemp='wget -q http://www.ndbc.noaa.gov/mobile/station.php?station=44042 -O - | grep Air | cut -c1-15'

(Buoy Station changed in code to reference an active station.  Sadly, the Upper Potomac is offline for winter maintenance)