Skip to content

Commit

Permalink
Extension for receiving WMBus messages (#1281)
Browse files Browse the repository at this point in the history
* WMBus enabled
* adaptation tests
  • Loading branch information
elektron-bbs authored Jan 6, 2025
1 parent 05e90de commit 239ad5e
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 31 deletions.
47 changes: 33 additions & 14 deletions FHEM/00_SIGNALduino.pm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# $Id: 00_SIGNALduino.pm 3.5.6 2024-12-03 16:26:12Z elektron-bbs $
# $Id: 00_SIGNALduino.pm 3.5.7 2024-12-23 12:38:38Z elektron-bbs $
# v3.5.6 - https://github.com/RFD-FHEM/RFFHEM/tree/master
# The module is inspired by the FHEMduino project and modified in serval ways for processing the incoming messages
# see http://www.fhemwiki.de/wiki/SIGNALDuino
Expand All @@ -8,7 +8,7 @@
#
# 2014-2015 S.Butzek, N.Butzek
# 2016-2019 S.Butzek, Ralf9
# 2019-2023 S.Butzek, HomeAutoUser, elektron-bbs
# 2019-2024 S.Butzek, HomeAutoUser, elektron-bbs


package main;
Expand Down Expand Up @@ -42,7 +42,7 @@ use List::Util qw(first);


use constant {
SDUINO_VERSION => '3.5.6+20240410', # Datum wird automatisch bei jedem pull request aktualisiert
SDUINO_VERSION => '3.5.7+20241101', # Datum wird automatisch bei jedem pull request aktualisiert
SDUINO_INIT_WAIT_XQ => 1.5, # wait disable device
SDUINO_INIT_WAIT => 2,
SDUINO_INIT_MAXRETRY => 3,
Expand Down Expand Up @@ -82,7 +82,7 @@ my %gets = ( # NameOFCommand => StyleMod for Fhemweb, SubToCall if get is exec
'uptime' => ['noArg', \&SIGNALduino_Get_Command, "t", \&SIGNALduino_CheckUptimeResponse, '^[0-9]+' ],
'cmds' => ['noArg', \&SIGNALduino_Get_Command, "?", \&SIGNALduino_CheckCmdsResponse, '.*' ],
'ping' => ['noArg', \&SIGNALduino_Get_Command, "P", \&SIGNALduino_GetResponseUpdateReading, '^OK$' ],
'config' => ['noArg', \&SIGNALduino_Get_Command, "CG", \&SIGNALduino_GetResponseUpdateReading, '^MS.*MU.*MC.*' ],
'config' => ['noArg', \&SIGNALduino_Get_Command, "CG", \&SIGNALduino_GetResponseUpdateReading, '^M[S|N]=.*' ],
'ccconf' => ['noArg', \&SIGNALduino_Get_Command, "C0DnF", \&SIGNALduino_CheckccConfResponse, 'C0Dn11=[A-F0-9a-f]+'],
'ccreg' => ['textFieldNL', \&SIGNALduino_Get_Command_CCReg,"C", \&SIGNALduino_CheckCcregResponse, '^(?:C[A-Fa-f0-9]{2}\s=\s[0-9A-Fa-f]+$|ccreg 00:)'],
'ccpatable' => ['noArg', \&SIGNALduino_Get_Command, "C3E", \&SIGNALduino_CheckccPatableResponse, '^C3E\s=\s.*'],
Expand Down Expand Up @@ -691,6 +691,9 @@ sub SIGNALduino_Set_raw {
my ($hash, @a) = @_;
$hash->{logMethod}->($hash->{NAME}, 4, "$hash->{NAME}: Set_raw, ".join(' ',@a));
SIGNALduino_AddSendQueue($hash,$a[1]);
if ($a[1] eq 'e') {
SIGNALduino_AddSendQueue($hash,'CDW'); # disable WMBus
}
if ($a[1] =~ m/^C[D|E]R/) { # enable/disable data reduction
SIGNALduino_Get_Command($hash,'config');
}
Expand Down Expand Up @@ -766,11 +769,16 @@ sub SIGNALduino_Attr_rfmode {
if ( (InternalVal($hash->{NAME},"cc1101_available",0) == 0) && (!IsDummy($hash->{NAME})) ) {
return 'ERROR: This attribute is only available for a receiver with CC1101.';
}

my $hardware = AttrVal($hash->{NAME},'hardware','unknown');
if ($aVal =~ /^WMBus_/ && substr($hardware,0,3) ne 'esp') {
return 'ERROR: This attribute is only available for a receiver with ESP8266 or ESP32.';
}

## DevState waitInit is on first start after FHEM restart | initialized is after cc1101 available
if ( ($hash->{DevState} eq 'initialized') && (InternalVal($hash->{NAME},"cc1101_available",0) == 1) ) {
$hash->{logMethod}->($hash->{NAME}, 3, "$hash->{NAME}: Set_rfmode, set to $aVal on DevState $hash->{DevState} (please check activated protocols via 'Display protocollist')");

SIGNALduino_AddSendQueue($hash,'CDW'); # disable WMBus
my $rfmode;
if ($aVal ne 'SlowRF') {
if ( scalar( @{$hash->{mnIdList}} ) >= 1 ) {
Expand All @@ -784,13 +792,22 @@ sub SIGNALduino_Attr_rfmode {

if ($register != -1) {
$hash->{logMethod}->($hash->{NAME}, 5, qq[$hash->{NAME}: Set_rfmode, register settings exist on ID=$id ]);

SIGNALduino_AddSendQueue($hash,'WS36'); # SIDLE, Exit RX / TX, turn off frequency synthesizer
SIGNALduino_AddSendQueue($hash,'WS3A'); # SFRX, Flush the RX FIFO buffer. Only issue SFRX in IDLE or RXFIFO_OVERFLOW states.
for my $i (0...scalar(@{$register})-1) {
$hash->{logMethod}->($hash->{NAME}, 5, "$hash->{NAME}: Set_rfmode, write value " . @{$register}[$i]);
my $argcmd = sprintf("W%02X%s",hex(substr(@{$register}[$i],0,2)) + 2,substr(@{$register}[$i],2,2));
main::SIGNALduino_AddSendQueue($hash,$argcmd);
}
main::SIGNALduino_WriteInit($hash);
main::SIGNALduino_WriteInit($hash); # set cc1101 SIDLE and then SRX
if ($rfmode =~ /^WMBus_/) {
if ($rfmode eq 'WMBus_S') {
SIGNALduino_AddSendQueue($hash,'CDT'); # WMBus_S
} else {
SIGNALduino_AddSendQueue($hash,'CET'); # enable WMBus_T
}
SIGNALduino_AddSendQueue($hash,'CEW'); # enable WMBus
}
last MNIDLIST; # found $rfmode, exit loop
} else {
$hash->{logMethod}->($hash->{NAME}, 1, "$hash->{NAME}: Set_rfmode, set to $aVal (ID $id, no register entry found in protocols)");
Expand Down Expand Up @@ -1686,14 +1703,15 @@ sub SIGNALduino_SendFromQueue {
} elsif ($msg =~ "^e") { # Werkseinstellungen
SIGNALduino_Get($hash,$name,'ccconf');
SIGNALduino_Get($hash,$name,'ccpatable');

SIGNALduino_Get($hash,$name,'config');
## set rfmode to default from uC
my $rfmode = AttrVal($name, 'rfmode', undef);
CommandAttr($hash,"$name rfmode SlowRF") if (defined $rfmode && $rfmode ne 'SlowRF'); # option with save question mark

} elsif ($msg =~ "^W(?:0F|10|11|1D|12|17|1F)") { # SetFreq, setrAmpl, Set_bWidth, SetDeviatn, SetSens
} elsif ($msg =~ "^W(?:0F|10|11|1D|12|17|1F)") { # cc1101_freq, cc1101_rAmpl, cc1101_bWidth, cc1101_deviatn, cc1101_sens
SIGNALduino_Get($hash,$name,'ccconf');
} elsif ($msg =~ "^x") { # patable
SIGNALduino_Get($hash,$name,'config');
} elsif ($msg =~ "^x") { # cc1101_patable
SIGNALduino_Get($hash,$name,'ccpatable');
}
# elsif ($msg eq 'C99') {
Expand Down Expand Up @@ -3079,6 +3097,7 @@ sub SIGNALduino_WriteInit {

# todo: ist dies so ausreichend, damit die Aenderungen uebernommen werden?
SIGNALduino_AddSendQueue($hash,'WS36'); # SIDLE, Exit RX / TX, turn off frequency synthesizer
SIGNALduino_AddSendQueue($hash,'WS3A'); # SFRX, Flush the RX FIFO buffer. Only issue SFRX in IDLE or RXFIFO_OVERFLOW states.
SIGNALduino_AddSendQueue($hash,'WS34'); # SRX, Enable RX. Perform calibration first if coming from IDLE and MCSM0.FS_AUTOCAL=1.
}

Expand Down Expand Up @@ -4884,11 +4903,11 @@ USB-connected devices (SIGNALduino):<br>
modulation ASK/OOK, <b>loads the standard setting from the uC</b>
</li>
<li>WMBus_S<br>
modulation FSK, Datarate=32.768 kbps, Sync Word=7696, frequency 868.300 MHz (processing needs to be integrated into firmware)
modulation FSK, Datarate=32.768 kbps, Sync Word=7696, frequency 868.300 MHz
<ul><small>example: water, gas, heat, electric meters and the data collecting devices</small></ul>
</li>
<li>WMBus_T<br>
modulation FSK, Datarate=100.0 kbps, Sync Word=543D, frequency 868.950 MHz (processing needs to be integrated into firmware)
modulation FSK, Datarate=100.0 kbps, Sync Word=543D, frequency 868.950 MHz
<ul><small>example: water, gas, heat, electric meters and the data collecting devices</small></ul>
</li>
</ul>
Expand Down Expand Up @@ -5499,11 +5518,11 @@ USB-connected devices (SIGNALduino):<br>
Modulation ASK/OOK, <b>l&auml;d die Standard Einstellung vom uC</b>
</li>
<li>WMBus_S<br>
Modulation FSK, Datenrate=32.768 kbps, Sync Word=7696, Frequenz 868.300 MHz (Verarbeitung muss noch in Firmware integriert werden)
Modulation FSK, Datenrate=32.768 kbps, Sync Word=7696, Frequenz 868.300 MHz
<ul><small>Beispiel: diverse Wasser-, Gas-, Wärme- und Stromzähler sowie die Datenerfassungsgeräte</small></ul>
</li>
<li>WMBus_T<br>
Modulation FSK, Datenrate=100.0 kbps, Sync Word=543D, Frequenz 868.950 MHz (Verarbeitung muss noch in Firmware integriert werden)
Modulation FSK, Datenrate=100.0 kbps, Sync Word=543D, Frequenz 868.950 MHz
<ul><small>Beispiel: diverse Wasser-, Gas-, Wärme- und Stromzähler sowie die Datenerfassungsgeräte</small></ul>
</li>
</ul>
Expand Down
20 changes: 7 additions & 13 deletions FHEM/lib/SD_ProtocolData.pm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# $Id: SD_ProtocolData.pm 26975 2024-12-03 16:26:12Z elektron-bbs $
# $Id: SD_ProtocolData.pm 26975 2024-12-23 12:38:38Z elektron-bbs $
# The file is part of the SIGNALduino project.
# All protocol definitions are contained in this file.
#
Expand Down Expand Up @@ -85,7 +85,7 @@ package lib::SD_ProtocolData;
use strict;
use warnings;

our $VERSION = '1.57';
our $VERSION = '1.58';
our %protocols = (
"0" => ## various weather sensors (500 | 9100)
# Mebus | Id:237 Ch:1 T: 1.9 Bat:low MS;P0=-9298;P1=495;P2=-1980;P3=-4239;D=1012121312131313121313121312121212121212131212131312131212;CP=1;SP=0;R=223;O;m2;
Expand Down Expand Up @@ -3542,8 +3542,6 @@ package lib::SD_ProtocolData;
},
"133" => # WMBus_S
# https://wiki.fhem.de/wiki/WMBUS
# note !!! Implementation in the FW still needs to be done, register settings are not sufficient
# - definition is in advance in order to dispatch a DMSG | https://github.com/RFD-FHEM/RFFHEM/issues/1247
{
name => 'WMBus_S',
comment => 'WMBus mode S',
Expand All @@ -3552,21 +3550,18 @@ package lib::SD_ProtocolData;
datarate => '32.720',
preamble => 'b',
modulation => '2-FSK',
sync => '7696',
rfmode => 'WMBus_S',
# registers need to be adjusted and can be optimized if necessary
register => ['0006','012E','0200','0300','0476','0596','06FF','0704','0802','0900','0A00','0B08','0C00','0D21','0E65','0F6A','106A','114A','1206','1322','14F8','1547','1607','1700','1818','192E','1A6D','1B04','1C09','1DB2','1E87','1F6B','20F8','21B6','2210','23EF','242A','2512','261F','2741'],
register => ['0006','0200','0340','0476','0596','06FF','0704','0802','0B08','0D21','0E65','0F6A','106A','114A','1206','1322','14F8','1547','192E','1A6D','1B04','1C09','1DB2'],
length_min => '56', # to filter messages | must check
clientmodule => 'WMBUS',
#regexMatch => qr/^b/, # ToDo, check! fuer eine regexp Pruefung am Anfang vor dem method Aufruf
},
"134" => # WMBus_T
# https://wiki.fhem.de/wiki/WMBUS
# note !!! Implementation in the FW still needs to be done, register settings are not sufficient
# - definition is in advance in order to dispatch a DMSG | https://github.com/RFD-FHEM/RFFHEM/issues/1247
# messages with normal identifier
# RAWMSG: MN;D=3E44FA1213871122011633057A1C002025417CD28E06770269857D8001EF3B8BBE56BA7E06855CBA0334149F51682F2E6E2960E6900F800C0001090086B41E003A6F140131414D7D88810A;R=10;A=16;
# DMSG: b3E44FA1213871122011633057A1C002025417CD28E06770269857D8001EF3B8BBE56BA7E06855CBA0334149F51682F2E6E2960E6900F800C0001090086B41E003A6F140131414D7D88810A
# messages with Y identifier
# messages with Y identifier for frame type B
# RAWMSG: MN;D=Y304497264202231800087A3E0020A5EE5B2074920E46E4B4A26B99C92C8DD3A55F44FAF6AE0256B354F9C48C717BFAD43400FB;R=251;A=0;
# DMSG: bY304497264202231800087A3E0020A5EE5B2074920E46E4B4A26B99C92C8DD3A55F44FAF6AE0256B354F9C48C717BFAD43400FB
{
Expand All @@ -3577,12 +3572,11 @@ package lib::SD_ProtocolData;
datarate => '100.000',
preamble => 'b',
modulation => '2-FSK',
sync => '543D',
rfmode => 'WMBus_T',
# registers need to be adjusted and can be optimized if necessary
register => ['0006','012E','0200','0300','0454','053D','06FF','0704','0802','0900','0A00','0B08','0C00','0D21','0E6B','0FD0','105C','1104','1206','1322','14F8','1544','1607','1700','1818','192E','1ABF','1B43','1C09','1DB5','1E87','1F6B','20F8','21B6','2210','23EF','242A','2513','261F','2741'],
register => ['0006','0200','0340','0454','053D','06FF','0704','0802','0B08','0D21','0E6B','0FD0','105C','1104','1206','1322','14F8','1544','192E','1ABF','1BC7','1C09','1DB2'],
length_min => '56', # to filter messages | must check
clientmodule => 'WMBUS',
#regexMatch => qr/^b/, # ToDo, check! fuer eine regexp Pruefung am Anfang vor dem method Aufruf
},

########################################################################
Expand Down
4 changes: 2 additions & 2 deletions controls_signalduino.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
UPD 2024-12-04_17:09:11 241885 FHEM/00_SIGNALduino.pm
UPD 2024-12-23_13:38:11 242922 FHEM/00_SIGNALduino.pm
UPD 2023-01-06_12:08:43 20082 FHEM/10_FS10.pm
UPD 2024-01-03_23:05:39 27250 FHEM/10_SD_GT.pm
UPD 2023-01-01_18:10:40 25403 FHEM/10_SD_Rojaflex.pm
Expand All @@ -14,5 +14,5 @@ UPD 2023-01-23_21:06:26 38569 FHEM/14_SD_WS09.pm
UPD 2023-01-09_19:54:48 16458 FHEM/14_SD_WS_Maverick.pm
UPD 2023-01-28_20:08:00 40378 FHEM/41_OREGON.pm
UPD 2020-12-17_23:16:30 15582 FHEM/90_SIGNALduino_un.pm
UPD 2024-12-04_17:09:11 255170 FHEM/lib/SD_ProtocolData.pm
UPD 2024-12-23_13:38:11 254167 FHEM/lib/SD_ProtocolData.pm
UPD 2024-01-06_20:21:35 81862 FHEM/lib/SD_Protocols.pm
4 changes: 2 additions & 2 deletions t/FHEM/00_SIGNALduino/02_SIGNALduino_SendFromQueue.t
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ InternalTimer(time()+1, sub {
my $tracking = $mock->sub_tracking;

SIGNALduino_SendFromQueue($targetHash,"e");
is(scalar @{$tracking->{SIGNALduino_Get}},2,"SIGNALduino_Get called twice");
is(scalar @{$tracking->{SIGNALduino_Get}},3,"SIGNALduino_Get called twice");
is($tracking->{SIGNALduino_Get}[1]{args}[2], "ccpatable", "check get with ccpatable is executed" );
$mock->restore('SIGNALduino_Get');
is($attr{$target}{rfmode},U,'verify attr rfmode');
Expand Down Expand Up @@ -101,7 +101,7 @@ InternalTimer(time()+1, sub {
my $tracking = $mock->sub_tracking;

SIGNALduino_SendFromQueue($targetHash,"$_");
is(scalar @{$tracking->{SIGNALduino_Get}},1,"SIGNALduino_Get called once");
is(scalar @{$tracking->{SIGNALduino_Get}},2,"SIGNALduino_Get called once");
is($tracking->{SIGNALduino_Get}[0]{args}[2], "ccconf", "check get with ccconf is executed" );
$mock->restore('SIGNALduino_Get');
};
Expand Down
10 changes: 10 additions & 0 deletions t/FHEM/00_SIGNALduino/03_SIGNALduino_Set.t
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ InternalTimer(time()+1, sub {
item match qr/^W1062$/;
item match qr/^W1176$/;
item 'WS36';
item 'WS3A';
item 'WS34';
end();
};
Expand All @@ -147,6 +148,7 @@ InternalTimer(time()+1, sub {
item match qr/^W10b0$/;
item match qr/^W1171$/;
item 'WS36';
item 'WS3A';
item 'WS34';
end();
};
Expand Down Expand Up @@ -176,6 +178,7 @@ InternalTimer(time()+1, sub {
item match qr/^W1062$/;
item match qr/^W1176$/;
item 'WS36';
item 'WS3A';
item 'WS34';
end();
};
Expand Down Expand Up @@ -213,6 +216,7 @@ InternalTimer(time()+1, sub {
return array {
item match qr/W1D[\dA-Fa-f]{2}/;
item 'WS36';
item 'WS3A';
item 'WS34';
end();
};
Expand All @@ -226,6 +230,7 @@ InternalTimer(time()+1, sub {
return array {
item match qr/W1F[\dA-Fa-f]{2}/;
item 'WS36';
item 'WS3A';
item 'WS34';
end();
};
Expand All @@ -240,6 +245,7 @@ InternalTimer(time()+1, sub {
return array {
item 'x84';
item 'WS36';
item 'WS3A';
item 'WS34';
end();
};
Expand All @@ -266,6 +272,7 @@ InternalTimer(time()+1, sub {
return array {
item 'x81';
item 'WS36';
item 'WS3A';
item 'WS34';
end();
};
Expand All @@ -281,6 +288,7 @@ InternalTimer(time()+1, sub {
return array {
item 'x84';
item 'WS36';
item 'WS3A';
item 'WS34';
end();
};
Expand Down Expand Up @@ -381,6 +389,7 @@ InternalTimer(time()+1, sub {
item 'W0F23';
item 'W3022';
item 'WS36';
item 'WS3A';
item 'WS34';
end();
};
Expand Down Expand Up @@ -800,6 +809,7 @@ InternalTimer(time()+1, sub {
item 'C10';
item 'W1257';
item 'WS36';
item 'WS3A';
item 'WS34';
end();
} ,"Verify expected queue element entrys");
Expand Down

0 comments on commit 239ad5e

Please sign in to comment.