Page 1 of 4 123 ... LastLast
Results 1 to 10 of 33

Thread: DM plugin for Connected by TCP lighting gateway working on one.

  1. #1
    Join Date
    Mar 2005
    Posts
    724

    Default DM plugin for Connected by TCP lighting gateway working on one.

    in the event that any is interested here is the first revision of my Connected by TCP lighting plugin at the moment it reads the gateway and creates devices and allows control of them using the lighting action in girder I will be making some more revisions as time goes by.

    Currently location is set by the room name in the gateway so make sure it matches your girder location name is set by the name in the gateway as well

    To set the ip of your gate way simply edit the tcpip variable at the top of the tcp.lua file

    also it will be fixted soon as setting the dimmer to 0 doesn't turn off the bulb but this appears to be a quirk of the bulbs I am working on a fix in the plugin and will post it asap

    I want to thank Tieske8 and Ron for there help I am sure they have thought I was nut or at least insanely stupid
    v 1.1 fixed dimming issue now turns off bulb at 0%
    tcp1.1.zip

    Attachment 6670 v1.0b


    Thanks and enjoy,
    Yonu



    ORIGINAL FIRST POST

    Ok all I am in need of some help here I want to integrate my Connected by TCP lighting gateway into Girder DM (I would prefer G6 but I rely to heavily on the DM to track device states at the moment to finish making the change over as I don't understand G6 that well yet).

    Ok I am able to control the Network gateway using HTTP requests thanks to the folks over at another automation programs site. but the issue I have is this the gateway can be polled via http to give a list of devices, device capabilities, and statuses. however I have no idea how to parse the xml data it returns and use it to create DM entries as a usable plugin.

    Here is a sample xml result

    Code:
    This XML file does not appear to have any style information associated with it. The document tree is shown below.
    <gwrcmds>
    <gwrcmd>
    <gcmd>RoomGetCarousel</gcmd>
    <gdata>
    <gip>
    <version>1</version>
    <rc>200</rc>
    <room>
    <rid>0</rid>
    <name>Unknown Room</name>
    <desc/>
    <known>1</known>
    <type>0</type>
    <color>000000</color>
    <colorid>0</colorid>
    <img>img/room/black.png</img>
    <power>0</power>
    <poweravg>0</poweravg>
    <energy>0</energy>
    <device>
    <did>216374521027362808</did>
    <known>1</known>
    <lock>0</lock>
    <state>0</state>
    <level>100</level>
    <node>123</node>
    <port>0</port>
    <nodetype>16386</nodetype>
    <name>LED</name>
    <desc>LED</desc>
    <colorid>0</colorid>
    <imgs>products/device/TCP-A19.png</imgs>
    <imgm>products/device/TCP-A19.png</imgm>
    <imgb>products/device/TCP-A19.png</imgb>
    <imgs_s>products/device/TCP-A19.png</imgs_s>
    <imgm_s>products/device/TCP-A19.png</imgm_s>
    <imgb_s>products/device/TCP-A19.png</imgb_s>
    <type>multilevel</type>
    <rangemin>0</rangemin>
    <rangemax>99</rangemax>
    <power>0</power>
    <poweravg>0</poweravg>
    <energy>0</energy>
    <score>0</score>
    <productid>1</productid>
    <prodbrand>TCP</prodbrand>
    <prodmodel>LED A19 11W</prodmodel>
    <prodtype>LED</prodtype>
    <prodtypeid>78</prodtypeid>
    <classid>2</classid>
    <class/>
    <subclassid>1</subclassid>
    <subclass/>
    <other>
    <rcgroup/>
    <manufacturer>TCP</manufacturer>
    <capability>
    productinfo,identify,meter_power,switch_binary,switch_multilevel
    </capability>
    <bulbpower>11</bulbpower>
    </other>
    </device>
    <device>
    <did>216374521027366519</did>
    <known>1</known>
    <lock>0</lock>
    <state>1</state>
    <level>100</level>
    <node>123</node>
    <port>0</port>
    <nodetype>16386</nodetype>
    <name>LED</name>
    <desc>LED</desc>
    <colorid>0</colorid>
    <imgs>products/device/TCP-A19.png</imgs>
    <imgm>products/device/TCP-A19.png</imgm>
    <imgb>products/device/TCP-A19.png</imgb>
    <imgs_s>products/device/TCP-A19.png</imgs_s>
    <imgm_s>products/device/TCP-A19.png</imgm_s>
    <imgb_s>products/device/TCP-A19.png</imgb_s>
    <type>multilevel</type>
    <rangemin>0</rangemin>
    <rangemax>99</rangemax>
    <power>0.011</power>
    <poweravg>0</poweravg>
    <energy>0</energy>
    <score>0</score>
    <productid>1</productid>
    <prodbrand>TCP</prodbrand>
    <prodmodel>LED A19 11W</prodmodel>
    <prodtype>LED</prodtype>
    <prodtypeid>78</prodtypeid>
    <classid>2</classid>
    <class/>
    <subclassid>1</subclassid>
    <subclass/>
    <other>
    <rcgroup/>
    <manufacturer>TCP</manufacturer>
    <capability>
    productinfo,identify,meter_power,switch_binary,switch_multilevel
    </capability>
    <bulbpower>11</bulbpower>
    </other>
    </device>
    </room>
    </gip>
    </gdata>
    </gwrcmd>
    </gwrcmds>
    Thanks,
    Yonu
    Last edited by yonu; March 20th, 2014 at 07:44 PM.

  2. #2
    Join Date
    Jan 1998
    Location
    Jupiter, FL
    Posts
    13,553

    Default

    Use LXP to parse it:

    Code:
    local lxp = require('lxp')
    local p = lxp.lom.parse(XMLtext)
    table.print(p)
    full lxp docs here: http://matthewwild.co.uk/projects/luaexpat/
    Ron
    No support through PM

  3. #3
    Join Date
    Mar 2005
    Posts
    724

    Default

    thanks will have a look at it

    now the loaded question is there a guide or how-to somewhere on how to do a plugin for the component manager.

    Thanks,
    Yonu

  4. #4
    Join Date
    Mar 2005
    Posts
    724

    Default

    ok I have to ask a loaded question I have copied and changed the x10 manager ui xml to meet mt needs I am currently looking at the corresponding x10.lua in treescript but it doesn't make a lot of sense the biggest issue I am having is where would I put the code to read and parse the device list into the DM.

    Thanks,
    Yonu

  5. #5
    Join Date
    Mar 2005
    Posts
    724

    Default

    please disregard last post I decided to start from scratch so I will repost when I get stuck

    yonu

  6. #6
    Join Date
    Mar 2005
    Posts
    724

    Default

    thanks for the xml parser info but I am a bit confused at how to use it but I suppose it will make sense eventually here is the output I am getting from it how I just have to set it up so that i can split it into variables

    Thanks,
    yonu

    Code:
    { -- #0
       ["attr"] = { -- #1
       } -- #1,
       [1] = { -- #2
          [1] = { -- #3
             ["attr"] = { -- #4
             } -- #4,
             [1] = "RoomGetCarousel",
             ["tag"] = "gcmd",
          } -- #3,
          [2] = { -- #5
             ["attr"] = { -- #6
             } -- #6,
             [1] = { -- #7
                [1] = { -- #8
                   ["attr"] = { -- #9
                   } -- #9,
                   [1] = "1",
                   ["tag"] = "version",
                } -- #8,
                [2] = { -- #10
                   ["attr"] = { -- #11
                   } -- #11,
                   [1] = "200",
                   ["tag"] = "rc",
                } -- #10,
                ["attr"] = { -- #12
                } -- #12,
                [3] = { -- #13
                   [1] = { -- #14
                      ["attr"] = { -- #15
                      } -- #15,
                      [1] = "0",
                      ["tag"] = "rid",
                   } -- #14,
                   [2] = { -- #16
                      ["attr"] = { -- #17
                      } -- #17,
                      [1] = "Unknown Room",
                      ["tag"] = "name",
                   } -- #16,
                   [3] = { -- #18
                      ["attr"] = { -- #19
                      } -- #19,
                      ["tag"] = "desc",
                   } -- #18,
                   [4] = { -- #20
                      ["attr"] = { -- #21
                      } -- #21,
                      [1] = "1",
                      ["tag"] = "known",
                   } -- #20,
                   [5] = { -- #22
                      ["attr"] = { -- #23
                      } -- #23,
                      [1] = "0",
                      ["tag"] = "type",
                   } -- #22,
                   [6] = { -- #24
                      ["attr"] = { -- #25
                      } -- #25,
                      [1] = "000000",
                      ["tag"] = "color",
                   } -- #24,
                   [7] = { -- #26
                      ["attr"] = { -- #27
                      } -- #27,
                      [1] = "0",
                      ["tag"] = "colorid",
                   } -- #26,
                   [8] = { -- #28
                      ["attr"] = { -- #29
                      } -- #29,
                      [1] = "img/room/black.png",
                      ["tag"] = "img",
                   } -- #28,
                   [9] = { -- #30
                      ["attr"] = { -- #31
                      } -- #31,
                      [1] = "0",
                      ["tag"] = "power",
                   } -- #30,
                   [10] = { -- #32
                      ["attr"] = { -- #33
                      } -- #33,
                      [1] = "0",
                      ["tag"] = "poweravg",
                   } -- #32,
                   [11] = { -- #34
                      ["attr"] = { -- #35
                      } -- #35,
                      [1] = "0",
                      ["tag"] = "energy",
                   } -- #34,
                   [12] = { -- #36
                      [1] = { -- #37
                         ["attr"] = { -- #38
                         } -- #38,
                         [1] = "216374521027362808",
                         ["tag"] = "did",
                      } -- #37,
                      [2] = { -- #39
                         ["attr"] = { -- #40
                         } -- #40,
                         [1] = "1",
                         ["tag"] = "known",
                      } -- #39,
                      [3] = { -- #41
                         ["attr"] = { -- #42
                         } -- #42,
                         [1] = "0",
                         ["tag"] = "lock",
                      } -- #41,
                      [4] = { -- #43
                         ["attr"] = { -- #44
                         } -- #44,
                         [1] = "0",
                         ["tag"] = "state",
                      } -- #43,
                      [5] = { -- #45
                         ["attr"] = { -- #46
                         } -- #46,
                         [1] = "100",
                         ["tag"] = "level",
                      } -- #45,
                      [6] = { -- #47
                         ["attr"] = { -- #48
                         } -- #48,
                         [1] = "123",
                         ["tag"] = "node",
                      } -- #47,
                      [7] = { -- #49
                         ["attr"] = { -- #50
                         } -- #50,
                         [1] = "0",
                         ["tag"] = "port",
                      } -- #49,
                      [8] = { -- #51
                         ["attr"] = { -- #52
                         } -- #52,
                         [1] = "16386",
                         ["tag"] = "nodetype",
                      } -- #51,
                      [9] = { -- #53
                         ["attr"] = { -- #54
                         } -- #54,
                         [1] = "LED",
                         ["tag"] = "name",
                      } -- #53,
                      [10] = { -- #55
                         ["attr"] = { -- #56
                         } -- #56,
                         [1] = "LED",
                         ["tag"] = "desc",
                      } -- #55,
                      [11] = { -- #57
                         ["attr"] = { -- #58
                         } -- #58,
                         [1] = "0",
                         ["tag"] = "colorid",
                      } -- #57,
                      [12] = { -- #59
                         ["attr"] = { -- #60
                         } -- #60,
                         [1] = "products/device/TCP-A19.png",
                         ["tag"] = "imgs",
                      } -- #59,
                      [13] = { -- #61
                         ["attr"] = { -- #62
                         } -- #62,
                         [1] = "products/device/TCP-A19.png",
                         ["tag"] = "imgm",
                      } -- #61,
                      [14] = { -- #63
                         ["attr"] = { -- #64
                         } -- #64,
                         [1] = "products/device/TCP-A19.png",
                         ["tag"] = "imgb",
                      } -- #63,
                      [15] = { -- #65
                         ["attr"] = { -- #66
                         } -- #66,
                         [1] = "products/device/TCP-A19.png",
                         ["tag"] = "imgs_s",
                      } -- #65,
                      [16] = { -- #67
                         ["attr"] = { -- #68
                         } -- #68,
                         [1] = "products/device/TCP-A19.png",
                         ["tag"] = "imgm_s",
                      } -- #67,
                      [17] = { -- #69
                         ["attr"] = { -- #70
                         } -- #70,
                         [1] = "products/device/TCP-A19.png",
                         ["tag"] = "imgb_s",
                      } -- #69,

  7. #7
    Join Date
    Mar 2005
    Posts
    724

    Default

    Ok I am to a point now that I think I am in need of help. How do I go about making the plugin create devices in the DM?

    Thanks,
    yonu

  8. #8
    Join Date
    Mar 2005
    Posts
    724

    Default

    ok I figured out the DM butit turned out I was having problems with my parser so I did some web serching and found a lua code to parse the same lighting gateway and have changed it work work or at least I thought I had however I am getting a error and I can't seem to locate it. Here is the error
    Code:
    [string "udp-server1.gml:\TCP test\basic"]:57: attempt to index global `parser' (a nil value)
    stack traceback:
    	[string "udp-server1.gml:\TCP test\basic"]:57: in main chunk
    Here is my code
    Code:
    require ('socket.http')
    tcpstats = socket.http.request("http://192.168.1.121/gwr/gop.php?cmd=GWRBatch&data=%3Cgwrcmds%3E%3Cgwrcmd%3E%3Cgcmd%3ERoomGetCarousel%3C/gcmd%3E%3Cgdata%3E%3Cgip%3E%3Cversion%3E1%3C/version%3E%3Ctoken%3E1234567890%3C/token%3E%3Cfields%3Ename,image,imageurl,control,power,product,class,realtype,status%3C/fields%3E%3C/gip%3E%3C/gdata%3E%3C/gwrcmd%3E%3C/gwrcmds%3E&fmt=xml")
    --print("update".. tcpstats)
    lxp = require('lxp')
    --p = lxp.lom.parse(tcpstats)
    --table.print(p)
        
        -- Local collection devices - will be added to master table after parsing
        local new_devices = {}
    
        -- enumerate the XML elements that we want to load into our tables
        local room_elements_of_interest = "|rid|name|desc|"
        local device_elements_of_interest = "|did|name|desc|state|level|offline|type|rangemin|rangemax|power|poweravg|energy|manufacturer|prodbrand|prodmodel|prodtype|capability|"
    
        -- used to keep track of the current context during the parsing process
        local current_room_object = nil
        local current_device_object = nil
        local current_element_name = nil
    
        -- XML parsing handler for the start of an element
        local function start_element_handler (parser, name)
            current_element_name = name
            if name == "room" then
                current_room_object = {}
            elseif name == "device" then
                current_device_object = {}
                --current_device_object["gateway_ip"] = gateway.gateway_ip
                current_device_object["room"] = current_room_object
            end
        end
    
        -- XML parsing handler for the end of an element
        local function end_element_handler (parser, name)
            current_element_name = name
            if name == "room" then
                current_room_object = nil
            elseif name == "device" then
                 new_devices[new_devices+1] = current_device_object
                current_device_object = nil
            end
        end
    
        -- XML parsing handler for the text of an element
        local function character_handler (parser, value)
            if current_device_object and string.find(device_elements_of_interest,"|"..current_element_name.."|") then
                current_device_object[current_element_name] = value
            elseif current_room_object and (not current_device_object) and string.find(room_elements_of_interest,"|"..current_element_name.."|") then
                current_room_object[current_element_name] = value
            end
        end
    
        -- Create a parser
        local callbacks = {StartElement = start_element_handler, EndElement = end_element_handler, CharacterData = character_handler}
        local parser = lxp.new(callbacks)
                             -
        -- Parse the XML
        parser:parse(tcpstats)
        parser:parse() -- finishes the document
        parser:close()

  9. #9
    Join Date
    Jul 2007
    Location
    Netherlands
    Posts
    370

    Default

    The error refers to line 57, but there is no line 57 in your code containing a reference to 'parser'.

    But then the only code indexing parser are the last three lines. So my guess is that 'lxp.new(callbacks)' does not return a valid parser. According to common Lua idiom, the second value returned is probably an error message. So try replacing;

    Code:
        local parser = lxp.new(callbacks)
    with

    Code:
        local parser, err = lxp.new(callbacks)
        if not parser then error("Error creating parser: "..tostring(err)) end
    and see whether that delivers a hint as to what goes wrong.

    Using: Win7 MCE, Girder, xPL, RFXcom, HomeEasy

    http://www.thijsschreijer.nl

  10. #10
    Join Date
    Mar 2005
    Posts
    724

    Default

    hmm that got me this error
    Code:
    [string "udp-server1.gml:\TCP test\basic"]:38: attempt to perform arithmetic on a table value
    stack traceback:
    	[C]: in function `parse'
    	[string "udp-server1.gml:\TCP test\basic"]:58: in main chunk

Page 1 of 4 123 ... LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •