Mail's Here!

Mail's Here!
Photo by Paula Hayes / Unsplash

I can't see my mailbox from my house so I thought it might be nice to get a notification when it opens.  Initially I had an ESP32 connecting over WiFi but it had poor signal strength and I wanted to try LoRa and it's working well.  I added a solar panel and rechargable battery and use deep sleep mode and it's been running itself for months.  I'm using Micropython, MQTT, Node-RED, and Twilio.


Supplies

Lora Dev Boards

You need one board to transmit and another to receive.  If you already have a LoRa Gateway (I don't) then you would only need 1 dev board.  You also need to make sure you get a board that uses the frequencies allowed in your country.  See here for what frequencies are allowed in what countries.

Make sure to attach the LoRa antenna before powering up!  Not having the antenna connected can damage the LoRa chip.

For the US and others this board does 868 or 915MHz:

See some other frequency options can be found here:

Common components

When you purchase through links on this site, I may earn an affiliate commission.


Wiring

The Heltec dev board is pretty cool with the integrated display and battery charging though the documentation was lacking.  For the V3 board even the pinout diagram was incorrect but hopefully they'll fix it soon.  I looked through the Meshtastic firmware code to find the correct ports for the display and SX1262 LoRa module.

Only the sender board near the mailbox needs any wiring.  The receiver board simply relays anything it gets from the transmitter to MQTT.

The only required wiring is for the reed switch.  One wire from the reed switch normally open goes to pin 6 and the other wire to ground.

The solar panel I wired into 5V and ground.


Code

I made the receiver code generic and it will pass whatever LoRa messages it receives to a default MQTT topic or if the message contains a "source" field it will use that as the sub topic.  I figure some future project might need long range wireless and I wanted to be able to re-use the same receiver.

Getting Started With Micropython

1. Getting started with MicroPython on the ESP32 — MicroPython latest documentation

micropySX126X

GitHub - ehong-tl/micropySX126X: Semtech SX126X LoRa driver for Micropython and CircuitPython.
Semtech SX126X LoRa driver for Micropython and CircuitPython. - GitHub - ehong-tl/micropySX126X: Semtech SX126X LoRa driver for Micropython and CircuitPython.

Grab sx1262.py, sx126x.py, and _sx126x.py, make the changes sx126x.py described below, and upload them to the root of the ESP32 without the subdirs.

6c6
<     from machine import SPI, Pin
---
>     from machine import SoftSPI, Pin
44c44
<               self.spi = SPI(spi_bus, mode=SPI.MASTER, baudrate=2000000, pins=(clk, mosi, miso))        # Pycom variant uPy
---
>               self.spi = SoftSPI(spi_bus, mode=SPI.MASTER, baudrate=2000000, pins=(clk, mosi, miso))        # Pycom variant uPy
46c46
<               self.spi = SPI(spi_bus, baudrate=2000000, sck=Pin(clk), mosi=Pin(mosi), miso=Pin(miso))   # Generic variant uPy
---
>               self.spi = SoftSPI(baudrate=2000000, sck=Pin(clk), mosi=Pin(mosi), miso=Pin(miso))   # Generic variant uPy

Receiver only: micropython-mqtt

GitHub - peterhinch/micropython-mqtt: A ‘resilient’ asynchronous MQTT driver. Plus a means of using an ESP8266 to bring MQTT to non-networked targets.
A &#39;resilient&#39; asynchronous MQTT driver. Plus a means of using an ESP8266 to bring MQTT to non-networked targets. - GitHub - peterhinch/micropython-mqtt: A &#39;resilient&#39; asynchronous M…

Grab mqtt_as/mqtt_as.py and mqtt_as/mqtt_local.py and upload them to the root of the ESP32 without the subdirs.  We'll need to tweak mqtt_local.py with your WiFi and MQTT broker settings.

config['server'] = '<broker hostname>'

config['ssid'] = '<SSID>'
config['wifi_pw'] = '<WiFi password>'
config['ssl'] = <True | False>
config['port'] = <broker port>
config['user'] = '<broker user>'
config['password'] = '<broker password>'
Sample mqtt_local.py updates.

Receiver only: ssd1306 driver

Grab that from here and upload to the root of the ESP32.

This project's code

GitHub - scarey/mail-is-here: Micropython code for sending notifications when your mailbox opens.
Micropython code for sending notifications when your mailbox opens. - GitHub - scarey/mail-is-here: Micropython code for sending notifications when your mailbox opens.

Grab jram.py and either sender or receiver main.py and upload them to the root of the ESP32.


Mounting

  • Figure out a good spot for the reed switch.  I put the magnet on the left side of the lid near the hinge and the switch nearby on the body.
  • Stuff the ESP32 and battery in a small project box.  I used double sided tape and mounted the box under the mailbox.
  • I 3D printed some bits and pieces to mount the solar panel behind the mailbox.
Heltec WiFi LoRa 32 (V3) minimal case, more room for antenna cable by mrtamer
I slightly modified the great original design to fit the 10cm antenna cable better to the enclosure.
Cute case for the receiver
Waterproof electronic box / enclosure by pbtec
Stable and waterproof / watertight OpenSCAD customizer case / box / enclosure V6.1 by pbtecEdit December 2022: Updated Version 6.1 --> Seems Openscad has in certain circumstances problem with special characters (like ä) in comments…. Created new fixed version 6.1 (Nothing else has changed)Latest n…
I used this near the mailbox

Notifications

See my Laundry's Done post for some notification options.

Laundry’s Done!
Well there’s still folding and stuff left but getting notified when the washer/dryer cycle finished was one of my first projects and is a big hit with the wife. An accelerometer detects when motion has ceased and sends a notification. I’m using micropython with an ESP32, MQTT, Home Assistant,

I use Node-RED to keep track of how many times the mailbox has opened each day and send a different message to different recipients.  I included my kids in the hopes that they might actually be helpful and get the mail some days but they seemed to ignore them along with all my other texts.  I included my neighbors on the first open of the day and they did appreciate that.

And one day I didn't get a package I was expecting via USPS and noticed that they said it was delivered 1 minute before I got my notification.  I pinged my neighbor and sure enough he got it.  Just a happy benefit of knowing when your mailbox opens.

Here's what my Node-RED flow looks like.  Let me know if it could be improved...I'm not yet an expert:

Download the flow here:

Here's what the texts look like:


Notes

  • Feel free to tweak what's on the display and/or add display for the sender.  I figured I would just stuff it somewhere out of sight though it's handy for initial debugging.
Technology icons created by Freepik - Flaticon