Built my own http interface using Node.JS

Discussion in 'General Discussion' started by ievolve, Jan 12, 2012.

  1. ievolve

    ievolve

    Joined:
    Mar 20, 2010
    Messages:
    112
    Likes Received:
    1
    Location:
    Idaho
    I wanted an http REST interface to be able to control my clipsal system, one that I could build html pages around to do stuff via the browser or other devices that talked http.

    So I fired up a simple Node.js server and it works great!

    If anyone is interested in the code, ping me and I will get you some src. Once it is up on github I'll drop a link here as well.

    For the impatient, you can fast forward to about 3:10 in video to see the interface in action.

     
    Last edited by a moderator: Jan 12, 2012
    ievolve, Jan 12, 2012
    #1
  2. ievolve

    DarylMc

    Joined:
    Mar 24, 2006
    Messages:
    1,308
    Likes Received:
    49
    Location:
    Cleveland, QLD, Australia
    Great video.
    It looks good and I assume it will work on most browsers?
    I suppose it says something since I need to ask but could you tell me how difficult it would be to set up and what hardware and software are required?
    Thanks
    Daryl
     
    DarylMc, Jan 12, 2012
    #2
  3. ievolve

    ievolve

    Joined:
    Mar 20, 2010
    Messages:
    112
    Likes Received:
    1
    Location:
    Idaho
    Hey Daryl,

    Only hardware needed is a network interface to your clipsal stuff. I have the 5500CN I think, and also something to run the node app.

    Node.js will run on windows/mac/linux, and is a free download here: www.nodejs.org

    From there you download the code, and from the folder you run the server.js file. Pretty simple really. I should have the code posted in a day or two. I need to clean it up as there is some other code scattered in there now specific to integration to my sonos audio system.

    The html page will run on any device with a browser, even your phone.

    Some people have asked why I would build something like this when there is already stuff like a wiser. Well, wiser does not have an http api, and I wanted one. Why not just write a mobile app to connect direct to the CNI? The CNI only allows for one connection to it at a time. Since I wanted to allow multiple devices (iphone, ipad, etc) to all be connected at the same time, this http proxy allows me to do that.

    Why node.js? Javascript is awesome :) Beyond that instead of having to have an actual computer running the proxy I have the option to run this simple little app on something like a beagle bone (http://beagleboard.org/bone) which can run node.js apps out of the box, and it very small and low power as opposed to other solutions.
     
    ievolve, Jan 12, 2012
    #3
  4. ievolve

    NickD Moderator

    Joined:
    Nov 1, 2004
    Messages:
    1,420
    Likes Received:
    62
    Location:
    Adelaide
    Nice work... and thanks for sharing it!

    Nick
     
    NickD, Jan 12, 2012
    #4
  5. ievolve

    Robbo_VIC

    Joined:
    Jan 24, 2011
    Messages:
    142
    Likes Received:
    0
    Location:
    Melbourne, VIC
    Nice work!:)
     
    Robbo_VIC, Jan 12, 2012
    #5
  6. ievolve

    DarylMc

    Joined:
    Mar 24, 2006
    Messages:
    1,308
    Likes Received:
    49
    Location:
    Cleveland, QLD, Australia
    DarylMc, Jan 13, 2012
    #6
  7. ievolve

    ievolve

    Joined:
    Mar 20, 2010
    Messages:
    112
    Likes Received:
    1
    Location:
    Idaho
    ievolve, Jan 13, 2012
    #7
  8. ievolve

    DarylMc

    Joined:
    Mar 24, 2006
    Messages:
    1,308
    Likes Received:
    49
    Location:
    Cleveland, QLD, Australia
    Ive been reading about rasberrypi also.
    If you could use the SIM it should be quite an inexpensive link to CBus.
     
    DarylMc, Jan 13, 2012
    #8
  9. ievolve

    ievolve

    Joined:
    Mar 20, 2010
    Messages:
    112
    Likes Received:
    1
    Location:
    Idaho
    Been looking over the cgate docs a bit tonight. If there is any interest, it might be a fun project to try and create a cgate port of the project. Talking direct to the CNI has very little latency, does anyone have an idea of how stable the CGate stuff is?

    In some ways I suppose that my nodejs server acts like a CGate, only instead of a TCP/IP socket, it uses http to receive events, and send realtime event notifications via websockets. Maybe adding a layer on top of CGate doesnt have much merit?

    I suppose that people already connecting other things to cgate (and have already tied up their CNI) would find something like this node app riding on CGate useful?
     
    ievolve, Jan 13, 2012
    #9
  10. ievolve

    kjayakumar

    Joined:
    Oct 27, 2008
    Messages:
    448
    Likes Received:
    0
    Nice work, thanks for posting the screencast. Just to clarify above, you are correct that Wiser does not have a HTTP/CGI interface. Instead, Wiser has an XML api. For example, the commands/events sent/received between the iPhone and Wiser are all in XML on a regular TCP/IP socket.
     
    kjayakumar, Jan 13, 2012
    #10
  11. ievolve

    ievolve

    Joined:
    Mar 20, 2010
    Messages:
    112
    Likes Received:
    1
    Location:
    Idaho
    Thanks for the clarification on that. I was unaware that even an XML api was available. Is the XML api published somewhere? I'd love to look it over.
     
    ievolve, Jan 13, 2012
    #11
  12. ievolve

    daniel C-Busser Moderator

    Joined:
    Jul 26, 2004
    Messages:
    766
    Likes Received:
    20
    Location:
    Adelaide
    Yes, a C-Gate connection lets multiple systems talk to C-Bus without conflicting with each other, C-Gate does a lot of the heavy lifting for you and the object model can be a little easier to work with particularly when you start dealing with bridged networks.

    The disadvantage is that you aren't as "close to the metal" so to speak, though in practice the latency is not that different.

    Here is a thread from last year on a similar browser-based project that used a C-Gate connection. I believe the code was intended to be open source, but the links don't seem to be working any more :(
     
    Last edited by a moderator: Jan 17, 2012
    daniel, Jan 17, 2012
    #12
  13. ievolve

    SBL

    Joined:
    Nov 11, 2009
    Messages:
    48
    Likes Received:
    0
    Location:
    NZ
    Wow

    That has to be up there in the ranks of cleverest C-Bus programmer ever..well done. Have previously toyed with the idea of delving more into TCP/IP interfacing and trying to build a MODBUS protocol interface. (to tie into power meters) Great to see people pushing the boundaries in what can be achieved and helping take C-Bus into the future..
     
    SBL, Jan 17, 2012
    #13
  14. ievolve

    ievolve

    Joined:
    Mar 20, 2010
    Messages:
    112
    Likes Received:
    1
    Location:
    Idaho
    @SBL, thank you for the kind words! I find it such a rush to be able to do this stuff via http, it is really opening whole new horizons, particularly in the every connected world in which we live, nearly everything around us talks http these days, now my home automation does too :)

    @all, many of you asked about connecting to C-Gate instead of to the CNI directly. I worked up a simple example, and must say I am loving talking to C-Gate, thanks for the suggestion, had I found it first I would not have likely had the determination to write the hook direct to the CNI, as that was pretty intense.

    Link to my source code on github is in here too:

    http://www.cbusforums.com/forums/showthread.php?p=38559
     
    ievolve, Jan 28, 2012
    #14
  15. ievolve

    tobex

    Joined:
    Nov 3, 2006
    Messages:
    728
    Likes Received:
    0
    Location:
    Sydney, Australia
    Happily, QNAP took the inniative to migrate NODE.JS to their NAS. What I need is a walkthrough for setting up NODE.JS and linking to my iPhone.
     
    tobex, Sep 30, 2013
    #15
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.