I have problems with Arduino Modbus serial and OpenHab

  • Platform information:

    • OS: _Windows 10
    • Java Runtime Environment: _build 1.8.0_172-b11
    • openHAB version: OpenHab2 2.4.0 Snapshot
  • Issue of the topic:

Hello, I am a student, and I am doing a home automation project using an arduino, I am trying to make the communication between Openhad and the Arduino by Modbus but I can not find a way to make it work.

Previously I had already configured the same arduino with the same program to a SCADA program. (ScadaBr) and everything works fine.

I am a beginner in Openhab, I have researched a lot but I still do not understand several things

I read all the documentation of Modbus Binding new and old, since this protocol was updated to Modbus 2.x I have placed the test codes, I created the things themselves (ModbusSerial bridge, Modbus Poller and Modbus Data) and nothing.

Note that in the OpenHab version 2.3.0 (install for choco) I had downloaded several modbus packages (transport modbus and modbus Binding) but they no longer appear only the modbus Binding and it does not let me create things from the Paper UI, nor does it let me create it using the. things in

C: \ openHAB2 \ conf \ things

Now using the version of Openhab 2.4.0 Snapshot if I can use the Modbus binding

If you need to know something to help me, please tell me where I look for it and I will publish it

i include my arduino test code

#include <Modbus.h>
#include <ModbusSerial.h>

//Modbus Registers Offsets (0-9999)
const int SWITCH_ISTS = 5; 
//Used Pins
const int switchPin = 3;

//ModbusSerial object
ModbusSerial mb;

void setup() {
    // Config Modbus Serial (port, speed, byte format) 
    mb.config(&Serial, 38400, SERIAL_8N1);
    // Set the Slave ID (1-247)
    mb.setSlaveId(10);  

    //Set ledPin mode
    pinMode(switchPin, INPUT);
    // Add SWITCH_ISTS register - Use addIsts() for digital inputs 
    mb.addIsts(SWITCH_ISTS);
}

void loop() {
   //Call once inside loop() - all magic here
   mb.task();
   
   //Attach switchPin to SWITCH_ISTS register     
   mb.Ists(SWITCH_ISTS, digitalRead(switchPin));
}

I’m using the arduino library modbus Serial RTU
https://github.com/andresarmento/modbus-arduino

i used the liFor the moment I want to test my arduino code, which works as follows:

Void Setup

mb.config(&Serial, 38400, SERIAL_8N1);

I declare that I will use Serial port, Speed 38400 baund and serial 8 bit data and 1 stop bit

mb.setSlaveId(10);

I declare that the Arduino is Slave ID 10

pinMode(switchPin, INPUT);

I set up Pin 3 mode as Input (I have a switch connected to it)

mb.addIsts(SWITCH_ISTS);

Finally I add my register as Digital Input with ID 5

Void Loop

mb.task();

Here I have a task that evaluates the changes between the modbus registers previously declared.

mb.Ists(SWITCH_ISTS, digitalRead(switchPin));

Finally I read the input data of pin 3 (Switch) and write it in the input data register modbus

I am using the OpenHab2 2.4.0 Snapshot since the other one did not work for me the modbus bindings and for its configuration I am using as reference the examples given by the documentation of Modbus bindings OpenHab
https://www.openhab.org/addons/bindings/modbus/#item-configuration

.things

Bridge modbus:serial:localhost [ port=COM10, id=10 , baud= 38400 ,  stopBits = "1" , parity = "none" , dataBits = 8 , encoding = "RTU"  ] {

    Bridge poller inputRegisters [ start=5, length=2, refresh=1000, type="input" ] {

        Thing data Data [ readStart="5", readValueType="float32" ] 
  }  

.Items

Number Input        "Input registers as float32 [%.1f]"    { channel="modbus:serial:localhost:inputRegisters:Data:number" }

I would like to know why it does not work for me
Thanks for reading and sorry for my bad English

MDieppa

Hi,

at least I can say that you are missing quotes with some parameters, please refer to https://www.openhab.org/addons/bindings/modbus/#thing-configuration section and re-check all the parameters in things file.

Also, please be careful with small and large letters, for example, encoding "rtu" instead of "RTU".

If thing file syntax is completely invalid, you should be able to find the offending line from the logs. Once you get the syntax right, you can refer to thing status in PaperUI to find possible configuration errors. I suggest you start from the logs, and learn to find the errors from there.

Best,
Sami

Thanks for answering!

If I already fix the syntax errors that I had in the .things file but likewise I have the same error, I previously configed it with the PaperUI but since many posts were configured by the .things file I started doing it that way

Here I put the poller status error and the openhab logs when it starts.

Status things Serial

the status of “Endpoint for Modbus serial slaves” If you are online

Status things Data

 Error (ModbusSlaveIOExceptionImpl) with read. Request: ModbusPollerThingHandlerImpl.ModbusPollerReadRequest@49b0608a[slaveId=10,functionCode=READ_INPUT_REGISTERS,start=5,length=2,maxTries=3]. Description: ModbusSlaveIOException(cause=ModbusIOException, EOF=false, message='I/O exception: IOException Error reading response (EOF)', cause2=null). Message: Modbus IO Error with cause=ModbusIOException, EOF=false, message='I/O exception: IOException Error reading response (EOF)', cause2=null

Status things Poller

org.openhab.io.transport.modbus.internal.ModbusSlaveIOExceptionImpl: Modbus IO Error with cause=ModbusIOException, EOF=false, message='I/O exception: IOException Error reading response (EOF)', cause2=null

Logs Openhab Start

2018-09-20 10:49:05.260 [ERROR] [pi.modbus.io.ModbusSerialTransaction] - execute try 1/1 error: I/O exception: IOException Error reading response (EOF). Request: net.wimpi.modbus.msg.ReadInputRegistersRequest@5a1f714b (unit id 10 & transaction 1). Serial parameters: SerialParameters@12243cc4[portName=COM10,baudRate=38400,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=none,encoding=rtu,echo=false,receiveTimeoutMillis=1500]
2018-09-20 10:49:05.261 [ERROR] [pi.modbus.io.ModbusSerialTransaction] - execute reached max tries 1, throwing last error: I/O exception: IOException Error reading response (EOF). Request: net.wimpi.modbus.msg.ReadInputRegistersRequest@5a1f714b (unit id 10 & transaction 1). Serial parameters: SerialParameters@12243cc4[portName=COM10,baudRate=38400,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=none,encoding=rtu,echo=false,receiveTimeoutMillis=1500]
2018-09-20 10:49:05.261 [WARN ] [rt.modbus.internal.ModbusManagerImpl] - Try 1 out of 3 failed when executing request (ModbusPollerThingHandlerImpl.ModbusPollerReadRequest@49b0608a[slaveId=10,functionCode=READ_INPUT_REGISTERS,start=5,length=2,maxTries=3]). Will try again soon. Error was I/O error, so reseting the connection. Error details: net.wimpi.modbus.ModbusIOException I/O exception: IOException Error reading response (EOF) [operation ID dd456062-cf4d-4cdb-bd47-54364813255a]
2018-09-20 10:49:06.809 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - Last request: 0a 04 00 05 00 02 60 b1
2018-09-20 10:49:06.809 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - failed to read: Error reading response (EOF)
2018-09-20 10:49:06.811 [ERROR] [pi.modbus.io.ModbusSerialTransaction] - execute try 1/1 error: I/O exception: IOException Error reading response (EOF). Request: net.wimpi.modbus.msg.ReadInputRegistersRequest@71222709 (unit id 10 & transaction 2). Serial parameters: SerialParameters@12243cc4[portName=COM10,baudRate=38400,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=none,encoding=rtu,echo=false,receiveTimeoutMillis=1500]
2018-09-20 10:49:06.812 [ERROR] [pi.modbus.io.ModbusSerialTransaction] - execute reached max tries 1, throwing last error: I/O exception: IOException Error reading response (EOF). Request: net.wimpi.modbus.msg.ReadInputRegistersRequest@71222709 (unit id 10 & transaction 2). Serial parameters: SerialParameters@12243cc4[portName=COM10,baudRate=38400,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=none,encoding=rtu,echo=false,receiveTimeoutMillis=1500]
2018-09-20 10:49:06.812 [WARN ] [rt.modbus.internal.ModbusManagerImpl] - Try 2 out of 3 failed when executing request (ModbusPollerThingHandlerImpl.ModbusPollerReadRequest@49b0608a[slaveId=10,functionCode=READ_INPUT_REGISTERS,start=5,length=2,maxTries=3]). Will try again soon. Error was I/O error, so reseting the connection. Error details: net.wimpi.modbus.ModbusIOException I/O exception: IOException Error reading response (EOF) [operation ID dd456062-cf4d-4cdb-bd47-54364813255a]
2018-09-20 10:49:08.357 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - Last request: 0a 04 00 05 00 02 60 b1
2018-09-20 10:49:08.357 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - failed to read: Error reading response (EOF)
2018-09-20 10:49:08.359 [ERROR] [pi.modbus.io.ModbusSerialTransaction] - execute try 1/1 error: I/O exception: IOException Error reading response (EOF). Request: net.wimpi.modbus.msg.ReadInputRegistersRequest@2029c023 (unit id 10 & transaction 3). Serial parameters: SerialParameters@12243cc4[portName=COM10,baudRate=38400,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=none,encoding=rtu,echo=false,receiveTimeoutMillis=1500]
2018-09-20 10:49:08.360 [ERROR] [pi.modbus.io.ModbusSerialTransaction] - execute reached max tries 1, throwing last error: I/O exception: IOException Error reading response (EOF). Request: net.wimpi.modbus.msg.ReadInputRegistersRequest@2029c023 (unit id 10 & transaction 3). Serial parameters: SerialParameters@12243cc4[portName=COM10,baudRate=38400,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=none,encoding=rtu,echo=false,receiveTimeoutMillis=1500]
2018-09-20 10:49:08.360 [ERROR] [rt.modbus.internal.ModbusManagerImpl] - Last try 3 failed when executing request (ModbusPollerThingHandlerImpl.ModbusPollerReadRequest@49b0608a[slaveId=10,functionCode=READ_INPUT_REGISTERS,start=5,length=2,maxTries=3]). Aborting. Error was I/O error, so reseting the connection. Error details: net.wimpi.modbus.ModbusIOException I/O exception: IOException Error reading response (EOF) [operation ID dd456062-cf4d-4cdb-bd47-54364813255a]
2018-09-20 10:49:08.367 [ERROR] [odbus.handler.ModbusDataThingHandler] - Thing modbus:data:localhost:inputRegisters:Data 'Modbus data' had ModbusSlaveIOExceptionImpl error on read: ModbusSlaveIOException(cause=ModbusIOException, EOF=false, message='I/O exception: IOException Error reading response (EOF)', cause2=null)
2018-09-20 10:49:10.885 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - Last request: 0a 04 00 05 00 02 60 b1
2018-09-20 10:49:10.885 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - failed to read: Error reading response (EOF)
2018-09-20 10:49:10.888 [ERROR] [pi.modbus.io.ModbusSerialTransaction] - execute try 1/1 error: I/O exception: IOException Error reading response (EOF). Request: net.wimpi.modbus.msg.ReadInputRegistersRequest@65929bfa (unit id 10 & transaction 4). Serial parameters: SerialParameters@12243cc4[portName=COM10,baudRate=38400,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=none,encoding=rtu,echo=false,receiveTimeoutMillis=1500]
2018-09-20 10:49:10.888 [ERROR] [pi.modbus.io.ModbusSerialTransaction] - execute reached max tries 1, throwing last error: I/O exception: IOException Error reading response (EOF). Request: net.wimpi.modbus.msg.ReadInputRegistersRequest@65929bfa (unit id 10 & transaction 4). Serial parameters: SerialParameters@12243cc4[portName=COM10,baudRate=38400,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=none,encoding=rtu,echo=false,receiveTimeoutMillis=1500]
2018-09-20 10:49:10.889 [WARN ] [rt.modbus.internal.ModbusManagerImpl] - Try 1 out of 3 failed when executing request (ModbusPollerThingHandlerImpl.ModbusPollerReadRequest@49b0608a[slaveId=10,functionCode=READ_INPUT_REGISTERS,start=5,length=2,maxTries=3]). Will try again soon. Error was I/O error, so reseting the connection. Error details: net.wimpi.modbus.ModbusIOException I/O exception: IOException Error reading response (EOF) [operation ID 7666e58a-f667-4f91-8fd5-4a5ba34f8ef9]
2018-09-20 10:49:12.438 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - Last request: 0a 04 00 05 00 02 60 b1
2018-09-20 10:49:12.438 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - failed to read: Error reading response (EOF)
2018-09-20 10:49:12.440 [ERROR] [pi.modbus.io.ModbusSerialTransaction] - execute try 1/1 error: I/O exception: IOException Error reading response (EOF). Request: net.wimpi.modbus.msg.ReadInputRegistersRequest@68040195 (unit id 10 & transaction 5). Serial parameters: SerialParameters@12243cc4[portName=COM10,baudRate=38400,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=none,encoding=rtu,echo=false,receiveTimeoutMillis=1500]
2018-09-20 10:49:12.441 [ERROR] [pi.modbus.io.ModbusSerialTransaction] - execute reached max tries 1, throwing last error: I/O exception: IOException Error reading response (EOF). Request: net.wimpi.modbus.msg.ReadInputRegistersRequest@68040195 (unit id 10 & transaction 5). Serial parameters: SerialParameters@12243cc4[portName=COM10,baudRate=38400,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=none,encoding=rtu,echo=false,receiveTimeoutMillis=1500]
2018-09-20 10:49:12.441 [WARN ] [rt.modbus.internal.ModbusManagerImpl] - Try 2 out of 3 failed when executing request (ModbusPollerThingHandlerImpl.ModbusPollerReadRequest@49b0608a[slaveId=10,functionCode=READ_INPUT_REGISTERS,start=5,length=2,maxTries=3]). Will try again soon. Error was I/O error, so reseting the connection. Error details: net.wimpi.modbus.ModbusIOException I/O exception: IOException Error reading response (EOF) [operation ID 7666e58a-f667-4f91-8fd5-4a5ba34f8ef9]

Thanks very useful! As you probably noticed you are getting communication issues when reading the response from the slave.

Please double check all serial parameters such as baud rate. Have you had success with some other modbus program with your pc?

If I have all the data in order, baud 38400, Com10, slave ID 10, as it is in the .things file of the post above.

Test this same code with ScadaBr and it works fine.

Also parity etc correct? Just double-checking…

Does fail every single time or does it manage read successfully ocassionally?

Also, could you take a picture of ScadaBr settings?

When I start the program it seems that if I read it but it does not, after 3 min online, the error is given by the things.

I will place all the Openhab and ScadaBr settings.

I deleted the configuration of the .things files and I did it through the interface of PaperUI

ScadaBr configuration

OpenHab configuration

Bridge Modbus Serial

Bridge Modbus Poller

!

Things Modbus Data 1

Things Modbus Data 2

But the system happens something strange, because it receives something and shows that only that error, The Log Openhab that I shared before, shows the error repetitively and remains in a cycle on the other hand, the arduino turns on the Rx LEDs but does nothing else , rather the Arduino totally ignores the program that is programmed.

Hello, I still have this problem, I still can not find a solution, I still have the same problem, I changed the code of arduino with another modbusRTUSerial liberia and I use a software other than scadaBr to guarantee that if the code works.

Software Test Modbus Serial

Help :’(