diff --git a/fhem/FHEM/69_SoftliqCloud.pm b/fhem/FHEM/69_SoftliqCloud.pm index 1ef4da7ea..8c1c6baed 100644 --- a/fhem/FHEM/69_SoftliqCloud.pm +++ b/fhem/FHEM/69_SoftliqCloud.pm @@ -21,6 +21,7 @@ # ############################################################################## # Changelog: +# 0.1.07: - 2021-05-08 - Optimize garbage JSON processing # 0.1.06: - 2021-04-26 - Split JSON strings to avoid processing multiple root nodes # 0.1.05: Fixed setting numeric parameters # 0.1.04: ANother fix to avoid "garbage" in JSON @@ -55,7 +56,7 @@ use Digest::MD5 qw(md5); use FHEM::Core::Authentication::Passwords qw(:ALL); -my $version = "0.1.06"; +my $version = "0.1.07"; my $missingModul = ''; eval 'use MIME::Base64::URLSafe;1' or $missingModul .= 'MIME::Base64::URLSafe '; @@ -296,7 +297,7 @@ sub Define { $hash->{helper}->{passObj} = FHEM::Core::Authentication::Passwords->new( $hash->{TYPE} ); # get password form old storage and save to new format - if ( !defined(ReadPassword($hash)) ) { + if ( !defined( ReadPassword($hash) ) ) { if ( defined( ReadPasswordOld($hash) ) ) { my ( $passResp, $passErr ) = $hash->{helper}->{passObj}->setStorePassword( $name, ReadPasswordOld($hash) ); if ( defined($passErr) ) { @@ -1965,6 +1966,23 @@ sub Ready { return; } +sub splitTest { + my $buf = shift; + my $name = "sd18"; + my @bufs; + $buf =~ s///xsm; + my $index = index( $buf, '}{' ); + if ( $index > 0 ) { + Log3( $name, LOG_RECEIVE, "[$name] - Splitting double-JSON buffer" ); + push( @bufs, decode_json(substr( $buf, 0, $index + 1 ) )); + push( @bufs, decode_json(substr( $buf, $index + 1 ))); + } + else { + push( @bufs, $buf ); + } + return Dumper(@bufs); +} + sub wsReadDevIo { my $hash = shift; my $name = $hash->{NAME}; @@ -1976,6 +1994,7 @@ sub wsReadDevIo { } $buf =~ s///xsm; $buf =~ s/\\x\{1e\}//xsm; + #if ( !( $buf =~ /}$/xsm ) ) { # $buf = substr( $buf, 0, rindex( $buf, "}" ) ); #} @@ -1983,19 +2002,20 @@ sub wsReadDevIo { return; } Log3( $name, LOG_DEBUG, qq([$name] Received from DevIo: $buf) ); - + my @bufs; - my $index = index($buf, '}{'); - if ($index > 0) { - Log3 ($name, LOG_RECEIVE, "[$name] - Splitting double-JSON buffer"); - @bufs = split(/,/xsm,join($COMMA,substr($buf,0,$index),substr($buf,$index+1))); + my $index = index( $buf, '}{' ); + if ( $index > 0 ) { + Log3( $name, LOG_RECEIVE, "[$name] - Splitting double-JSON buffer" ); + push( @bufs, substr( $buf, 0, $index + 1 ) ); + push( @bufs, substr( $buf, $index + 1 ) ); } else { - push(@bufs,$buf); + push( @bufs, $buf ); } foreach my $bufi (@bufs) { - Log3 ($name, LOG_RECEIVE, "[$name] - Extracted".$bufi ); + Log3( $name, LOG_RECEIVE, "[$name] - Extracted" . $bufi ); parseWebsocketRead( $hash, $bufi ); }