Serial Binding, i need help for "String filtering with Regex for generic thing"

Hi All,

runtimeInfo:
  version: 3.1.0
  buildString: Release Build
locale: tr-TR
systemInfo:
  configFolder: /etc/openhab
  userdataFolder: /var/lib/openhab
  logFolder: /var/log/openhab
  javaVersion: 11.0.12
  javaVendor: Azul Systems, Inc.
  javaVendorVersion: Zulu11.50+19-CA
  osName: Linux
  osVersion: 5.10.60-sunxi
  osArchitecture: arm
  availableProcessors: 4
  freeMemory: 91725960
  totalMemory: 194772992
bindings:
  - astro
  - icalendar
  - icloud
  - kodi
  - remoteopenhab
  - serial
  - systeminfo

I am working on the system that I described in the first topic I opened and I want to control the Relays according to the commands I receive from the real world.
I get commands like this from the real world.


I am working on the system that I described in the first topic I opened and I want to control the Relays according to the commands I receive from the real world.
I get commands like this from the real world.

DTYPE: it shows the type of device sending data
DID  : it shows the ID Number of device sending data
PID  : it shows which button information is coming from. (There are 75 buttons in total)
CID  : shows ON OFF information.

What I want to do is to change the status of the relevant channel of the INPUT(Thing) module according to the commands coming from the buttons in the real world and to control the relevant Relay of the OUTPUT(Thing) Module that I associate with this channel.

THING INPUT 1

THING INPUT 1 Channels

THING INPUT 1 Channel 1 config
THING INPUT 1 Channel 1 config

THING INPUT CODE
THING INPUT CODE

The command string I got over Serial Bridge; I’m thinking of passing the MAP transform to the Input Module by filtering it with Regex and transferring the ON-OFF information to change the status of the relevant channel with this information.

input_item.map
input_item.map

THING OUTPUT 1 Channel 1 config
THING OUTPUT 1 Channel 1 config

THING OUTPUT 1 Channel 1

THING OUTPUT CODE


This is the lamp item I want to control
ITEM ODA 1 LAMP

I haven’t been able to control Input Things channels with the incoming string information yet.

2021-09-15 20:45:32.437 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'serial:serialBridge:7ba76b895f' changed from UNINITIALIZED to INITIALIZING
2021-09-15 20:45:32.583 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'serial:serialBridge:7ba76b895f' changed from INITIALIZING to ONLINE
2021-09-15 20:45:32.641 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'serial:serialDevice:7ba76b895f:2c1b65a1d2' changed from UNINITIALIZED to INITIALIZING
2021-09-15 20:45:32.763 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'serial:serialDevice:7ba76b895f:2c1b65a1d2' changed from INITIALIZING to ONLINE
2021-09-15 20:45:32.772 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'serial:serialDevice:7ba76b895f:RGB_1' changed from UNINITIALIZED to INITIALIZING
2021-09-15 20:45:32.792 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'serial:serialDevice:7ba76b895f:RGB_1' changed from INITIALIZING to ONLINE
2021-09-15 20:45:32.801 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'serial:serialDevice:7ba76b895f:e9989b85d4' changed from UNINITIALIZED to INITIALIZING
2021-09-15 20:45:32.822 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'serial:serialDevice:7ba76b895f:e9989b85d4' changed from INITIALIZING to ONLINE
2021-09-15 20:45:32.833 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'serial:serialDevice:7ba76b895f:BlindModule_1' changed from UNINITIALIZED to INITIALIZING
2021-09-15 20:45:32.848 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'serial:serialDevice:7ba76b895f:BlindModule_1' changed from INITIALIZING to ONLINE
==> /var/log/openhab/openhab.log <==
2021-09-15 20:45:48.490 [INFO ] [af.deployer.kar.KarArtifactInstaller] - Found a .kar file to deploy.
2021-09-15 20:45:48.494 [INFO ] [af.deployer.kar.KarArtifactInstaller] - KAR openhab-addons-3.1.0.kar is already installed. Please uninstall it first.
==> /var/log/openhab/events.log <==
2021-09-15 20:47:09.497 [INFO ] [openhab.event.ChannelTriggeredEvent ] - serial:serialBridge:7ba76b895f:data triggered PRESSED
2021-09-15 20:47:09.553 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'CANBUS' changed from DTYPE=11;DID=01;PID=041;CID=01
 to DTYPE=11;DID=01;PID=041;CID=00
2021-09-15 20:47:14.473 [INFO ] [openhab.event.ChannelTriggeredEvent ] - serial:serialBridge:7ba76b895f:data triggered PRESSED
2021-09-15 20:47:14.486 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'CANBUS' changed from DTYPE=11;DID=01;PID=041;CID=00
 to DTYPE=11;DID=01;PID=041;CID=01
