Feature #62
closedmodbus-binding should support RTU Modbus in addition to TCP Modbus
0%
Description
For a new project, we would like to have a modbus-binding supporting RTU Modbus on RS485 in addition to TCP Modbus.
Updated by Stephane Desneux [IoT.bzh] about 1 year ago
As the modbus binding is using libmodbus for low level protocol, the answer for supporting RTU mode mostly depends on libmodbus. It seems that libmodbus supports RTU mode, but a deeper analysis is needed.
Updated by Sebastien Douheret [IoT.bzh] 12 months ago
- Assignee changed from Stephane Desneux [IoT.bzh] to Louis-Baptiste Sobolewski
Updated by Sebastien Douheret [IoT.bzh] 10 months ago
- Status changed from New to In Progress
Updated by Louis-Baptiste Sobolewski 10 months ago
- Status changed from In Progress to Resolved
Updated by Emmanuel Jubera [SAFT] 8 months ago
- Target version set to batz-2.0-update
- OS Affects Version/s batz-2.0 added
We use modbus-binding to get values from the ANDIVI RHT sensor.
When issuing several read commands for temperature / humidity in a row, the binding reported a humidity reading when asked to report the temperature, as show below:
[root@localhost ~]# afb-client --human 'ws://localhost:9999/api'
modbus info
ON-REPLY 1:modbus/info: OK
{
"jtype":"afb-reply",
"request":{
"status":"success",
"code":0
},
"response":{
"groups":[
{
"uid":"ANDIVI RHT",
"info":"ANDIVI RHT sensor",
"status":{
"uri":"tty://dev/ttymxc2:57600",
"slaveid":50,
"status":true
},
"verbs":[
{
"uid":"admin",
"info":"RTU admin cmd",
"verb":"ANDIVI/admin",
"usage":{
"action":[
"info",
"connect",
"disconnect"
],
"verbose":3
}
},
{
"uid":"temperature",
"verb":"ANDIVI/temperature",
"type":"INT16 ReadOnly register",
"format":"INT16",
"usage":{
"action":[
"read",
"subscribe",
"unsubscribe"
],
"data":"json_integer"
},
"sample":[
{
"action":"read"
},
{
"action":"subscribe"
}
],
"count":1
},
{
"uid":"humidity",
"verb":"ANDIVI/humidity",
"type":"INT16 ReadOnly register",
"format":"INT16",
"usage":{
"action":[
"read",
"subscribe",
"unsubscribe"
],
"data":"json_integer"
},
"sample":[
{
"action":"read"
},
{
"action":"subscribe"
}
],
"count":1
},
{
"uid":"dewpoint",
"verb":"ANDIVI/dewpoint",
"type":"INT16 ReadOnly register",
"format":"INT16",
"usage":{
"action":[
"read",
"subscribe",
"unsubscribe"
],
"data":"json_integer"
},
"sample":[
{
"action":"read"
},
{
"action":"subscribe"
}
],
"count":1
}
]
}
],
"metadata":{
"uid":"modbus-svc",
"info":"Modbus test",
"version":"1.0"
}
}
}
modbus ANDIVI/temperature {"action":"read"}
ON-REPLY 2:modbus/ANDIVI/temperature: OK
{
"jtype":"afb-reply",
"request":{
"status":"success",
"code":0
},
"response":202
}
modbus ANDIVI/humidity {"action":"read"}
ON-REPLY 3:modbus/ANDIVI/humidity: OK
{
"jtype":"afb-reply",
"request":{
"status":"success",
"code":0
},
"response":680
}
modbus ANDIVI/humidity {"action":"read"}
ON-REPLY 4:modbus/ANDIVI/humidity: OK
{
"jtype":"afb-reply",
"request":{
"status":"success",
"code":0
},
"response":680
}
modbus ANDIVI/humidity {"action":"read"}
ON-REPLY 5:modbus/ANDIVI/humidity: ERROR
{
"jtype":"afb-reply",
"request":{
"status":"internal-error",
"info":"read-error, ModbusSensorRequest: fail to read rtu=ANDIVI RHT sensor=humidity error=Connection timed out",
"code":-1
}
}
modbus ANDIVI/humidity {"action":"read"}
ON-REPLY 6:modbus/ANDIVI/humidity: OK
{
"jtype":"afb-reply",
"request":{
"status":"success",
"code":0
},
"response":681
}
modbus ANDIVI/temperature {"action":"read"}
ON-REPLY 7:modbus/ANDIVI/temperature: OK
{
"jtype":"afb-reply",
"request":{
"status":"success",
"code":0
},
"response":681
}
NB: Values are in tenth of Celsius degrees for temperature and tenth of percent for humidity.
The binding reported these logs during the test:
NOTICE: Loading config file etc/modbus-config.json
------BEGIN OF CONFIG-----
-- {
-- "name": "afb-modbus",
-- "binding": [
-- {
-- "path": "lib/modbus-binding.so",
-- "config": {
-- "$schema": "http://iot.bzh/download/public/schema/json/ctl-schema.json",
-- "metadata": {
-- "uid": "modbus-svc",
-- "version": "1.0",
-- "api": "modbus",
-- "info": "Modbus test"
-- },
-- "modbus": {
-- "uid": "ANDIVI RHT",
-- "info": "ANDIVI RHT sensor",
-- "uri": "tty://dev/ttymxc2:57600",
-- "prefix": "ANDIVI",
-- "slaveid": 50,
-- "timeout": 250,
-- "autostart": 1,
-- "privilege": "ANDIVI:Modbus",
-- "hertz": 1,
-- "idle": 10,
-- "sensors": [
-- {
-- "uid": "temperature",
-- "register": 20,
-- "type": "Register_input",
-- "format": "INT16",
-- "sample": [
-- {
-- "action": "read"
-- },
-- {
-- "action": "subscribe"
-- }
-- ]
-- },
-- {
-- "uid": "humidity",
-- "register": 21,
-- "type": "Register_input",
-- "format": "INT16",
-- "sample": [
-- {
-- "action": "read"
-- },
-- {
-- "action": "subscribe"
-- }
-- ]
-- },
-- {
-- "uid": "dewpoint",
-- "register": 23,
-- "type": "Register_input",
-- "format": "INT16",
-- "sample": [
-- {
-- "action": "read"
-- },
-- {
-- "action": "subscribe"
-- }
-- ]
-- }
-- ]
-- }
-- }
-- }
-- ],
-- "port": 9999,
-- "ws-server": [
-- "unix:/tmp/modbus"
-- ],
-- "cache-eol": 100000,
-- "apitimeout": 20,
-- "cntxtimeout": 32000000,
-- "session-max": 200,
-- "jobs-max": 200,
-- "threads-max": 5,
-- "threads-init": 1,
-- "uploaddir": ".",
-- "rootbase": "/opa",
-- "rootapi": "/api",
-- "workdir": ".",
-- "rootdir": ".",
-- "log": "error+warning+notice+info+debug"
-- }
------END OF CONFIG-----
INFO: running with pid 1632
INFO: API monitor added
INFO: Can't connect supervision socket to @urn:AGL:afs:supervision:socket: Connection refused
NOTICE: Browser URL= http://localhost:9999
NOTICE: Serving rootdir=. uploaddir=.
INFO: binding [lib/modbus-binding.so] looks like an AFB binding V4
INFO: API modbus added
DEBUG: Init config done
NOTICE: API modbus starting...
INFO: API modbus started
NOTICE: API monitor starting...
INFO: API monitor started
INFO: HTTP server starting
NOTICE: Listening interface *:9999
DEBUG: received websocket request for modbus/info: null
DEBUG: received websocket request for modbus/ANDIVI/temperature: {"action":"read"}
DEBUG: received websocket request for modbus/ANDIVI/humidity: {"action":"read"}
DEBUG: received websocket request for modbus/ANDIVI/humidity: {"action":"read"}
DEBUG: received websocket request for modbus/ANDIVI/humidity: {"action":"read"}
ERROR: [API modbus] ModbusReadRegisters: fail to read rtu=ANDIVI RHT sensor=humidity error=Connection timed out [/builddir/build/BUILD/modbus-binding-2.0.1+1+g1d43325/src/modbus-glue.c:202,ModbusReadRegisters]
NOTICE: [API modbus] ModbusReconnect: Try reconnecting rtu=ANDIVI RHT
DEBUG: received websocket request for modbus/ANDIVI/humidity: {"action":"read"}
DEBUG: received websocket request for modbus/ANDIVI/temperature: {"action":"read"}
Updated by Louis-Baptiste Sobolewski 8 months ago
Emmanuel Jubera [SAFT] wrote in #note-5:
We use modbus-binding to get values from the ANDIVI RHT sensor.
When issuing several read commands for temperature / humidity in a row, the binding reported a humidity reading when asked to report the temperature, as show below:...