ECMD NMEA-Daten verarbeiten

Begonnen von AlbinBallad, 16 Oktober 2018, 13:35:51

Vorheriges Thema - Nächstes Thema

AlbinBallad

Hallo Forenteilnehmer,

ich komme einfach nicht weiter bei der Verarbeitung von NMEA-Daten eines Windinstruments.
Dast Teil sendet unaufgefordert folgenden String im Sekundentakt über die Serielle Schnittstelle z.B.: $WIMWV,186,R,0,N,A*2C\r\n
Ich benötige hiervon die beiden Zahlenwerte Windrichtung (186) und Windgeschwindigkeit (0). Die Zahlen können von 1 bis 3 Stellen enthalten.

Folgende ECMD-Versionen sind im Einsatz:
66_ECMD.pm        16372 2018-03-10 13:09:24Z neubert
67_ECMDDevice.pm  12877 2016-12-26 09:15:55Z neubert

Definitionen in der fhem.cfg:

define NMEA_I0 ECMD serial /dev/ttyUSB0@4800
attr NMEA_I0 classdefs NMEA=/opt/fhem/NMEA.classdef
attr NMEA_I0 logTraffic 5
attr NMEA_I0 partial 2
attr NMEA_I0 split \n

define NMEA_Wind ECMDDevice NMEA WAngle
attr NMEA_Wind IODev NMEA_I0


Und hier das Problem, die Class-Datei:

params WAngle
#.
reading WAngle match ".*"
reading WAngle postproc { \d{1,3} }

Hatte gehofft, wenigstens den ersten Wert zu erhalten  - aber ich raffe es einfach nicht wie ich die regex definieren muss ?!




