sjief
(Wesley Schijven)
August 30, 2017, 6:20am
1
I’m unable to get the correct DS18B20 values from my Pokeys57E through Modbus.
When the sensor value through the Pokeys software is 24,31 °C,
the value in OH is 158924800 °C.
My modbus config:
poll=200
tcp.slave1.connection=192.168.178.250:502
tcp.slave1.type=input
tcp.slave1.id=111
tcp.slave1.start=400
tcp.slave1.length=2
tcp.slave1.valuetype=int32
My items config:
Number temperature “Test [%.2f °C]” (gTemperature) { modbus=“slave1:0” }
Anybody an idea what goes wrong?
Thanks
sjief
(Wesley Schijven)
August 30, 2017, 10:13am
2
The manual of Pokeys says that the register of the sensor values are 32-bit.
But the value that i get isn’t the temperature.
No more sensors on the pockey, only one ds18b20
The value i get in OH: 169148416.0 °C
Anybody experience with this?
AndrewZ
(Andrew)
August 30, 2017, 10:25am
3
I guess that should be float32
and the value may need additional conversion as the negatives could have the most high bit set (as seen on another device).
sjief
(Wesley Schijven)
August 30, 2017, 10:39am
4
float gives the same value.
I think you are right about the conversion.
Anybody a method how to convert?
The value is LSB first i see, don’t know if that has something to do with it.
AndrewZ
(Andrew)
August 30, 2017, 10:44am
5
Can you get the binary values from Pokeys registers 400 and 401?
Then we can try to manually decode it.
sjief
(Wesley Schijven)
August 30, 2017, 11:01am
6
Don’t know how to do that?
Maybe this has someting to do with it:
From the binding WIKI
Note: The way Decimal commands are handled currently means that it is probably not useful to try to use Decimal commands with non-16bit valuetypes.
You cannot simply write 32-bit at present.
We’ll have to try to hack it with two 16-bit Items. It gets complicated because of the sign.
This is untested -
modbus.cfg to deal with this register pair as 16-bits, important note - Unsigned
writemultipleregisters = true
...
serial.slave3.type=holding
serial.slave3.start=5016…
sjief
(Wesley Schijven)
August 30, 2017, 11:58am
7
I found these in the protocol manual of pokeys and the datasheet of DS18B20.
Is this the output that I get?
Also this script that i found:
ds18b20.py
def ds18b20_convert(lsb, msb):
"""
Converts the 16-bit sign-extended two’s complement number, stored
in the DS18B20's temperature register, into a temperature.
"""
reading = lsb + (msb << 8)
inv = reading & 0x8000
if inv: # two's compliment
reading = (reading ^ 0xffff) + 1
val = reading / 16.0
This file has been truncated. show original
AndrewZ
(Andrew)
August 30, 2017, 12:43pm
8
I suggest to read the data using external tool, outside of OH.
For example, with modpoll
it could be something like this:
./modpoll -a 111 -r 400 -c 2 -1 -t 3 192.168.178.250
sjief
(Wesley Schijven)
August 30, 2017, 2:21pm
9
This is what I get:
C:\>modpoll -a 111 -r 400 -c 1 -1 -t 3 -p 502 192.168.178.250
modpoll 3.4 - FieldTalk(tm) Modbus(R) Master Simulator
Copyright (c) 2002-2013 proconX Pty Ltd
Visit http://www.modbusdriver.com for Modbus libraries and tools.
Protocol configuration: MODBUS/TCP
Slave configuration...: address = 111, start reference = 400, count = 1
Communication.........: 192.168.178.250, port 502, t/o 1.00 s, poll rate 1000 ms
Data type.............: 16-bit register, input register table
-- Polling slave...
Illegal Data Address exception response!
Illegal Data Address
The data address received in the query is not an allowable address for the slave. More specifically, the combination of reference number and transfer length is invalid. For a controller with 100 registers, a request with offset 96 and length 4 would succeed, a request with offset 96 and length 5 will generate exception 02.
Tried other length combination with no succes
Try this
poll=200
tcp.slave1.connection=192.168.178.250:502
tcp.slave1.type=input
tcp.slave1.id=111
tcp.slave1.start=400
tcp.slave1.length=2
tcp.slave1.valuetype=float32_swap
Reason why I want you to try this.
I got myself over 400 modbus items.
Some are encoded with LSB some with MSB which is a pain in the A**
I had crazy values to like 2001365010340160 to -164215124345
The swap function solved this for me. So I suggest maybe its that
Docs
sjief
(Wesley Schijven)
August 30, 2017, 5:52pm
11
This one worked :), I only changed float to uint32
But now the value is 100 times to big.
An easy way to convert the number dividing by 100?
Number temperature "Test [%d °C]" <temperature> (gTemperature) { modbus="slave1:0" }
Yes with javascript transfrom service
save as div100.js in openHAB2/transfrom/div100.js
(function(i){
return (i/100)
})(input)
Number temperature "Test [JS(div100.js):%d °C]" <temperature> (gTemperature) { modbus="slave1:0" }
AndrewZ
(Andrew)
August 30, 2017, 6:21pm
13
Transformation may be used within { }
as described here
Ready-to-use example is here
This is a diffrent type of transformation. Its modbus binding specific. The other one is generall js transformation
But could be used also, nevery tryed
http://docs.openhab.org/addons/transformations/javascript/readme.html
@sjief So this is Solved?
If yes please don’t forget to mark your Topic as Solved
Just click the first button on the response that solved your Issue.
Have a nice day
sjief
(Wesley Schijven)
August 31, 2017, 7:56am
16
Strange the conversion isn’t worked. Tried both methods. The value keeps the same
AndrewZ
(Andrew)
August 31, 2017, 8:51am
17
@sjief Please show your current configuration. Make sure you have no errors in the log.
rossko57
(Rossko57)
August 31, 2017, 9:25am
18
There may be a clue from earlier. Changing int with float cannot produce the value, so that tells you that changes do not always take immediate effect. Same probably applies to your transform.
You must at the very least restart OH, and might need to see
From Karaf:
config:delete org.openhab.binding.modbus
or delete file /var/lib/openhab2/config/org/openhab/modbus.config
sjief
(Wesley Schijven)
August 31, 2017, 6:50pm
19
Modbus:
poll=200
tcp.slave1.connection=192.168.178.250:502
tcp.slave1.type=input
tcp.slave1.id=111
tcp.slave1.start=400
tcp.slave1.length=2
tcp.slave1.valuetype=uint32_swap
Items:
Number temperature "Test [JS(div100.js):%d °C]" <temperature> (gTemperature) { modbus="slave1:0" }
Sitemap:
sitemap demo label="Main Menu" {
Frame label="Date" {
Text item=Date
}
Frame label="Demo" {
Text item=temperature icon="temperature"
How do I get the log file?
sjief
(Wesley Schijven)
August 31, 2017, 6:52pm
20
Tried to restart several times, also deleted the modbus.config by going to the directory with cd
and than rm modbus.config
but no succes.