Help REGEXP for HTTP Binding Result

Hello to all,

I’ve got some Issues with http binding now resolved and documented here. Thanks to @Udo_Hartmann

What now I need is to parse the result of the values take from the remote http device and change the switch status. The definition is done as follow:

Switch IPCam01_MDetect "Motion Detection - Soggiorno [%s]" { http=">[ON:POST:http://<MY-IP>/web/cgi-bin/hi3510/param.cgi?cmd=setmdattr&-name=1&-enable=1{Authorization=Basic MY-KEY}] >[OFF:POST:http://<MY-IP>/web/cgi-bin/hi3510/param.cgi?cmd=setmdattr&-name=1&-enable=0{Authorization=Basic MY-KEY}] <[http://<MY-IP>/web/cgi-bin/hi3510/param.cgi?cmd=getmdattr{Authorization=Basic MY-KEY}:30000:JS(getOnOff.js)]" }

getOnOff.js in script folder:

(function(i) {
    var re = new RegExp('.*m1_enable=.(.).*');
    var out = re.exec(i);
    return if(out=="1") ON else OFF;
})(input)

The POST ON and OFF works well. The way I get the informations from the remote cam is the problem. The output is like follow in DEBUG:

2017-08-09 14:17:43.828 [DEBUG] [.httpclient.params.DefaultHttpParams] - Set parameter http.socket.timeout = 5000
2017-08-09 14:17:43.829 [DEBUG] [.httpclient.params.DefaultHttpParams] - Set parameter http.method.retry-handler = org.apache.commons.httpclient.DefaultHttpMethodRetryHandler@a7b1df
2017-08-09 14:17:43.830 [DEBUG] [he.commons.httpclient.HttpConnection] - Open connection to <CAM-IP>:80
2017-08-09 14:17:43.835 [DEBUG] [httpclient.wire.header              ] - >> "GET /web/cgi-bin/hi3510/param.cgi?cmd=getmdattr HTTP/1.1[\r][\n]"
2017-08-09 14:17:43.836 [DEBUG] [he.commons.httpclient.HttpMethodBase] - Adding Host request header
2017-08-09 14:17:43.837 [DEBUG] [httpclient.wire.header              ] - >> "Authorization: Basic YWRtaW46Yms4NjdzbXhlZmls[\r][\n]"
2017-08-09 14:17:43.839 [DEBUG] [httpclient.wire.header              ] - >> "User-Agent: Jakarta Commons-HttpClient/3.1[\r][\n]"
2017-08-09 14:17:43.840 [DEBUG] [httpclient.wire.header              ] - >> "Host: <CAM-IP>[\r][\n]"
2017-08-09 14:17:43.840 [DEBUG] [httpclient.wire.header              ] - >> "[\r][\n]"
2017-08-09 14:17:43.854 [DEBUG] [httpclient.wire.header              ] - << "HTTP/1.1 200 OK[\r][\n]"
2017-08-09 14:17:43.856 [DEBUG] [httpclient.wire.header              ] - << "HTTP/1.1 200 OK[\r][\n]"
2017-08-09 14:17:43.857 [DEBUG] [httpclient.wire.header              ] - << "Server: Hipcam[\r][\n]"
2017-08-09 14:17:43.858 [DEBUG] [httpclient.wire.header              ] - << "Cache-Control: no-cache[\r][\n]"
2017-08-09 14:17:43.859 [DEBUG] [httpclient.wire.header              ] - << "Content-Type:text/html[\r][\n]"
2017-08-09 14:17:43.860 [DEBUG] [httpclient.wire.header              ] - << "Connection: close[\r][\n]"
2017-08-09 14:17:43.861 [DEBUG] [httpclient.wire.header              ] - << "Content-Length: 545[\r][\n]"
2017-08-09 14:17:43.861 [DEBUG] [httpclient.wire.header              ] - << "[\r][\n]"
2017-08-09 14:17:43.863 [DEBUG] [httpclient.wire.content             ] - << "    var m1_enable="1";[\r][\n]"
2017-08-09 14:17:43.863 [DEBUG] [httpclient.wire.content             ] - << "    var m1_x="30";[\r][\n]"
2017-08-09 14:17:43.864 [DEBUG] [httpclient.wire.content             ] - << "    var m1_y="31";[\r][\n]"
2017-08-09 14:17:43.865 [DEBUG] [httpclient.wire.content             ] - << "    var m1_w="1214";[\r][\n]"
2017-08-09 14:17:43.866 [DEBUG] [httpclient.wire.content             ] - << "    var m1_h="667";[\r][\n]"
2017-08-09 14:17:43.866 [DEBUG] [httpclient.wire.content             ] - << "    var m1_sensitivity="50";[\r][\n]"
2017-08-09 14:17:43.867 [DEBUG] [httpclient.wire.content             ] - << "    var m1_threshold="0";[\r][\n]"
2017-08-09 14:17:43.868 [DEBUG] [httpclient.wire.content             ] - << "    var m2_enable="0";[\r][\n]"
2017-08-09 14:17:43.869 [DEBUG] [httpclient.wire.content             ] - << "    var m2_x="1120";[\r][\n]"
2017-08-09 14:17:43.869 [DEBUG] [httpclient.wire.content             ] - << "    var m2_y="0";[\r][\n]"
2017-08-09 14:17:43.870 [DEBUG] [httpclient.wire.content             ] - << "    var m2_w="160";[\r][\n]"
2017-08-09 14:17:43.871 [DEBUG] [httpclient.wire.content             ] - << "    var m2_h="160";[\r][\n]"
2017-08-09 14:17:43.871 [DEBUG] [httpclient.wire.content             ] - << "    var m2_sensitivity="50";[\r][\n]"
2017-08-09 14:17:43.872 [DEBUG] [httpclient.wire.content             ] - << "    var m2_threshold="0";[\r][\n]"
2017-08-09 14:17:43.873 [DEBUG] [httpclient.wire.content             ] - << "    var m3_enable="0";[\r][\n]"
2017-08-09 14:17:43.874 [DEBUG] [httpclient.wire.content             ] - << "    var m3_x="0";[\r][\n]"
2017-08-09 14:17:43.874 [DEBUG] [httpclient.wire.content             ] - << "    var m3_y="560";[\r][\n]"
2017-08-09 14:17:43.875 [DEBUG] [httpclient.wire.content             ] - << "    var m3_w="160";[\r][\n]"
2017-08-09 14:17:43.876 [DEBUG] [httpclient.wire.content             ] - << "    var m3_h="160";[\r][\n]"
2017-08-09 14:17:43.876 [DEBUG] [httpclient.wire.content             ] - << "    var m3_sensitivity="50";[\r][\n]"
2017-08-09 14:17:43.877 [DEBUG] [httpclient.wire.content             ] - << "    var m3_threshold="0";[\r][\n]"
2017-08-09 14:17:43.878 [DEBUG] [httpclient.wire.content             ] - << "    var m4_enable="0";[\r][\n]"
2017-08-09 14:17:43.879 [DEBUG] [httpclient.wire.content             ] - << "    var m4_x="1120";[\r][\n]"
2017-08-09 14:17:43.880 [DEBUG] [httpclient.wire.content             ] - << "    var m4_y="560";[\r][\n]"
2017-08-09 14:17:43.886 [DEBUG] [httpclient.wire.content             ] - << "    var m4_w="160";[\r][\n]"
2017-08-09 14:17:43.887 [DEBUG] [httpclient.wire.content             ] - << "    var m4_h="160";[\r][\n]"
2017-08-09 14:17:43.888 [DEBUG] [httpclient.wire.content             ] - << "    var m4_sensitivity="50";[\r][\n]"
2017-08-09 14:17:43.889 [DEBUG] [httpclient.wire.content             ] - << "    var m4_threshold="0";[\r][\n]"
]
org.openhab.core.transform.TransformationException: An error occurred while loading script.
    at org.openhab.core.transform.TransformationHelper$TransformationServiceDelegate.transform(TransformationHelper.java:62)[176:org.openhab.core.compat1x:2.2.0.201707122217]
    at org.openhab.binding.http.internal.HttpBinding.execute(HttpBinding.java:189)[202:org.openhab.binding.http:1.11.0.201708050109]
    at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:157)[176:org.openhab.core.compat1x:2.2.0.201707122217]
    at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:169)[176:org.openhab.core.compat1x:2.2.0.201707122217]
