Sending serial commands in OpenHab3

Hello,

I am new to OH3, but really liked the concept and wanted to integrate several things on its platform. I should also preface that I am a beginner and have very limited experience with writing code.

Primarily, I am trying to send serial commands to an existing proprietary Colorado Vnet system ( unfortunately this system only receives outside serial commands ). I have a USB/RS232 device which I have successfully tested via Putty, in both Windows and Linux environments.

I have OH3 installed in a VM Docker in Proxmox. After reading the OH3 documentation it appeared pretty intuitive, and created a widget button in Hab panel.

Initially downloaded the serial binding. I have the USB/RS 232 adapter plugged in. Went to Things thereafter, and added Serial Bridge. In Advanced Settings: Port /dev/ttyUSB0, Baud 115200 ( according to Vnet), data bits 8, parity None, stop bits 1. Left Charset unfilled, and assumed it went to default since the Serial Bridge appears to be green ONLINE.

Next I created an item, named it Test and liked to Serial Bridge. I have then opened Hab Panel and in the previously created widget button added Test item. In the command value box I entered the serial command:
3,OH,x,x,x
Unfortunately, no success…

I have used the above string command in Putty successfully as previously mentioned. The only thing i can think of, is that I had to set Putty Local Echo and Local Line editing to Force On. These setting were not available under the Serial Bridge Settings in OH3.
I have read prior posts which suggested adding \r,\n,\r\n… tried all without success.

At this point , I would really appreciate it if someone could point me into the right direction and offer an example of the string command format needed to make this work.

Thank you all in advance!

Is the Linux environment that you successfully tested from that VM in Proxmox?

Is your USB serial adaptor available in your VM? Does your Docker container have access to it?

If you’ve tried that by entering the value in the UI then it won’t work due to those values being double escaped when saved to the JSON db, i.e. it will send a slash and an r, rather than a carriage return.

If you need to terminate with a carriage return and/or new line then you will have to configure the serial binding using the config file rather than the UI.

Yes the VM has the USB devices successfully passed through to an Ubuntu 20.04 VM. I have also added the device to the docker container via docker compose.

Here is my docker-compose.yml

version: '2.2'

services:
  openhab:
    image: "openhab/openhab:3.2.0"
    restart: always
    container_name: openhab
    network_mode: host
    volumes:
      - "/etc/localtime:/etc/localtime:ro"
      - "/etc/timezone:/etc/timezone:ro"
      - "./openhab_addons:/openhab/addons"
      - "./openhab_conf:/openhab/conf"
      - "./openhab_userdata:/openhab/userdata"
    environment:
      OPENHAB_HTTP_PORT: "8080"
      OPENHAB_HTTPS_PORT: "8443"
      USER_ID: "1000"
      GROUP_ID: "1000"
      EXTRA_JAVA_OPTS: "-Dgnu.io.rxtx.SerialPorts=/dev/ttyUSB0"     
    devices:
      - /dev/ttyUSB0:/dev/ttyUSB0

I also installed picocom on the docker host to test that I could send a command directly to the device.

picocom --baud 115200 --echo /dev/ttyUSB0 

If I use that command it will open a connection and the I can send to the command

2,OpenHab,1,1,1

This works as expected, and turns on the lights I set up in colorado vnet for testing.
I guess I am failing to understand exactly how the serial binding will send a string command to the /dev/ttyUSB0.

Can you post some screenshots of how you have the serial binding configured, including your test item and how it is linked. Can you also include the section of the event.log which shows what happens when you try and test it.

Here are some screenshots.



events.log

