Modbus openHAB2 binding available for alpha testing

I suppose one approach might be to have access to some kind of “poll complete” flag, which is only set after the binding has updated OH Items with register values read from Modbus. And presumably unset before commencing a read poll. A property of each Bridge poller?

Seems clonky though. With correct configuration, all registers will get read in a single Modbus transfer. The only asynchronous part is where the binding updates related OH Items one by one. I reckon a simple delay of a couple of milliseconds would allow that to complete (after triggering a rule from any Item update).

Alternatively, figure out which will be the last Item to get updated in each poll, and trigger the rule that demands synchronizing off of that Item?
I think if the binding’s update behaviour is predictable, we already have the tools to ensure a block of data is synchronized.

(@jotpehenn:slight_smile: I would appreaciate this feature, let me know if there is news, I can serve as guinea pig if you need one.

(@rossko57:slight_smile: Alternatively, figure out which will be the last Item to get updated in each poll, and trigger the rule that demands synchronizing off of that Item?
I think if the binding’s update behaviour is predictable, we already have the tools to ensure a block of data is synchronized.

I checked the code – the current order is “arbitrary”/unspecified but probably the same every poll. Not sure if the order would be different over time (when openHAB is rebooted). In other words, it’s all error-prone implementation details…

Following from @rossko57 clunky idea, I guess it would be easier if the poller would have the the lastReadSuccess and lastReadError as channels. You could then use these to process the data. However, you would have to assume that data would not be changed in the meanwhile while you are iterating over the individual pieces of data.

Will think about this…

For now I’m not proceeding with implementation, would like to get the pull request through, and then introduce incremental improvements and new features. So don’t hold your breath…

(@jotpehenn:slight_smile: … then use universalwrite.js to “dynamically” generate the JSON to basically write anything anywhere in any quantity, i.e the data thing is not bound to a specific address, data type or how many registers are written in one go.

This is possible using “Advanced write using JSON”, quoting README:

There are some more advanced use cases which need more control how the command is converted to set of bits or requests. Due to this reason, one can return a special JSON output from the transformation (step 3). The JSON directly specifies the write requests to send to Modbus slave.

You should even specify the writeMultipleEvenWithSingleRegisterOrCoil since the transform output specifies the exact function code that will be used.

Please also find the Rollershutter config example as practical tutorial how to use the feature.

Ah, knocks that plan down. I presume this (binding updating multiple Items) is a fairly rapid process though, happening before/while update events are put on the bus? A short delay at the beginning of a rule triggered from an Item update should surely allow ‘associated’ Items to all settle down.

There may be other benefits in having those poller properties available, dunno what they might be yet. A user needing synchronised data is going to have to manage polling carefully, to ensure processing completes in between polls.

Hi, I have avr device with modbus implementing by MBS38. It works fine. it works with mbpoll and openHAB ver2.3.0 market bindings - PAPER UI.
but I try to use .items . things .sitemap files. with using this files my data are unavalaible - in BASIC UI. Can anybody look at this files? is there any mistake?
thanx Martin

file .things
//poller thing -lenght, type are required
Bridge modbus:serial:endpointMOXA[port=“COM7”,baud=9600,id=11,dataBits=8,
parity=“none”,stopBits=“1”,encoding=“rtu”] {
Bridge poller holdingsREG[ start=0, length=6, refresh=2000, type=“holding”] {
Thing data temp1 [ readStart=“0”, readValueType=“int16” ]
Thing data temp2 [ readStart=“1”, readValueType=“int16” ]
Thing data temp3 [ readStart=“2”, readValueType=“int16” ]
Thing data temp4 [ readStart=“3”, readValueType=“int16” ]
Thing data temp5 [ readStart=“4”, readValueType=“int16” ]
Thing data temp6 [ readStart=“5”, readValueType=“int16” ]
}

}

file .items
//itemtype itemname “labeltext [stateformat]” //<iconname{channel=“modbus:data:nameOfBridge:nameOfPoller:nameOfVariable:number”
Number S1 “Temperature [%d]” {channel=“modbus:data:endpointMOXA:holdingsREG:temp1:number”}
Number S2 “Temperature [%d]” {channel=“modbus:data:endpointMOXA:holdingsREG:temp2:number”}
Number S3 “Temperature [%d]” {channel=“modbus:data:endpointMOXA:holdingsREG:temp3:number”}
Number S4 “Temperature [%d]” {channel=“modbus:data:endpointMOXA:holdingsREG:temp4:number”}
Number S5 “Temperature [%d]” {channel=“modbus:data:endpointMOXA:holdingsREG:temp5:number”}
Number S6 “Temperature [%d]” {channel=“modbus:data:endpointMOXA:holdingsREG:temp6:number”}

file .sitemap
sitemap default label=“My house” {
Frame label=“Temperatures” {
//Text item=datum
Text item=vychodS
Text item=zapadS
Text item=S1 label=“Sensor1[%d °C]” icon=“temperature”
Text item=S2 label=“Sensor2[%d °C]” icon=“temperature”
Text item=S3 label=“Sensor3[%d °C]” icon=“temperature”
Text item=S4 label=“Sensor4[%d °C]” icon=“temperature”
Text item=S5 label=“Sensor5[%d °C]” icon=“temperature”
Text item=S6 label=“Sensor6[%d °C]” icon=“temperature”
}

}

What do you mean by “data are unavailable”?

In case of configuration errors, the thing status should tell what is the problem. You can use Paper UI to find check that one out.

Alternatively, checkout the logs for ERROR messages.

in PAPER UI all things are online.


thanx martin

sitemap PAPER UI

in Classic UI it works too, in HABmin - there are 2 sitemaps : my house - it is from BASIC no data from modbus, in home - configured in PAPER UI - all data are relevant

I can’t see the thing status from the pictures. The things are in Paper UI, Configuration / Things.

The pictures you pasted are 1) basic UI (see the URL) 2) Paper UI

Thanx for your reply. I wrote , all things are green online. thank you for your job in this, martin. if you mention what I have to send, please tell me. May be it is any basic, elemntary thing , Which I do not know. Last items and things are corrected as your last document at github

second one screenshot of things

maybe it is all.
thanx

Very good, thank you for the screenshots!

I can see the data as well for temp1, temp2, etc. in one of the screenshots. For example, temp5 is 268.

Perhaps there is some format error with S1 etc. labels? Try to remove the labels from sitemap, that is, having the following default.sitemap:

sitemap default label="My house" {
  Frame label="Temperatures" {
    //Text item=datum
    Text item=vychodS
    Text item=zapadS
    Text item=S1 icon="temperature"
    Text item=S2 icon="temperature"
    Text item=S3 icon="temperature"
    Text item=S4 icon="temperature"
    Text item=S5 icon="temperature"
    Text item=S6 icon="temperature"
  }
}

this same result. another thing will be wrong.

at the end I tried to delete all entries in default.sitemap.the web page was untouched. It was in Firefox and IE, after deleting history.

thanx Martin

Right. I’m afraid I don’t know what is the issue…it does sound like something basic with the sitemap & items.

I recommend posting a new thread, to Items & Sitemaps section. Since you can see the data (the second picture you posted here), the problem should not be in the binding.

Best,
Sami

thanx, I will look at this thread
Martin

it is solved.
the problem was en-coding of notepad++. default was ANSI. and in my PC was UTF-8 BOM.
I have to convert encoding for .items file - now works
thanx Martin

1 Like

Hi Sami,

I can’t get the TCP slave or polling service to work with your binding. I have installed both the transport bundle and the binding. I have stopped the Modbus 1.12.0 binding.

I create a TCP slave thing, and insert my modbus gw IP:port, and this is my error message:

2018-03-31 07:27:48.322 [WARN ] [ore.thing.internal.ThingRegistryImpl] - Cannot create thing. No binding found that supports creating a thing of type 'modbus:tcp'.

This is an overview of the bundles from karaf:

openhab> bundle:list | grep -i modbus
234 | Resolved |  80 | 1.12.0.201803300110    | openHAB ModbusTCP Master Binding
257 | Active   |  80 | 2.3.0.201803230608     | openHAB MODBUS Transport Bundle
258 | Active   |  80 | 2.3.0.201803230608     | Modbus Binding

This is the status of my slave in Paper ui:

And this is my config of the slave thing:

Thanks for reporting this!

Could you please try to remove the old binding and restart the openhab?

Best
Sami

So I’ve uninstalled the old binding and restarted OH2, and here is the log:

==> /var/log/openhab2/openhab.log <==

2018-03-31 19:05:11.250 [INFO ] [core.karaf.internal.FeatureInstaller] - Uninstalled 'openhab-binding-modbus1'

==> /var/log/openhab2/events.log <==

2018-03-31 19:05:11.257 [thome.event.ExtensionEvent] - Extension 'binding-modbus1' has been uninstalled.

==> /var/log/openhab2/openhab.log <==

2018-03-31 19:05:16.342 [INFO ] [b.core.service.AbstractActiveService] - Modbus Polling Service has been shut down

2018-03-31 19:09:36.486 [INFO ] [rt.modbus.internal.ModbusManagerImpl] - Modbus manager activated

2018-03-31 19:09:36.782 [INFO ] [modbus.internal.ModbusHandlerFactory] - Setting manager: org.openhab.io.transport.modbus.internal.ModbusManagerImpl@182182f

2018-03-31 19:09:37.082 [hingStatusInfoChangedEvent] - 'modbus:tcp:7c70c957' changed from UNINITIALIZED to UNINITIALIZED (HANDLER_REGISTERING_ERROR): org.eclipse.smarthome.core.thing.internal.ThingImpl cannot be cast to org.eclipse.smarthome.core.thing.Bridge

2018-03-31 19:09:37.081 [ERROR] [ome.core.thing.internal.ThingManager] - Exception occurred while calling thing handler factory 'org.openhab.binding.modbus.internal.ModbusHandlerFactory@1d06784': org.eclipse.smarthome.core.thing.internal.ThingImpl cannot be cast to org.eclipse.smarthome.core.thing.Bridge

	at org.openhab.binding.modbus.internal.ModbusHandlerFactory.createHandler(ModbusHandlerFactory.java:66) ~[?:?]

2018-03-31 19:09:37.377 [hingStatusInfoChangedEvent] - 'modbus:poller:791bca5f' changed from UNINITIALIZED to UNINITIALIZED (BRIDGE_UNINITIALIZED)

I tried to update the thing in Paper UI:

2018-03-31 19:11:59.253 [ERROR] [st.core.internal.thing.ThingResource] - Exception during HTTP PUT request for update config at 'things/modbus:tcp:7c70c957/config'

java.lang.IllegalStateException: Thing with UID modbus:tcp:7c70c957 has no handler attached.
1 Like

Thanks!

Please remove the thing and recreate it, it seems to be messed up and you have to start “fresh”

Best
Sami

Hi Sami,

Thanks for your time and help.
After several rounds of deleteing and recreating of things, I now got my slaves up and running :slight_smile:
Seems like the old binding also caused some issues when installed and stopped. So uninstalling as suggested was a good idea.

The binding work great now, and I have to congratulate you with a great job on this binding. Thanks!

1 Like

Hi,

I’m starting a project for my smart home with openhab2. I want to avoid wireless systems and use a wired network. I choose the RS485 Modbus. I will connect some arduinos on the modbus with sensors and switches.

I’m trying now to start with a simple example just for testing purposes of swithing a LED on the arduino throught a modbus connection between the arduino and the Raspberry Pi with Openhab2.

I have this material:

  • Raspberry Pi with Openhab2 (raspbian);
  • USB-to-RS485 FT232 FTDI Adapter (to connect the Raspberry pi to Modbus); IMG
  • MAX485 RS-485-TTL Module (to connect arduino to Modbus); IMG

Connection:
[Raspberry Pi] ----- [USB-to-RS485 FTDI Adapter] =========== [MAX485 RS-485-TTL Module] ------- Arduino

I connected everything in accordance with this image:
https://techsparx.com/energy-system/modbus/img/HTB1vCDNGFXXXXbCXVXXq6xXFXXXI.jpg

Can anyone explain how to make the example of making a LED blink on the arduino side using a switch on the Openhab?

I tried some examples from the internet but without success. I also tried with several USB adapters (I have 3 different).

I think It will be very useful for others to have this example as a wired way of connect things on openhab2.