Hallo liebe Leute,
ich häng an der Einrichtung von ECMD & ECMDDevices fest.
Leider verstehe ich die Commandref & Beispiele & RegEx nicht so gut, dass ich sie in meinen gewünschten Fall umbauen kann.
Die Antwort kommt eigentlich in einem 'Schwung' aber FHEM logged immer ein Zeichen und dann den Rest
write N;1;\032
read N (\116)
obwohl die Antwort
N;1;18.9;50.0;10.0;0;\032
sein sollte.
Der Wert den ich hier als Reading gern hätte ist Temp 18.9
das gleiche dann für ph
modbus: write K;1;\032
modbus: read K (\113)
2020.05.13 18:14:10 5: modbus: received answer K (\113)
die gwünschte Antwort wäre
K;1;785;999;200;0;\032
Wobei 785 der Wert für das Reading ph sein sollte.
Mit dem ECMD modbus öffne ich einen ASCII Modbus:
defmod modbus ECMD serial /dev/ttyS0@9600
attr modbus classdefs Pool=./Pool.classdef
attr modbus logTraffic 5
attr modbus partial 3
attr modbus responseSeparator \032
attr modbus split ;;
Mit dem ECMDDevice Pool_Interface möchte ich Nachrichten auf den modbus schicken und Antworten auswerten:
defmod Pool_Interface ECMDDevice Pool
attr Pool_Interface IODev modbus
mit Pool.classdef
get TEMP cmd {"N;1;\x1A"}
get PH cmd {"K;1;\x1A"}
get MV cmd {"H;1;\x1A"}
get TEMP expect "N*.*"
get PH expect "K*.*"
get MV expect "H*.*"
Hier die Log für N
2020.05.13 18:01:26 5: Cmd: >get Pool TEMP<
2020.05.13 18:01:26 5: ECMDDevice: Analyze command >{"N;1;\x1A"}<
2020.05.13 18:01:26 5: modbus: sending command N;1;\032 (\116\073\061\073\032)
2020.05.13 18:01:26 5: modbus: write N;1;\032 (\116\073\061\073\032), expect N*.*
2020.05.13 18:01:26 5: SW: 4e3b313b1a
2020.05.13 18:01:27 5: modbus: read N (\116)
2020.05.13 18:01:27 5: modbus: received answer N (\116)
2020.05.13 18:01:27 5: Starting notify loop for Pool, 2 event(s), first is TEMP: N
2020.05.13 18:01:27 5: createNotifyHash
2020.05.13 18:01:27 5: End notify loop for Pool
2020.05.13 18:01:27 5: modbus: read ;1;18.9;50.0;10.0;0;\032 (\073\061\073\061\070\056\071\073\065\060\056\060\073\061\060\056\060\073\060\073\032)
2020.05.13 18:01:27 5: modbus: Spontaneously received ;1;18.9;50.0;10.0;0;\032 (\073\061\073\061\070\056\071\073\065\060\056\060\073\061\060\056\060\073\060\073\032)
2020.05.13 18:01:27 5: modbus: dispatch ;1;18.9;50.0;10.0;0;\032
2020.05.13 18:01:27 5: modbus: partial message \032 (\032) expired.
2020.05.13 18:01:27 5: modbus: ;1;18.9;50.0;10.0;0;\032 (\073\061\073\061\070\056\071\073\065\060\056\060\073\061\060\056\060\073\060\073\032) split into 7 parts
2020.05.13 18:01:27 5: modbus: trying to match message ; (\073)
2020.05.13 18:01:27 5: modbus: trying to match message 1; (\061\073)
2020.05.13 18:01:27 5: modbus: trying to match message 18.9; (\061\070\056\071\073)
2020.05.13 18:01:27 5: modbus: trying to match message 50.0; (\065\060\056\060\073)
2020.05.13 18:01:27 5: modbus: trying to match message 10.0; (\061\060\056\060\073)
2020.05.13 18:01:27 5: modbus: trying to match message 0; (\060\073)
2020.05.13 18:01:27 5: modbus: trying to match message \032 (\032)
2020.05.13 18:01:27 5: modbus: partial message \032 (\032) kept
hier die Log für ph K
020.05.13 18:14:10 5: Cmd: >get Pool_Interface PH<
2020.05.13 18:14:10 5: ECMDDevice: Analyze command >{"K;1;\x1A"}<
2020.05.13 18:14:10 5: modbus: sending command K;1;\032 (\113\073\061\073\032)
2020.05.13 18:14:10 5: modbus: write K;1;\032 (\113\073\061\073\032), expect K*.*
2020.05.13 18:14:10 5: SW: 4b3b313b1a
2020.05.13 18:14:10 5: modbus: read K (\113)
2020.05.13 18:14:10 5: modbus: received answer K (\113)
2020.05.13 18:14:10 5: Starting notify loop for Pool_Interface, 2 event(s), first is PH: K
2020.05.13 18:14:10 5: End notify loop for Pool_Interface
2020.05.13 18:14:10 5: modbus: read ;1;785;999;200;0;\032 (\073\061\073\067\070\065\073\071\071\071\073\062\060\060\073\060\073\032)
2020.05.13 18:14:10 5: modbus: Spontaneously received ;1;785;999;200;0;\032 (\073\061\073\067\070\065\073\071\071\071\073\062\060\060\073\060\073\032)
2020.05.13 18:14:10 5: modbus: dispatch ;1;785;999;200;0;\032
2020.05.13 18:14:10 5: modbus: partial message \032 (\032) expired.
2020.05.13 18:14:10 5: modbus: ;1;785;999;200;0;\032 (\073\061\073\067\070\065\073\071\071\071\073\062\060\060\073\060\073\032) split into 7 parts
2020.05.13 18:14:10 5: modbus: trying to match message ; (\073)
2020.05.13 18:14:10 5: modbus: trying to match message 1; (\061\073)
2020.05.13 18:14:10 5: modbus: trying to match message 785; (\067\070\065\073)
2020.05.13 18:14:10 5: modbus: trying to match message 999; (\071\071\071\073)
2020.05.13 18:14:10 5: modbus: trying to match message 200; (\062\060\060\073)
2020.05.13 18:14:10 5: modbus: trying to match message 0; (\060\073)
2020.05.13 18:14:10 5: modbus: trying to match message \032 (\032)
2020.05.13 18:14:10 5: modbus: partial message \032 (\032) kept
Internals:
DEF serial /dev/ttyS0@9600
DeviceName /dev/ttyS0@9600
FD 7
FUUID 5eb85f53-f33f-9eb0-c9ee-51eebbbfd443a5c2
NAME modbus
NR 14
PARTIAL
Protocol serial
STATE opened
TYPE ECMD
READINGS:
2020-05-10 22:26:42 raw A
2020-05-13 20:01:33 state opened
fhem:
classDefs:
Pool:
filename ./Pool.classdef
gets:
MV:
cmd {"H;1;\x1A"}
expect H.*
PH:
cmd {"K;1;\x1A"}
expect K.*
TEMP:
cmd {"N;1;\x1A"}
expect N.*
sets:
partial:
msg
ts 1589392915.64743
Attributes:
classdefs Pool=./Pool.classdef
logTraffic 5
partial 3
responseSeparator \032
split ;
Internals:
DEF Pool
FUUID 5ebc09d0-f33f-9eb0-df95-f3022e5a7aef4943
IODev modbus
NAME Pool_Interface
NR 20
STATE TEMP N
TYPE ECMDDevice
READINGS:
2020-05-13 17:58:22 MV H
2020-05-13 18:14:10 PH K
2020-05-13 20:01:55 TEMP N
2020-05-13 20:01:55 state TEMP N
fhem:
classname Pool
cache:
specials:
%NAME Pool_Interface
%TYPE ECMDDevice
Attributes:
IODev modbus
Ich hab über die Suche einen alten Thread gefunden ( https://forum.fhem.de/index.php?topic=63899.0 ) der das ähnlich Problem hatte und mit einem partial 3 lösen konnte.
Das hat leider keine Besserung in meinem Fall gebracht.
Doch das Partial & expect & match hat geholfen.
Jetzt bekomme ich die Daten :-)
hier meine aktuelle Konfiguration:
defmod modbus ECMD serial /dev/ttyS0@9600
attr modbus classdefs Pool=./Pool.classdef
attr modbus logTraffic 5
attr modbus partial 2
attr modbus verbose 5
defmod Pool ECMDDevice Pool
attr Pool IODev modbus
attr Pool userReadings Temp2 {(split ';;',ReadingsVal("Pool","temp",0))[2]},MV2 {(split ';;',ReadingsVal("Pool","mv",0))[3]},PH2 {(split ';;',ReadingsVal("Pool","ph",0))[2]}
get temp cmd {"N;1;\x1A"}
get temp expect "N;[1]\;[0-9.]+\;[0-9.]+;[0-9.]+;[0-9.]+;[\\032]+"
reading temp match "N;[1]\;([0-9.]+)\;[0-9.]+;[0-9.]+;[0-9.]+;[\\032]+"
get mv cmd {"K;1;\x1A"}
get mv expect "K;[1]\;[0-9]+\;[0-9]+;[0-9]+;[0-9]+;[\\032]+"
reading mv match "K;[1]\;([0-9]+)\;[0-9]+;[0-9]+;[0-9]+;[\\032]+"
get ph cmd {"H;1;\x1A"}
get ph expect "H;[1]\;[0-9.]+\;[0-9.]+;[0-9.]+;[0-9.]+;[0-9]+;[0-9]+;[0-9]+;[0-9]+;[\\032]+"
reading ph match "H;[1]\;([0-9.]+)\;[0-9.]+;[0-9.]+;[0-9.]+;[0-9]+;[0-9]+;[0-9]+;[0-9]+;[\\032]+"
Über Hilfe wie ich das ganze gut & sauber zum Laufen bekomme, wäre ich sehr dankbar!
Danke an KölnSolar für die Unterstützung