Sony Arouje

a programmer's log

Distributed Raspberry pi based Hydroponic Controller

leave a comment »

Last couple of weeks I was building a Hydroponic system controlled by Raspberry pi. As of yesterday night my system was based on a single Raspberry pi that control one or more water pumps. It was one of my design goal to add more Pi’s based controllers to the network with zero configuration.

Why more Controllers?

As I am living in an apartment and the hydroponic system is going to be installed in the balconies. Connecting the motors installed in different balconies to a single Raspberry controller will make things ugly, I don’t want wires hanging here and there. So one option is, add another Raspberry pi controller. It’s easily doable, just install the controller software I created and plug the water pump.

As I explained in my last post, this system is controlled via mobile devices. So when ever I add a controller to my hydroponic network I have to create an entry in each of the device in which my mobile app installed. Also I have to assign a static ip to each Raspberry controller or keep track of the host name. When I start thinking about it, I see a system with some complications. Yesterday night I modified my controller application, this is what I come up with.

Unifying server and Controllers with self advertisement

I created a Unifying server in node js. The controller system running in different Raspberry pi’s advertise about it when ever it joins to my wifi network. This Unifying server will get notification whenever a new controller joins. I use Node Discovery module for service discovery and publishing. In this scenario I don’t have to worry about any configuration of the controllers. Just install my controller software in each raspberry pi and plug it into my hydroponic system.

My mobile app connects to this unifying server instead of individual controller system. All the commands to the controllers will be routed via this unifying server to respective controller. Below is the routing function I come up with.

app.use('/', router);
router.use(function (req, res, next) {
    options.host = req.headers.hostid;
    options.path = req.originalUrl;
    options.method = req.method;
    


    var request = http.request(options, function (response) {
            response.on('data', function (data) {
                res.setHeader('content-type', 'application/json');
                res.send(data);
            });
        });
        if (req.method === 'POST') {
            request.setHeader('content-type', 'application/json');
            request.write(JSON.stringify(req.body));
        }
        request.end();
       
});

 

This unifying server is a very light weight system and can run in a Raspberry pi or in my computer. On of my design goal is that Controller should be self sufficient and should run in any circumstances even if there is no connection to unifying server.

The Unifying server and the Controller system is based on Node js. It’s a beautiful platform and I learned a lot about node js while building this system. Also become a huge fan of Javascript.

 

Next post I will go through the mobile app I created.

 

Happy coding…

download Scan using your mobile phone and access/share the post from your phone.

Written by Sony Arouje

November 22, 2014 at 5:37 pm

Posted in Raspberry Pi

Tagged with ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: