Modbus openHAB2 binding available for alpha testing

You can try unsigned 32 bit integer, uint32. That spans over two 16 bit registers.

Best
Sami

Since the value type is int32, you are actually getting registers 202 and 203 combined to single signed integer. Is this what you want?

Good point regarding two serial devices, have to test it my self. Does not sound correct.

Interesting idea. Will let you know tomorrow after testing it out.
As long it shows the amount of air flow (m3/h) an integer is from 0 to 300 “my case”. Nevertheless will check.

Regards

@narf27 checked the issue with two serial devices. I can reproduce it with other bindings as well, e.g. zwave. Must be an openHAB core / ESH issue. I wonder if it is reported already


Best,
Sami

=)

in the end my config was correct and i was able to read the right values - i just figured out that i the comma was one place farther to the left
 that’s how you waste your time! :grinning:

now it gets interesting. trying to write to register 5016
with the old binding we (meaing: rossko57 and you) tried different things, Modbus RTU Drexel & Weiss <> openHAB

how should i configure this with the new binding? probably the “Write value type” is pretty important, but what’s the right setting here?

cheers,
Peter

1 Like

I guess you want to write 32 bit signed integers (int32)? In the new binding you can just use it, it works as expected.

Best
Sami

1 Like

wow, that was easy! i tried “32bit integer, as two’s complement (int32)” and it worked!
thank you so much for this great binding!

1 Like

Hi @ssalonen,
thanks for the hint, uint32 - reading data from 2 registers works like a charm!

Very good work on the binding, thanks!
Regards

1 Like

Dear @ssalonen,

I appreciate your work on implementing the OH2 binding.

Only for my understanding: Is it possible that there are contradictory statements regarding relative and absolute addressing of modbus registers at https://github.com/ssalonen/openhab2-addons/blob/modbus-openhab2-native-binding/addons/binding/org.openhab.binding.modbus/README.md? The “full example” suggests relative addresses as where there is a paragraph about “Absolute addresses instead of relative”.

The only way I can get to input register values at all is using the absolute addressing method. Corresponding to the documentation of my solar inverter SMA STP 5000TL-20 the register 30535 (unsigned int 32) should return todays yield in Wh (watts per hour).
The crazy thing is, that it returns almost the correct value of 3072. The correct value would be 3215 regarding the Sunny Explorer Client Application. When I use Modbus Poll I get the correct value:
30535 = 000000
30536 = 003215

Log:
2018-01-07 21:59:49.933 [DEBUG] [nding.modbus.internal.Transformation] - Could not transform item state ‘3072’ (of type DecimalType) to a State (tried the following types: [class org.eclipse.smarthome.core.library.types.PercentType, class org.eclipse.smarthome.core.library.types.UpDownType, class org.eclipse.smarthome.core.types.UnDefType])! Input state as string ‘3072’, transformed string ‘3072’, transformation 'default’
2018-01-07 21:59:49.933 [DEBUG] [odbus.handler.ModbusDataThingHandler] - Thing modbus:data:sma:inputRegisters:daily_yield_kWh ‘Modbus data’, channel modbus:data:sma:inputRegisters:daily_yield_kWh:rollershutter will not be updated since transformation was unsuccesful
_2018-01-07 21:59:51.130 [DEBUG] [nding.modbus.internal.Transformation] - transformed response is ‘3072’

Configuration:

Bridge modbus:tcp:sma [ host="<deleted>", port=502, id=3 ] {
  Bridge poller inputRegisters [ start=30535, length=2, refresh=1000, type="input"
        Thing data daily_yield_kWh [ readStart="30535", readValueType="uint32" ]
    }
}

I would be glad if you could give me some advice if I am doing wrong.

Thank you in advance.

Kind regards

1 Like

okay, next one!
i need 2 items.

is it possible to have 2 data things from 1 poll?

this is working:
poll:

Start = 200
Length = 2

data:

Address = 200

this is NOT working:

Start = 200
Length = 4

data1:

Address = 200

data2:

Address = 202

shouldn’t i be able to read both registers (each with length 2) from with one poll?

this is probably a dumb question but i’m not getting anywhere with my trial&error methods :frowning:

1 Like

Yes, definitely two data items can refer to polled data. In fact, this is the purpose of these things.

From your example it unclear what value type you have, but not sure if it matters. I am not sure I understand what you are exactly trying to do.

Please note that slave can decide to answer with error, this would be visible in logs with ERROR level.

Best
Sami

The documentation uses the word relative address to mean addressing used in 1.x binding where the address was relative to polled data (0=first polled item, etc).

Absolute addressing is explained in this section: https://github.com/ssalonen/openhab2-addons/blob/modbus-openhab2-native-binding/addons/binding/org.openhab.binding.modbus/README.md

The paragraph has a case similar to yours. I believe you are polling input registers?

Please let me know if you still find it contradictory, and how to improve the docs. I am sure there is room for improvement :slight_smile:

