Read specific protocol on serial port

I have a control-box, that sends commands over serial port. The protocol is a bit outside of any standards, using baudrate of 1000 for example. The
It consists of 3 x 8 databits, where first byte is constant, second byte is a command, then third byte contains some value.
I wrote a C-program to decode this protocol on my Raspberry Pi running openHABian. Now the next step would be to get the values into openHAB. Those Values are usually sent to a display to show them, but should also be visible in openHAB

example of a full command might be
0x01 0x81 0xff which is a special case, because here the next triplet would be
0x01 0x00 0xab for example which has a 16bit int value in byte 2 and 3

My thoughts were

  • using a serial binding, but i didn’t find one that could handle all that
  • writing the processed data to one or more files and read them with binding

Does anybody have any tips on how i could implement that?

I do have a similar problem. My controller for my heating system also runs a pretty unusual protocol. What I did:

  1. write a script for reading and Decoding
  2. let the script update the items
    2.1 at first I did it with the REST API
    curl --header "Content-Type: text/plain" --request PUT --data '<VALUE>' http://<OH2SERVER>:8080/rest/items/<ITEM>/state
    2.2 after experimenting a bit with MQTT, I now update the item values via MQTT
    mosquitto_pub -h <BROKER> -t '/openHAB/IN/<ITEM>/state' -m '<VALUE>'

I think, the MQTT-way is a bit faster.

PS: you have to configure MQTT (should be pretty obvious) on OH2 and the MQTT-EVENTBUS: stateSubscribeTopic=/openHAB/IN/${item}/state => that way, OH2 updates every item, which gets updated in the Broker via the selected pattern.

there is a third option indeed. I did not test it: you could invoke the script from OH2 (from a rule in a cronjob) and parse the output, which you provide from the script. As I have about 30 sensors, which my script reads, I figured best to have the script doing all the logic.

I will try it with MQTT then, thank you for now

I got it working after a whole day of bugfixing ^^
I did implement the mosquitto library directly in my decoding program, now it will publish a message on every change of my values, for now i have picked only the most important messages.

I struggled a lot getting the mqtt to work first, but i found some post about mqtt_action should be left uninstalled.
Then my config didn’t work, but after a minimal edit it did, such things.