in reply to Module name: PDL::WebSocket?

I thought the relatively easy part of this would be to make a script that connected to the lightningmaps server and printed out the events. I haven't done the PDL/3D side yet, but 4 hours of agony wasn't incredibly easy. This was mainly due to lightningmaps "proper" having a somewhat complicated protocol you have to keep sending it, and the quasi-underlying blitzortung service doing some overly-clever compression on its messages (see https://github.com/mrk-its/homeassistant-blitzortung/issues/74 for a Python decoder, and my Perl port). Nevertheless, here is a script that will spam your terminal with JSON messages about lightning strikes around the world:
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_webs +ocket; $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/issue +s/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); }
Edit to add: actually, the user-facing lightningmaps protocol is revealed by reading the JS (see https://www.lightningmaps.org/min/index.php?f=js/realtime.js&1687455813), which isn't overly minified, and with text-search for data.ws. shows what's being sent and received. The blitzortung JS on the other hand goes all in on minification, including actually obfuscating var names with randomised hex numbers.