Raspberry Pi Lightning Detector v4.0

So it is an issue with the code, not my installation?
I seem to have the data being sent to MQTT, but nothing on the web page as per midenison.

Got it working by adding:
allow_anonymous true
to:
/etc/mosquitto/conf.d/websockets.conf

2 Likes

Thank you for finding that and giving us the answer. I didn’t know where the problem was but that’s mostly because I shelved the project during very quiet thunderstorm period. I have no way of testing without storms. Hopefully the increased solar activity might trigger some more lightning storms this year!

Just had the same issue, spent a week sorting this out to work and inject data into Weewx. A storm went past with very close strikes and nothing was detected. Really bummed here too. I wish there was a better way to test.

You sir are a genius

I had the same issue and this fixed it for me many thanks.

1 Like

when i tried updating my Pi 4 a couple of months ago the lightning stopped working do not know why so currently powered off

I have a replacement Development Pi now and I’m currently rebuilding it so that I can put the Lightning software back on it. The Pi is on my network so now it’s software load time.

EDIT:

I have the software installed and after making the following change (I assume a change to the MQTT server needs this) it’s running as I remember it did.

So I’m back up and running, but also back to the point where was before the Pi hardware shortage hit, namely waiting for a thuderstorm. The nearest lightning seems to be about 400km away so well outside the sensor range. I wish I had a handheld unit that would be reliably detected as lightning! Properly testing the code is difficult without the ability to see lightning - real or fake.

Couple of months ago I updated my pi4 after that the lightning failed to work I suspect the update has upset thing and it probably need a fresh install but as it did not in my case pick up lightning on Christmas Eve that I got a picture of so decided to turn it off but may get back to it in the future when time and life allows

I’ve found a lightning simulator that can be used to test the AS3935 and other lightning detectors. It’s coming from halfway round the world (WA, USA) and it’s not cheap but it will be good to be able to test the hardware and software. I suspect it might be a week or so before it arrives but I’ll let you know what I find when it’s here.

One of our members had a Van de Graaff generator in his garage, but his website has been suspended. . .

I hope he wasn’t charged with electrocuting people!

It lives!

We’ve just had a thunderstorm but I missed the start of it. The power was off in the house yesterday and I’d not restarted the Pi that’s running the AS3935 software. I quickly got it up and running but there was only one strike that I know of after that. The AS3935 seems to have detected that one. All the false strikes I’ve ever seen have shown as 1km away. This strike was 5km away which was about the distance to the storm.

Lightning tester has arrived but I don’t think I’ll be able to properly test it for a few days because we have long-time friends in town to see us.

Chris,
Thank you for this fantastic walkthrough. You’re the only SPI config of a lightning detector I can find, and it’s awesome to have the apache and MQTT components as well. I’ve learned a lot in my failures to get this thing working!
I’m building the raspberry pi weather station project:
https://projects.raspberrypi.org/en/projects/build-your-own-weather-station
and adding a sparkfun lightning detector to it. I had to redo the wiring for the weather station to accommodate the SPI wiring of the lightning detector. For now, however, I’ve removed the lightning detector and put it on it’s own breadboard with it’s own raspberry pi (I bought them before covid, so they were cheaper then :blush:). Everything seems to be working, except…… it doesn’t detect any lighting, disturbances, or noises!
Here’s the result of: sudo python3 as3935_pigpio_test.py 0:

And here’s the apache:

I’ve tried various permutations of bus and address in as3935_config.py, but I get a python error if I even try to change the bus to = 1, so I assume my bus needs to be 0. (That’s how it’s wired too!) Do you have any ideas of where I can go from here?

Thanks!

Chris

Hi Chris

Regarding bus - default is bus 0 and whilst the Pi can support two buses it’s rare that you’d need the second one so it’s just there in case. You pigpio output looks reasonable. That means you probably have the correct address configured because the code seems to be able to access the AS3935 registers. You usually get all zeros if it’s not able to see the sensor. I’m surprised that you get no detections though…whilst I don’t see strikes, I get loads of disturbers and quite a few noises.

I’m still looking into my own installation. The lightning simulator sometimes generates a strike, but not reliably, even when it’s in the same place compared to the sensor. So I’m starting to go back to basics and trying to get some code working from another source to see if that more reliably recognises strikes. Despite the other code saying that it supports the SPI connection I get an error saying the sensor isn’t detected. So that’s slowed me down. I also need to find time to do a deeper dive and monitor the sensor pins whilst triggering a strike to see if I can see any difference in output. I want to check whether the sensor is sending an interrupt that isn’t being detected on the Pi for some reason.

I also want to modify the code to just continuously loop reading the registers in real time and looking for changed values. That’s like doing the pin monitoring…seeing if the sensor is seeing strikes that aren’t being picked up for some reason.

So in summary, I’ve no ideas to help you right now but as soon as I’ve got something to go on I’ll let you know.

Hi Chris,

Appreciate the quick response, and thank you for continuing to look. If there’s anything I can do, especially code-wise, let me know. For your installation, is this faulty detection new? You wrote v’s 1-3 as well, correct? Are you questioning the SPI setup? Were you I2C before?

As to my set up, I forgot to mention that I left my entire weather station setup on the old raspberry pi / breadboard with just the lightning detector header left, so I can easily move the lighting detector board back to the main set up easily when we solve this problem. The webpage readout is exactly as I published in my original question: meaning the headers are all there but so is the data as all zero strikes/noises. This implies that mosquitto is still running and reading nothing, just like in my new setup. So it’s just not reading the board at all is my conclusion. That all said, if I switch in the configuration file to simulate strikes, I do get those:

