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.
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:
- Reed switch
- 3.7V 1100mAh Lithium Rechargeable Battery Micro JST 1.25 or the LoRa boards come with a JST 1.25 wire connector you could attach to some other rechargable battery like an 18650 but you should get something with built-in charge protection.
- Optional Solar panel
- Soldering iron - The dev board comes without the header pins soldered. The solar panel would also need some wire soldered on.
When you purchase through links on this site, I may earn an affiliate commission.
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.
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
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
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.
Receiver only: ssd1306 driver
Grab that from here and upload to the root of the ESP32.
This project's code
Grab jram.py and either sender or receiver main.py and upload them to the root of the ESP32.
- 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.
See my Laundry's Done post for some notification options.
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:
- 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.