Computing stuff tied to the physical world

DIJN.12 – Final checks and unattended use

In Uncategorized on Feb 22, 2013 at 00:01

Welcome to the last instalment of Dive Into JeeNodes. Let’a make an unattended setup!

Everything is working now. The only step that remains is to automate things a bit further, so that the RPi will automatically start up HouseMon when powered up. This turns it into a fire-and-forget system, so that it becomes a permanent service on your LAN.

Auto-startup is convenient, but it means we also have to think a bit about how to upgrade HouseMon. This is where the nodemon utility comes in: it can be used to start up a Node.js application, and restart it whenever certain source files change. This is mostly intended as development tool, but at this stage where HouseMon is still so young and evolving rapidly, it’s actually going to be quite practical – even in an unattended mode.

Install the nodemon package by entering the command: npm install nodemon -g

The “-g” flag causes nodemon to be installed in a central location instead of as part of HouseMon, so that we can type in “nodemon” from the command line.

Now we’re ready to configure an unattended setup. Copy and paste these commands:

    cd ~/housemon
    echo 'cd ~/housemon' >go.sh
    echo 'PATH=/usr/local/bin:$PATH' >>go.sh
    echo 'nodemon >nohup.out 2>nohup.err &' >>go.sh
    chmod +x go.sh
    echo '@reboot ~/housemon/go.sh' | crontab

This creates a “go.sh” script which will be used to start up HouseMon while you’re not around and sets up an entry in the “cron” table which will run that script right after reboot, even when you are not logged in.

Warning: this loses any previous crontab entries, if this is not a fresh Raspbian install.

Reboot now, using sudo reboot to start the ball rolling. After a few minutes, the RPi will be up and running again, and you will be able to visit the HouseMon server via your web browser – no need to log in for that!

Screen Shot 2013-02-10 at 13.57.11

Congratulations: you have created your own personal Wireless Sensor Network, with a JeeNode sending out light readings once a second over wireless, to a JeeLink connected to a stand-alone Raspberry Pi, and via HouseMon running on Node.js, you’re able to watch the current light level in real time, from any web browser with access to your LAN.

Is this a home monitoring / home automation system? Heh.. not quite, but it is definitely an important first step towards such a system. All the foundations are in place, yearning to be filled-in and extended in numerous directions. The load on a Raspberry Pi looks fine:

Screen Shot 2013-02-21 at 15.36.54

This also concludes this initial series of “Dive Into JeeNodes”. The goal was to set up a basic – but fully functional – system, as a baseline for lots and lots of further explorations. As far as I’m concerned, there will be many more posts building upon everything that has been accomplished so far. For now, I’d like to leave this to settle down a bit, and to reconcile loose ends – such as going through these 12 instalments using Windows. Since I don’t use Windows myself, I’m hoping that someone else will chime in with details, so that the exact steps to get going can be documented in a follow-up post or how-to page in the project.

Cheers for now, I hope you’ve enjoyed this “PhysComp+WSN fun pack” DIJN series!

(This series of posts is also available from the Dive Into JeeNodes page on the Café wiki.)

PS – I’ve set up an SD card image pre-configured with Raspbian and HouseMon 0.5.1, so if you want to bypass all the setup work, download the hm051.img.gz file (550 MB!), and follow the instructions in DIJN.05 to set up that SD card. Then insert the JeeLink and SD card, and power up the RPi. It’ll start with HouseMon running – including the demo page.

PPS – Another milestone, this is weblog post #1250. Onwards! :)

  1. And it WORKS. Great stuff!!

    Just one question: What happens with my data if I reboot the RPi without properly shutting down the Redis database before?

    • Redis only saves every few minutes, so the rest of the last entries will not be saved. The log files should have them, though (within Linux’es 30s or so fsync timer). Same for archive files, for the past hour.

      One idea would be to replay the last entries of the logfiles to “prime” both Redis and the archiver aggregated slots on restart.

      It’s not really a top priority: history in Redis will eventually drop out of the cache, and log file replaying to feed the archiver is needed for all my old data anyway. Once implemented, any day in the archive files can then be restored / fixed at a later time.

  2. It may be just me but I appeared to loose my current cron entries when I ran your cron setup commands.

  3. Ah, yes, this was written assuming a from-scratch setup. I’ll add a note, thanks.

  4. Thanks for the SD card image pre-configured with Raspbian and HouseMon 0.5.1. Everything had worked for me up to the Demo screen, which came up with no updates. Now with the SD card image I have updated. Thanks again.

  5. Ok, I’m a newbie to this. So thank you for all the great info. I have followed this step by step. Everything seems to be working but stops after about 10 minutes. I’m running a jeelink on a raspberry pi with a jeenode as the LDL remote. I think the jeenodes are working fine. Here is my log print out, but I’m not sure what I’m looking at. Any help will be most appreciated. I’m also using you sd card image.

    ➙ event:all ss-tick ➙ event:all ss-tick ➙ event:all ss-tick ➙ event:all ss-tick [...] ➙ event:all ss-tick ➙ event:all ss-tick ➙ event:all ss-tick

    events.js:71 throw arguments[1]; // Unhandled ‘error’ event ^ Error: socket hang up at createHangUpError (http.js:1360:15) at ServerResponse.OutgoingMessage._writeRaw (http.js:507:26) at ServerResponse.OutgoingMessage._send (http.js:476:15) at ServerResponse.OutgoingMessage.write (http.js:749:16) at ServerResponse.OutgoingMessage.end (http.js:882:16) at XHR.doWrite (/home/pi/housemon/node_modules/socketstream/node_modules/engine.io/lib/transports/polling-xhr.js:45:12) at XHR.Polling.write (/home/pi/housemon/node_modules/socketstream/node_modules/engine.io/lib/transports/polling.js:211:8) at XHR.Polling.send (/home/pi/housemon/node_modules/socketstream/node_modules/engine.io/lib/transports/polling.js:199:8) at Timer.check (/home/pi/housemon/node_modules/socketstream/node_modules/engine.io/lib/socket.js:181:26) at Timer.exports.setInterval.timer.ontimeout (timers.js:234:14) 25 Feb 04:09:47 – [nodemon] app crashed – waiting for file changes before starting…

    • Please consider posting this as a bug report over here, as weblog comments are really not suited for this type of information. You will need to register at GitHub, but I hope this is not a problem (it’ll come in handy if you start doing more with GitHub).

      Hm, I have seen this happen here as well, although I have two HouseMon configurations running for days on end here. The workaround is to restart the server, as this seems to be related to just a single request failure.

    • Never mind – I’ve created an issue here, since I think it’s a problem in SocketStream.

  6. Thanks. FYI I have rebooted several times and this problem persists.

  7. The DIJN series is outstanding. Had to wait some time for delivery of Raspberry Pi (seems every body wants one!), but got it up and running today and hopefully DIJN 7-12 will go as smoothly – I suspect the latter ones are more tricky! Many thanks for re-igniting my interest in this area.

  8. Worked through the 12 posts using Windows XP, Windows 7 and Putty, and can confirm that everthing works providing you carefully follow the instructions provided by jcw. Had to go back a few time and redo things but that’s probably down to my age!

    Only issue had was IE8 would not display HouseMon web page correctly, upgrading to IE10 under Win7 resolved the problem. Google Chrome and Firefox were OK.

    Just for information the hardware I am using is a JeeNode USB v3 and a JeeLink v2 purchased back in December 2010 !

Comments are closed.