2022-02-25 23:56:30.468 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'serial:serialBridge:4bd7deb941' changed from UNINITIALIZED to INITIALIZING
2022-02-25 23:56:30.785 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'serial:serialBridge:4bd7deb941' changed from INITIALIZING to OFFLINE (CONFIGURATION_ERROR): Port is not known
2022-02-25 23:59:41.979 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'test' received command ON
2022-02-25 23:59:42.012 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'test' changed from NULL to ON
2022-02-26 00:00:25.971 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'serial:serialBridge:4bd7deb941' changed from OFFLINE (CONFIGURATION_ERROR): Port is not known to UNINITIALIZED
2022-02-26 00:00:25.995 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'serial:serialBridge:4bd7deb941' changed from UNINITIALIZED to UNINITIALIZED (DISABLED)
2022-02-26 00:00:28.354 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'serial:serialBridge:4bd7deb941' changed from UNINITIALIZED (DISABLED) to INITIALIZING
2022-02-26 00:00:28.645 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'serial:serialBridge:4bd7deb941' changed from INITIALIZING to OFFLINE (CONFIGURATION_ERROR): Port is not known
2022-02-26 00:00:46.054 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'serial:serialBridge:4bd7deb941' changed from OFFLINE (CONFIGURATION_ERROR): Port is not known to REMOVING
2022-02-26 00:00:46.102 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'serial:serialBridge:4bd7deb941' changed from REMOVING to REMOVED
2022-02-26 00:00:46.115 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'serial:serialBridge:4bd7deb941' changed from REMOVED to UNINITIALIZED
2022-02-26 00:00:46.131 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'serial:serialBridge:4bd7deb941' changed from UNINITIALIZED to UNINITIALIZED (HANDLER_MISSING_ERROR)
2022-02-26 02:27:38.774 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'serial:serialBridge:edb52034dc' changed from UNINITIALIZED to INITIALIZING
2022-02-26 02:27:39.010 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'serial:serialBridge:edb52034dc' changed from INITIALIZING to ONLINE
2022-02-26 02:33:16.765 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'SerialBridge_StringData' received command 2,OpenHab,1,1,1
2022-02-26 02:33:16.786 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'SerialBridge_StringData' predicted to become 2,OpenHab,1,1,1
2022-02-26 02:33:16.796 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'SerialBridge_StringData' changed from NULL to 2,OpenHab,1,1,1
2022-02-26 02:33:35.861 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'test' received command 2,OpenHab,1,1,1
2022-02-26 02:33:35.870 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'test' predicted to become 2,OpenHab,1,1,1
2022-02-26 02:33:35.878 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'test' changed from NULL to 2,OpenHab,1,1,1
2022-02-26 02:33:39.149 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'test' received command 2,OpenHab,1,1,1
2022-02-26 02:33:39.181 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'test' predicted to become 2,OpenHab,1,1,1
2022-02-26 02:33:56.218 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'SerialBridge' received command 2,OpenHab,1,1,1
2022-02-26 02:33:56.221 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'SerialBridge_StringData' received command 2,OpenHab,1,1,1
2022-02-26 02:33:56.224 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'SerialBridge_StringData' predicted to become 2,OpenHab,1,1,1
2022-02-26 02:34:02.981 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'SerialBridge' received command 2,OpenHab,1,1,1
2022-02-26 02:34:02.983 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'SerialBridge_StringData' received command 2,OpenHab,1,1,1
2022-02-26 02:34:02.988 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'SerialBridge_StringData' predicted to become 2,OpenHab,1,1,1
2022-02-26 02:35:40.306 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'SerialBridge_StringData' received command 2,OpenHab,1,1,1\n
2022-02-26 02:35:40.312 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'SerialBridge_StringData' predicted to become 2,OpenHab,1,1,1\n
2022-02-26 02:35:40.320 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'SerialBridge_StringData' changed from 2,OpenHab,1,1,1 to 2,OpenHab,1,1,1\n
2022-02-26 02:35:42.259 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'SerialBridge_StringData' received command 2,OpenHab,1,1,1\n
2022-02-26 02:35:42.262 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'SerialBridge_StringData' predicted to become 2,OpenHab,1,1,1\n
2022-02-26 02:35:56.389 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'SerialBridge_StringData' received command 2,OpenHab,1,1,1\r
2022-02-26 02:35:56.392 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'SerialBridge_StringData' predicted to become 2,OpenHab,1,1,1\r
2022-02-26 02:35:56.396 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'SerialBridge_StringData' changed from 2,OpenHab,1,1,1\n to 2,OpenHab,1,1,1\r
2022-02-26 02:36:15.115 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'SerialBridge_StringData' received command 2,OpenHab,1,1,1\r\n
2022-02-26 02:36:15.119 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'SerialBridge_StringData' predicted to become 2,OpenHab,1,1,1\r\n
2022-02-26 02:36:15.123 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'SerialBridge_StringData' changed from 2,OpenHab,1,1,1\r to 2,OpenHab,1,1,1\r\n
2022-02-26 02:36:22.321 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'SerialBridge_StringData' received command 2,OpenHab,1,1,1\r\n
2022-02-26 02:36:22.325 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'SerialBridge_StringData' predicted to become 2,OpenHab,1,1,1\r\n
2022-02-26 02:49:10.891 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'SerialBridge' received command 2,OpenHab,1,1,1\r\n
2022-02-26 02:49:10.893 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'SerialBridge_StringData' received command 2,OpenHab,1,1,1\r\n
2022-02-26 02:49:10.902 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'SerialBridge_StringData' predicted to become 2,OpenHab,1,1,1\r\n
2022-02-26 02:49:28.498 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'test' received command 2,OpenHab,1,1,1\r\n
2022-02-26 02:49:28.502 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'test' predicted to become 2,OpenHab,1,1,1\r\n
2022-02-26 02:49:28.506 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'test' changed from 2,OpenHab,1,1,1 to 2,OpenHab,1,1,1\r\n
2022-02-28 18:21:38.105 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'serial:serialBridge:edb52034dc' changed from ONLINE to OFFLINE (CONFIGURATION_ERROR): Invalid charset
2022-02-28 18:23:00.778 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'serial:serialBridge:edb52034dc' changed from OFFLINE (CONFIGURATION_ERROR): Invalid charset to ONLINE
2022-03-01 05:48:53.739 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'serial:serialBridge:edb52034dc' changed from ONLINE to REMOVING
2022-03-01 05:48:53.745 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'serial:serialBridge:edb52034dc' changed from REMOVING to REMOVED
2022-03-01 05:48:53.758 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'serial:serialBridge:edb52034dc' changed from REMOVED to UNINITIALIZED
2022-03-01 05:48:54.122 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'serial:serialBridge:edb52034dc' changed from UNINITIALIZED to UNINITIALIZED (HANDLER_MISSING_ERROR)
2022-03-01 06:04:08.153 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'serial:serialBridge:5cc0a1e37f' changed from UNINITIALIZED to INITIALIZING
2022-03-01 06:04:08.187 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'serial:serialBridge:5cc0a1e37f' changed from INITIALIZING to UNINITIALIZED (HANDLER_INITIALIZING_ERROR): Illegal character in path at index 0:  /dev/ttyUSB0
2022-03-01 06:04:51.113 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'serial:serialBridge:5cc0a1e37f' changed from UNINITIALIZED (HANDLER_INITIALIZING_ERROR): Illegal character in path at index 0:  /dev/ttyUSB0 to INITIALIZING
2022-03-01 06:04:51.765 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'serial:serialBridge:5cc0a1e37f' changed from INITIALIZING to ONLINE
2022-03-01 06:10:49.756 [INFO ] [openhab.event.ItemUpdatedEvent      ] - Item 'SerialBridge_StringData' has been updated.
2022-03-01 06:18:37.159 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Test' received command ON
2022-03-01 06:18:37.165 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Test' changed from NULL to ON
2022-03-01 17:40:13.760 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Test' changed from NULL to ON
2022-03-01 17:40:13.761 [INFO ] [openhab.event.ItemUpdatedEvent      ] - Item 'Test' has been updated.
2022-03-01 17:46:34.719 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Test' received command OFF
2022-03-01 17:46:34.722 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Test' predicted to become OFF
2022-03-01 17:46:34.726 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Test' changed from ON to OFF
2022-03-01 17:54:36.696 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Test' received command 2,OpenHab,1,1,1
2022-03-01 17:54:36.703 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Test' predicted to become 2,OpenHab,1,1,1
2022-03-01 17:54:36.712 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Test' changed from NULL to 2,OpenHab,1,1,1
2022-03-01 17:56:16.086 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Test' received command 2,OpenHab,1,1,1
2022-03-01 17:56:16.090 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Test' predicted to become 2,OpenHab,1,1,1
2022-03-01 18:00:41.704 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Test' received command 2,OpenHab,1,1,1
2022-03-01 18:00:41.714 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Test' predicted to become 2,OpenHab,1,1,1
2022-03-01 21:39:18.957 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Test' received command 2,OpenHab,1,1,1
2022-03-01 21:39:18.964 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Test' predicted to become 2,OpenHab,1,1,1
2022-03-01 21:39:25.662 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Test' received command 2,OpenHab,1,1,1
2022-03-01 21:39:25.665 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Test' predicted to become 2,OpenHab,1,1,1