Thanks again!

Chris

Good afternoon,
I tried v4 (and v3.2) on a RPi3 and both did not work.

I have:

From ChangeLog.txt:
4.1 - Released 10Sep2020

and the Thunderclip directly connected with wires 3.3V, GND, GPIO10, GPIO9, GPIO11, GPIO8 (see SPI at Raspberry Pi GPIO Pinout).
The test works:

pi@raspberrypi:~/Sensors $ sudo python3 as3935_pigpio_test.py 
Test starting
Good version of pigpio found - Version 79
Register 0x00 is 0x24
Register 0x01 is 0x02
Register 0x02 is 0xC2
Register 0x03 is 0x04
Register 0x04 is 0xAA
Register 0x05 is 0xE0
Register 0x06 is 0x07
Register 0x07 is 0x3F
Register 0x08 is 0x0A
Test complete

But the calibration not!

pi@raspberrypi:~/Sensors $ sudo python3 calibrate_pig.py 
Starting calibration run - Please wait approximately 16 seconds
calibration_run - At 0 pF 0.0 IRQs/sec with variance from ideal of -3906.2 ( -100.00 %)
calibration_run - At 8 pF 0.0 IRQs/sec with variance from ideal of -3906.2 ( -100.00 %)
calibration_run - At 16 pF 0.0 IRQs/sec with variance from ideal of -3906.2 ( -100.00 %)
calibration_run - At 24 pF 0.0 IRQs/sec with variance from ideal of -3906.2 ( -100.00 %)
calibration_run - At 32 pF 0.0 IRQs/sec with variance from ideal of -3906.2 ( -100.00 %)
calibration_run - At 40 pF 0.0 IRQs/sec with variance from ideal of -3906.2 ( -100.00 %)
calibration_run - At 48 pF 0.0 IRQs/sec with variance from ideal of -3906.2 ( -100.00 %)
calibration_run - At 56 pF 0.0 IRQs/sec with variance from ideal of -3906.2 ( -100.00 %)
calibration_run - At 64 pF 0.0 IRQs/sec with variance from ideal of -3906.2 ( -100.00 %)
calibration_run - At 72 pF 0.0 IRQs/sec with variance from ideal of -3906.2 ( -100.00 %)
calibration_run - At 80 pF 0.0 IRQs/sec with variance from ideal of -3906.2 ( -100.00 %)
calibration_run - At 88 pF 0.0 IRQs/sec with variance from ideal of -3906.2 ( -100.00 %)
calibration_run - At 96 pF 0.0 IRQs/sec with variance from ideal of -3906.2 ( -100.00 %)
calibration_run - At 104 pF 0.0 IRQs/sec with variance from ideal of -3906.2 ( -100.00 %)
calibration_run - At 112 pF 0.0 IRQs/sec with variance from ideal of -3906.2 ( -100.00 %)
calibration_run - At 120 pF 0.0 IRQs/sec with variance from ideal of -3906.2 ( -100.00 %)
Failure - minimum variance ( 100.00 %) > 3.5% of LCO frequency

Which brings me to the problem with ā€˜irq_cb.cancel()’ and ā€˜UnboundLocalError: cannot access local variable ā€˜irq_>’’. Do you think the device is working after even if the calibration does not work?

sudo systemctl status as3935_monitor.service
ā— as3935_monitor.service - AS3935 Monitor service
     Loaded: loaded (/lib/systemd/system/as3935_monitor.service; enabled; preset: enabled)
     Active: active (running) since Sat 2024-08-17 19:16:41 CEST; 16min ago
   Main PID: 2280 (python3)
      Tasks: 3 (limit: 1557)
        CPU: 19.656s
     CGroup: /system.slice/as3935_monitor.service
             ā”œā”€2280 /usr/bin/python3 /home/pi/Sensors/as3935_monitor.py
             └─2292 /usr/bin/python3 /home/pi/Sensors/as3935_monitor.py

Aug 17 19:16:59 raspberrypi python3[2281]: Process Process-1:
Aug 17 19:16:59 raspberrypi python3[2281]: Traceback (most recent call last):
Aug 17 19:16:59 raspberrypi python3[2281]:   File "/usr/lib/python3.11/multiprocessing/process.p>
Aug 17 19:16:59 raspberrypi python3[2281]:     self.run()
Aug 17 19:16:59 raspberrypi python3[2281]:   File "/usr/lib/python3.11/multiprocessing/process.p>
Aug 17 19:16:59 raspberrypi python3[2281]:     self._target(*self._args, **self._kwargs)
Aug 17 19:16:59 raspberrypi python3[2281]:   File "/home/pi/Sensors/as3935_monitor.py", line 180>
Aug 17 19:16:59 raspberrypi python3[2281]:     irq_cb.cancel()
Aug 17 19:16:59 raspberrypi python3[2281]:     ^^^^^^
Aug 17 19:16:59 raspberrypi python3[2281]: UnboundLocalError: cannot access local variable 'irq_>
lines 1-20/20 (END)

I think nobody else is seeing this error as long as the calibration is working =).

Thank you in advance,
BR
HoWil

It’s a while since I looked at this so I suspect the code needs updating to reflect OS and other software changes.

Despite it being near the sunspot maximum we’ve had very few thunderstorms here this year so I hadn’t been giving this project much thought. I’ll try to take another look at it soon, but I’ll need to ā€˜borrow’ a Raspberry Pi from another project first!

1 Like