Close
0%
0%

The Mailblocks: Physical Inbox for Virtual Alerts

This mailbox coordinates with a Raspberry Pi based router to block push notifications network-wide until a phone is placed inside.

Similar projects worth following
I find myself easily distracted by push notifications, and Do Not Disturb just isn't sticky enough for me. After particularly screen-time-heavy night, I joked to my wife: "push notifications should be like regular mail - you should have to go somewhere to collect them. Once a day, max."

Seemed like an experiment worth running.

At a high level, here's what's happening:

  1.  A Raspberry Pi acts as a wireless router, with custom DHCP, DNS, and HTTP servers running on board.
  2. The DNS server redirects lookups seeking any of Google's listed domains for their push service to... nowhere!
  3. In the mailbox, a switch is closed when a phone is inserted. The switch wakes up an embedded ESP-32 microcontroller.
  4. Upon waking, the ESP-32 connects to WiFi, raises the mailbox's flag, and alerts the HTTP server on the Pi that a phone has been inserted and that notifications may flow.
  5. The HTTP server tells the DNS server to turn off redirects and pass all lookups through to a "real" server.
  6. At the same time, the DHCP server is instructed to boot any connected devices off of the network (they are allowed to, and will, reconnect).
  7. The phone inside the mailbox disconnects (see 6), reconnects, and immediately tries (and succeeds) to reach Google's push servers. Any notifications that have been queued up should come through.
  8. After the phone is removed (or 30 seconds, whichever comes first), the ESP-32 reaches back out to the HTTP server and asks it to revert the changes made in step 5. DNS redirects are turned back on.
  9. Once again, the DHCP boots all connected devices in order to sever any existing connections.

    [will be back to give detailed instructions tomorrow]

View all 7 components

  • Detailed breakdown

    Guy Dupont12/22/2023 at 21:01 0 comments

    The Raspberry Pi

    As a router

    My original idea was to run a MITM and see if I could actually intercept the push notifications as my phone received them. I would have been fine not being able to decrypt/read them, I just wanted to know they were there and redirect them to /dev/null.  So I played around with the tools associated with mitmproxy. Specifically, I followed this tutorial from Dino Fizzotti. I had fun playing with mitmproxy, but ultimately decided this project would work well enough with the simple, DNS based approach. However, I still ended up using two of the tools that got pulled in during this phase of the project:

    1. hostapd - which allows the Pi to act as a WiFi access point.
    2. isc-dhcp-server - which acts as a DHCP server on the Pi (assigns IP addresses to devices that connect)

    These two tools running together effectively turn the Pi into a wireless router. 

    Interesting note - whenever the system changes state (notifications blocked or not, read below how that works), I use hostapd's "disassociate" command to briefly kick all devices off the access point. Unlike the "deauthenticate" command, this allows them to reconnect immediately. Doing this ensures that any existing TCP connections are broken and ensures that the phone either will or won't get the data it should or should not.

    As a DNS server

    The way the Pi blocks push notifications is by providing invalid IP addresses any time a device on the WiFi network makes a request to any of the hostnames Google lists as being used for messaging. So there is a DNS server running on the Pi that all connected devices are forced to use. When the phone is not inside the mailbox (and notifications are blocked), the DNS server redirects the targeted lookups, and when the phone goes in, the DNS server acts as a passthrough for every request. 

    I am using fakedns, which is a standalone DNS server written in Python. It's great! No dependencies to install, very easy to get up and running. I was able to add a single line of code to add the functionality of toggling redirects on and off - I'm simply checking if a file named '.disabled' exists in the directory the server is run right as each request comes in.

    Note - I think dnsmasq may have been a good option here, it seems to handle both DHCP and DNS.

    As an HTTP server

    I needed a way for the microcontroller in the mailbox to turn the DNS server redirects on and off. I set up a simple HTTP server with two endpoints: block and passthrough. When "block" is hit, I make sure that there is no file named ".disabled" is in the DNS server's local directory. When "passthrough" is hit, I write a blank file named ".disabled" is in the DNS server's local directory. Kludgy but simple! I wrote the server with fastapi/uvicorn.

    The Mailbox

    (Please see the video for a better description/images of the mailbox hardware)

    - Contains a homemade switch consisting of two springs with different lengths and diameters. I glued the longer/slimmer spring to dangle inside the shorter/wider spring. The longer spring hangs down into the area of the mailbox that the phone slides into. When the phone is inserted, the longer spring bends and makes contact with the outer spring. One of the springs is wired to a GPIO pin on the ESP-32, and the other is wired to ground. This switch is responsible for waking the ESP from deep sleep, at which point it hits the "passthrough" endpoint on the HTTP server running on the Pi (see last section). When the phone is removed and the springs no longer touch, the ESP hits the Pi's "block" endpoint and goes back to sleep. (Sidenote - there is also a timer. If the phone is not removed before 30 seconds passes, the ESP will perform the same "bedtime" routine. This is so you can't just leave something inside the mailbox to allow notifications indefinitely)

    - Contains a cheap MG90S hobby servo. When the phone goes in and the ESP wakes up, it uses the servo to move the mailbox's arm up. Before the ESP goes to sleep, it brings the servo...

    Read more »

View project log

Enjoy this project?

Share

Discussions

vladllen1054 wrote 01/24/2024 at 11:12 point

Hello, and thanks for the info. It`s really interesting. I just stumbled upon this fascinating project - the Mailblocks Physical Inbox for Virtual Alerts on Hackaday. It got me thinking about optimizing my email experience. I recently found a helpful guide on refreshing mail on Mac at https://setapp.com/how-to/refresh-mail-on-mac Thought it might be useful for those interested in innovative email solutions. What are your thoughts on merging the digital and physical aspects of notifications? 

  Are you sure? yes | no

sunnyguy2390 wrote 01/16/2024 at 09:08 point

Thanks for sharing!

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates