Send command to serial port and receive a answer

EDIT :
changed a charset :

and communication is working. Received back data. Running via serial bridge.

Now it’s question how to make a processing hex to get a relevant data. Like when I will send a request for all temperatures, then calculate from answer temperatures and link to correct rooms.

3 Likes

:partying_face:

Huge win. I know its a first step but now you know it will all work.

Now first do the power switch. Get it to turn on and off with openHAB.

Then you will need openHAB to update when the power is turned off by any other means.

First win, but I need to know how to take a HEX answer from serial port and calculate a values.
Can I do it directly from the rule script (after send command) or …?

Yeah when the string item receives a command you can use that command to start a rule that will transform the data however you want it and put that data into items.

do you know how to transform received string to hex?
now received string isn’t nice :

image

let me check. thanks
also not clear for me, how to link decoded temperature with exact room.
I think I must create a item and add semantic class for this item ? But how to write a value to this item after decoding ?

It is probably sensible to keep your complete input string in one Item and process the useful parts of it into other Items, yes.

You don’t need semantics for this (or any other) Item. Worry about that later.

There are a number of ways to do this.

One way is to use a transformation, probably a javascript for complex work, and process the raw incoming binary string at the serial binding channel or using a profile, before it gets to an Item. Extracting just the data you want. These can be hard to debug.

Another way is to use a rule to process one Item containing the whole input binary string, extract the part you want, and post an update to another Item(s). openHAB provides a number of different rule languages that you can use. You’re likely to find this easier to understand and debug.

None of this is easy, you are doing a quite technical job here.

3 Likes

ok. clear. I’m thinking about rule, but serial binding will show different informations depends on sent command. So also rule and decoding of recevied data from serial binding must be flexible depends on command which was sent. I have one command for all actual temperatures, one for set temperatures etc…

You have data incoming on a string item and now it is not tied to Serial Binding. You can lookup generic info on openHAB forums.

You can use many different ways to achieve what you want.

If I were to do it I would probably go with a combination of Regex to filter out result as per address and javascript transformation to convert

What you are doing now is not easy and will take some time to get it all working. When you are done write up what you have done and post it on forum for others to find.

1 Like

for me it’s for long long time. I must go step by step and test each instruction
first of all must somehow transform a serial binding string to hex or binary as a part of rule

Old posts but give the general method. You need to break down your binary string into bytes.

and the linked

In general, rules can be as flexible as you write them.

But a serial input string is a serial input string. If it might be one several different types of data, you will somehow need the rule to figure out which type it has to work with. Either by looking at the string, if it contains some type marker. Or by “remembering” what the last query command was, so you know what type to expect.

Start simple, make a rule to log your binary bytes. You’re going to need to choose which of several ways to write rules that you want to use. And how to use and read your openhab logs, because you are going to have to debug this a lot.

idea is following - button or switch which will send command to the serial bridge also write string information to special string item. Rule will start when serial bridge string will change (data received) and in the rule we will look which information is in the special string item and depends on it will run correct data processing.
But first of all yes, I must transfer received data to expected HEX or somethink similar.

The command needs to pass through an Item. Why not use that same Item to “remember” the last command?

Unlike transformations, rules can look at the state of several different Items

If you had any control over the target device, it would be much smarter if it said itself what kind of data it was sending - even just included the command it is responding to.

I don’t have a control over target device, but I know which data is sending :

B0 B1 B2 B3 B4 B5 B6 B6+n B7+n B8+n B9+n B10+n
0FFH 0FFH DLE ETB BUSH BUSL D0 Dn S0 S1 ADDS XORS

0FFH, 0FFH - start bytes
DLE = 10H, ETB = 17H
BUSH ,BUSL main unit address, in my case: BUSH = FFH ,BUSL = FFH
D0 … Dn - data
S0, S1 - answer status. when both 0x00 = all ok, when both 0x04 = unknown address or command, not executed
ADDS = control sum (ADD B2 … B8+2n)
XORS = control sum (XOR B2 … B8+2n)

I can look on the B4 and B5 - it’s memory adress where from are data send. On the each address are still the same data.

I checked a tutorial and found that there is a support for rule programing in Visual Studio?
If yes, how it’s working ? I have good experience with VS

VS Code (not VS) is just a convenience tool to edit files.
It can be used with text based xxx.rules files, which can be in a variety of languages.

You can’t/don’t use VSC with rules (in a variety of rules languages) entered in openHABs GUI.

You’re going to have to choose both a rules management systsm (files or GUI) and a rules language.
I would advise against “beginners” GUI-only Blockly for now, because it can’t really deal with your technical hex/binary requirement and you’d end up working in javascript anyway.

If it were me I’d be doing rules in files using DSL language - but that’s only because I’ve done it that way since before there were choices. It’s now considered old-fashioned, and many users use Jython or javascript via GUI.

ok, javascript isn’t in the option :

Ok, I don’t have all this options. How to enable? Install some components?