Raspberry Pi Lightning Detector - v1 and v2

Merci “Chris”

A little extra bit that might help if you’re not too familiar with Linux…

If you run the web server from a terminal session, e.g. using putty, then if you shut the putty session down, or as in my case you lose your connection between putty and the Pi because your router has a scheduled reboot at 03:30 on a Sunday, then the web server shuts down too. A little script file to run the server in the background can help here. To do this…

In the Sensors directory create a new file, e.g. ‘run_web.sh’, by typing ‘nano run_web.sh’. When the file is open in the editor type in…

/usr/bin/python3 as3935_web.py > /dev/null 2>&1 &

This runs the web server as normal but the ‘> /dev/null’ and ‘2>&1’ ensure that any output from the server won’t bleed through to your terminal session. This does have the side effect that you won’t see any errors reported but we’ll try to fix that later. The final ‘&’ says to run the process in the background.

Save the file then make it executable by typing:_

chmod +x run_web.sh

Then run it by typing:

./run_web.sh

You won’t see anything happen, but your web server will now be running in the background. If you type:

ps ax | grep as3935

you’ll see something like this…

pi@DevPi:~/Sensors $ ps ax | grep as3935 3452 pts/0 Sl 0:01 /usr/bin/python3 as3935_web.py 3460 pts/0 Sl 0:01 /usr/bin/python3 as3935_web.py 3470 pts/0 S+ 0:00 grep --color=auto as3935

I’m not sure why it’s listed twice, but the lines beginning with 3452 and 3460 are the web server. If you want to restart the web server, use the ‘ps ax’ command to find the process number of the server (the number at the start of the first line…in this case 3452). Then type:

sudo kill 3452

This will stop the web server, allowing you to modify the code, change the config, etc

The good news is that now that it runs in the background you can end your terminal session and it will carry on running.

Merci pour ces informations.

Hi Chris
i think i have this working ok but still have in test mode
as yet i take it the pigpiod still has to be manually started after reboot or power up as does the python3 as3935_web.py or if set up the ./run_web.sh
if the nowcast.txt is to be used for WD how is it auto updated if not viewed via browser

I’m off to a slow start. Although I’m still waiting on the 2nd board, I’m assembling the hardware. It appears that the CanaKit Pi case won’t work because the interior design won’t accomodate the Pi once the Click Shield is plugged in. I’ve got another case due in today.

The case came with a tiny cooling fan that clips into the lid. Unfortunately, the Click Shield uses the whole header pins which include pins 3 and 4 for the fan. I don’t want to solder anything just yet. I’m not sure in the fan is really needed.

That’s correct for now. I’ll tidy this up soon but I need to do a bit of research to find out how to do it the best way.

if the nowcast.txt is to be used for WD how is it auto updated if not viewed via browser

It’s not updated outside of the web browser, but it could easily be. I think I have a small test script that did it before I created the web server. If I still have the script (I rarely thrown anything away!) then it could be set up to run from a cron job. Having said that I was assuming people would download the nowcast.txt through the browser, i.e. get WD to grab the file every so often using the built-in WD functionality to download files by HTTP. That wouldn’t work for consolewd though, but I don’t think Brian has built the nowcast functionality into consolewd yet.

ok will wait for the startup updates

the http setup in WD seams to work ok getting the nowcast.txt

couple of things I have noticed in the nowcast.txt is it’s using stroke instead of strike and I do not see any distances is that correct

Cases are tricky for GPIO connected devices. I’m running mine without a lid and no fan too. Did your Pi come with heatsinks to stick on three of the chips? If so they’re probably good enough unless you’re going to load the Pi up with lots of software and have it running CPU intensive applications 247. Mine doesn’t seem to be having problems without the fan and it’s running the web server 247 at the moment.

The nowcast format I’ve seen uses strokes instead of strikes. I think stroke is the correct term for lightning with ‘strike’ the act of it hitting something but I’m not an expert in such things.

Also the file format doesn’t include distances (or energy - which is actually a made up number!) We could always ask Brian to invent (yet another) interface file that included distance (and energy). You’d then have to think how WD could display the data. At the moment it’s just strokes within a given period. You’d need to add another dimension onto that, giving number of strokes in a given period in a given distance range. However, as there’s only a handful of us using this, at least at the moment, then I’m not sure it’s worth making WD even more complex.

I guess another way to go would be to have the web server generate a table (or maybe graphic) of distance v time and then get WD to download that to upload to your web site?

I’ll probably quit worrying about the fan then. It’ll just be running your stuff. It has the 3 heatsinks.

Thanks,
Mort

ok the format of the nowcast is common to more than this project and looking at WD it is only looking for strikes

this maybe the way to go to complement the nowcast

the Pi3 case is worse at present mine is only fitted on the base part

I guess one option could be to modify an existing Pi3 and Pi4 3D printed case to house the Pi, Click Shield and Thunder Click. I have a 3D printer but the redesign of cases is beyond my skills at the moment. I could ask my son if he’d like to try it because he’s done more of that than I have.

2 stupid questions…

what case are you using?

Does the PI need to be placed outside?

The case is the bottom half of one that came in a Labists kit. I’m running without a top at the moment. I’ll either continue to do that or possibly 3D print something suitable.

The Pi can be indoors. There is an indoor/outdoor setting for the sensor which reduces the front end gain for indoor use. That’s because indoors is likely to be more electrically noisy. The reduced gain almost certainly means that you won’t get the full 40km distance with the indoor setting. I plan on putting the Pi in the electrically quietest part of the house and run it in outdoor mode. Hopefully the sensor won’t notice that I’m cheating :wink:

i did come across this one for the pi4

but not exactly cheap

If you have a 3D-printer.

Ouch! I don’t think I need a case that much.

I saw that one too but wasn’t that keen on the style.

This https://shop.4tronix.co.uk/products/gpio-interceptor might be a way to power a fan and still plug the Click Shield in. If this was plugged in the wrong way round (so it doesn’t stick out of the side of the Pi footprint, then the fan wires could be soldered to this board (being aware of course that the silk screen markings would all be wrong!) It does add extra height though, needing a much taller box to allow this to plug into GPIO, then the Click Shield plug into this, then the Thunder Click plug into the Click Shield and finally leave room for the fan at the top!

I’m coming to the conclusion that the fan isn’t essential though. I read something today where someone was explaining that the fan is really only needed on a Pi 4 when you’re trying to use its full power, e.g. as a desktop environment or heavy graphics processing (within the bounds of what it’s capable of). Their experience with adding a hat board and running some simple software was that the CPU didn’t really get very hot and certainly not near the temperature where it would be a problem.

I needed a distraction this morning so made a little update to the web server. The attached version (1.1) adds a new page which shows the current value of the important settings. Some of these settings are values that we set from the config file, or auto-adjust as the server runs, e.g. noise floor, and others are just values to display at the moment, e.g. AFE_GB, SREJ and WDTH. If you want to see what these values mean you can look in the AS3935 data sheet.

Without seeing any lightning I’ve no experience of how significant these values are or how they might be usefully set or adjusted. I’m hoping that as people start to use the AS3935 and actually see some lightning there might be some proposals about whether it’s useful to be able to set or adjust them. If it is useful then the code can be changed appropriately.

To install the new version, just upload the as3935_web_v1_1.zip file to your Sensors directory (or wherever you have the web server running), stop the web server and then unzip the file. If there are warnings about overwriting any files just accept them (your config file won’t be touched). Then run the server again. On the home page there’s a link to the new ‘/current’ page and that page has a link back to the home page.


as3935_web_v1_1.zip (8.95 KB)