Monday, August 19, 2013

Node.js and the single thread

For a few weeks I've been playing with Node.js and my irrigation controller. So far it was worked very well and I'm beginning to get the hang of 'async programming' (I think). While mowing the lawn today I gave the issue of Node.js and a home automation controller more thought. In home automation, most things are asynchronous so Node.js seems like a perfect fit, we'll see. The model I want to use is that of the HCS II but update the user language and allow for user developed devices. The thing that gives me the most trouble is the user language which basically runs in a loop, continuously. I was thinking of using one of the threading libraries to put the user language in it's own thread and the rest of the device handing in another. But then it dawned on me that most code isn't really a program that runs as a sequential program but rather as blobs that need to run in no particular order (mostly). So instead of a loop I can take the user code and do a single run through on a timer (Misterhouse is like this except it's a loop) and repeat at regularly timed intervals. Right now I'm thinking about how to implement this with a Javascript based user language. I've already done the equivalent of a for loop with timers (and it works well).

2 Comments:

At 8/19/2013 6:49 AM, Blogger Jason Sharpee said...

Unfortunately in order to do away with looping user code, you need to do away with user code itself. As I discovered with Pytomation, its a very large paradigm shift for a lot of hobbyist HA folks.

Asynchronous threading is how I designed that system from the get go with individual threads for each and every driver and device. Users then just need to provide context to the configured items behaviors. I didnt even have a mechanism for a user code loop. Shortly after first release though that was the most requested feature.

While the user base is very low still, I believe that no one is still using the user code loop. Most behaviors people want are being coded into context properties. This has a huge advantage of code reuse across the entire user platform and eliminates having folks do the same things a thousand different ways (like Misterhouse)

 
At 8/19/2013 8:10 AM, Blogger Neil Cherry said...

Okay, so I'm a little slow to learn. ;-)

I had also wondered about that too (how Pytomation does it). A sudden change in my job situation (unfortunately) may give me some time to look more deaply into Pytomation. My thinking is that Python is still a better route than Javascript. It's just been getting more time than 5 minutes to do anything useful.

 

Post a Comment

<< Home