Auszug aus dem LOG
read $ (\044)
2018.10.16 12:49:56.596 5: NMEA_I0: Spontaneously received $ (\044)
2018.10.16 12:49:56.597 5: NMEA_I0: dispatch $
2018.10.16 12:49:56.599 5: NMEA_I0: partial message $WIMWV,186,R,0,N,A*2C\r\n (\044\127\111\115\127\126\054\061\070\066\054\122\054\060\054\116\054\101\052\062\103\015\012) expired.
2018.10.16 12:49:56.599 5: NMEA_I0: trying to match message $ (\044)
2018.10.16 12:49:56.601 5: NMEA_I0: partial message $ (\044) kept
2018.10.16 12:49:56.602 5: NMEA_I0: read WIM (\127\111\115)
2018.10.16 12:49:56.603 5: NMEA_I0: Spontaneously received WIM (\127\111\115)
2018.10.16 12:49:56.604 5: NMEA_I0: dispatch WIM
2018.10.16 12:49:56.606 5: NMEA_I0: merging partial message $ (\044) and WIM (\127\111\115)
2018.10.16 12:49:56.606 5: NMEA_I0: trying to match message $WIM (\044\127\111\115)
2018.10.16 12:49:56.608 5: NMEA_I0: partial message $WIM (\044\127\111\115) kept
2018.10.16 12:49:56.610 5: NMEA_I0: read WV, (\127\126\054)
2018.10.16 12:49:56.610 5: NMEA_I0: Spontaneously received WV, (\127\126\054)
2018.10.16 12:49:56.611 5: NMEA_I0: dispatch WV,
2018.10.16 12:49:56.612 5: NMEA_I0: merging partial message $WIM (\044\127\111\115) and WV, (\127\126\054)
2018.10.16 12:49:56.613 5: NMEA_I0: trying to match message $WIMWV, (\044\127\111\115\127\126\054)
2018.10.16 12:49:56.615 5: NMEA_I0: partial message $WIMWV, (\044\127\111\115\127\126\054) kept
2018.10.16 12:49:56.616 5: NMEA_I0: read 186 (\061\070\066)
2018.10.16 12:49:56.617 5: NMEA_I0: Spontaneously received 186 (\061\070\066)
2018.10.16 12:49:56.618 5: NMEA_I0: dispatch 186
2018.10.16 12:49:56.620 5: NMEA_I0: merging partial message $WIMWV, (\044\127\111\115\127\126\054) and 186 (\061\070\066)
2018.10.16 12:49:56.620 5: NMEA_I0: trying to match message $WIMWV,186 (\044\127\111\115\127\126\054\061\070\066)
2018.10.16 12:49:56.622 5: NMEA_I0: partial message $WIMWV,186 (\044\127\111\115\127\126\054\061\070\066) kept
2018.10.16 12:49:56.624 5: NMEA_I0: read ,R, (\054\122\054)
2018.10.16 12:49:56.624 5: NMEA_I0: Spontaneously received ,R, (\054\122\054)
2018.10.16 12:49:56.625 5: NMEA_I0: dispatch ,R,
2018.10.16 12:49:56.627 5: NMEA_I0: merging partial message $WIMWV,186 (\044\127\111\115\127\126\054\061\070\066) and ,R, (\054\122\054)
2018.10.16 12:49:56.628 5: NMEA_I0: trying to match message $WIMWV,186,R, (\044\127\111\115\127\126\054\061\070\066\054\122\054)
2018.10.16 12:49:56.629 5: NMEA_I0: partial message $WIMWV,186,R, (\044\127\111\115\127\126\054\061\070\066\054\122\054) kept
2018.10.16 12:49:56.631 5: NMEA_I0: read 0,N, (\060\054\116\054)
2018.10.16 12:49:56.632 5: NMEA_I0: Spontaneously received 0,N, (\060\054\116\054)
2018.10.16 12:49:56.632 5: NMEA_I0: dispatch 0,N,
2018.10.16 12:49:56.634 5: NMEA_I0: merging partial message $WIMWV,186,R, (\044\127\111\115\127\126\054\061\070\066\054\122\054) and 0,N, (\060\054\116\054)
2018.10.16 12:49:56.635 5: NMEA_I0: trying to match message $WIMWV,186,R,0,N, (\044\127\111\115\127\126\054\061\070\066\054\122\054\060\054\116\054)
2018.10.16 12:49:56.636 5: NMEA_I0: partial message $WIMWV,186,R,0,N, (\044\127\111\115\127\126\054\061\070\066\054\122\054\060\054\116\054) kept
2018.10.16 12:49:56.638 5: NMEA_I0: read A*2 (\101\052\062)
2018.10.16 12:49:56.638 5: NMEA_I0: Spontaneously received A*2 (\101\052\062)
2018.10.16 12:49:56.639 5: NMEA_I0: dispatch A*2
2018.10.16 12:49:56.641 5: NMEA_I0: merging partial message $WIMWV,186,R,0,N, (\044\127\111\115\127\126\054\061\070\066\054\122\054\060\054\116\054) and A*2 (\101\052\062)
2018.10.16 12:49:56.642 5: NMEA_I0: trying to match message $WIMWV,186,R,0,N,A*2 (\044\127\111\115\127\126\054\061\070\066\054\122\054\060\054\116\054\101\052\062)
2018.10.16 12:49:56.643 5: NMEA_I0: partial message $WIMWV,186,R,0,N,A*2 (\044\127\111\115\127\126\054\061\070\066\054\122\054\060\054\116\054\101\052\062) kept
2018.10.16 12:49:56.645 5: NMEA_I0: read C\r\n (\103\015\012)
2018.10.16 12:49:56.646 5: NMEA_I0: Spontaneously received C\r\n (\103\015\012)
2018.10.16 12:49:56.647 5: NMEA_I0: dispatch C\r\n
2018.10.16 12:49:56.648 5: NMEA_I0: merging partial message $WIMWV,186,R,0,N,A*2 (\044\127\111\115\127\126\054\061\070\066\054\122\054\060\054\116\054\101\052\062) and C\r\n (\103\015\012)
2018.10.16 12:49:56.650 5: NMEA_I0: trying to match message $WIMWV,186,R,0,N,A*2C\r\n (\044\127\111\115\127\126\054\061\070\066\054\122\054\060\054\116\054\101\052\062\103\015\012)
2018.10.16 12:49:56.651 5: NMEA_I0: partial message $WIMWV,186,R,0,N,A*2C\r\n (\044\127\111\115\127\126\054\061\070\066\054\122\054\060\054\116\054\101\052\062\103\015\012) kept
2018.10.16 12:49:58.969 5: NMEA_I0: read $ (\044)
2018.10.16 12:49:58.969 5: NMEA_I0: Spontaneously received $ (\044)
2018.10.16 12:49:58.970 5: NMEA_I0: dispatch $
2018.10.16 12:49:58.972 5: NMEA_I0: partial message $WIMWV,186,R,0,N,A*2C\r\n (\044\127\111\115\127\126\054\061\070\066\054\122\054\060\054\116\054\101\052\062\103\015\012) expired.



Prof. Dr. Peter Henning

Tipp: Auswertung des Datenstrings in Perl machen, nicht im Modul.

LG

pah

AlbinBallad

So, nach einer Mütze voll Schlaf einem neuen Anlauf ergibt folgende classdef die Lösung:

/opt/fhem/NMEA.classdef                                                                             
params WAngle WSpeed

reading WAngle match ".*\n"
reading WAngle postproc {\
my @array = split(/,/,$_);\
my $angle = $array[1]+150.0;\
if ($angle >= 360.) { $angle = $angle-360.};\
sprintf("%3d", $angle);\
}

reading WSpeed match ".*\n"
reading WSpeed postproc {\
my @array = split(/,/,$_);\
sprintf("%3d", $array[3]);\
}

Damit habe ich die Readings WAngle und WSpeed. Vielleicht nicht die Beste Lösung aber es klappt.  ;)