2017-08-09 14:17:19.525 [DEBUG] [ab.binding.http.internal.HttpBinding] - transformed response is '    var m1_enable="1";^M
var m1_x="30";^M
var m1_y="31";^M
var m1_w="1214";^M
var m1_h="667";^M
var m1_sensitivity="50";^M
var m1_threshold="0";^M
var m2_enable="0";^M
var m2_x="1120";^M
var m2_y="0";^M
var m2_w="160";^M
var m2_h="160";^M
var m2_sensitivity="50";^M
var m2_threshold="0";^M
var m3_enable="0";^M
var m3_x="0";^M
var m3_y="560";^M
var m3_w="160";^M
var m3_h="160";^M
var m3_sensitivity="50";^M
var m3_threshold="0";^M
var m4_enable="0";^M
var m4_x="1120";^M
var m4_y="560";^M
var m4_w="160";^M
var m4_h="160";^M
var m4_sensitivity="50";^M
var m4_threshold="0";^M
'
2017-08-09 14:17:19.526 [DEBUG] [ab.binding.http.internal.HttpBinding] - Couldn't create state for item 'IPCam01_MDetect' from string '    var m1_enable="1";^M
var m1_x="30";^M
var m1_y="31";^M
var m1_w="1214";^M
var m1_h="667";^M
var m1_sensitivity="50";^M
var m1_threshold="0";^M
var m2_enable="0";^M
var m2_x="1120";^M
var m2_y="0";^M
var m2_w="160";^M
var m2_h="160";^M
var m2_sensitivity="50";^M
var m2_threshold="0";^M
var m3_enable="0";^M
var m3_x="0";^M
var m3_y="560";^M
var m3_w="160";^M
var m3_h="160";^M
var m3_sensitivity="50";^M
var m3_threshold="0";^M
var m4_enable="0";^M
var m4_x="1120";^M
var m4_y="560";^M
var m4_w="160";^M
var m4_h="160";^M
var m4_sensitivity="50";^M
var m4_threshold="0";^M
'

