Spontaneously received ECMD

Begonnen von NeuFehm, 15 November 2016, 21:03:50

Vorheriges Thema - Nächstes Thema

NeuFehm

#15
Hast mich erwischt ;)

also hier meine classdef:
]
params M_Adresse M_Relais
set on cmd {chr(35).chr(77).chr(%M_Adresse).chr(69).chr(1).chr(%M_Relais).chr(1).chr(13).chr(10)}
set on expect "!M.*\r\n"
set on postproc {s/([!M.*|;]*)/success/; "$_" eq "success" ? "ok" : "error";}
set off cmd {chr(35).chr(77).chr(%M_Adresse).chr(69).chr(1).chr(%M_Relais).chr(0).chr(13).chr(10)}
set off expect "!M.*\r\n"
set off postproc {s/([!M.*|;]*)/success/; "$_" eq "success" ? "ok" : "error";}
reading Test1 match "M.*\r"


und der aktuelle fhem.cfg-Bereich:
define myMModul ECMD serial /dev/ttyUSB0@9600
attr myMModul classdefs MModul=/opt/fhem/MModul.classdef
attr myMModul logTraffic 5
attr myMModul partial 2
attr myMModul requestSeparator workaround
attr myMModul responseSeparator \n
attr myMModul verbose 5
define 40Relais1 ECMDDevice MModul 40 1
attr 40Relais1 IODev myMModul
attr 40Relais1 room Buero



und hier das log. Zunächst per Fhem geschaltet:

2016.11.25 20:42:07 5: myMModul: sending command "#M(E\001\001\001\r\n"
2016.11.25 20:42:07 5: myMModul: write "#M(E\001\001\001\r\n", expect !M.*\r\n
2016.11.25 20:42:07 5: SW: 234d28450101010d0a
2016.11.25 20:42:07 5: myMModul: read "!M(E\001\001\001\r\n"
2016.11.25 20:42:07 5: myMModul: received answer "!M(E\001\001\001\r\n"
2016.11.25 20:42:12 5: myMModul: sending command "#M(E\001\001\000\r\n"
2016.11.25 20:42:12 5: myMModul: write "#M(E\001\001\000\r\n", expect !M.*\r\n
2016.11.25 20:42:12 5: SW: 234d28450101000d0a
2016.11.25 20:42:13 5: myMModul: read "!M(E\001\001\000\r\n"
2016.11.25 20:42:13 5: myMModul: received answer "!M(E\001\001\000\r\n"


und nun per Hardware:
2016.11.25 20:44:43 5: myMModul: read "#"
2016.11.25 20:44:43 5: myMModul: Spontaneously received "#"
2016.11.25 20:44:43 5: myMModul dispatch #
2016.11.25 20:44:43 5: myMModul: read "M(E\001\001\001\r\n"
2016.11.25 20:44:43 5: myMModul: Spontaneously received "M(E\001\001\001\r\n"
2016.11.25 20:44:43 5: myMModul dispatch M(E

2016.11.25 20:44:43 5: myMModul: read "!"
2016.11.25 20:44:43 5: myMModul: Spontaneously received "!"
2016.11.25 20:44:43 5: myMModul dispatch !
2016.11.25 20:44:43 5: myMModul: read "M(E\001\001\001\r\n"
2016.11.25 20:44:43 5: myMModul: Spontaneously received "M(E\001\001\001\r\n"
2016.11.25 20:44:43 5: myMModul dispatch M(E

2016.11.25 20:44:45 5: myMModul: read "#"
2016.11.25 20:44:45 5: myMModul: Spontaneously received "#"
2016.11.25 20:44:45 5: myMModul dispatch #
2016.11.25 20:44:45 5: myMModul: read "M(E\001\001\000\r\n"
2016.11.25 20:44:45 5: myMModul: Spontaneously received "M(E\001\001\000\r\n"
2016.11.25 20:44:45 5: myMModul dispatch M(E

2016.11.25 20:44:45 5: myMModul: read "!"
2016.11.25 20:44:45 5: myMModul: Spontaneously received "!"
2016.11.25 20:44:45 5: myMModul dispatch !
2016.11.25 20:44:45 5: myMModul: read "M(E\001\001\000\r\n"
2016.11.25 20:44:45 5: myMModul: Spontaneously received "M(E\001\001\000\r\n"
2016.11.25 20:44:45 5: myMModul dispatch M(E


Ich werde das Gefühl immer noch nicht los, dass die spontanen Antworten gar nicht erst durch Deine gewünschte Routine laufen,
also weder am \n separiert, noch per partial 2 zusammengesetzt werden... aber ich habe leider zu wenig Ahnung ob die IODEV
oder die zusammenhängenden Dateien nicht schon vorher die Daten "abzweigen"....?

P.S.: ich starte vor dem Test mit /etc/init.d/fhem stop und /etc/init.d/fhem start, anschließend
tail -f /opt/fhem/log/fhem-2016-11.log um das log zu verfolgen....

Kann auch gern mal eine debugg-Datei von Dir einbinden, die Testausgaben ins log schreibt.
Ist eh mein Testsystem...
Vlt so, dass der Eintrag:
2016.11.25 20:44:43 5: myMModul: read "!"
geprüft wird, ob an der Stelle "$partial" verfügbar und den richtigen Inhalt hat, also das Ganze dann so aussieht:
2016.11.25 20:44:43 5: myMModul: read "!" [partial:2]




Raspberry Pi B+
RS 485 Schnittstellen: DIGITUS DA-70157, LINKSPTITE RS485/GPIO Shield for Raspberry Pi
RS485 Geräte: Ultraschallsensor für Zisternenfüllstand (Eigenbau), 4x8 Relais-M-Mastermodule (Eigenbau), 6 T-Module (Schalter und 3 analoge Eingänge) (Eigenbau)
sonstige Hardware: 2 Relay Modul

Dr. Boris Neubert

Hallo,

in dem expect muss das \n weg. Aber dann geht es vermutlich immer noch nicht, weil ich meine, dass in attr requestSeparator \n das \n nicht als Steuerzeichen sondern als literales Backslash+n verstanden wird. Außerdem versteht eh kein Mensch, wie er das Modul in diesen Situationen konfigurieren soll.

Ich breche daher den Support an dieser Stelle ab und mache mich am Sonntag ausgeschlafen an eine Überarbeitung des Moduls. Testfälle habe ich aus Deinen Logs genug.

Ich melde mich wieder, wenn ich fertig bin. Dann komme ich auf Dein Angebot zurück, es zu testen.

Viele Grüße
Boris
Globaler Moderator, Developer, aktives Mitglied des FHEM e.V. (Marketing, Verwaltung)
Bitte keine unaufgeforderten privaten Nachrichten!

NeuFehm

Boris, echt lieb von Dir.
Ich kann Dir auch die Hardware schicken, wenn das für Dich ok ist.....
Ich mache es so, wie Du es magst...
DANKE!!!
Raspberry Pi B+
RS 485 Schnittstellen: DIGITUS DA-70157, LINKSPTITE RS485/GPIO Shield for Raspberry Pi
RS485 Geräte: Ultraschallsensor für Zisternenfüllstand (Eigenbau), 4x8 Relais-M-Mastermodule (Eigenbau), 6 T-Module (Schalter und 3 analoge Eingänge) (Eigenbau)
sonstige Hardware: 2 Relay Modul

Dr. Boris Neubert

Hallo,

bitte finde anbei überarbeitete Versionen von ECMD, ECMDDevice und der dazugehörigen Commandref.

changes as of 27 Nov 2016:
- if split is used, the string at which the messages are split are still part of the messages
- no default attributes for requestSeparator and responseSeparator
- input of raw data as perl-encoded string (for setting attributes)
- be more verbose and explicit at loglevel 5
- documentation corrected and amended


Bitte setze das Attribut split auf \r\n und das Attribut partial auf 2. Die Attribute requestSeparator und responseSeparator werden nicht gesetzt (das war ein Irrweg).

Bitte lies Dir auch in der Commandref den Abschnitt zu diesen Attributen und den Abschnitt "Separators" durch.

Viele Grüße
Boris
Globaler Moderator, Developer, aktives Mitglied des FHEM e.V. (Marketing, Verwaltung)
Bitte keine unaufgeforderten privaten Nachrichten!

NeuFehm

#19
Hallo Boris,

Ergebnisse:
1. der "attr myMModul requestSeparator �" schreibt sich immer noch von alleine rein. (stört aber nicht)

2. Schaltung per FHEM sieht sehr gut aus!

# Anschalten
2016.11.28 18:51:53 5: myMModul: sending command #M(E\001\001\001\r\n (\043\115\050\105\001\001\001\015\012)
2016.11.28 18:51:53 5: myMModul: write #M(E\001\001\001\r\n (\043\115\050\105\001\001\001\015\012), expect !M.*\r\n
2016.11.28 18:51:53 5: SW: 234d28450101010d0a
2016.11.28 18:51:53 5: myMModul: read !M(E\001\001\001\r\n (\041\115\050\105\001\001\001\015\012)
2016.11.28 18:51:53 5: myMModul: received answer !M(E\001\001\001\r\n (\041\115\050\105\001\001\001\015\012)

# Ausschalten
2016.11.28 18:52:47 5: myMModul: sending command #M(E\001\001\000\r\n (\043\115\050\105\001\001\000\015\012)
2016.11.28 18:52:47 5: myMModul: write #M(E\001\001\000\r\n (\043\115\050\105\001\001\000\015\012), expect !M.*\r\n
2016.11.28 18:52:47 5: SW: 234d28450101000d0a
2016.11.28 18:52:47 5: myMModul: read !M(E\001\001\000\r\n (\041\115\050\105\001\001\000\015\012)
2016.11.28 18:52:47 5: myMModul: received answer !M(E\001\001\000\r\n (\041\115\050\105\001\001\000\015\012)


Das ist ja schon mal topp!!! Auch schön, dass Du den String gleich zerlegt hast.

Hardware-Schalter an:
2016.11.28 18:56:53 5: myMModul: read #M (\043\115)
2016.11.28 18:56:53 5: myMModul: Spontaneously received #M (\043\115)
2016.11.28 18:56:53 5: myMModul dispatch #M
2016.11.28 18:56:53 5: myMModul: partial message !M(E\001\001\001\r\n (\041\115\050\105\001\001\001\015\012) expired.
2016.11.28 18:56:53 5: myMModul: trying to match message #M (\043\115)
2016.11.28 18:56:53 5: myMModul: partial message #M (\043\115) kept
2016.11.28 18:56:53 5: myMModul: read (E\001\001\001\r\n (\050\105\001\001\001\015\012)
2016.11.28 18:56:53 5: myMModul: Spontaneously received (E\001\001\001\r\n (\050\105\001\001\001\015\012)
2016.11.28 18:56:53 5: myMModul dispatch (E

2016.11.28 18:56:53 5: myMModul: merging partial message #M (\043\115) and (E\001\001\001\r\n (\050\105\001\001\001\015\012)
2016.11.28 18:56:53 5: myMModul: trying to match message #M(E\001\001\001\r\n (\043\115\050\105\001\001\001\015\012)
2016.11.28 18:56:53 5: myMModul: partial message #M(E\001\001\001\r\n (\043\115\050\105\001\001\001\015\012) kept
2016.11.28 18:56:53 5: myMModul: read ! (\041)
2016.11.28 18:56:53 5: myMModul: Spontaneously received ! (\041)
2016.11.28 18:56:53 5: myMModul dispatch !
2016.11.28 18:56:53 5: myMModul: merging partial message #M(E\001\001\001\r\n (\043\115\050\105\001\001\001\015\012) and ! (\041)
2016.11.28 18:56:53 5: myMModul: #M(E\001\001\001\r\n! (\043\115\050\105\001\001\001\015\012\041) split into 2 parts
2016.11.28 18:56:53 5: myMModul: trying to match message #M(E\001\001\001\r\n (\043\115\050\105\001\001\001\015\012)
2016.11.28 18:56:53 5: myMModul: trying to match message ! (\041)
2016.11.28 18:56:53 5: myMModul: partial message ! (\041) kept
2016.11.28 18:56:53 5: myMModul: read M(E\001\001\001\r\n (\115\050\105\001\001\001\015\012)
2016.11.28 18:56:53 5: myMModul: Spontaneously received M(E\001\001\001\r\n (\115\050\105\001\001\001\015\012)
2016.11.28 18:56:53 5: myMModul dispatch M(E

2016.11.28 18:56:53 5: myMModul: merging partial message ! (\041) and M(E\001\001\001\r\n (\115\050\105\001\001\001\015\012)
2016.11.28 18:56:53 5: myMModul: trying to match message !M(E\001\001\001\r\n (\041\115\050\105\001\001\001\015\012)
2016.11.28 18:56:53 5: myMModul: partial message !M(E\001\001\001\r\n (\041\115\050\105\001\001\001\015\012) kept


Hardwareschalter aus:
2016.11.28 18:59:18 5: myMModul: read # (\043)
2016.11.28 18:59:18 5: myMModul: Spontaneously received # (\043)
2016.11.28 18:59:18 5: myMModul dispatch #
2016.11.28 18:59:18 5: myMModul: partial message !M(E\001\001\001\r\n (\041\115\050\105\001\001\001\015\012) expired.
2016.11.28 18:59:18 5: myMModul: trying to match message # (\043)
2016.11.28 18:59:18 5: myMModul: partial message # (\043) kept
2016.11.28 18:59:18 5: myMModul: read M(E\001\001\000\r\n (\115\050\105\001\001\000\015\012)
2016.11.28 18:59:18 5: myMModul: Spontaneously received M(E\001\001\000\r\n (\115\050\105\001\001\000\015\012)
2016.11.28 18:59:18 5: myMModul dispatch M(E

2016.11.28 18:59:18 5: myMModul: merging partial message # (\043) and M(E\001\001\000\r\n (\115\050\105\001\001\000\015\012)
2016.11.28 18:59:18 5: myMModul: trying to match message #M(E\001\001\000\r\n (\043\115\050\105\001\001\000\015\012)
2016.11.28 18:59:18 5: myMModul: partial message #M(E\001\001\000\r\n (\043\115\050\105\001\001\000\015\012) kept
2016.11.28 18:59:18 5: myMModul: read ! (\041)
2016.11.28 18:59:18 5: myMModul: Spontaneously received ! (\041)
2016.11.28 18:59:18 5: myMModul dispatch !
2016.11.28 18:59:18 5: myMModul: merging partial message #M(E\001\001\000\r\n (\043\115\050\105\001\001\000\015\012) and ! (\041)
2016.11.28 18:59:18 5: myMModul: #M(E\001\001\000\r\n! (\043\115\050\105\001\001\000\015\012\041) split into 2 parts
2016.11.28 18:59:18 5: myMModul: trying to match message #M(E\001\001\000\r\n (\043\115\050\105\001\001\000\015\012)
2016.11.28 18:59:18 5: myMModul: trying to match message ! (\041)
2016.11.28 18:59:18 5: myMModul: partial message ! (\041) kept
2016.11.28 18:59:18 5: myMModul: read M(E\001\001\000\r\n (\115\050\105\001\001\000\015\012)
2016.11.28 18:59:18 5: myMModul: Spontaneously received M(E\001\001\000\r\n (\115\050\105\001\001\000\015\012)
2016.11.28 18:59:18 5: myMModul dispatch M(E

2016.11.28 18:59:18 5: myMModul: merging partial message ! (\041) and M(E\001\001\000\r\n (\115\050\105\001\001\000\015\012)
2016.11.28 18:59:18 5: myMModul: trying to match message !M(E\001\001\000\r\n (\041\115\050\105\001\001\000\015\012)
2016.11.28 18:59:18 5: myMModul: partial message !M(E\001\001\000\r\n (\041\115\050\105\001\001\000\015\012) kept


Das sieht doch schon mal gut aus oder?
Manchmal scheint der Response vertauscht...?
Aber es fühlt sich trotzdem super an...

So und jetzt lese ich mir noch die commandref durch... ;)
Raspberry Pi B+
RS 485 Schnittstellen: DIGITUS DA-70157, LINKSPTITE RS485/GPIO Shield for Raspberry Pi
RS485 Geräte: Ultraschallsensor für Zisternenfüllstand (Eigenbau), 4x8 Relais-M-Mastermodule (Eigenbau), 6 T-Module (Schalter und 3 analoge Eingänge) (Eigenbau)
sonstige Hardware: 2 Relay Modul

Dr. Boris Neubert

1. deleteattr myMModul requestSeparator
Save.

2. Bitte classdef und Definition von myMModul zeigen (aktuell). Da ist das regex nicht okay, es kommt kein Match.
Globaler Moderator, Developer, aktives Mitglied des FHEM e.V. (Marketing, Verwaltung)
Bitte keine unaufgeforderten privaten Nachrichten!

NeuFehm

ja, ich glaube das waren noch Altlasten und tests: reading Test1 match "M.*\r"

aktuell geändert auf:
]
params M_Adresse M_Relais
set on cmd {chr(35).chr(77).chr(%M_Adresse).chr(69).chr(1).chr(%M_Relais).chr(1).chr(13).chr(10)}
set on expect "!M.*\r\n"
set on postproc {s/([!M.*|;]*)/success/; "$_" eq "success" ? "ok" : "error";}
set off cmd {chr(35).chr(77).chr(%M_Adresse).chr(69).chr(1).chr(%M_Relais).chr(0).chr(13).chr(10)}
set off expect "!M.*\r\n"
set off postproc {s/([!M.*|;]*)/success/; "$_" eq "success" ? "ok" : "error";}
reading Test1 match "!M.*\r\n"


und hier das log:
Hardwareschalter an:

2016.11.29 12:58:43 5: myMModul: read #M (\043\115)
2016.11.29 12:58:43 5: myMModul: Spontaneously received #M (\043\115)
2016.11.29 12:58:43 5: myMModul dispatch #M
2016.11.29 12:58:43 5: myMModul: trying to match message #M (\043\115)
2016.11.29 12:58:43 5: myMModul: partial message #M (\043\115) kept
2016.11.29 12:58:43 5: myMModul: read (E\001\001\001\r\n (\050\105\001\001\001\015\012)
2016.11.29 12:58:43 5: myMModul: Spontaneously received (E\001\001\001\r\n (\050\105\001\001\001\015\012)
2016.11.29 12:58:43 5: myMModul dispatch (E

2016.11.29 12:58:43 5: myMModul: merging partial message #M (\043\115) and (E\001\001\001\r\n (\050\105\001\001\001\015\012)
2016.11.29 12:58:43 5: myMModul: trying to match message #M(E\001\001\001\r\n (\043\115\050\105\001\001\001\015\012)
2016.11.29 12:58:43 5: myMModul: partial message #M(E\001\001\001\r\n (\043\115\050\105\001\001\001\015\012) kept
2016.11.29 12:58:43 5: myMModul: read !M (\041\115)
2016.11.29 12:58:43 5: myMModul: Spontaneously received !M (\041\115)
2016.11.29 12:58:43 5: myMModul dispatch !M
2016.11.29 12:58:43 5: myMModul: merging partial message #M(E\001\001\001\r\n (\043\115\050\105\001\001\001\015\012) and !M (\041\115)
2016.11.29 12:58:43 5: myMModul: #M(E\001\001\001\r\n!M (\043\115\050\105\001\001\001\015\012\041\115) split into 2 parts
2016.11.29 12:58:43 5: myMModul: trying to match message #M(E\001\001\001\r\n (\043\115\050\105\001\001\001\015\012)
2016.11.29 12:58:43 5: myMModul: trying to match message !M (\041\115)
2016.11.29 12:58:43 5: myMModul: partial message !M (\041\115) kept
2016.11.29 12:58:43 5: myMModul: read (E\001\001\001\r\n (\050\105\001\001\001\015\012)
2016.11.29 12:58:43 5: myMModul: Spontaneously received (E\001\001\001\r\n (\050\105\001\001\001\015\012)
2016.11.29 12:58:43 5: myMModul dispatch (E

2016.11.29 12:58:43 5: myMModul: merging partial message !M (\041\115) and (E\001\001\001\r\n (\050\105\001\001\001\015\012)
2016.11.29 12:58:43 5: myMModul: trying to match message !M(E\001\001\001\r\n (\041\115\050\105\001\001\001\015\012)
2016.11.29 12:58:43 5: myMModul: !M(E\001\001\001\r\n (\041\115\050\105\001\001\001\015\012) matches regex !M.*\r\n for reading Test1 of device 40Relais1 with class MModul


offensichtlich mit gefundener richtiger Antwort ;)

und hier Hardware aus:

2016.11.29 12:59:49 5: myMModul: read # (\043)
2016.11.29 12:59:49 5: myMModul: Spontaneously received # (\043)
2016.11.29 12:59:49 5: myMModul dispatch #
2016.11.29 12:59:49 5: myMModul: trying to match message # (\043)
2016.11.29 12:59:49 5: myMModul: partial message # (\043) kept
2016.11.29 12:59:49 5: myMModul: read M(E\001\001\000\r\n (\115\050\105\001\001\000\015\012)
2016.11.29 12:59:49 5: myMModul: Spontaneously received M(E\001\001\000\r\n (\115\050\105\001\001\000\015\012)
2016.11.29 12:59:49 5: myMModul dispatch M(E

2016.11.29 12:59:49 5: myMModul: merging partial message # (\043) and M(E\001\001\000\r\n (\115\050\105\001\001\000\015\012)
2016.11.29 12:59:49 5: myMModul: trying to match message #M(E\001\001\000\r\n (\043\115\050\105\001\001\000\015\012)
2016.11.29 12:59:49 5: myMModul: partial message #M(E\001\001\000\r\n (\043\115\050\105\001\001\000\015\012) kept
2016.11.29 12:59:49 5: myMModul: read !M (\041\115)
2016.11.29 12:59:49 5: myMModul: Spontaneously received !M (\041\115)
2016.11.29 12:59:49 5: myMModul dispatch !M
2016.11.29 12:59:49 5: myMModul: merging partial message #M(E\001\001\000\r\n (\043\115\050\105\001\001\000\015\012) and !M (\041\115)
2016.11.29 12:59:49 5: myMModul: #M(E\001\001\000\r\n!M (\043\115\050\105\001\001\000\015\012\041\115) split into 2 parts
2016.11.29 12:59:49 5: myMModul: trying to match message #M(E\001\001\000\r\n (\043\115\050\105\001\001\000\015\012)
2016.11.29 12:59:49 5: myMModul: trying to match message !M (\041\115)
2016.11.29 12:59:49 5: myMModul: partial message !M (\041\115) kept
2016.11.29 12:59:49 5: myMModul: read (E\001\001\000\r\n (\050\105\001\001\000\015\012)
2016.11.29 12:59:49 5: myMModul: Spontaneously received (E\001\001\000\r\n (\050\105\001\001\000\015\012)
2016.11.29 12:59:49 5: myMModul dispatch (E

2016.11.29 12:59:49 5: myMModul: merging partial message !M (\041\115) and (E\001\001\000\r\n (\050\105\001\001\000\015\012)
2016.11.29 12:59:49 5: myMModul: trying to match message !M(E\001\001\000\r\n (\041\115\050\105\001\001\000\015\012)
2016.11.29 12:59:49 5: myMModul: !M(E\001\001\000\r\n (\041\115\050\105\001\001\000\015\012) matches regex !M.*\r\n for reading Test1 of device 40Relais1 with class MModul


und auch hier die richtige Antwort separiert :)
Jetzt sieht es aber gut aus oder?

ach und hier mein fhem.cfg

define myMModul ECMD serial /dev/ttyUSB0@9600
attr myMModul classdefs MModul=/opt/fhem/MModul.classdef
attr myMModul logTraffic 5
attr myMModul partial 2
attr myMModul split \r\n
attr myMModul verbose 5
define 40Relais1 ECMDDevice MModul 40 1
attr 40Relais1 IODev myMModul
attr 40Relais1 room Buero
Raspberry Pi B+
RS 485 Schnittstellen: DIGITUS DA-70157, LINKSPTITE RS485/GPIO Shield for Raspberry Pi
RS485 Geräte: Ultraschallsensor für Zisternenfüllstand (Eigenbau), 4x8 Relais-M-Mastermodule (Eigenbau), 6 T-Module (Schalter und 3 analoge Eingänge) (Eigenbau)
sonstige Hardware: 2 Relay Modul

Dr. Boris Neubert

Jupp. Und wenn es dann auch klappt... Werde das Modul zunächst zum allgemeinen Test stellen nebst Warnungen und dann nach einer Karenzzeit einchecken.
Globaler Moderator, Developer, aktives Mitglied des FHEM e.V. (Marketing, Verwaltung)
Bitte keine unaufgeforderten privaten Nachrichten!

NeuFehm

#23
Oh, das sieht gut aus...
habe meine fhem.cfg mit einem 2. Relais erweitert:
define myMModul ECMD serial /dev/ttyUSB0@9600
attr myMModul classdefs MModul=/opt/fhem/MModul.classdef
attr myMModul logTraffic 5
attr myMModul partial 2
attr myMModul split \r\n
attr myMModul verbose 5
define 40Relais1 ECMDDevice MModul 40 1
attr 40Relais1 IODev myMModul
attr 40Relais1 room Buero
define 40Relais2 ECMDDevice MModul 40 2
attr 40Relais2 IODev myMModul
attr 40Relais2 room Buero


außerdem die classdef mit einem postproc:

reading Test1 match "!M.*\r\n"
reading Test1 postproc {ProcessmyECMD($_);}


und dann auch die 99_Utils.pm:
zu Beginn:
my $myECMDString="off";
my $a7status = "leer";

und weiter unten bei den SUBs:
sub ProcessmyECMD($)
{
my $Modulname = "Relais";
my $answer = $_;
print "Antwort: ".$answer."\n";
my $a1 = chr(ord(substr $answer,0,1));
my $a2 = chr(ord(substr $answer,1,1));
my $a3 = ord(substr $answer,2,1);
my $a4 = ord(substr $answer,3,1);
my $a5 = ord(substr $answer,4,1);
my $a6 = ord(substr $answer,5,1);
my $a7 = ord(substr $answer,6,1);
my $a8 = ord(substr $answer,7,1);
my $a9 = ord(substr $answer,8,1);

# Vorbereitung Status
if ($a7 == 1) {
    $a7status = "on";
}
elsif ($a7 == 0) {
    $a7status = "off";
}

# Debug
print "Antwort: ".$answer."\n";
print "a1:".$a1."\n";
print "a2:".$a2."\n";
print "a3:".$a3."\n";
print "a4:".$a4."\n";
print "a5:".$a5."\n";
print "a6:".$a6."\n";
print "a7:".$a7."\n";
print "a8:".$a8."\n";
print "a9:".$a9."\n";
print "\n";

# Testausgabe für FHEM
my $Befehm = "setstate ".$a3.$Modulname.$a6." ".$a7status;
print "generierter Befehl für FHEM:".$Befehm."\n";
fhem ("$Befehm");
}


Im log gibt er schon aus:
generierter Befehl für FHEM:setstate 40Relais1 on (HURRAAA!!!! :))
auch das Schalten des 2. Relais wird richtig ausgewertet:
generierter Befehl für FHEM:setstate 40Relais2 on
Das ist alles schon mal SUPER :)

Allerdings habe ich noch einen kleinen Denkfehler irgendwo in der letzten Zeile mit dem fhem-Befehl??,
weil der Status nicht richtig gesetzt wird.
Außerdem steht im Frontend:
---------------------
ECMDDevice
40Relais1 Test1 on off
40Relais2 Test1 on off
--------------------
Das ist bestimmt ne Kleinigkeit, wahrscheinlich stimm die classdef noch nicht und müsste einen Rückgabewert verarbeiten?
oder doch in der 99_Utils ein Fehler...., kann jemand helfen?
Raspberry Pi B+
RS 485 Schnittstellen: DIGITUS DA-70157, LINKSPTITE RS485/GPIO Shield for Raspberry Pi
RS485 Geräte: Ultraschallsensor für Zisternenfüllstand (Eigenbau), 4x8 Relais-M-Mastermodule (Eigenbau), 6 T-Module (Schalter und 3 analoge Eingänge) (Eigenbau)
sonstige Hardware: 2 Relay Modul

NeuFehm

#24
Liebe Freunde...mir raucht der Kopf:

Das PERL setzt nun den Status, aber irgenwer hackt mir noch dazwischen:
Wenn alle Relais per Fhem Status auf an gesetzt werden (setstate 40Relais1 on, usw.) (siehe Bild)
und ich dann das 2 Relais ausschalte dann geht die Lampe weg und ein "answerMModul" steht da (siehe 2. Bild)

Hat jemand eine Erklärung?

Hier meine MModul.classde:

reading answerMModul match "!M.*\r\n"
reading answerMModul postproc {ProcessmyECMD($_);}


Und hier das Programm, gespeichert in den 99_Utils.pm:
sub ProcessmyECMD($)
{
my $Modulname = "Relais";
my $answer = $_; # hier !M(E\005\002\000\r\n
my $a7status = "leer";

my $a3 = ord(substr $answer,2,1); # hier 40
my $a6 = ord(substr $answer,5,1); # hier 2
my $a7 = ord(substr $answer,6,1);# hier 0

# Vorbereitung Status
if ($a7 == 1) {
    $a7status = "on";
}
elsif ($a7 == 0) {
    $a7status = "off";
}

# Status-Befehl zusammensetzen
my $Befehm = "setstate ".$a3.$Modulname.$a6." ".$a7status; # hier "setstate 40Relais2 off"

# Status Befehl ausführen
fhem ("$Befehm");
}


Raspberry Pi B+
RS 485 Schnittstellen: DIGITUS DA-70157, LINKSPTITE RS485/GPIO Shield for Raspberry Pi
RS485 Geräte: Ultraschallsensor für Zisternenfüllstand (Eigenbau), 4x8 Relais-M-Mastermodule (Eigenbau), 6 T-Module (Schalter und 3 analoge Eingänge) (Eigenbau)
sonstige Hardware: 2 Relay Modul

Dr. Boris Neubert

Für mich Problemursache auch nicht offensichtlich.

Tipps:
In Deiner Routine mit Debug "bla" gesprächig werden.
Die Matches spezifischer auf das einzelne Relais machen (%M_Relais ins Regex einbauen)
Globaler Moderator, Developer, aktives Mitglied des FHEM e.V. (Marketing, Verwaltung)
Bitte keine unaufgeforderten privaten Nachrichten!

NeuFehm

#26
Muss ich bei 10 Relais 10 readings machen?
Ich dachte ich kann ein Reading machen, das übergibt das Matching an das Programm, dieses wertet das Matching aus, erzeugt den entsprechenden FHEM-Befehl und löst sich dann selber auf ;).
Oder anders, weißt Du warum fhem sich veranlasst fühlt den Name des Readings in den Status des Devices zu schreiben? (hier "answerMModul")

PS.: Ich kann nicht das %M einbauen, da ich ja noch gar nicht weiß, welches Relais geschaltet wird aus der Sicht von Fhem. Ich muss also auf dem Bus lauschen und das gehörte auswerten und danach sagen, welches Relais geschaltet wurde...

DEBUG habe ich im Post rausgelassen.
Also der gematchte Befehl wird einwandfrei übergeben, in einzelne Teile zerlegt und der FHEM-Befehl wird richtig erzeugt, abgeschickt und in der letzten Zeile stimmt was nicht.
also ich denke entweder das
return() ist falsch, und hier muss was anderes hin, oder das postprog muss fhem sagen, dass es nichts gefunden hat weil das ja schon das eigene Programm dies erledigt hat.

Gibt es also eine Möglichkeit in der classdef oder dem Programm das so zu gestalten, dass zwar der gematchte Parameter ans Programm übergeben wird, aber dann das postproc keine weitere Aktion macht?
Raspberry Pi B+
RS 485 Schnittstellen: DIGITUS DA-70157, LINKSPTITE RS485/GPIO Shield for Raspberry Pi
RS485 Geräte: Ultraschallsensor für Zisternenfüllstand (Eigenbau), 4x8 Relais-M-Mastermodule (Eigenbau), 6 T-Module (Schalter und 3 analoge Eingänge) (Eigenbau)
sonstige Hardware: 2 Relay Modul

Dr. Boris Neubert

10 Relais = 10 ECMDDevice (Standard) oder 10 Readings an einem Device (Exotenoption)

Das ganze setstate-Zeug ist überflüssig und ich weiß nicht, wer diesen Overhead im Wiki verbreitet. Das postprocessing alleine genügt, aus dem Wert, den das Gerät liefert, ein Reading nach Geschmack zu machen. In der Commandref ist ein Beispiel.
Globaler Moderator, Developer, aktives Mitglied des FHEM e.V. (Marketing, Verwaltung)
Bitte keine unaufgeforderten privaten Nachrichten!

NeuFehm

#28
aber mache ich das nicht schon?
hier die aktuelle fhem.cfg
define myMModul ECMD serial /dev/ttyUSB0@9600
attr myMModul classdefs MModul=/opt/fhem/MModul.classdef
attr myMModul logTraffic 5
attr myMModul partial 2
attr myMModul split \r\n
attr myMModul verbose 5
define 40Relais1 ECMDDevice MModul 40 1
attr 40Relais1 IODev myMModul
attr 40Relais1 room Buero
define 40Relais2 ECMDDevice MModul 40 2
attr 40Relais2 IODev myMModul
attr 40Relais2 room Buero
define 40Relais3 ECMDDevice MModul 40 3
attr 40Relais3 IODev myMModul
attr 40Relais3 room Buero


Oder ich versuche mal zu übersetzen:

1. meine fhem.cfg ist richtig
2. da lt. commandref "A spontaneous data transmission from the physical device that matches the Perl regular expression <regex> is evaluated to become the value of the named reading. All ECMDDevice devices belonging to the ECMD device with readings with matching regular expressions will receive an update of the said readings. <regex> must match the entire reply, as in m/^<regex>$/." bedeutet, dass ein reading namens "answerMModul" als Status in alle ECMDDEvices geschrieben wird, ist es mir also nicht möglich, das Regex so zu gestalten, dass es nur für ein Device passt, denn sobald es für irgendein Device passt wird es in alle Devices geschrieben.
Oder gibt es irgendeine Idendifikationsmöglichkeit der Devices, also eine interne ID oder sonst irgendetwas. Aber auch die würde mir ja nicht helfen.
Denn angenommen ich schreibe das Regex exact der Antwort von Device 2. Woher will denn Fhem wissen, dass das die Antwort von Device 2 ist.
Ich müsste also die Möglichkeit haben dem Regex noch die Info mitzugeben oder zurückzugeben, dass das match für device 2 galt.

Oder ich definiere ein dummy ECMD mit oder ohne einem ECMD-Device, deren Status mir egal ist und schreibe vom Programm aus, welches vom Reading der dummyclassdef gestartet wurde, dann die Statusbefehle für das "reale" Device. Das scheint mir aber umständlich...
Raspberry Pi B+
RS 485 Schnittstellen: DIGITUS DA-70157, LINKSPTITE RS485/GPIO Shield for Raspberry Pi
RS485 Geräte: Ultraschallsensor für Zisternenfüllstand (Eigenbau), 4x8 Relais-M-Mastermodule (Eigenbau), 6 T-Module (Schalter und 3 analoge Eingänge) (Eigenbau)
sonstige Hardware: 2 Relay Modul

NeuFehm

#29
Oder brauche ich einfach nur ein reading "on" und ein reading "off"?
Aber das ist zu banal...
Außerdem schaltet das reading ja dann eh wieder alle Relais auf on oder off...

gerade getestet, wie prognostiziert und den Weg wieder verworfen. :(
Komme nicht weiter.
Das war die entsprechende classdef:
0
reading on match "!M.*\001\r\n"
reading on postproc {ProcessmyECMD($_);}
reading off match "!M.*\000\r\n"
reading off postproc {ProcessmyECMD($_);}
Raspberry Pi B+
RS 485 Schnittstellen: DIGITUS DA-70157, LINKSPTITE RS485/GPIO Shield for Raspberry Pi
RS485 Geräte: Ultraschallsensor für Zisternenfüllstand (Eigenbau), 4x8 Relais-M-Mastermodule (Eigenbau), 6 T-Module (Schalter und 3 analoge Eingänge) (Eigenbau)
sonstige Hardware: 2 Relay Modul