[lua_parsesr script] XML parsing for HTTP poller help

Moderator: leecollings

Post Reply
nmaster
Posts: 54
Joined: Saturday 16 August 2014 17:17
Target OS: Linux
Domoticz version: 3.6304
Contact:

[lua_parsesr script] XML parsing for HTTP poller help

Post by nmaster »

Hi,

have a air quality internet xml source in my country I would like to add in domoticz for my city.

The XML looks like this:

Code: Select all

<!--  -->
<root>
	<node>
		<dateIndice>2017-01-03</dateIndice>
		<agglomerationCodeInsee>97209</agglomerationCodeInsee>
		<agglomeration>FORT-DE-FRANCE</agglomeration>
		<valeurIndice>3</valeurIndice>
		<SousIndiceO3>2</SousIndiceO3>
		<SousIndiceNO2>2</SousIndiceNO2>
		<SousIndicePM10>3</SousIndicePM10>
		<SousIndiceSO2/><Commentaire/>
		<sourceAASQA>http://www.lcsqa.org/aasqa/code/39</sourceAASQA>
	</node>
	<node>
		<dateIndice>2017-01-03</dateIndice>
		<agglomerationCodeInsee>76540</agglomerationCodeInsee>
		<agglomeration>ROUEN</agglomeration>
		<valeurIndice>5</valeurIndice>
		<SousIndiceO3>1</SousIndiceO3>
		<SousIndiceNO2>2</SousIndiceNO2>
		<SousIndicePM10>5</SousIndicePM10>
		<SousIndiceSO2>1</SousIndiceSO2>
		<Commentaire/><sourceAASQA>http://www.lcsqa.org/aasqa/code/25</sourceAASQA>
		</node>
	...
	...
</root>
Before creating my lua script, I used xmllint with xpath option to get value I need for my city (agglomerationCodeInsee=76540)

So on linux I tried:

Code: Select all

$ wget -O test.xml http://www.lcsqa.org/surveillance/indices/prevus/jour/xml/
$ xmllint --xpath '//node[agglomerationCodeInsee=76540]/valeurIndice/text()' test.xml
Result is:

Code: Select all

5
Now, I created a HTTP poller with the URL, and a airquality.lua in the domoticz/scripts/lua_parsers folder.

It looks like this:

Code: Select all

-- ID domoticz
local deviceId = 133

-- Retrieve the request content
s = request['content'];

-- Parse XML values
local iGlobal = domoticz_applyXPath(s,'//node[agglomerationCodeInsee=76540]/valeurIndice/text()')

print('Indice: ' .. iGlobal)

-- Update device
domoticz_updateDevice(deviceId,'',iGlobal)
Issue I have is I never retrieve the actual value, it's not an integer but a boolean I get.

In domoticz logs:

Code: Select all

2017-01-04 13:24:36.408 CLuaHandler: udevices: Indice: true
Is there a bug or I'm doing something wrong ?
nmaster
Posts: 54
Joined: Saturday 16 August 2014 17:17
Target OS: Linux
Domoticz version: 3.6304
Contact:

Re: [lua_parsesr script] XML parsing for HTTP poller help

Post by nmaster »

Nobody has same issue ?
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest