PDA

View Full Version : DM plugin for Connected by TCP lighting gateway working on one.



yonu
February 28th, 2014, 06:59 PM
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%
6671

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




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,swi tch_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,swi tch_multilevel
</capability>
<bulbpower>11</bulbpower>
</other>
</device>
</room>
</gip>
</gdata>
</gwrcmd>
</gwrcmds>


Thanks,
Yonu

Ron
February 28th, 2014, 07:07 PM
Use LXP to parse it:



local lxp = require('lxp')
local p = lxp.lom.parse(XMLtext)
table.print(p)


full lxp docs here: http://matthewwild.co.uk/projects/luaexpat/

yonu
February 28th, 2014, 07:18 PM
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

yonu
March 2nd, 2014, 12:34 AM
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

yonu
March 2nd, 2014, 01:11 AM
please disregard last post I decided to start from scratch so I will repost when I get stuck

yonu

yonu
March 3rd, 2014, 01:26 PM
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



{ -- #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,

yonu
March 3rd, 2014, 10:59 PM
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

yonu
March 7th, 2014, 08:45 PM
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


[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


require ('socket.http')
tcpstats = socket.http.request("http://192.168.1.121/gwr/gop.php?cmd=GWRBatch&data=%3Cgwrcmds%3E%3Cgwrcmd%3E%3Cgcmd%3ERoomGetCar ousel%3C/gcmd%3E%3Cgdata%3E%3Cgip%3E%3Cversion%3E1%3C/version%3E%3Ctoken%3E1234567890%3C/token%3E%3Cfields%3Ename,image,imageurl,control,po wer,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|r angemax|power|poweravg|energy|manufacturer|prodbra nd|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()

Tieske8
March 8th, 2014, 06:10 AM
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;



local parser = lxp.new(callbacks)


with



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.

yonu
March 8th, 2014, 09:16 AM
hmm that got me this error


[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

yonu
March 8th, 2014, 09:17 AM
which is this line
elseif name == "device" then
new_devices[new_devices+1] = current_device_object
current_device_object = nil

Tieske8
March 8th, 2014, 05:50 PM
was the code I provided all you changed? because initialy the `parser` returned was nil, and now it suddenly has a value? So you made other changes as well?

yonu
March 8th, 2014, 10:29 PM
you have gotten methe only thing I changed was the line you sent I have even tried changing it back I still get the error code I sent you I even tried restarting girder an PC

Tieske8
March 10th, 2014, 04:15 AM
Your error appears here


new_devices[new_devices+1] = current_device_object


new_devices has been initialized as 'new_devices = {}' which makes it a table. So when you do `new_devices+1` you get the arithemtic on table value error. Which is logical.

I think the code you copy/pasted was;


new_devices[#new_devices+1] = current_device_object

(mind the '#' in there)

# is the length operator in Lua 5.1 onwards, but Girder uses Lua 5.0 and hence doesn't know the length operator and gives you a compilation error. What the original code did, including the #, was simply adding the element `current_device_object` at the end of the list 'new_devices'.
To do the same thing in Lua 5.0 use;


table.insert(new_devices, current_device_object)


hth
Thijs

yonu
March 12th, 2014, 01:09 PM
ok that worked however I get the same error here is the error [string "TEST"]:266: unexpected symbol near `#' the line is


if #new_devices > 0 then

if # is the length operator what exactly is it looking for?

here is the chunk of code


-- Save the devices, uniquely indexed by did
if #new_devices > 0 then
for i,device in ipairs(new_devices) do
gateway.devices[device.did] = device
-- tweak for interpretation of load level for dimmers - always set to zero if device is off
if device.state == "0" then
device.level = "0"
end
end
gateway.initialized = true
gateway.error_text = nil


Thanks,
yonu

Tieske8
March 12th, 2014, 03:57 PM
if # is the length operator what exactly is it looking for?

see here: http://www.lua.org/manual/5.1/manual.html#2.5.5

It returns the size of the list with devices (or the number of devices in the table). But be aware of the details in the description, because there are some quircks that might bite you if you're not carefull.

`table.getn(new_devices)` does the same in Lua 5.0, as `#new_devices` does in 5.1

Ron
March 12th, 2014, 06:51 PM
Note: Girder 5 uses Lua 5.0, which does not have the # operator. Use table.getn as Tieske suggests.

yonu
March 14th, 2014, 03:55 PM
thanks I didn't realize there were so many differences in lua 5 and 5.1

yonu
March 14th, 2014, 05:16 PM
Thanks ok i have no errors now but I am confused and not sure what I have done wrong as best I can tell it is working but I am getting nothing in the variable inspector or with print statements.

here is the lua console from the last run


test2
test
start
test
start
test
start
test
start
test
start
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
start
test
start
start
start
test
start
test
start
test
start
start
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
test
start
start
test
start
start
start
test
start
test
start
test
start
start
start
start
start
start
start
start
{ -- #0
["initialized"] = true,
["HTTP_TIMEOUT"] = 5,
["devices"] = { -- #1
} -- #1,
["gateway_ip"] = "192.168.1.121",
["error_text"] = "TCP Lighting Gateway not yet initialized",
["autodiscovered"] = true,
} -- #0


Here is my code


require ('socket.http')
tcpstats = socket.http.request("http://192.168.1.121/gwr/gop.php?cmd=GWRBatch&data=%3Cgwrcmds%3E%3Cgwrcmd%3E%3Cgcmd%3ERoomGetCar ousel%3C/gcmd%3E%3Cgdata%3E%3Cgip%3E%3Cversion%3E1%3C/version%3E%3Ctoken%3E1234567890%3C/token%3E%3Cfields%3Ename,image,imageurl,control,po wer,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 MAX_SSDP_RETRIES = 5

-- create an empty gateway object
gateway = {}
gateway.initialized = true
gateway.autodiscovered = true
gateway.error_text = "TCP Lighting Gateway not yet initialized" -- error text for last failed operation
gateway.gateway_ip = "192.168.1.121"
gateway.gateway_uuid = nil
gateway.devices = {} -- a cache of device info indexed by unique did
gateway.HTTP_TIMEOUT = 5 -- 5 seconds should be fine on a local network

-- 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|r angemax|power|poweravg|energy|manufacturer|prodbra nd|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)
print ("start")
current_element_name = name
if name == "room" then
current_room_object = nil
elseif name == "device" then
table.insert(new_devices, current_device_object)
current_device_object = nil
end
end

-- XML parsing handler for the text of an element
local function character_handler (parser, value)
print ("test")
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}
print ("test2")
local parser, err = lxp.new(callbacks)
if not parser then error("Error creating parser: "..tostring(err)) end

-- Parse the XML
parser:parse(tcpstats)
parser:parse() -- finishes the document
parser:close()
table.print(gateway)


Here is the XML results it is parsing from


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</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>1</state>
<level>100</level>
<node>123</node>
<port>0</port>
<nodetype>16386</nodetype>
<name>front porch</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,swi tch_multilevel
</capability>
<bulbpower>11</bulbpower>
</other>
</device>
<device>
<did>216374521027366519</did>
<known>1</known>
<lock>0</lock>
<state>0</state>
<level>100</level>
<node>123</node>
<port>0</port>
<nodetype>16386</nodetype>
<name>Doggie Door</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,swi tch_multilevel
</capability>
<bulbpower>11</bulbpower>
</other>
</device>
</room>
</gip>
</gdata>
</gwrcmd>
</gwrcmds>

yonu
March 14th, 2014, 06:00 PM
ok I just added in some print statements to the parsing routines and It is parsing the xml data but I get nothing in the table variables

Thanks,
Yonu

yonu
March 16th, 2014, 10:16 AM
please disregard the last post I have the parsing working I had taken out a block of code while I was fixing errors and forgot to put it back when I was done. It helps if it has the routine to save the devices.



-- Save the devices, uniquely indexed by did
if table.getn(new_devices) > 0 then
for i,device in ipairs(new_devices) do
gateway.devices[device.did] = device
-- tweak for interpretation of load level for dimmers - always set to zero if device is off
if device.state == "0" then
device.level = "0"
end
end
gateway.initialized = true
gateway.error_text = nil
else
gateway.error_text = "No devices found at gateway " .. gateway.gateway_ip .. " while parsing " .. config_xml
end

return

end


Thanks,
Yonu

yonu
March 17th, 2014, 06:57 PM
ok I have the code importing the devices to a table with is grate but I am having trouble getting it in the ui here is what I have so far however I need getting blank tables.

I want to get a quick opinion should I simply throw the idea of a ui out the window and code the plugin to directly import the devices to the DM since all the info is imported from the gateway as I am leaning towards giving up on having edit options in the girder interface.



local names = {}
table.print (gateway.devices)
for k,v in ipairs (gateway.devices) do
table.insert (names,v.Location ..' '..v.name)
end
table.print(names)
table.sort (names)
-- build index for name
local l = ''
local i = 0
dui.Forms[Index].locnameindex = {}
for k,v in ipairs (names) do
dui.Forms[Index].locnameindex [i] = v
l = l .. v ..'\n'
i = i + 1
end
Controls.locname.Strings = l
dui.Forms[Index].locnames = names -- store this table


Thanks,
Yonu

Tieske8
March 18th, 2014, 06:36 AM
Give up. Only code the UI if you really need it.

yonu
March 18th, 2014, 03:35 PM
Thanks I just wanted to hear it from someone else :)

Thanks,
Yonu

yonu
March 19th, 2014, 11:42 AM
First Let me say thanks for the help I have a basic working plugin I do have a couple things I want to change or at least know how to do where do I begin to code so that if I make a change to the DM it triggers in the plugin.

Thanks,
Yonu

Tieske8
March 20th, 2014, 04:44 AM
I don't understand your question (and if I did, I doubt whether I would know the answer ...) but maybe Ron knows

yonu
March 20th, 2014, 07:46 PM
ok I got it working but let me explain what I meant when a Device manager change was made say by the Lighting action in girder it was changing the device manager status but that was it. What it turned out to be and I feel stupid for not catching it but I used the device with no provider script that was posted to the forum way back and I forgot to code the provider section to actually make it do something.

yonu
March 20th, 2014, 07:56 PM
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

6670 v1.0b

Thanks and enjoy,
Yonu

Tieske8
March 21st, 2014, 03:33 AM
Glad it works!

Thijs

PS: I merely thought you were persisent, which is a good thing when working with Girder internals :)

yonu
March 21st, 2014, 09:22 AM
well what can I say I wanted it to work the opnly thing that has ticked me off is that tcp modified there zigbee protocol just enough that it don't see other zigbee devices or at least I can't get it to.

Thanks again,
Yonu

Tieske8
March 21st, 2014, 01:59 PM
zigbee requires a membership fee. Some manufacturers use the chipsets, but are not a member. From what I've heard the difference is a single configurable bit that they are not allowed to set (or they'll get sued). That makes the difference for a device being recognized or not as a zigbee device.

yonu
March 21st, 2014, 08:42 PM
Ok that makes since.
So I would assume that means it is possible to sniff device networks and make a fairly universal controller none public of course or am I stretching the bubble on the theory

Thanks,
yonu

Tieske8
March 23rd, 2014, 05:00 PM
That would require a device with 2 zigbee radios, and it could never be sold. So only tinkerers could build one themselves. And then still if it has further limitations (eg. all device discovery disabled for the non-zigbee version) then it still wouldn't work.

I don't think it will ever work...