These are never required and should not be imported.
Are you certain that
var Pattern pattern = Pattern::compile("\+CMGR:.*\r*\n*.*")
is the line that is causing the problem? Are you certain that your regular expression is valid and is not throwing a PatternCompileException? Maybe there is an asterisk that is incorrect?
Is there easiest way to split multiline in something like String[] and iterate over each item.
I’ ve tried this and that but nothing works.
Here is what I’ ve already tried:
var String data = GPRS_Shield.state.toString
logInfo("[SERIAL GPRS1]", data)
logInfo("[SERIAL GPRS2]", data.split("\r\n"))
2017-01-09 15:49:23.257 [INFO ] [.o.model.script.[SERIAL GPRS1]] - AT+CMGR=4
+CMGR: "REC READ","+380683577253","","16/12/26,23:39:52+08"
Lalala
OK
2017-01-09 15:49:23.428 [INFO ] [.o.model.script.[SERIAL GPRS1]] - AT+CMGR=4
2017-01-09 15:49:23.684 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'SMS Protocol': Could not invoke method: org.openhab.model.script.actions.LogAction.logInfo(java.lang.String,java.lang.String,java.lang.Object[]) on instance: null
2017-01-09 15:49:23.768 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'SMS Protocol': Could not invoke method: org.openhab.model.script.actions.LogAction.logInfo(java.lang.String,java.lang.String,java.lang.Object[]) on instance: null
I think it would make more sense to invest the effort in perfecting your regular expression with captures for the bits you want to extract. The regex should be able to match everything up to the OK and capture the regions you want to isolate.
Actually with this string script do nothing at all. IT doesn’t print to log.
Behaviour highly depend on regexpr string.
But looks like openhab engine cann’t digest more less complex regexpr.
but when I add complexity to regexpr this particular rule stops to response,
it doesn’t log any error messages from inside catch neither from inside finally.
Since the regex pattern string is being specified in the script language, which is Java-like, I thought that string literals like “\n” mean newline (ASCII 10), but if you wanted the two literal characters “\n” to appear in the string, you needed to escape the meaning of the backslash character with “\\n”. Does this part of the Xtend language apply here?
Have you yet tried my suggestion to use two backslashes instead of one when specifying it via the rule language? Java does indeed understand \s as shown here. I have to think that the rule language handles string literals similarly to the Java language, where this paragraph is given:
Backslashes within string literals in Java source code are interpreted as required by The Java™ Language Specification as either Unicode escapes (section 3.3) or other character escapes (section 3.10.6) It is therefore necessary to double backslashes in string literals that represent regular expressions to protect them from interpretation by the Java bytecode compiler. The string literal “\b”, for example, matches a single backspace character when interpreted as a regular expression, while “\\b” matches a word boundary. The string literal “\(hello\)” is illegal and leads to a compile-time error; in order to match the string (hello) the string literal “\(hello\)” must be used.