Hi please help ☺ – I’m wrestling with 2-way control. I can control the device and demoted is receiving the response but I am struggling to successfully pull out the state data I want from the xml response. I’ve read all of the posts I could find on this including advice to use Hercules and various combinations of \x0A and \x0D but no joy.
I have a Tercaom TCW240B network relay which has 4 relay outputs and a number of analogue and digital inputs. All of this is controllable via Ethernet and is seems to be working fine. It accepts the following commands (by way of example):
“GET /status.xml HTTP/1.0\x0D\x0A” – returns an xml structure containing status of relays, and various inputs connected to the device.
“GET /status.xml?r1=1 HTTP/1.0\x0D\x0A” – sets the status of relay 1 to ON (audible click and light on the unit) and returns the same XML structure.
So far so good. However I want to use two-way feedback to set flags in demopad for the state of the relays and inputs and this is where the problem lies. In turn this will be used to implement toggle button and power light in demopad.
In order to test that it is working I have set up a label that I want to populate with the value (i.e. state) of Relay1.
The returned XML is spread across multiple lines and unfortunately the pattern I am trying to match relies on multiple lines of XML but I cannot get Demopad to match it. The format of the XML is as follows:
<?xml version="1.0" encoding="UTF-8"?>
… other stuff…
… other tags not interested in…
… other stuff …
Therefore the pattern I want to use is something like "<R1>.*?<value>(.*?)</value>" OR "Relay1</description><value>(.*)</value>"
After much playing around trying to pull the text into a label to make sure it is parsing correctly, I have managed the following:
- I can parse the result from the unit to return a value. For example using pattern “<value>(.*?)<\value>” does return ON or OFF and displays it in the label. However I need the pattern to also include the ID or description of the specific relay or sensor.
- I tried “<R1>\x0A<description>Relay1</description>\x0A<value>(.*?)</value>” but still nothing. I tried it using all combinations of \x0A and \x0D but none work.
- I set Hercules up and pointed demopad at it so that it received the demopad commands all look normal. I then manually returned a manufactured response from Hercules to demopad as follows: “<R1>$0A<description>Relay1</description>$0A<value>ON</value>$0A</Monitor> and set the terminator to </Monitor> and it worked perfectly with DemoPad pulling out the ON or OFF value and displaying it.
- Note that I set the terminator to </Monitor> so that it would pull all of the content and not stop at first line. This works in the Hercules test but not when the data is returned from the unit.
- I think I have deduced therefore that the end of line character being included in the xml returned by the unit is not any of \x0A, \x0D, \x0A\x0D or \x0Dx0A.
This is where I am struggling – how do I determine what control characters are being included in the returned XML.
Please help DemoPad forum you’re my only hope .
Forum to ask for any help
1 post • Page 1 of 1