[SOLVED] Does udp binding with regex have to be ((.*))?

when I try use udp input,
Items: String Light_LivingRoom_CeilingLED2_WWhite { udp="<[192.168.0.66:*:'REGEX((.*))']" }
I got update on items state on below
{
“uuid”: “6601-12345678-123456789a12-3”,“fw”: 2915,“mode”: 5,
“rgb”: {“red”: 1,“green”: 0,“blue”: 1,“cwhite”: 0,“wwhite”: 0}
}
but if I made any changes on Regex like

    { udp="<[192.168.0.66:*:'REGEX((ccwhite.*))']" } or
    { udp="<[192.168.0.66:*:'REGEX((mode.*))']" } or
    { udp="<[192.168.0.66:*:'REGEX((.*)wwhite)']" }

it will fail and update state to null

16:45:40.162 [INFO ] [smarthome.event.ItemStateChangedEvent] - Light_LivingRoom_CeilingLED2_WWhite changed from

{
        "uuid": "6601-12345678-123456789a12-3","fw": 2915,"mode": 5,
        "rgb": {"red": 1,"green": 0,"blue": 1,"cwhite": 0,"wwhite": 0}
} to null

does regex is limited when use with tcp/udp binding?

Please kindly advise

I think there may have bug at somewhere

when I try on rules to regex, I can’t get any info after newline \n

openhab> items list Light_LivingRoom_CeilingLED1_WWhite
Light_LivingRoom_CeilingLED1_WWhite (Type=StringItem, State={
        "uuid": "6601-13344421-18fe34cb9ea5-2","fw": 2915,"mode": 9,
        "rgb": {"red": 0,"green": 0,"blue": 0,"cwhite": 0,"wwhite": 900}
}, Label=LED Warm, Category=null)

I run rules as

rule "Test for color temp input"
when
	Item Light_LivingRoom_CeilingLED1_WWhite changed or
	Item DebugMode changed
then
	Thread::sleep(200)
	val String WarmWhite1 = transform("REGEX", "\n.*\n.*wwhite.*(\\d)}.*", Light_LivingRoom_CeilingLED1_WWhite.state.toString)
	val String ColdWhite1 = transform("REGEX", "(cwhite.*)", Light_LivingRoom_CeilingLED1_WWhite.state.toString)
	logInfo("MS_Living","{}",Light_LivingRoom_CeilingLED1_WWhite.state.toString)
	logInfo("MS_Living", "Living LED1: Cold White:{}, Warm White: {}", ColdWhite1, WarmWhite1)
end

I tyried, “(cwhite.)", "\n.(.*)”
result still as below


2018-11-23 18:52:28.621 [INFO ] [eclipse.smarthome.model.script.DeBug] - TEST FrontDoor:Start on Door Open Automate
2018-11-23 18:52:28.822 [INFO ] [pse.smarthome.model.script.MS_Living] - {
2018-11-23 18:52:28.825 [INFO ] [pse.smarthome.model.script.MS_Living] - Living LED1: Cold White:null, Warm White: null

if I use default regex (.*)
result as below

2018-11-23 19:01:05.957 [INFO ] [pse.smarthome.model.script.MS_Living] - {
2018-11-23 19:01:05.962 [INFO ] [pse.smarthome.model.script.MS_Living] - Living LED1: Cold White:{

packet content should as below

{\n\t"uuid": "6601-12345678-123456789a12-3","fw": 2915,"mode": 0,\n\t"rgb": {"red": 1,"green": 0,"blue": 0,"cwhite": 0,"wwhite": 0}\n}

why Regex and not jsonpath xform?

this is a valid json:

{
	"uuid": "6601 - 12345678 - 123456789 a12 - 3",
	"fw": 2915,
	"mode": 5,
	"rgb": {
		"red": 1,
		"green": 0,
		"blue": 1,
		"cwhite": 0,
		"wwhite": 0
	}
}

because I got 2 devices with difference UUID when all broadcast to port 9999, let me try on jsonpath,

by the way (first post has the Item outside code fences :stuck_out_tongue:)

Also, when you paste within the forum, put the code fences first, then paste (otherwise, the forum will change some characters)

brilliant, problem solved by jsonpath, Thanks Dim

String Light_LivingRoom_CeilingLED1_CWhite { udp="<[192.168.0.67:*:'JSONPATH($.rgb.cwhite)']" }
String Light_LivingRoom_CeilingLED1_WWhite { udp="<[192.168.0.67:*:'JSONPATH($.rgb.wwhite)']" }

1 Like