Home - MarkGrimwood/Mognet-All-Sky-Camera-install GitHub Wiki

What is an All Sky Camera?

An all sky camera is designed to point at the sky and take images at specified periods for capturing cloud cover, cloud types, and to show if the night skies are clear enough for astronomy.

What it is Not

It can't really be used as CCTV or a trail cam. There are other Raspberry Pi applications that are more suitable for those roles. Take a look at MotionEyeOS for a lightweight CCTV application

Why Use This One?

It's simple, basic and cheap. The code has been written to be run on a minimal installation, and a Pi Zero copes with it quite happily, as does an old model B. The idea is that if it gets accidentally broken, stolen, or suffers a weather related failure then it doesn't cost too much to fix or replace. I think the whole thing can be made for around £60

Parts Required

Note: I'm in the UK, so these are local links. If you are outside the UK then you may have a more local supplier. Or there's Amazon

  • A Raspberry Pi Zero W (or WH) like this: https://thepihut.com/collections/raspberry-pi/products/raspberry-pi-zero-wh-with-pre-soldered-header It doesn't have to be the Zero specifically as any model Pi should work, with the exception of the Pico and Compute modules. It does however need a method of network access, either wired or wireless
  • A camera with an IMX477 or an IMX219 sensor as these are more sensitive. Cameras that are equipped with these sensors include the Pi V2 camera and the Pi HQ camera. Other cameras that can be called with the raspistill command could also be used but may not be as sensitive. Webcams are not generally suitable as they need to be called by fswebcam instead (although I might make this an option in the future if I can get it working nicely)
  • A suitable wide angle lens. Some of the cameras linked to above may come with a suitable lens or have one available. I'm using a Pi V2.1 camera and a https://thepihut.com/collections/raspberry-pi-camera-lenses/products/magnetic-fisheye-lens with a 3D printed case
  • A power supply for the Pi
  • A suitable memory card. This needs to be a fast transfer one suitable for video or CCTV capture and ideally 16 or 32Gb in size. A 16Gb card holds around ten days worth of captures, a 64Gb holds seven weeks worth!
  • A clear CCTV dome and housing

How to Install

I have tried to make the install as simple as possible. There are a couple of manual steps that I've not been able to automate, and these are detailed below

Before installation

Follow the standard setup instructions to install the Legacy (Buster) version of Raspbian on your memory card, and set it up for wifi and ssh. A quick internet search will find instructions for your particular model of RPi. Don't forget to do the bug fix and security updates

Note: The code uses Raspistill, which has been removed from Raspbian in the latest versions, hence the need to use an older version of Raspbian. I need to look at a fix for this so the latest versions of Raspbian can be used.

First up configure the Pi for camera use, set the host name, and change the password

  • Enter sudo raspi-config at the prompt
  • Go to System Options -> Hostname and give it the name you want your pi to be known as
  • Now go to System Options -> Password and change the password away from the default. Make sure it's something you can remember
  • And then enable the camera in Interface Options -> Camera Select Finish, and reboot the RPi if required

I've also been advised to install Hardware Watchdog on the RPi when running remotely and out of physical reach. I'm going to give it a try too. The installation instructions are here https://diode.io/raspberry%20pi/running-forever-with-the-raspberry-pi-hardware-watchdog-20202/

You will need to know your latitude and longitude. An approximate location is fine as this information is only used for timings of sunrise, sunset etc. The values are entered separately in decimal format with the N/S and E/W indicators. Those values will be truncated to two decimal points, so a precise location of 52.202175N, 0.128179E will become 52.20N and 0.12E

Installation Instructions

I have been testing and running mine headless (i.e. remote access via command line) to install and modify. For installation this way, ssh onto the Pi and use the following commands for set up:
wget https://github.com/MarkGrimwood/Mognet-All-Sky-Camera-install/archive/refs/heads/main.zip
unzip main.zip
cd Mognet-All-Sky-Camera-install-main/
chmod +x autodeploy
./autodeploy

The autodeploy script will ask for the GPS coordinates as mentioned above. Once the install is done there's a little bit of cleaning up to do
cd ~/
rm -r Mognet-All-Sky-Camera-install-main/
rm main.zip

And that's it. It will now sit there and run quite happily without any additional maintenance, unless I've made an update that you want to add. Once the deployment script has completed it will give the URL for browser access to the front end, with the first proper image turning up on the current image page after a minute or two. It should also recover from power outages and router reboots, although for the latter it might take extra time to reconnect with the network

Alternative Installation Instructions

Sometimes the above installation instructions fail. On one occasion ffmpeg failed to install for no obvious reason, so I just run the autodeploy script again and it installed second time with no problem

One early user couldn't unzip the downloaded file using the unzip command, so they downloaded it onto a PC, unzipped it there, and then transferred it via a memory stick, after which they continued with the autodeploy

Another method after unzipping on a PC is to transfer the files using WinSCP and then deploy it

If you are running the GUI version of Rasbian, then it is ok to download, extract, and execute the code that way. Just remember to execute it in the terminal so that the setup questions can be answered

Focusing the Camera