i’d like to read two input registers, int32
i tried to set it up like this (via paper UI, this are not my exact settings, as i don’t know where to find this code 
)
as i said before, with length=2 for poller and only data with start=200 it works fine!

    Bridge poller inputRegisters [ start=200, length=4, refresh=1000, type="input" ] {
        Thing data input1 [ readStart="200", readValueType="int32" ]
        Thing data input2 [ readStart="202", readValueType="int32" ]

this looks just like the example given (although with float32)

but as soon as “length” of the poller thing is changed to 4 i get this:

2018-01-08 23:24:18.139 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - Last request: 01 04 00 c8 00 04 70 37
2018-01-08 23:24:18.141 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - failed to read: CRC Error in received frame: 0 bytes: 
2018-01-08 23:24:18.144 [ERROR] [pi.modbus.io.ModbusSerialTransaction] - execute try 1/1 error: I/O exception: IOException CRC Error in received frame: 0 bytes: . Request: net.wimpi.modbus.msg.ReadInputRegistersRequest@1b56074 (unit id 1 & transaction 21863). Serial parameters: SerialParameters@891b67[portName=/dev/ttyAMA0,baudRate=9600,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=none,encoding=rtu,echo=false,receiveTimeoutMillis=1500]
2018-01-08 23:24:18.147 [ERROR] [pi.modbus.io.ModbusSerialTransaction] - execute reached max tries 1, throwing last error: I/O exception: IOException CRC Error in received frame: 0 bytes: . Request: net.wimpi.modbus.msg.ReadInputRegistersRequest@1b56074 (unit id 1 & transaction 21863). Serial parameters: SerialParameters@891b67[portName=/dev/ttyAMA0,baudRate=9600,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=none,encoding=rtu,echo=false,receiveTimeoutMillis=1500]
2018-01-08 23:24:18.151 [ERROR] [rt.modbus.internal.ModbusManagerImpl] - Last try 3 failed when executing request (ModbusPollerThingHandlerImpl.ModbusPollerReadRequest@126243e[slaveId=1,functionCode=READ_INPUT_REGISTERS,start=200,length=4,maxTries=3]). Aborting. Error was I/O error, so reseting the connection. Error details: net.wimpi.modbus.ModbusIOException I/O exception: IOException CRC Error in received frame: 0 bytes:  [operation ID e8fa2492-384a-4b4e-b49b-249f91ced319]
2018-01-08 23:24:18.180 [ERROR] [odbus.handler.ModbusDataThingHandler] - Thing modbus:data:cc1262f7 'DW Data Read' had error on read: ModbusSlaveIOExceptionImpl null

Hi @ssalonen,

thank you for your quick reply.
I want to clarify, that I didn’t mean to critizise your documentation :slight_smile: Maybe I just don’t understand modbus addressing well enought.

I think I want to poll input registers, but to be honest I assume this regarding the register number from the SMA Docu “30535”. It is also read only which would also perfectly fit to input register.

Thank you for your support!

No offence taken, sorry if I sounded rude! :slight_smile:

In the traditional standard, [entity] numbers for those entities start with a digit, followed by a number of four digits in range 1–9,999:


input register numbers start with a three and then span from 30001 to 39999

This translates into [entity] addresses between 0 and 9,998 in data frames.

The openHAB modbus binding uses data frame entity addresses when referring to modbus entities. That is, the entity address configured in modbus binding is passed to modbus protocol frame as-is. For example, Modbus poller thing with start=3, length=2 and type=holding will read modbus entities with the following numbers 40004 and 40005.

So 30535 address in documentation probably refers to entity number. This would correspond to entity address 534 with type="input".

This is my best guess at least


Best,
Sami

The log indicates that the poll itself actually fails so the problem is certainly not in the way you have defined data things.

In fact, I bet you would see the error even without the data things.

When using PaperUI, you can take screenshots of the settings pages and paste them here. Are you using default settings with the serial thing? Are all reads failing or is it failing just occasionally?

atm length is set to “2”, so i don’t get errors, as soon as i set it to “4” the log is full of errors. so to me it seems that all the reads fail. (i can leave it to “4” if that could help?).

I’m using default settings, yes. Can post screenshot later?

Thanks @narf27. Sounds bad.

Can you shutdown openhab and try to replicate with 3rd party tool, e.g. modpoll or pollmb.py

Try to replicate the read requests with these tools. Note the 1-based indexing with modpoll.

This would help to analyse whether 3rd party tools have the same issue or if the issue is in openhab.

Best
Sami

i could shutdown openhab, but i don’t even know how to install either of the tools :frowning:
here it says

and here i can’t find anything on how to connect to a serial port

i’d be happy to test but i’m afraid without a helping hand i won’t be ablte to!

Hi @narf27,

don’t forget that you have to “add 1” when providing a length number:
registers index and (index + 1).

At least for me, that was the case not getting full register readings.