use strict; use warnings; use Mojo::UserAgent; use Mojo::JSON qw(decode_json); use Encode qw(encode); my $ua = Mojo::UserAgent->new; $ua->websocket("wss://ws1.blitzortung.org/" => sub { my ($ua, $tx) = @_; print "WebSocket handshake failed!\n" and return unless $tx->is_websocket; $tx->on(message => sub { my ($tx, $chars) = @_; $chars = blitz_decode($chars); my $bytes = encode('UTF-8', $chars, Encode::FB_CROAK); my $hash = decode_json $bytes; use Data::Dumper; print "message ", Dumper $hash; }); $tx->send({json=>{a=>111}}); }); Mojo::IOLoop->start unless Mojo::IOLoop->is_running; # code from https://github.com/mrk-its/homeassistant-blitzortung/issues/74 sub blitz_decode { my ($data) = @_; my %e; my @d = split //, $data; my @g = my $f = my $c = $d[0]; my $o = 256; for my $ind (1..$#d) { my $ord = ord($d[$ind]); my $str = $ord < 256 ? $d[$ind] : exists $e{$ord} ? $e{$ord} : $f . $c; push @g, $str; $c = substr $str, 0, 1; $e{$o++} = $f . $c; $f = $str; } join('', @g); }