Thursday, May 30, 2013

Node.js, Raspberry Pi and irrigation control

This is my first post in a long time! I've experienced some severe burn out from a great many things. So after about 9 months I'm starting to get back to normal. So let's get back to Home Automation.

I have an ancient but working sprinkler controller. It's a very simple device and can control: 6 zones and 3, 14 day programs. For most of my needs it's fine (but when has that stopped me?). Also my wife could use a few more custom zones for her potted plants. The problem with the irrigation system is that it sometimes loses it's program and it isn't flexible enough (odd/even days, temperature, rain, wind, etc.) and no web interface. So I have a nice Raspberry Pi which can easily handle the control of a few zones (heck it could handle half a dozen easily). I've already completed one project with the Raspberry Pi, Python and the ADAFruit 16 port PWM driver. I've decided that I like Python and that's it's a nice language to work with. Now I have a tendency to want to play with new technology (it helps to keep up with things) and I've noticed node.js (Squirrel!). So far I've done simple things with node.js and it's been fun but I've decided to jump head first into node.js and use it to interface between the User Interface in the browser and the Raspberry Pi GPIO . I've found a nice Raspberry Pi GPIO library, a nice cron scheduling library and I've begun writing code. I've quickly learned that event based program is confusing when you are not used to it. I'm not convinced that node.js is perfect for many of my projects. I know I won't be using it for my home automation system as I need event based and real concurrency but I think node.js and the Raspberry Pi Irrigation Controller is perfect for this. So far I've been confused by callbacks, anonymous functions, variable scope, and a few other things. Loops are a real pain to do in node.js (forget for and while loops). Obviously I'm doing somethings very wrong as I have no experience with node.js but I must say I'm not too comfortable with event programming. It feels very unnatural especially when you have to wait for the callbacks to finish before you can go onto the next thing (config information that's needed for the rest of the program is not asynchronous). I really need to sit down and read a bit more but I have managed to get some basic parts working. I'm no where near done and I hope to have something operational within the week. Expect a lot of beginner mistakes and some kludges but working code. I'll correct things later.

As far as my main home automation system? I may look at Twisted and Python for the primary programming language for the home automation system of course we have Pytomation which may be a pretty good option.

3 Comments:

At 6/14/2013 6:15 PM, Blogger Nicholas Stein said...

I am about to embark on replacing my RainBird with a wifi enabled sprinkler system. I am thinking of using OpenSprinker. What are you using.
http://rayshobby.net/blog/?page_id=562#ospi

 
At 6/14/2013 9:17 PM, Blogger Neil Cherry said...

Hi Nick, it started out pretty simple (the software might not be considered simple). The hardware: Raspberry Pi B, an Adafruit protoboard, ribbon cable, some small screw terminals, a 74xx595 (can't recall which one at the moment) and I need a driver chip to deal with the 24v valve solenoid. I could also do any computer that supports node.js and some kind of IO. I might try to run my software with node.js on the NSLU2 with a USB IO device I have (but that's later).

I also have an Adafruit 16 port PWM board that I can use. I could also use a Phillips I2C to parallel out instead. There are a number of different ways to do that part. The hardware is very simple and it allows me to use simple GPIO commands.

On the software side I wanted to learn about Node.js (I'm also using XML, JSON, CSS and HTML, of course) for no other reason than to learn about async programming (event based programming). Initially I was going to attempt to do my entire HA system in Node.js but the sync vs async aspect of the programming is difficult for me to deal with. The user language needs to be completely synchronous while dealing with everything else asynchronous. I haven't decided what language to write that in yet (but I already have Perl with Misterhouse and Python with Pytomation).

I'm putting this project on my Hackerspace's (IXR) wiki pages: Node-irrigate

At the moment I haven't posted my code yet but I think I've got a base that works. A few more tweeks and I'll have something to add to the repo.

 
At 7/05/2013 11:08 AM, Blogger Neil Cherry said...

I've updated the project on IXR and I've created a driver for the Elexol IO24 UDP board (an older version). I need to get my code up on the IXR git repo but I should have that completed soon. The code should still be considered alpha because it requires a lot of manual editing of the JSON files to configure it. My new blog entry is: Node.js, Raspberry Pi and irrigation control, Part 2 .

Theoretically I could hook this up to my sprinkler system and have it work. But since that requires board approval (the CFO aka my wife), I'll let this version cook a bit longer. ;-)

Now I'll begin to work on the user configuration portion of the code. That part requires a lot of thinking and design work. I'd like to create drag-n-drop for the programming. That way my wife won't require any hand holding. We'll see how that goes.

BTW, I went the IO24 route because I suddenly got an idea in my head and the board was just sitting there idle. This is often how I make progress on things. I still intend to develop interfaces to other devices as I like to play with electronics as well as software.

 

Post a Comment

<< Home