A Mastodon bot to find EV charging stations

santisbon

santisbon

Posted on August 31, 2023

A Mastodon bot to find EV charging stations

I have a new addition to my homelab. I wanted to do a project that was fun to build but also let me apply a few different technical concepts. Read along if you're interested in any of the following:

  • Homelabs based on Raspberry Pi.
  • Mastodon and the wider Fediverse.
  • Civic tech.
  • Electric vehicles.
  • Loosely-coupled microservices.
  • Message brokers with long-running producers and consumers.
  • Caching.
  • Container orchestration.
  • Secrets management.
  • Handling server-sent events from a streaming API.
  • Consuming REST APIs.

The goal was simple: a bot that, whenever you mention it with a location, will reply with a list of nearby EV charging stations. It must also display the type of connectors available and link to the location of each station using Apple or Google Maps, depending on the user's device.

Once you've set up your Raspberry Pi and lightweight Kubernetes distribution, it's time to think about our architecture.

Our solution has:

  • A watcher that keeps track of Mastodon notifications for mentions of our bot account and prepares a request for the task to be done.
  • A worker that fulfills the task of putting together the response and sending it to the user.
  • A message broker that the watcher and the worker will use to communicate with each other.
  • A cache to store the responses from the external service that helps us translate user requests into a geographic location.
  • A Mastodon instance hosting our bot account and offering a streaming API with notifications and a web API for posting.
  • A third-party API with a geocoding service.
  • A third-party API with charging station locations.

Here's the high-level architecture

Image description

We'll take advantage of Docker container images to package our two microservices (watcher and worker) and their dependencies. We'll also use Kubernetes for container orchestration.

Each microservice consists of:

  • App container.
  • Configuration and secrets.
  • Horizontal autoscaling to meet an increase in demand.
  • Init container to delay the creation of the app container until the message broker is available.
  • In the case of the worker, a cache to avoid unnecessary calls to the geocoding API as required by its terms of service.

Dive into the instructions, code, a detailed diagram of the Kubernetes objects, and documentation here:

GitHub logo santisbon / evstations

Mastodon bot to get electric vehicle charging stations.

EV Stations

🧪 Experimental

@ev@botsin.space is a Mastodon bot to get electric vehicle (EV) charging stations near a location in the United States or Canada.

Highlights

  • Mention it with just a requested location and it will reply with some charging stations near it.
  • The links provided in the results (even though they point to Apple Maps) will automatically open either Apple or Google Maps depending on your device.
  • If the response doesn't fit in one post due to Mastodon's character limit it will be split into a couple of posts.
  • The response includes symbols for the available connector types at each station
    • Ⓣ Tesla aka North American Charging Standard (NACS)
    • â’¿ J1772
    • ⒸⒸⓈ Combined Charging System (CCS) aka J1772 Combo
    • Ⓝ⑭-㊿ NEMA 14-50
    • Ⓝ⑤-â‘® NEMA 5-15
    • Ⓝ⑤-⑳ NEMA 5-20
    • ⒸⒽⒶ CHAdeMO

Usage

Post this from your Fediverse account:

@ev@botsin.space Brickell, Miami

Query examples:

  • 60601
  • Wrigley Field
  • chinatown, chicago
  • financial…
💖 💪 🙅 🚩
santisbon
santisbon

Posted on August 31, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related