Try to substitute Intertechno Binding by Serial Binding without success

Hello all,
with openHAB 2 I used a nanoCUL USB device with the Intertechno Binding to control several power outlets from DUEWI and other manufacturers successfully. Now I migrated my installation to openHAB 3.1.0 Release Build, where the Intertechno binding is no longer available. So I installed the serial binding and it is initialized and seems to be running:

2021-08-29 18:20:48.138 [DEBUG] [internal.handler.SerialBridgeHandler] - Serial port '/dev/ttyUSB0' charset 'ISO-8859-1' set

When I send the IT code from the shell to the device, the outlet is switching as expected:
Code:

 echo is00000F0FFFFF > /dev/ttyUSB0

events.log:

2021-08-29 20:34:46.964 [INFO ] [openhab.event.ChannelTriggeredEvent ] - serial:serialBridge:nanoCUL866:data triggered PRESSED
2021-08-29 20:34:46.966 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'SerialBridge_EinfacheTaste' received command ON
2021-08-29 20:34:46.966 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'SerialBridge_StringData' changed from is00000F0FFFF0
 to is00000F0FFFFF

2021-08-29 20:34:46.967 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'SerialBridge_BinaryData' changed from data:application/octet-stream;base64,aXMwMDAwMEYwRkZGRjANCg== to data:application/octet-stream;base64,aXMwMDAwMEYwRkZGRkYNCg==
2021-08-29 20:34:46.967 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'SerialBridge_EinfacheTaste' predicted to become ON

I created a switch item linked to the switch channel:

When I press the switch I see these entries in the logs:

events.log:

2021-08-29 20:34:46.964 [INFO ] [openhab.event.ChannelTriggeredEvent ] - serial:serialBridge:nanoCUL866:data triggered PRESSED
2021-08-29 20:34:46.966 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'SerialBridge_EinfacheTaste' received command ON
2021-08-29 20:34:46.966 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'SerialBridge_StringData' changed from is00000F0FFFF0
 to is00000F0FFFFF

openhab.log:

2021-08-29 20:36:30.142 [DEBUG] [erial.internal.channel.DeviceChannel] - Mapped command is 'is00000F0FFFFF'
2021-08-29 20:36:30.151 [DEBUG] [internal.handler.SerialBridgeHandler] - Writing 'is00000F0FFFFF' to serial port /dev/ttyUSB0

The outlet is not switched on or off. I also tried the UTF-8 encoding in the Serial Bridge without any change.

What is the trick to get this running?

Regards Christoph

What is the username that you used when you executed the command

What is the output of

id openhab

and

ls -l /dev/ttyUSB0

?

The command was executed as root that time. openHAB is running in a docker container on a Synology NAS DS218+. Now I also tried the command as admin (admin user of my Synology NAS) and as openhab from inside the docker container and both are working as well.

Here is the output of both requested commands:

root@DS218plus:~# docker-enter a5534986cfbf
root@DS218plus:/openhab# id openhab
uid=1030(openhab) gid=9001(openhab) groups=9001(openhab),10(uucp),20(dialout),14(uucp2),16(dialout2),18(dialout3),32(uucp3),997(gpio)
root@DS218plus:/openhab# ls -l /dev/ttyUSB0
crwxrwxrwx 1 root root 188, 0 Aug 30 10:22 /dev/ttyUSB0

then I do not have further ideas for the moment.

Could it be something with the newline character? When the string is sent by the binding, it seems to stay in a buffer. When I subsequently send the identical string from the shell, both strings appear in the string item and can be seen in the log. With the second echo the outlet finally proceeds the switching.

Did you try to add β€œ\n” to the strings that you send to the serial interface in your channel definition so the resulting string would look like:

"is00000F0FFFFF\n"

Yes, I tried it already with and without double quotes without success.

openhab.log:

2021-08-30 22:41:53.507 [DEBUG] [erial.internal.channel.DeviceChannel] - Mapped command is '"is00000F0FFFF0\n"'
2021-08-30 22:41:53.508 [DEBUG] [internal.handler.SerialBridgeHandler] - Writing '"is00000F0FFFF0\n"' to serial port /dev/ttyUSB0
2021-08-30 22:43:41.263 [DEBUG] [erial.internal.channel.DeviceChannel] - Mapped command is 'is00000F0FFFFF\n'
2021-08-30 22:43:41.264 [DEBUG] [internal.handler.SerialBridgeHandler] - Writing 'is00000F0FFFFF\n' to serial port /dev/ttyUSB0
2021-08-30 22:44:17.454 [DEBUG] [erial.internal.channel.DeviceChannel] - Mapped command is 'is00000F0FFFF0\n'
2021-08-30 22:44:17.454 [DEBUG] [internal.handler.SerialBridgeHandler] - Writing 'is00000F0FFFF0\n' to serial port /dev/ttyUSB0
2021-08-30 22:44:31.709 [DEBUG] [erial.internal.channel.DeviceChannel] - Mapped command is 'is00000F0FFFFF\n'
2021-08-30 22:44:31.711 [DEBUG] [internal.handler.SerialBridgeHandler] - Writing 'is00000F0FFFFF\n' to serial port /dev/ttyUSB0