I found some instructions on Medium that work. Scroll down to the section Install UV4L and WebRTC and work from that short section (Note: These instructions don't seems to get updated often, so also look at https://www.linux-projects.org/uv4l/installation/ ) After using WebRTC you'll need to reboot the Pi to clear the processes that it used otherwise the all sky camera won't work. It doesn't like two processes trying to access the camera module at once

Updating

I've added in some code for updates, as it's likely at some point they'll be needed

Updating the Code

Performing a code update is similar to an install. The code is downloaded as before, but a different script is run. This time use the update script instead of install. The update script will overwrite the back end and front end code leaving the current and captured images intact. Note: Any customisations will be overwritten!
wget https://github.com/MarkGrimwood/Mognet-All-Sky-Camera-install/archive/refs/heads/main.zip
unzip main.zip
cd Mognet-All-Sky-Camera-install-main/
chmod +x update
./update

And after the update, a little bit of cleaning up
cd ~/
rm -r Mognet-All-Sky-Camera-install-main/
rm main.zip

Updating GPS Coordinates

In the directory /home/pi/Mognet-All-Sky-Camera there is a script called gpsupdate that when run will request the new GPS location coordinates, and will recalculate the timings. To update them navigate to the directory, enter chmod +x gpsupdate and then ./gpsupdate. The coordinate entry is the same as in the install.

How it works

The code has been created to capture an image once per minute both day and night. The image capture timing is driven from a cron job that is set up in mgasc.sh. This cron job is also set to trigger the dailyupdate.sh script every day at noon.

Back end

All the back end scripts are written in Bash as they set things up, initialise the cron job, handle files and call other programs

mgasc.sh

This script calls sunwait to ascertain the video start times, sets out the capture schedule and initialises the cron job. It produces the files daily which is passed to the web code, daily_times.txt which is only for internal information, and mgasccron for setting up the cron job
From this script the timing of the captures can be adjusted in values ShotD and ShotN. These are already set at the minimum values for the most frequent capture. After changing these timings the cron job needs to be regenerated. For this execute the script using the command sudo ./mgasc.sh

dailyupdate.sh

This is a simple script that calls mgasc.sh at noon every day to regenerate the timings. It produces the update.log file to report on these updates

capture.sh

The main image capture script. It is called by the cron job with a parameter of either day or night and will use raspistill to capture the image, and then adds the informational text to the image using imagemagick, creates a thumbnail image for the front end display, and then concatenates the image onto the current movie using ffmpeg before moving everything across to the web directories

The raspistill commands can be adjusted here if necessary (and see the caveat in the update script)

newmovie.sh

This script is run at the start of every capture period. It checks the remaining space on the memory card and removes the oldest capture sets from the history until at least there is at least 2Gb of free space, archives the last equivalent period (day or night) into the history folder of the web directory, and then creates a new directory, the info file within it containing the start date and time (in Unix timestamp format), and initialises the movie. Like capture.sh it takes a parameter of either day or night and uses raspistill to capture the initial image, which can be adjusted

Front end

A quick note, JavaScript needs to be enabled in the browser for some bits of this to work

Home page

A fairly minimal home page showing the complete history available in latest first order, links to the current and historic captures, sunrise and set times, and a brief About page
Example home page

Current View

The latest image capture, tagged with sunrise and sunset times too

Taken on a reasonably clear night through double glazing. Pleiades can be seen in this
Example night image
Yours truly in the daytime
Example daytime

Video

Not so much a page as the video itself. I've written it so the link goes straight to the mp4 and the browser handles all the scaling

Images

A list of images for the period, along with file names and capture times
Image list

Image display

Displays the archived images as linked to in the Images page. Left and right arrows can be clicked on to move backwards and forwards in time. This page needs fixing as it's not obvious if it's loading the next image or not.

Sunrise, Sunset and Twilight Times

A table of sunrise and set times, along with astronomical twilights and video start times, etc. Also included are links to true sun times and Clear Outside Astronomer's Weather Forecast for your location based on the GPS coordinates provided

About

Just some basic information about the project

Known issues

There are a few known issues. Some of these will hopefully be fixed in the next version

  • Sometimes the live display gets corrupted. This only seems to affect the live display and doesn't appear on the saved images or videos. I suspect it's a timing thing when adding text to the image in some PHP code
  • Downloading the current video sometimes gets interrupted. This is due to the back end code overwriting the video file while it's still in use. I'm sure it's fixable but I don't yet know how exactly (I assume that the OS or lighttpd can report that the file is in use even if set to read only, and then I could create something to overwrite when free)
  • In very limited circumstances it is possible to corrupt the movie file. I think it was from powering off my test Pi while ffmpeg was still writing the output file. I need to make that bit more resilient

The History

This project was originally written by Pete https://github.com/rederikus/AllSky-Camera-Raspberry-Pi and I only intended to add capture history to it. And fix a couple of timing defects. And make compiling the movie more efficient. Then when I realised I'd already rewritten a large part of it I went for code improvements and installation scripts, and anything else I could think of. Some of Pete's original code still remains in places

The Future

There are always improvements that could be made and defects to be fixed. I have few planned

  • Air temperature sensor code. Pete's original version had that as an option and I didn't get round to buying the necessary sensor, so I disabled the code for now.
  • Revisit the timing setup script. I don't know how well it will work for locations close to the polar circles towards midsummer and midwinter, and for inside the polar circles at those times I haven't written anything yet. I think there may be a better way to do it than what I've done for this version
  • Fix the historic image navigation. At the moment it's not possible to see if it's fetching the next picture or not
  • Fix the image list display so that it only recalls the thumbnails for the areas of screen seen and not attempt the whole lot at once
  • Make webcam usage an option too...
  • ...which means I should also create a common file that capture.sh and newmovie.sh can use for the capture command so that things only need to be changed in one place
  • I might also add keograms if they don't make too much impact on a minimal installation

Why Mognet?

I'm a cat magnet. Literally! I joined Stargazer's Lounge the day I realised that I'd been adopted by another cat