Fediverse Enabled IoT Camera

fediverseiot

I have a pretty good view from the top of the garden. It looks quite different every time I look at it, and often on the way back in from walking the dog I catch myself zoned out, staring out down the loch.

A hint of a rainbow over Loch Earn

Last year I hatched a plan for a bunch of different sensors around the garden, and it seems a camera to capture the sunrise over the loch every day might be a simple place to start.

So, a camera that wakes up once a day, uploads a picture, goes back to sleep. A bit uninteresting, however: This camera is also part of the Fediverse.

Huh, how can a camera be part of the Fediverse?

The camera is an ActivityPub Actor. If you have an mastodon account, go to the search bar, and search for @lochearnhead-sunrise@agoodmooring.com and you'll find the camera. Then you can:

  • Follow the camera and you'll get a picture of the sunrise over Loch Earn every day in your feed.

  • Reply to those messages and your reply will show up as a comment at the picture's page here (after moderation...)

  • Favourite or boost the picture, and that also should be reflected on the picture's page here.

The Camera

The camera is an esp32-cam. These things are low-cost microcontrollers with built in bluetooth, wifi, sd card slot (usually) and in this case a camera. They're not that powerful, but they are low energy and run micropython, which is cool.

You can check out the code the camera is running over at github. It might be a good starting point for your own esp32 project. It has some cool features:

Wifi configuration

The camera obviously needs a way to connect to the internet, but the first time you switch it on, it doesn't know about any wifi networks. When that happens, it creates a local hotspot. You connect to that with your phone, and it does one of those captive webpage things... The sort of thing that happens when you try to get on the internet on a train. That page lists all the wifi networks the device can find, and lets you select one and enter its password - Now the camera can get on the internet.

OTA updates

Once the camera is gaffa taped to a pole in your garden, it is a total pain if you want to change the code that's on it. Enter over-the-air updates.

There's a bit of back and forth that goes on to make these work, but the upshot is: If you change the code, and create a release on GitHub, that code will end up on the device after the next photo it takes (tomorrow at sunrise).

Taking photos

So, the camera wakes up 10 minutes after the sunrise. It then does this:

  • Connects to the server
  • Uploads a photo
  • Sends the server a device status message (wifi strength, firmware version)
  • Asks if there is a new firmware (and if so does an OTA update)
  • Asks server what time it should wake up tomorrow
  • Deepsleep until that time.

When the camera wakes up and does this stuff, it's probably awake for about 10 seconds or so. The esp32 doesn't use much power when it's in deep sleep. It is running off a single 18650 battery, sitting in one of these things.

The entire assembly is bundled into a hastily designed 3d printed enclosure, and gaffa taped to a pole in the garden.

The server

The camera obviously needs a server to talk to; somewhere it can send its photos, ask when tomorrow's sunrise is going to be, things of that nature. That server (which you're possibly reading there words at) is running a little library called IOT Manager. I'd talk about it a bit, but I've already been typing for long enough, so you'll just have to look at the code if you're interested in how it works.

Not 100% successful...

I think the idea wasn't a bad one, however the results leave quite a lot to be desired. Basically, the camera modules I tested with the esp32 simply aren't up to much. The best result came from a 3.6mm lens, but I that lens doesn't have an IR filter, which is less than ideal for taking pictrues of sunrises.

A bunch of good things have come from this though:

  1. I now have a bit of a framework for more micropython devices with a bunch of useful functionality
  2. I have a server library for IoT devices to send data/get ota updates/etc
  3. I have some IoT thing -> Fediverse shenanigans working
  4. In the process I've managed to extend my wifi to cover the entire garden, and a good way up the hill behind my house - I'm optimistic for my chances of catching red squirrels, pine martens and all the dear with my next camera 🦌

So that's lochearnhead-sunrise. The first Fediverse enabled IoT thing out in the garden 🎉