HTTP control proxy via C-Gate and NodeJS

Discussion in 'C-Gate Developers' started by ievolve, Jan 28, 2012.

  1. ievolve

    ievolve

    Joined:
    Mar 20, 2010
    Messages:
    112
    Likes Received:
    1
    Location:
    Idaho
    One frustration that I definitely have is that the CNI will only allow one device to connect at a time. I briefly spent some time trying to write a proxy that would allow my server code to act as a pass through for other devices, but didnt have time to finish it off.

    For those of you running cgate. Are you running a PC with the cbus toolkit? I have recently seen people using a raspberry pi to run cgate, might be worth exploring the cgate option a little deeper again.
     
    ievolve, Nov 6, 2014
    #21
  2. ievolve

    jboer

    Joined:
    Apr 27, 2012
    Messages:
    458
    Likes Received:
    35
    Location:
    Sydney
    I would have to +1 Mr Mark's comments regarding the use of C-Gate vs direct connection to a PCI. Once you start getting outside of the realm of just setting events in a lighting application, C-Gate just makes it so much simpler and the ability to have multiple connections through it. As well as it is as fast as your device running it!

    (Still plan on working out how to create a virtual network one day)
     
    jboer, Nov 7, 2014
    #22
  3. ievolve

    ievolve

    Joined:
    Mar 20, 2010
    Messages:
    112
    Likes Received:
    1
    Location:
    Idaho
    @all, thanks for the feedback. As a result, I have gone back and am resurrecting the cgate integration. I was able to find enough time for a good start. You can check it out here:

    https://github.com/anthonywebb/node-cbus/

    For now it is just an HTTP interface to all the cgate commands, and a web console where you can watch the commands in realtime as they execute. You may also type a command into the web console as well.

    I've got some work to do to port over all the features of my direct CNI connector and the full web UI, but will get there.

    More to follow.
     
    Last edited by a moderator: Nov 9, 2014
    ievolve, Nov 9, 2014
    #23
  4. ievolve

    ievolve

    Joined:
    Mar 20, 2010
    Messages:
    112
    Likes Received:
    1
    Location:
    Idaho
    Just a brief update.

    Today I was able to make significant progress on the cgate based project. I *think* I have the bones that make a great engine for rules, scenes, scheduled tasks, etc. Some great features in there that have been partially documented in the project README.
     
    ievolve, Nov 9, 2014
    #24
  5. ievolve

    ievolve

    Joined:
    Mar 20, 2010
    Messages:
    112
    Likes Received:
    1
    Location:
    Idaho
    One thing of note here. I have noticed that the lag between a keypress and the actual event being reported by cgate can sometimes be significant. IIRC this is one reason I ended up going with the CNI based approach. The CNI direct connect method is very very snappy as compared to the CGate connector.

    Is anyone out there aware of any tricks to eliminate the lag? Is there some sort of message prioritization that would help?
     
    ievolve, Nov 9, 2014
    #25
  6. ievolve

    ievolve

    Joined:
    Mar 20, 2010
    Messages:
    112
    Likes Received:
    1
    Location:
    Idaho
    I have installed both cgate and my node project on my raspberry pi. Here are some links that others looking to do this may find helpful:

    http://www.addictedtopi.com/post/96351714013/installing-c-gate-on-a-raspberry-pi

    http://joshondesign.com/2013/10/23/noderpi (I changed 10.2 to 10.28 to get a later version of nodejs)

    Once both of these were complete. I then could do an "npm install" from the project root dir, and then run it with "node server.js"

    Now I needed to set it to run automatically each time the raspberry pi booted.

    http://www.addictedtopi.com/post/101165284373/setting-up-cgateweb-c-bus-to-mqtt-on-linux
     
    ievolve, Nov 10, 2014
    #26
  7. ievolve

    Mr Mark

    Joined:
    Jan 27, 2006
    Messages:
    323
    Likes Received:
    5
    Location:
    FNQ
    Do you find the lag to be consistent? C-Gate on RPi works fine for me - the only time I see a lag if if the networks are in a "sync" state instead of an "ok" state. Mind you, this usually only happens when I'm doing a bit of plug and play with test units.
     
    Mr Mark, Nov 10, 2014
    #27
  8. ievolve

    ievolve

    Joined:
    Mar 20, 2010
    Messages:
    112
    Likes Received:
    1
    Location:
    Idaho
    Lag is not consistent at all, I can press the same button on my switch 5 times 5 seconds apart. 3 times the lag may be under a second, one may be almost instantaneous, and another may take a full 3 seconds. I'm not thinking it has anything to do with the fact it is running on a raspberry pi, as I have seen the same previously on my windows machine running cgate which is a fairly substantial machine.
     
    Last edited by a moderator: Nov 10, 2014
    ievolve, Nov 10, 2014
    #28
  9. ievolve

    Mr Mark

    Joined:
    Jan 27, 2006
    Messages:
    323
    Likes Received:
    5
    Location:
    FNQ
    In my experience, C-Gate should be almost instantaneous.
    Going back to basics, is the network ok (power, clocks, burden)?

    Not the best practice (more of a temporary workaround) try adding "force" to your command eg:
    instead of "on 254/56/1";
    try "on 254/56/1 force".

    I'd look at the network first though...
     
    Mr Mark, Nov 10, 2014
    #29
  10. ievolve

    ievolve

    Joined:
    Mar 20, 2010
    Messages:
    112
    Likes Received:
    1
    Location:
    Idaho
    @MrMark What is a good way to pull the values? (power, clocks, burden)

    I've not had any issues with my system, and still dont, switches respond immediately, etc.

    On a positive note, I posted a UI that will let you navigate, search, and control the devices on your network via a browser. Simply hit http://localhost:8080 (assuming you are running stuff on 8080) The settings page is not there yet, and I still need to wire up the scenes (it lists them in the UI, just firing them wont work)

    If anyone wants to give it a whirl, feel free.
     
    ievolve, Nov 10, 2014
    #30
  11. ievolve

    Mr Mark

    Joined:
    Jan 27, 2006
    Messages:
    323
    Likes Received:
    5
    Location:
    FNQ
    In "Toolkit", after you have scanned the network, try the "Diagnostics" option in the "Unit on Network" half of the screen.
    There you will have the options to Get Network Voltage, Get Network Burden and Get Network Clock. For voltage, you should be looking for more than 22 VDC. The next option would be an oscilloscope.

    I'm having some trouble getting your code up and running - currently tripping over the time module.
     
    Last edited by a moderator: Nov 10, 2014
    Mr Mark, Nov 10, 2014
    #31
  12. ievolve

    ievolve

    Joined:
    Mar 20, 2010
    Messages:
    112
    Likes Received:
    1
    Location:
    Idaho
    Found the diagnostics. My low voltage is 26.9, high is 30.9. Network burden has all "-" in them. When I try "get network clock" the toolkit app crashes. Running toolkit 1.13.3

    It was brought to my attention that the time module may have a hard time compiling on windows. I have so far run the code on my macs as well as a raspberry pi. Hunting for a replacement for that module that will work better cross platform.
     
    ievolve, Nov 10, 2014
    #32
  13. ievolve

    ievolve

    Joined:
    Mar 20, 2010
    Messages:
    112
    Likes Received:
    1
    Location:
    Idaho
    I have updated the project with a new module that should be 100% cross platform compatible. @MrMark can you give it a whirl now?
     
    ievolve, Nov 10, 2014
    #33
  14. ievolve

    Mr Mark

    Joined:
    Jan 27, 2006
    Messages:
    323
    Likes Received:
    5
    Location:
    FNQ
    Once again - amazing work Anthony!

    A few config issues, but all running now. The weekend will be spent playing under the hood to get a better understanding.
     
    Mr Mark, Nov 10, 2014
    #34
  15. ievolve

    Mr Mark

    Joined:
    Jan 27, 2006
    Messages:
    323
    Likes Received:
    5
    Location:
    FNQ
    Voltages look OK, no software network burden shown so there should be a hardware burden plugged in somewhere - most likely in the C-Bus panel. This device is a RJ45 plug with some red heat shrink covering a capacitor/resister combo. This is where we say "get your local friendly electrician to open the board and have a look", due to mains rated voltages being present.

    Scanning for clocks causing a crash, doesn't sound good. I just checked on my setup (TK 1.13.3) and the same happened (Get Network Clock being the only option checked). Checking all three options before running worked ok.
    More checking: found that if using diagnostics before the network has finished being scanned throws an error.
     
    Mr Mark, Nov 10, 2014
    #35
  16. ievolve

    ievolve

    Joined:
    Mar 20, 2010
    Messages:
    112
    Likes Received:
    1
    Location:
    Idaho
    Glad you got it working! Follow the project as I do have a bit of work to bring it into parity of where my CNI based project was at.

    Ass you look it over you will find that I have left it modular enough that the connection piece (cgate.js in this case) can easily be swapped with another connector (perhaps cni.js, zwave.js, whatever) the idea being that the rest of the code doesnt care how it is being routed or what technology is driving the device.

    This modularity also means that I can add other connectors and devices, like sonos for instance. Right now my wife likes to long press a switch on the wall and start playing her favorite sonos playlist, then short press to skip tracks. It works very well and is something easily accomplished with this code.

    As always, reach out if you have any questions, I appreciate the feedback.
     
    ievolve, Nov 11, 2014
    #36
  17. ievolve

    ievolve

    Joined:
    Mar 20, 2010
    Messages:
    112
    Likes Received:
    1
    Location:
    Idaho
    Dumb question, what is a "software/hardware burden" and what will I do with it when I find it? I feel so dumb asking, you think I would know more about this stuff, but I am still learning.
     
    ievolve, Nov 11, 2014
    #37
  18. ievolve

    fleetz

    Joined:
    Nov 21, 2005
    Messages:
    362
    Likes Received:
    9
    Hi Anthony,

    You are in good hands with Mr Mark.....a C-Bus guru.

    A hardware burden is an AC filter that must live across the C-Bus network. It consists of a 1k ohm resistor in series with a 10uF capacitor. It is required for reliable C-Bus network communication.

    You are required to have ONLY one network burden on a C-Bus network. If you have a physical burden which comes in the form of a RJ-45 connector with the resistor and capacitor in series you can connect that into any unused C-Bus port.

    If you use the hardware burden you must ensure that any other device on the C-Bus network has not got a software burden selected. Either one or the other is required.

    All of your output units or your CNI unit has the ability to enable or disable a software network burden. You can be select or deselect a network burden from within toolkit on the devices I have mentioned. Just make sure you don't have multiple network burden selected and or physical burdens connected at the same time.

    If you do you can effectively kill the communication bus by over filtering.

    Just to clarify what is meant by a software burden.....from within an output unit (relay or dimmer module) it is a resistor and capacitor in series that resides within these that connect across the C-Bus network only it is electronically switched and connected to the C-Bus network under software control via Toolkit.

    Clipsal have a ton of excellent training material on C-Bus.

    http://www2.clipsal.com/cis/__data/page/2857/14084_C-Bus_Basics_Training_Manual_Vol_1.pdf (See page 23 re network burdens)

    http://www2.clipsal.com/cis/technic...ing2/cbus_control_and_management_system/basic

    Of course happy to assist you here.....fire any questions you may have.

    Sorry I didn't see your earlier questions for whatever reason the instant email notification has never worked for me.......have to keep remembering to log on and look.

    Hope this helps.

    Regards,

    Ian
     
    Last edited by a moderator: Nov 12, 2014
    fleetz, Nov 12, 2014
    #38
  19. ievolve

    fleetz

    Joined:
    Nov 21, 2005
    Messages:
    362
    Likes Received:
    9
    Hi Anthony,

    Also noticed you mentioned C-Bus clocks. Again these can be selected on output devices (relays and dimmers) under Toolkit. See page 39 of Volume 1 training manual explains the C-Bus clock requirements.

    Basically you should have 2 or 3 clocks running on a network, C-Bus will determine which one it uses. Having multiple clocks running just provides some redundancy.

    It is not recommended that you enable clocks on Network CNI or Network bridges......use your output modules.

    Regards,

    Fleetz
     
    Last edited by a moderator: Nov 12, 2014
    fleetz, Nov 12, 2014
    #39
  20. ievolve

    ashleigh Moderator

    Joined:
    Aug 4, 2004
    Messages:
    2,398
    Likes Received:
    26
    Location:
    Adelaide, South Australia
    Reason being that bridges can be physically relocated if an installation changes, and the various interfaces can sometimes be the property of an installer who takes them away when the setup is done.... if clock enabled there then the network promptly fails.

    So the idea is, keep a clock generator in a device thats ALWAYS physically attached for ever and ever amen.
     
    ashleigh, Nov 12, 2014
    #40
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.