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.

In reply to Re: Module name: PDL::WebSocket? by etj
in thread Module name: PDL::WebSocket? by etj

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.