Linux / Code
I taught my ATOM Cam to catch meteors!
Or: how a tiny cheap camera became my night sky guard :3
Every August the same story: Perseids are coming, I promise myself I will stay outside all night, and at 1 a.m. I am sleeping on the sofa with a blanket on my face ^^'
Meteors are short. Blink once, and they are gone, and you can't really ask the sky to repeat. So I thought: I already have a small ATOM Cam looking at the sky, why can't it stay awake instead of me? Let it watch, and when something flies over, save a video to my NAS. And in the morning I can drink my morning coffee and open the folder like a Christmas present :3 I don't write C code every day, so I was asking Claude heavy and a lot of questions while developing it - no shame! At least I learned a lot :) This post is the story of what came out of it (and what I still don't know yet).
The base is atomcam_tools by mnakada, a custom firmware for the ATOM Cam. I used Ver.2.6.1 (the newest one). And it is not a cheap Chinese toy: inside the camera runs a real little Linux (on a MIPS CPU, so no comfort anywhere), the original camera system lives in a chroot cage, and the project adds RTSP streams, a NAS upload, a time lapse, a nice WebUI and a lot of scripts. So adding a feature mostly means: write a shell script, write a small program, add a tab to the WebUI, and don't break anything that already works ^^
How does the camera see a meteor? It is not magic, it's subtraction! The camera gives two RTSP streams: a big 1080p one (Main) and a tiny 360p one (Sub). The detector takes the tiny one, shrinks it to 256x144, makes it grey, 10 pictures per second, and compares every picture with the one from a moment ago. Stars don't move much between frames, so they disappear from the difference. Something bright that moves appears as a light spot. Then the program follows the spots and asks: is it a straight line? Is it fast? Does it live only a fraction of a second? If yes, it's a meteor. If it blinks, lives for half a minute or goes in a calm line across the whole sky, it's a plane or a satellite. If it is erratic and big, it's a moth that fell in love with the infrared LEDs (they always do) and if the whole picture flashes, it's a light, not the universe.
The detector is a Python 2.7 script with only the standard library, because that's what lives in the camera. No numpy, no OpenCV. Everything is done with old simple tricks, which is a bit like painting with a stick, but it works ^^ You can call me Python Picasso xD
The video part was my favorite. While the detector watches the small stream, a second ffmpeg copies the 1080p stream (without re-encoding, so the CPU has almost nothing to do) into 2-second pieces in RAM. Only the last few seconds are kept. When the detector shouts "METEOR!", a script takes the pieces from 5 seconds before to 5 seconds after, glues them to one mp4 and sends it to the NAS: meteor/20261127/021344.mp4 and so on. That's why you see the meteor and not just the sad empty sky after it :3 If the NAS is sleeping, the clip waits on the SD card and tries again every minute.
A few safety things I added because I know myself: no more than 60 clips per hour (so one bad night of false alarms won't fill the card), clips are skipped when the SD card is almost full, and the whole thing runs with low priority, so the camera's own work goes first. The IR night vision is also switched off while detecting, because it makes the stars disappear and the bugs glow. After the night it turns back to how it was.

Of course nobody wants to edit config files at night, so there is a new Meteor tab in the WebUI. You switch it on, choose the night window (for example 21:00 to 04:00, it can cross midnight, that was a small adventure by itself xD), choose Low / Mid / High sensitivity, how many seconds to keep before and after, and the NAS folder name. There is a status line that tells what it is doing now (watching the sky, waiting for the night, and so on) and a "Send test clip" button that records 6 seconds and sends them to the NAS, so I can check the connection in the afternoon and not in the middle of the Perseids. The tab also turns on the RTSP streams by itself, because without them there is nothing to look at. I even made the Japanese translation, because the project is Japanese first, and I didn't want the new tab to be a foreigner there ^^
Now the part that cost me the most nerves: how to give you something you can just put on the SD card. The official way is make with Docker, it builds the whole kernel and system and takes about one hour. I prepared a script for that, but waiting one hour for every rebuild? Noo..... So there is a second, faster way: take the official release, open its rootfs_hack.squashfs, put my files inside, rebuild the web page and pack it again with the same settings. That takes a few minutes. The result is the same four files as always (factory_t31_ZMC6tiIDQN, rootfs_hack.squashfs, hostname, authorized_keys), only the squashfs is different. Copy them to the SD card, power on, wait about 40 seconds, and the Meteor tab is there. One warning: don't press "Update" in the Maintenance tab when a new official version appears, it will give you the original firmware back and my tab goes to heaven :(
I tested it on a fake camera: the real software of the camera running in an emulator and a synthetic night sky with stars, noise, planes, satellites, insects and 8 meteors. On "Mid" it found all 8 with 1 false alarm; "High" found all 8 with 4 false alarms; "Low" found 7 of 8 with 2. A fake sky is not a real sky, so please treat these numbers like a school exam with open book xD I did not try it on real meteors yet.
Things I don't know: how hot the little CPU gets when it decodes the small stream the whole night, and whether the 360p picture is enough for the faint ones (probably only the bright ones, the small stream is very compressed). The first night I will watch it with top over ssh like a worried parent.
Leonids were a few days ago, and I missed them, but the Geminids are coming in December, a great chance for the first real test :3 If it catches something, I will put the clips here. And if you have an ATOM Cam and want to try it let me know and I'll send you the source :)
Started as "maybe my camera can sleep less than me" and ended with a detector, a WebUI tab and a build script, that's how all my night projects go, I guess. But I am happy, so it's a win :)
*The code is based on atomcam_tools Ver.2.6.1 and the idea is still very fresh, no big conclusions yet. If you know a better way to catch meteors with a cheap camera, tell me ^^/
COMMENTS 0
No comments yet.
Log in or sign up to leave a comment.