No reaction, no PRESS is triggered and no item is updated,

Then I fired the echo two times:

admin@DS218plus:~$ echo is00000F0FFFFF > /dev/ttyUSB0
admin@DS218plus:~$
admin@DS218plus:~$ echo is00000F0FFFFF > /dev/ttyUSB0
admin@DS218plus:~$

The first echo shows this in the events.log:

2021-08-30 22:45:49.852 [INFO ] [openhab.event.ChannelTriggeredEvent ] - serial:serialBridge:nanoCUL866:data triggered PRESSED
2021-08-30 22:45:49.855 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'SerialBridge_EinfacheTaste' received command ON
2021-08-30 22:45:49.856 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'SerialBridge_StringData' changed from i41001522
 to ? ("is00000F0FFFFF\n""is00000F0FFFF0\n"is00000F0FFFFF\n"is00000F0FFFF0\n"is00000F0FFFFF\nis00000F0FFFF0\nis00000F0FFFFF\nis000

The second run shows this:

2021-08-30 22:51:43.500 [INFO ] [openhab.event.ChannelTriggeredEvent ] - serial:serialBridge:nanoCUL866:data triggered PRESSED
2021-08-30 22:51:43.501 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'SerialBridge_EinfacheTaste' received command ON
2021-08-30 22:51:43.503 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'SerialBridge_StringData' changed from ? ("is00000F0FFFFF\n""is00000F0FFFF0\n"is00000F0FFFFF\n"is00000F0FFFF0\n"is00000F0FFFFF\nis00000F0FFFF0\nis00000F0FFFFF\nis000
 to is00000F0FFFFF

And now the light in the outlet is really switched on!

I learned the parameter -e and saw, that this echo is also working:

admin@DS218plus:~$ echo -e "is00000F0FFFFF\n" > /dev/ttyUSB0

While these are not working:

admin@DS218plus:~$ echo "is00000F0FFFFF\n" > /dev/ttyUSB0
admin@DS218plus:~$ echo is00000F0FFFFF\n > /dev/ttyUSB0

This is the corresponding events.log:

2021-08-30 23:16:44.111 [INFO ] [openhab.event.ChannelTriggeredEvent ] - serial:serialBridge:nanoCUL866:data triggered PRESSED
2021-08-30 23:16:44.117 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'SerialBridge_EinfacheTaste' received command ON
2021-08-30 23:16:44.117 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'SerialBridge_StringData' changed from is00000F0FFFF0
 to is00000F0FFFFFFF

The string is00000F0FFFFFFF has 16 characters now, with additional trailing β€œFF”!

2021-08-30 23:21:08.023 [INFO ] [openhab.event.ChannelTriggeredEvent ] - serial:serialBridge:nanoCUL866:data triggered PRESSED
2021-08-30 23:21:08.025 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'SerialBridge_EinfacheTaste' received command ON
2021-08-30 23:21:08.025 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'SerialBridge_StringData' changed from is00000F0FFFFFFF
 to is00000F0FFFFFF

Now the string has 15 characters, one β€œF” is gone!

When I proceed these test cases, my conslusion is, that the escape sequence "\n " is not interpreted correctly by the Serial Binding, while the echo -e does this job.

Any ideas where to configure the behaviour similar to β€œecho -e”?

Could you share the details of the configuration of the switch / channel ?

This is the serial thing:

UID: serial:serialBridge:nanoCUL866
label: Serial Bridge
thingTypeUID: serial:serialBridge
configuration:
  baudRate: 38400
  charset: ISO-8859-1
  serialPort: /dev/ttyUSB0
  dataBits: 8
  stopBits: "1"
  parity: N
location: Arbeitszimmer

I also tried with charset: UTF-8 but got same issue.

This is the switch thing:

UID: serial:serialDevice:nanoCUL866:COMAG_2
label: COMAG 2
thingTypeUID: serial:serialDevice
configuration:
  patternMatch: .*
bridgeUID: serial:serialBridge:nanoCUL866
channels:
  - id: switch
    channelTypeUID: serial:switch
    label: COMAG 2 Switch
    description: ""
    configuration:
      onValue: is00000F0FFFFF\n
      offValue: is00000F0FFFF0\n

Try configuring your serial things in a things file rather than using the UI. I believe the UI double escapes the newline character so the binding is actually sending a β€œ\” and β€œn” rather than the newline character.

2 Likes

You made my day! Using .things file it works as expected!

Thanks for the solution, I hit the same issue :+1:

Does anyone know if there is a possibility to make the UI interpret newlines and other escaped characters as intended here?

grafik

I found a solution:

  • Switch to the Code tab in the thing configuration of the serial device
  • Put the commands into double quotes
  • Now escape sequences like \n can be used

grafik

After saving, it works but the rendering is strange when switching to the code tab again. The quotes are not displayed anymore, there is a pipe symbol and the value is shown in the next line:

grafik

If you want to edit the commands again, they have to be moved to the previous line again, the pipe has to be deleted and the quotes and the newlines have to be added again. I’m not sure if this is the intended behavior concerning the UI, but apart from that it is possible to use newlines etc. as shown in the first screenhot.

2 Likes