This page last changed on Jan 28, 2014 by garfield.arbuckle.

Hey everyone,
Yes here I am again. This time with Regex issues.
I'm trying to read telnet responses from my multiroom audio controller.
The multiroom audio controller accepts RS232 codes on its telnet connection.
These codes consist out of 6 digits (Hex values possible)
For instance sending 040150 sets the volume of zone one to 50%.
The first two digits specify the function (Volume control in this case)
The second two digits specify the zone (Zone 1 in this case)
The third two digits specify the value (50% in this case)
Now when you want to request status from the device you only send the function and the zone. The device will then reply with 6 digits.
For instance when you send 0401 it will reply with 040150
So I have been trying to request this value through a sensor.
I have made a Sensor with a range value between 0 and 100.
This sensor is based on the following command

Protocol:telnet
IP: <IP of audio controller>
command: null|0401
Read Regex Filter: ....(..)
Read Regex Group: 1

Ok so from what I can gather from limited documentation available http://www.openremote.org/display/docs/OpenRemote+2.0+How+To+-+Telnet+Interfaces

This should return the last two characters from a 6 character string.
I have also tried the following filters
^....(..)
/d/d/d/d(/d/d)
^/d/d/d/d(/d/d)
(..)$
(/d/d)$

All filters resulted in the following or similar log

DEBUG 2014-01-28 16:42:48,650 (Telnet): Executing status command for sensor: Range Sensor (Name = 'KeukenZoneVOLUMESTATUS', ID = '232204', Min: 0, Max: 100)
INFO 2014-01-28 16:42:48,653 (Telnet): send: 0401                  
INFO 2014-01-28 16:42:49,732 (Telnet): received: 040140

DEBUG 2014-01-28 16:42:49,732 (Telnet): Telnet status command received value: 040140


WARN 2014-01-28 16:42:49,733 (Telnet): Telnet Read Status: No Match using Regex: '....(..)' on response from command 'null|0401'
DEBUG 2014-01-28 16:42:49,733 (Telnet): Telnet status command value after regex: null
DEBUG 2014-01-28 16:42:49,733 (Telnet): Telnet status command updating sensor 'KeukenZoneVOLUMESTATUS' (ID: 232204)  with value 'null'

I have also tried a filter like ^(.) just to try if I can get any filter to match but with no luck.

Any thoughts?
Thanks
Stijn

^\d{4}(\d*)$
Posted by kurrazyman at Jan 28, 2014 17:22

Hi - your first and fourth one should in theory work for you. Richard's one also works.
I suspect if none of these work for you on your setup, something somewhere has gone wrong with your controller configuration. I have seen similar kind of things when using telnet and shell execution commands. I found that changing the config of regex or a parameter passed by OR to the command didn't seem to 'stick' no matter how many times I saved my online design and re-sync'd the controller. I gave up trying to find out why, as I lazily figured out its just easier to delete the webapps folder and copy in a new one to replace it. A quick re-sync with the fresh controller to your online account works every time. I wrote a bash script to do this quickly for me...

Other than that, are you sure you are using one of the developer 2.1 controller versions? some features in the standard 2.0 versions are not fully implemented. You can still configure them in Markab 2.14, but if there's nothing in the controller to receive them, they wont work. At least that what I found with trying to regex returns from shell commands....

Posted by holeymoley at Jan 28, 2014 22:23

Ok I tried Richards regex and I got the same result

INFO 2014-01-28 23:41:18,762 (Telnet): send: 0401
INFO 2014-01-28 23:41:19,767 (Telnet): received: 040144

DEBUG 2014-01-28 23:41:19,769 (Telnet): Telnet status command received value: 040144


WARN 2014-01-28 23:41:19,771 (Telnet): Telnet Read Status: No Match using Regex: '^\d{4}(\d*)$' on response from command 'null|0401'

I'm using the pro controller. I must say your workaround is very cumbersome.
I will give it a try tomorrow
Anyone any other ideas?
Thanks
Stijn

Posted by garfield.arbuckle at Jan 28, 2014 22:52

Could you try

\d{4}(\d{2}).*

Seems from looking at the source code that a \n is added after the read value. No idea why but this might confuse the regexp.

Posted by ebariaux at Jan 29, 2014 08:44

If the telnet server response is exactly as you stated then the regex I provided would work.