Any insight on this?

Seems pretty clear.
/dev/TTYUSB0 is not available to openHAB; probably a permissions issue.

Have you tried terminating with a newline? When trying that enable DEBUG logging for the binding to check it’s actually sending a newline.

It’s not sending anything. It cannot get to the serial port.

1 Like

I have got some more logs after making sure the port can be found. It looks like it is sending commands appropriately by looking at this line

18:29:11.635 [DEBUG] [.internal.handler.SerialBridgeHandler] - Writing '2,OpenHab,1,1,1' to serial port /dev/ttyUSB0

But I see other lines that I don’t understand.

18:29:11.578 [DEBUG] [org.eclipse.jetty.server.HttpInput   ] - HttpInputOverHTTP@543e3165[c=0,q=0,[0]=null,s=STREAM] addContent Content@5f83b15c{HeapByteBufferR@60d8980e[p=496,l=511,c=8192,r=15]={POST /res...b61\r\n\r\n<<<2,OpenHab,1,1,1>>>mJmIjoxNj...\x00\x00\x00\x00\x00\x00\x00}}

Am I on the right track here? I think openhab is configured correctly and is sending the expected command and the issue is with my dockerhost and permissions outside of the container.

Hello all,
Thank you much for all the responses received on this topic. I was finally able to configure OH3 to send the serial command to my Vnet system successfully. I also noticed that after configuring multiple switches, as I send the command through OH3 my Vnet system responds by sending back a string corresponding to the state of all the actual light switches.
I was wondering if I could get some direction on how to have OH interpret that information and update the state of the switch on the UI/ site map. Thank you much!