This page last changed on Nov 24, 2015 by freddyc.

I have the following rule, modified from rules provided by Michal Rutka to PZ1. In my case the received message is 3 uppercase characters followed by a comma followed by "on" or "off" or a temperature value of ##.# (range of -9.9 to 99.9). eg, LCL,on or LAT,21.2
I have tested the following regex rule on regex planet with no problems.

rule "UDPListener"
                                                                                      
when
  Event(source=="UDP-1-Status", $v: value!="")
then
  java.util.regex.Pattern regexPattern = java.util.regex.Pattern.compile ([A-Z]{3}),([-1-9]?[0-9]?\.[0-9]|on|off)
 java.util.regex.Matcher matcher = regexPattern.matcher ($v.toString());
  if (matcher.find()) {
    execute.command(matcher.group(1), matcher.group(2));
  }
end

When I start the controller I get the following errors

2015-11-25 09:19:55,783 ERROR [main]: Rule definition 'modeler_rules.drl' could not be deployed. See errors below.
2015-11-25 09:19:55,784 ERROR [main]: Rule Compilation error Syntax error on token(s), misplaced construct(s)
Syntax error, insert ")" to complete Expression
Syntax error on tokens, delete these tokens
Syntax error on token "?", Expression expected after this token
Syntax error on token "?", Expression expected after this token
Syntax error on token "|", ( expected
Syntax error, insert ": Expression" to complete Expression
Syntax error, insert ": Expression" to complete Expression
Syntax error, insert "}" to complete ArrayInitializer
Syntax error, insert ";" to complete LocalVariableDeclarationStatement
2015-11-25 09:19:55,786 ERROR [main]: There was an error parsing the rule definition 'modeler_rules.drl' : Could not parse knowledge.
java.lang.IllegalArgumentException: Could not parse knowledge.

However, at the end of controller startup I receive

2015-11-25 09:19:55,843 INFO [main]: Initialized event processor : Drools Rule Engine
2015-11-25 09:19:55,870 INFO [main]: Initialized event processor : RRD4J Data Logger
2015-11-25 09:19:55,871 INFO [main]: Initialized event processor : EmonCMS Data Logger
2015-11-25 09:19:55,887 WARN [main]: Unknown virtual protocol property '<property name = "name" value = "LCL"/>'.
2015-11-25 09:19:55,900 INFO [main]: Registered sensor : Sensor (Name = 'UDP-1-Status', ID = '107672251', State Mappings: {})
2015-11-25 09:19:55,901 INFO [main]: Registered sensor : Sensor (Name = 'LCL', ID = '107672861', State Mappings: {})
2015-11-25 09:19:55,902 INFO [Polling Sensor Thread ID = 107672861, Name ='LCL']: Started polling thread for sensor (ID = 107,672,861, name = LCL).
2015-11-25 09:19:55,903 TRACE [Polling Sensor Thread ID = 107672861, Name ='LCL']: Processed '', received ''
2015-11-25 09:19:55,904 INFO [main]: Startup complete.
2015-11-25 09:19:55,904 INFO [main]: Controller Definition File Watcher for Default Deployer started.
2015-11-25 09:19:56,409 TRACE [Polling Sensor Thread ID = 107672861, Name ='LCL']: Processed '', received ''

Finally, when an input "LCL,on" is received I get

2015-11-25 09:21:30,415 TRACE [Polling Sensor Thread ID = 107672861, Name ='LCL']: Processed '', received ''
2015-11-25 09:21:30,519 INFO [HTTP-Thread-4]: Querying changed state from ChangedStatus table...
2015-11-25 09:21:30,519 INFO [HTTP-Thread-4]: Found: [device => 651cbb27-f2cf-472e-89aa-1fbc9a97a714, sensorIDs => [107672251, 107672861]] in ChangedStatus table.
2015-11-25 09:21:30,520 INFO [HTTP-Thread-4]: ChangedStatusRecord:651cbb27-f2cf-472e-89aa-1fbc9a97a714-[107672251, 107672861] sensorID:[107672251, 107672861] statusChangedSensorID:[]Waiting...
2015-11-25 09:21:30,915 TRACE [Polling Sensor Thread ID = 107672861, Name ='LCL']: Processed '', received ''

Thanks.


UDPListeners.PNG (image/png)
UDPlistener.png (image/png)
UDPsensor.png (image/png)
Untitled.png (image/png)
Dev list.png (image/png)
ESP_1_Status sensor.png (image/png)
ESP_1_Status command.png (image/png)

Perhaps Python coder? Anyway, you need more Java /syntax beauty/ to make it work. Try the rule below (not tested):

rule "UDPListener"
                                                                                      
when
  Event(source=="UDP-1-Status", $v: value!="")
then
  java.util.regex.Pattern regexPattern = java.util.regex.Pattern.compile("([A-Z]{3}),([-1-9]?[0-9]?\\.[0-9]|on|off)");
  java.util.regex.Matcher matcher = regexPattern.matcher ($v.toString());
  if (matcher.find()) {
    execute.command(matcher.group(1), matcher.group(2));
  }
end
Posted by aktur at Nov 25, 2015 09:27

Thanks Michal, I haven't found anything to work yet so I took the easy way out and am trying (LCL|LFL|LRT|LCM),(on|off) .
I think it is working because I don't get any error to say it is not.
I am trying to link it to a label but ,even after reading quite a few posts in the forums (including your temperature example)
I still find it difficult to understand linking imvc's to switches and labels.
Thanks for your help.

Posted by freddyc at Nov 26, 2015 01:00

Can anyone provide explanation of the following error.

2015-11-27 14:54:13,059 INFO [HTTP-Thread-2]: ChangedStatusRecord:4cb484d7-b5cb-4948-a49b-9da190722a60-[107673053] sensorID:[107673053] statusChangedSensorID:[]Waiting...
2015-11-27 14:55:03,059 INFO [HTTP-Thread-2]: Had timeout for waiting status change.

This is the result from my custom sensor (LCLsensor) connected to a udplistener command with custom state items LCL,on mapped to on, and LCL,off mapped to off.
sensorID:107673053 is the LCLsensor and it eppears to have received the command and changed state but what is it waiting for?
Thanks, Fraser.

Posted by freddyc at Nov 27, 2015 04:12

I still find it difficult to understand linking imvc's to switches and labels.

Can you elaborate a bit more about what is difficult or confusing about this with reference
to my descriptions about UDP and the In Memory Virtual Commands?

Posted by pz1 at Nov 27, 2015 10:13

I have studied your How To guide (and other forum posts on UDPlistener and imvc etc). I worked through your How to again today
and this is what I ended up with.

'Lounge Ceiling Light' device with
'LCLon' command type UDP
'LCLoff' "
'LCL' command type imvc status address lcl
'LCL' sensor type custom using LCL status above
'LCLsw' binary switch

'UDPListener-1' device with
'ESP-1-Status' command protocol UDPlistener, UDP port 9034 Regex (.*)
'ESP-1-Status' sensor type custom using "ESP-1-Status' command above.

My simplified rules for simple people are

rule "UDPListener-Lounge"
                                                                                      
when
  Event(source=="ESP-1-Status", $v: value!="")
then
  java.util.regex.Pattern regexPattern = java.util.regex.Pattern.compile (LCL|LFL|LRT|LCM),(on|off);
 java.util.regex.Matcher matcher = regexPattern.matcher ($v.toString());
  if (matcher.find()) {
    execute.command(matcher.group(1), matcher.group(2));
  }
end

Since I have made these changes I can't send command from my mobile anymore which I have not had problem with before.
I do not see where the memory variable is set except directly in the status command in the switch.
I tried putting an imvc status command under UDPListener name 'LCL to save the variable lcl and changed the
switch status command to 'LCLstatus" type imvc address lcl, but made no difference.
When I restart the controller I get an error that modeler rules could not be deployed but further on I grt
message 'Initialized event processor : Drools Rule Engine'so I am guessing rules are deployed OK.
When 'LCL,on' is received on UDP port I get message

2015-11-28 11:21:55,876 INFO [HTTP-Thread-1]: Querying changed state from ChangedStatus table...
2015-11-28 11:21:55,876 INFO [HTTP-Thread-1]: Not Found: [device => 4cb484d7-b5cb-4948-a49b-9da190722a60, sensorIDs => [107673053]] in ChangedStatus table.
2015-11-28 11:21:55,876 INFO [HTTP-Thread-1]: ChangedStatusRecord:4cb484d7-b5cb-4948-a49b-9da190722a60-[107673053] sensorID:[107673053] statusChangedSensorID:[]Waiting...

A large part of my problem (I think) is I am not sure where the problems are. I think the message is received but is it correct?
Is it my regex or how I try to store and use the IMVC's. I can see the message is sent from the ESP8266 device to the controller,
but maybe the format is incorrect.
Thanks again for your good work.

Posted by freddyc at Nov 28, 2015 01:36

'Initialized event processor : Drools Rule Engine'so I am guessing rules are deployed OK.

You are guessing wrongly. The rule is broken (I've explained earlier where) and it is never executed. Moreover, because of the syntax error the whole modeler_rules.drl file is discarded.

Posted by aktur at Nov 28, 2015 06:57

Thanks Michal and Pieter. The best I have been able to do is to get controller to start without any errors. I do however get this warning

"WARN main: Unknown virtual protocol property '<property name = "name" value = "LCLstate"/>'."

LCLstate is the sensor associated with the switch and the IMVC LCLstate command to read memory address.
Once the controller is running and a UDP message (e.g. LCL,on ) I get the following

2015-12-03 08:42:53,695 TRACE [Polling Sensor Thread ID = 107673490, Name ='LCLstate']: Processed '', received ''
2015-12-03 08:42:54,195 TRACE [Polling Sensor Thread ID = 107673490, Name ='LCLstate']: Processed '', received ''
2015-12-03 08:42:54,423 ERROR [UDPListener Port: 9034]: Error in UDPListenerThread
java.lang.IllegalStateException: No match found
	at java.util.regex.Matcher.group(Matcher.java:468)
	at org.openremote.controller.protocol.socket.UDPListenerCommand$UDPListenerThread.run(UDPListenerCommand.java:122)
2015-12-03 08:42:54,695 TRACE [Polling Sensor Thread ID = 107673490, Name ='LCLstate']: Processed '', received ''
2015-12-03 08:42:55,195 TRACE [Polling Sensor Thread ID = 107673490, Name ='LCLstate']: Processed '', received ''

I have a Label that should display LCL-state which is UDPlistener sensor but it never displays anything (N/A)'
I have tried sending the LCL,on and LCL,off from UDPsender on my phone with same result.
Both UDP messages from the ESP8266 device and from my phone display correctly on wireshark.
Sorry to bother you again but I am out of ideas completely.
Thanks, Fraser.

Posted by freddyc at Dec 02, 2015 22:13

I have a Label that should display LCL-state which is UDPlistener sensor but it never displays anything (N/A)

Apparantly your UDPListener isn't receiving anything. I have two separate listeners for commands coming from two RaspberryPi devices.
See monitor below

The one Pi I stopped also gives this N/A. You should fix that first (see if port numbers are correct, firewalls...)
Please give screendumps of your UDPListener and the sensor that you based on that UDPListener

Posted by pz1 at Dec 03, 2015 08:16

I agree, but I have not been able to find out why. I can use telnet or tcp on this port OK, and I have tried UDPlisteneron a port I used for tcp
without any problems. In the code I included on my last post it definitely states "error in UDPlistener thread". I tried to send a 'new line' on the end
of the string without success.
Did you get 0,1,2 or more screen dumps of UDPListener and command? I haven't tried it before and I can't preview to see what happened.

Posted by freddyc at Dec 03, 2015 09:52

First displaying your images

To see the two images at the right better, do click on them!

It looks like you are messing with the sensor and command names.
Do not use dashes in names but use "CamelBack" style instead.
The name of the UDPListener command does not correspond
to the name in the hierarchy of the left most picture.
To be compliant with that use name Esp1Status for both UDPListener command
and sensor.
What is the LCL command under UDPListener-1 supposed to do? If not used, remove!
Do Use name 'LCL' only for your LoungeCeilingLights. Not with the Listener, that
confuses yourself and us

Posted by pz1 at Dec 03, 2015 10:22

Sorry Pieter, I have messed you about. The first image of device commands was out of date. When I did the other 2 I saw that and thought it would help to include it,
not realising I had re-done all the commands. I am imcluding up to date screen dumps after changing names etc as you recommended.
After a lot of further testing the main and only problem I am concerned with is not recognising the UDP packet.

2015-12-04 17:27:29,912 TRACE [Polling Sensor Thread ID = 107673490, Name ='LCL']: Processed '', received ''
2015-12-04 17:27:30,412 TRACE [Polling Sensor Thread ID = 107673490, Name ='LCL']: Processed '', received ''
2015-12-04 17:27:30,576 ERROR [UDPListener Port: 9034]: Error in UDPListenerThread
java.lang.IllegalStateException: No match found
	at java.util.regex.Matcher.group(Matcher.java:468)
	at org.openremote.controller.protocol.socket.UDPListenerCommand$UDPListenerThread.run(UDPListenerCommand.java:122)

When I restart the controller it runs OK until a UDP packet is received giving the above error. I think the UDPlistener then shuts down.
I have sent udp packets from the ESP-8266 back to a UDP tester on the port I am using, from the ESP-8266, and from a UDP tester on another PC using the same address and from a UDP tester on my Phone. I have tried just the LCL,on string, "LCL,on" (in quotes), also with cr and with lf and with cr & lf. I also tried a longer string. Each time I tried something different I would shut down the controller and restart it. ( in the process I also found a problem with my code on the ESP-8266 but I will worry about that later)
Everything worked to UDP test programs but OR gave me the same code error every time.
So, everything normal - I am stuck again.

Posted by freddyc at Dec 04, 2015 06:53

Sorry, I must leave this to those who have more in depth knowledge about UDPListener

Posted by pz1 at Dec 04, 2015 07:52

The only thing I can think off in case you are following pz1's guidance is that the version of controller you have is outdated. I remember that there were problems with old controller builds and the UDPlistener protocol. In any case a sensor connected to the UDPlistener command should get something more than N/A.

Posted by aktur at Dec 05, 2015 16:07

Thanks Michal, sounded like a good idea. I was running 2.1.0. I have only been using OR for a few months and assumed it was the latest version.
When I checked on Sourceforge I found 2.1.1 which is not the version that downloads if you just click on the big download button.
2.1.1 included the bugfix ' - Remerge issue ORCJAVA-392 to correctly
include changes in UDP listener'
so I got all excited. However, on testing it appears to do exactly the same as 2.1.0
I then went back and downloaded 2.0.2 and that tested the same as well.
I am just unzipping these downloads into the openremote/controller**** folder and deleting the old controller directory and then restart the controller.
I will go back to an earlier version again and try it.
Thanks.

Posted by freddyc at Dec 05, 2015 23:18

Thank you for checking this. I made a note on my Recipe page

Posted by pz1 at Dec 06, 2015 09:12

I am just unzipping these downloads into the openremote/controller**** folder and deleting the old controller directory and then restart the controller.

You should stop the controller before deleting/overwriting its folder. Otherwise some files can be locked and left behind.

BTW, at what platform are you running?

Posted by aktur at Dec 06, 2015 10:01

I have tested further with all controller versions on Sourceforge making sure I stop the controller and then delete before loading new controller,
saving from designer and syncing new controller. Still get same result on all.

Posted by freddyc at Dec 08, 2015 00:39

BTW, at what platform are you running?

It is in your own interest to answer the questions from those who try to help. We all are volunteers who do this in our free time.

Posted by pz1 at Dec 08, 2015 08:23

I am using Windows 7. I started another thread to see if anyone using OR free and windows has had any success.

Posted by freddyc at Dec 08, 2015 08:40
Document generated by Confluence on Jun 05, 2016 09:33