What you sometimes find is that there is a new line / carriage return character at the end, so try: -

 ^\d{4}(\d*).*$ 
Posted by kurrazyman at Jan 29, 2014 08:46

Same results

INFO 2014-01-29 10:34:53,342 (Telnet): send: 0401
INFO 2014-01-29 10:34:54,343 (Telnet): received: 040140

DEBUG 2014-01-29 10:34:54,344 (Telnet): Telnet status command received value: 040140


WARN 2014-01-29 10:34:54,346 (Telnet): Telnet Read Status: No Match using Regex: '\d{4}(\d{2}).*' on response from command 'null|0401'
DEBUG 2014-01-29 10:34:54,346 (Telnet): Telnet status command value after regex: null
INFO 2014-01-29 10:40:50,392 (Telnet): send: 0401
INFO 2014-01-29 10:40:51,394 (Telnet): received: 040140

DEBUG 2014-01-29 10:40:51,394 (Telnet): Telnet status command received value: 040140


WARN 2014-01-29 10:40:51,395 (Telnet): Telnet Read Status: No Match using Regex: '^\d{4}(\d*).*$' on response from command 'null|0401'
DEBUG 2014-01-29 10:40:51,395 (Telnet): Telnet status command value after regex: null
DEBUG 2014-01-29 10:40:51,396 (Telnet): Telnet status command updating sensor 'KeukenZoneVOLUMESTATUS' (ID: 232204)  with value 'null'

Thanks a lot already guys for all the efforts.

Posted by garfield.arbuckle at Jan 29, 2014 09:41

WARN 2014-01-29 10:34:54,346 (Telnet): Telnet Read Status: No Match using Regex: '\d{4}(\d{2}).*' on response from command 'null|0401'

This line shows that regex was applied to 'null|0401'. Now wonder that is did not match. Try regex '\d{2}(\d{2})'

Posted by aktur at Jan 29, 2014 13:29

Hey Michal,
'null|0401' is not the command being received from the audio controller it's the command being sent to the controller.

INFO 2014-01-29 10:40:50,392 (Telnet): send: 0401
INFO 2014-01-29 10:40:51,394 (Telnet): received: 040140

DEBUG 2014-01-29 10:40:51,394 (Telnet): Telnet status command received value: 040140
Telnet status command received value: 040140

Can someone confirm that if I would do ^(.) it should just match the first character? This should work in any form right?
This also doesn't work.
Thanks
Stijn

Posted by garfield.arbuckle at Jan 29, 2014 13:35

Any other ideas?

Posted by garfield.arbuckle at Jan 31, 2014 23:44

Anyone?
Is there anyone who's using this function with success?
Thanks guys
Stijn

Posted by garfield.arbuckle at Feb 03, 2014 22:21

Bump?

Posted by garfield.arbuckle at Feb 20, 2014 23:12

Hi Stijn,

I built a unit test for your use case, and can confirm the proposed regular expressions didn't work (why they didn't is still unclear to me, logically they appear correct to me but the parser didn't seem to agree).

Mostly in test what throws things off is the ending line feed/carriage return characters. I'm guessing this might be the case for you as well, as Richard suspected.

However, the way I get around this is different, by turning on the so called DOTALL mode "(?s)" that matches all input to the end of the line including line terminator characters.

So:

(?s)\d{4}(\d{2}).*

Passed the test. Does that help you?

Posted by juha at Feb 21, 2014 06:05

Hey Juha,
Thanks a lot that indeed did the trick.
I stumbled onto a very unfortunate other problem though .
It seems my audio controller only accepts hex values for volume control.
I assume there is no easy way to have OR send hex values from a slider and receive hex values through regex on that slider.
Thanks
Stijn

Posted by garfield.arbuckle at Feb 21, 2014 09:26

Hey everyone,
So I've changed the above tip from Juha to
(?s)....(..).*
This allows my last two characters to be anything.
Since the value being returned from the amp is hex I couldn't just use digits.
The above works without a problem.
My main issue now is I would need a slider which can process hex values.
So the slider would need to be able to send hex values and interpret hex values coming from the amp.
Is this possible?
Thanks

Posted by garfield.arbuckle at Feb 23, 2014 01:33

You can create slider with In-memory virtual command and then use rules to convert it to and from hex.

Posted by aktur at Feb 23, 2014 10:16
Document generated by Confluence on Jun 05, 2016 09:38