Help accessing table elements

Sorry for the dumb question, i have searched high and low and am still stumped after reading lots of Lua docs…

I have a table i converted from XML (with lxp) but can not figure out how to access the values in it. I want to, for example, grab the value of “pump” (which is “0” in this case), and “spasp” (which is “96” in this case) and stick them into variables.

vTable={ [1]="\ ", [2]={ [1]="\ ", [2]={ [1]="8", attr={ }, tag="runstate" }, [3]="\ ", [4]={ [1]="6521", attr={ }, tag="model" }, [5]="\ ", [6]={ [1]="00000000", attr={ }, tag="dip" }, [7]="\ ", [8]={ [1]="0", attr={ }, tag="opmode" }, [9]="\ ", [10]={ [1]="589", attr={ }, tag="vbat" }, [11]="\ ", [12]={ [1]="0", attr={ }, tag="lowbat" }, [13]="\ ", [14]={ [1]="1.5.5", attr={ }, tag="version" }, [15]="\ ", [16]={ [1]="1398059089", attr={ }, tag="time" }, [17]="\ ", attr={ }, tag="system" }, [3]="\ ", [4]={ [1]="\ ", [2]={ [1]="0", attr={ }, tag="pump" }, [3]="\ ", [4]={ attr={ }, tag="pumplo" }, [5]="\ ", [6]={ [1]="0", attr={ }, tag="spa" }, [7]="\ ", [8]={ attr={ }, tag="waterfall" }, [9]="\ ", [10]={ attr={ }, tag="cleaner" }, [11]="\ ", [12]={ attr={ }, tag="poolht2" }, [13]="\ ", [14]={ [1]="0", attr={ }, tag="poolht" }, [15]="\ ", [16]={ [1]="0", attr={ }, tag="spaht" }, [17]="\ ", [18]={ [1]="0", attr={ }, tag="solarht" }, [19]="\ ", [20]={ [1]="0", attr={ }, tag="aux1" }, [21]="\ ", [22]={ [1]="0", attr={ }, tag="aux2" }, [23]="\ ", [24]={ [1]="0", attr={ }, tag="aux3" }, [25]="\ ", [26]={ [1]="0", attr={ }, tag="aux4" }, [27]="\ ", [28]={ [1]="0", attr={ }, tag="aux5" }, [29]="\ ", [30]={ attr={ }, tag="aux6" }, [31]="\ ", [32]={ attr={ }, tag="aux7" }, [33]="\ ", [34]={ attr={ }, tag="aux8" }, [35]="\ ", [36]={ attr={ }, tag="aux9" }, [37]="\ ", [38]={ attr={ }, tag="aux10" }, [39]="\ ", [40]={ attr={ }, tag="aux11" }, [41]="\ ", [42]={ attr={ }, tag="aux12" }, [43]="\ ", [44]={ attr={ }, tag="aux13" }, [45]="\ ", [46]={ attr={ }, tag="aux14" }, [47]="\ ", [48]={ attr={ }, tag="aux15" }, [49]="\ ", [50]={ attr={ }, tag="aux16" }, [51]="\ ", [52]={ attr={ }, tag="aux17" }, [53]="\ ", [54]={ attr={ }, tag="aux18" }, [55]="\ ", [56]={ attr={ }, tag="aux19" }, [57]="\ ", [58]={ attr={ }, tag="aux20" }, [59]="\ ", [60]={ attr={ }, tag="aux21" }, [61]="\ ", [62]={ attr={ }, tag="aux22" }, [63]="\ ", [64]={ attr={ }, tag="aux23" }, [65]="\ ", attr={ }, tag="equipment" }, [5]="\ ", [6]={ [1]="\ ", [2]={ [1]="82", attr={ }, tag="poolsp" }, [3]="\ ", [4]={ [1]="60", attr={ }, tag="poolsp2" }, [5]="\ ", [6]={ [1]="96", attr={ }, tag="spasp" }, [7]="\ ", [8]={ [1]="0", attr={ }, tag="pooltemp" }, [9]="\ ", [10]={ [1]="0", attr={ }, tag="spatemp" }, [11]="\ ", [12]={ [1]="58", attr={ }, tag="airtemp" }, [13]="\ ", [14]={ [1]="0", attr={ }, tag="solartemp" }, [15]="\ ", [16]={ [1]="F", attr={ }, tag="tempunits" }, [17]="\ ", attr={ }, tag="temp" }, [7]="\ ", attr={ }, tag="response" }

the source xml (which if i could extract elements from directly i could avoid the table entirely, but alas i do not know how to do that either) i get from the device (Autelis pool controller) is:

<response> <system> <runstate>8</runstate> <model>6521</model> <dip>00000000</dip> <opmode>0</opmode> <vbat>589</vbat> <lowbat>0</lowbat> <version>1.5.5</version> <time>1398051199</time> </system> <equipment> <pump>0</pump> <pumplo></pumplo> <spa>0</spa> <waterfall></waterfall> <cleaner></cleaner> <poolht2></poolht2> <poolht>0</poolht> <spaht>0</spaht> <solarht>0</solarht> <aux1>0</aux1> <aux2>0</aux2> <aux3>0</aux3> <aux4>0</aux4> <aux5>0</aux5> <aux6></aux6> <aux7></aux7> <aux8></aux8> <aux9></aux9> <aux10></aux10> <aux11></aux11> <aux12></aux12> <aux13></aux13> <aux14></aux14> <aux15></aux15> <aux16></aux16> <aux17></aux17> <aux18></aux18> <aux19></aux19> <aux20></aux20> <aux21></aux21> <aux22></aux22> <aux23></aux23> </equipment> <temp> <poolsp>82</poolsp> <poolsp2>60</poolsp2> <spasp>96</spasp> <pooltemp>0</pooltemp> <spatemp>0</spatemp> <airtemp>61</airtemp> <solartemp>0</solartemp> <tempunits>F</tempunits> </temp> </response>

I would very much appreciate a point in the right direction!

Thanks

Just access them as array elements…

pump =vTable[0]
spasm =vTable[96]

Or directly from the XML…

pump = XML: match "<pump>([^<]*)</pump>"

Thanks @akbooer !

@mda, it looks like you are doing something with Autelis…

Would you mind sharing? I one as well and I’m slowly trying to integrate it.

Yep… It is all the stuff here http://forum.micasaverde.com/index.php?topic=15176

:slight_smile:

Sent from my iPhone using Tapatalk