Simply Dashing!

I’ve finally gotten around to making a web frontend for my Raspberry Pi & Arduino wireless sensor network.

I chose Shopify’s Dashing dashboard, as its opensource and can be installed locally and not via some cloud crap.

Essentially you have a HTML template into which you feed JSON data. I got a bit tied up in the JSON formatting so it took longer than it should have to get working (about 3 hours) but once I realised that most of the job placeholders were a single line of JSON, and not a whole entity, it was quite straightforward. Here’s 90% of my entire dashboard code:

SCHEDULER.every '30m', :first_in => 0 do
    require 'sqlite3'
    db = SQLite3::Database.open "/var/tmp/weather.db"
    
    study = db.execute "SELECT reading FROM weather WHERE node=2 ORDER BY date DESC LIMIT 3"
    send_event('study_temp', { current: study[0][0].round(2), last: study[2][0].round(2) })

    shed = db.execute "SELECT reading FROM weather WHERE node=1 AND type=2 ORDER BY date DESC LIMIT 3"
    send_event('shed_temp', { current: shed[0][0].round(2), last: shed[2][0].round(2) })

    outside = db.execute "SELECT reading FROM weather WHERE node=1 AND type=1 ORDER BY date DESC LIMIT 3"
    send_event('outside_temp', { current: outside[0][0].round(2), last: outside[2][0].round(2) })

    lounge = db.execute "SELECT reading FROM weather WHERE node=3 ORDER BY date DESC LIMIT 3"
    send_event('lounge_temp', { current: lounge[0][0].round(2), last: lounge[2][0].round(2) })
     
    light = db.execute "SELECT reading FROM weather WHERE node=4 ORDER BY date DESC LIMIT 1"    
    send_event('lightsensor', { value: light[0][0].round(1) })

    bedroom = db.execute "SELECT reading FROM weather WHERE node=0 ORDER BY date DESC LIMIT 3"
    send_event('bedroom_temp', { current: bedroom[0][0].round(2), last: bedroom[2][0].round(2) })

    db.close
end

Here’s a screenshot of the finished dashboard, including an additional widget that shows the RPi-1B’s very stretched RAM:

It installed a lot easier on Debian Sid than Raspbian Wheezy, but I hear Raspbian Jessie is easier due to updated bundler/exec_json/nodejs packages – every time I use Ruby I seem to go through dependency hell, Ruby seems to have a lot of issues with backwards/forwards compatibility with Gems – why things like bundler/rvm are necessary I guess. Makes Java look portable.