2021-09-15 20:47:17.053 [INFO ] [openhab.event.ChannelTriggeredEvent ] - serial:serialBridge:7ba76b895f:data triggered PRESSED
2021-09-15 20:47:17.063 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'CANBUS' changed from DTYPE=11;DID=01;PID=041;CID=01
 to DTYPE=11;DID=01;PID=041;CID=00
2021-09-15 20:47:19.166 [INFO ] [openhab.event.ChannelTriggeredEvent ] - serial:serialBridge:7ba76b895f:data triggered PRESSED
2021-09-15 20:47:19.173 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'CANBUS' changed from DTYPE=11;DID=01;PID=041;CID=00
 to DTYPE=11;DID=01;PID=042;CID=01
2021-09-15 20:47:20.668 [INFO ] [openhab.event.ChannelTriggeredEvent ] - serial:serialBridge:7ba76b895f:data triggered PRESSED
2021-09-15 20:47:20.678 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'CANBUS' changed from DTYPE=11;DID=01;PID=042;CID=01
 to DTYPE=11;DID=01;PID=041;CID=00

Where am I going wrong, any suggestions?
Thank you

Please post text in code fences when possible, rather than screen shots.

Dunno, it is complex.
Go one step at a time.
Maybe concentrate on inbound decoding for now.

This is an excellent start, a diagnostic view of the whole incoming string.
Adding temporary string channels/Items to see what’s what is a good technique, you can always tidy them away later.

So the first hurdle seems to be that other channels you are expecting don’t get an update.
It would make sense to add these channels to the Thing you know works, supplying the CANBUS Item. I can’t make out if that is already the case.

Is the patternMatch working as you expect? Try that with no other transformation to begin with.

Then add the REGEX that you expect to pull out a data Item. If you are unclear about REGEX (I hate working with it) you can more conveniently play with it in a test rule using transform Action. Careful with online testers, openHAB REGEX Transformation service is not regular REGEX, you must match the whole string.

Thank you Rossko57

I see, I will pay attention to this issue.

I will rebuild the system and share the information step by step.


I know, I am getting the Serial data in the Serial Bridge and Input Thing’s Channel

...[INFO ] [openhab.event.ChannelTriggeredEvent ] - serial:serialBridge:SBC:data triggered PRESSED
...[INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'In1_IN11' changed from DTYPE=11;DID=01;PID=041;CID=00 to DTYPE=11;DID=01;PID=041;CID=01
...[INFO ] [openhab.event.ChannelTriggeredEvent ] - serial:serialBridge:SBC:data triggered PRESSED
...[INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'In1_IN11' changed from DTYPE=11;DID=01;PID=041;CID=01 to DTYPE=11;DID=01;PID=041;CID=00
Strings must arrive to serial bridge.     OK
The Serial Bridge should forward this raw string data to relevant Things and their Channels. *OK (It can be seen in the above log file.)*

So, I guess I should create an alias key (Input Thing’s channel and an item) in the virtual world that will simulate the response of the key in the real world.

What should the order of operations be? I couldn’t resolve this point.

  1. Receive string data with Serial Bridge.
  2. Route this data to that channel of the Input Module that matches the PID value. E.g; if the PID value is 003, this data should be directed to channel 3 and processed there, we should not occupy other channels.
    Channel 3 should synchronize its state with the switch in the real world, and the state of channel 3 should be ON or OFF.

am I right?

I don’t understand much of that. Do you want your incoming data packet to trigger an openHAB event, like pressing a button? Or seeing as we started off talking about relays, is it supposed to represent a (new) static state?

As per the docs, the Bridge thing represents “the serial port”. A channel attached here shows every message.

That port might be attached to a bus of many devices, so the binding provides a hierarchy where serialDevice represents one, only handling messages where a key string matches like “deviceID=22” or suchlike.

If you choose to use that, you can further process the messages in the serialDevice channels.

If you can take the time to read (I would be grateful), I have explained the whole system and what I want to do in detail on this topic.

btw, I didn’t edit to avoid spoiling the first post. After this message, I changed the data structure as you see in this topic.

this is old strig structure

"VID_110100101*"
"VID_"                :Header
"11" (First 2 digits) :Type Identifier ("10"=VLI-20, "11"=VLI-35)
"01" (Next  2 digits) :Module ID (1st Input Module in this example)
"001"(Next  3 digits) :Input ID (Can be between 1 and 35 for Short press, 41 to 75 for Long press)
"01" (Last  2 digits) :Status (Can be "0" or "1".)

main subject link
(Suggestion and help request for Openhab Serial Binding ; General Things integration)

thank you

I followed this approach when built the openhab design. My first goal is to filter messages for a serial Device (in this example Input Module) like this so that it only processes messages that are of interest to it.