I’ve tested with REGEXP as well, but seems not to work:

Switch IPCam01_MDetect "Motion Detection - Soggiorno [%s]" { http=">[ON:POST:http://<MY-IP>/web/cgi-bin/hi3510/param.cgi?cmd=setmdattr&-name=1&-enable=1{Authorization=Basic MY-KEY}] >[OFF:POST:http://<MY-IP>/web/cgi-bin/hi3510/param.cgi?cmd=setmdattr&-name=1&-enable=0{Authorization=Basic MY-KEY}] <[http://<MY-IP>/web/cgi-bin/hi3510/param.cgi?cmd=getmdattr{Authorization=Basic MY-KEY}:30000:REGEX(.*m1_enable=.(.).*)]" }

In this case I get:

2017-08-08 16:01:03.147 [DEBUG] [he.commons.httpclient.HttpMethodBase] - Should close connection in response to directive: close
2017-08-08 16:01:03.151 [DEBUG] [he.commons.httpclient.HttpConnection] - Releasing connection back to connection manager.
2017-08-08 16:01:03.158 [DEBUG] [ab.binding.http.internal.HttpBinding] - transformed response is '1'
2017-08-08 16:01:03.163 [DEBUG] [ab.binding.http.internal.HttpBinding] - Couldn't create state for item 'IPCam01_MDetect' from string '1'

Any ideas?

Thanks,

Simon

I tried also to use http binding with REGE
X and Basic Authorization.
Unfortunately it does not update the item:
String Abus_Status "Abus State [%s]" (G_jdbc) {http="<[cache-Abus-Secvest{Authorization=Basic xxxx}:30000:REGEX(Mode=(.*))]"}

This should return Unset or Set, which works well with
cache-Abus-Secvest.url=http://root:xxx@192.168.178.24:8060/getMode.cgi

Any suggestion?