I finally got rid of the A9G GPRS module and Vodafone network limitations! After moving into my new apartment, I found that the mailbox is right at the front door, which is within my WiFi network range. This gave me the opportunity to redesign the mail notifier, breaking free from the reliance on mobile networks. I cancelled the ATtiny402, battery charging, and GPS devices, and replaced them with the ESP-M2 WiFi module, allowing the mail notifier to connect to my WiFi network. The new design makes the mail notifier more streamlined and reliable, and I no longer have to worry about its stability issues.
General Operation
The ESP’s main task is to send an HTTP network request when mail arrives, and to maximize battery life, the ESP is only powered on when the switch is triggered, and then powered off after the request is completed, which usually takes around 4-10 seconds.
To achieve this, I designed a special circuit. The switch input is connected to a 74LVC1G98 logic gate, configured as a NAND gate with an inverted input. Normally, the switch input is pulled high through R1, and the gate output remains low, disabling the 3.3V voltage regulator.
When the switch is triggered, capacitor C3 discharges, the gate input becomes low, and then the output drives high, powering on the ESP. After the ESP starts up, it drives the second input of the logic gate high from IO15, and then C3 recharges through R1. This keeps the gate output high until the network request is completed.
The role of C3 is to ensure that the ESP has enough time to start up and drive the second input of the logic gate high, which takes around 500 milliseconds. Then, the mailbox lid closes, and the switch opens again.
Additionally, the logic gate can also be used to measure the battery voltage by opening and closing the voltage divider R8 and R9. This can prevent the voltage divider from wasting power when the ESP is off, thus extending the battery life.
Truth table and system state:
IN 1 (Switch) | IN 2 (ESP) | OUT (Regulator) | State |
---|---|---|---|
HIGH | LOW | LOW | Mail flap closed, ESP is off, idle |
LOW | LOW | HIGH | Mail flap opened, ESP is booting up |
LOW | HIGH | HIGH | Mail flap opened, ESP is running and has set IO15 HIGH to keep regulator enabled |
HIGH | HIGH | HIGH | Mail flap closed, ESP is still running and has set IO15 HIGH to keep regulator enabled |
Internet of Things
The notifier makes a web request similar to the previous A9G version. The POST request contains some JSON data, which is processed by a PHP script which then formats and sends a message to a Telegram group chat.
And of course, there is a SHT31-DIS temperature and humidity sensor, this time placed in a much better area.
{
"key": "aabbccddeeff11223344556677889900abcdef12",
"millis": 7220,
"notify": "mail",
"battery": 3915,
"lastfail": 0,
"fw": {
"version": "1.0.0 211109",
"build": "Nov 24 2021 23:19:24"
},
"counts": {
"success": 109,
"wififail": 1,
"netfail": 0
},
"net": {
"ip": "10.0.0.98",
"subnet": "255.255.255.0",
"gateway": "10.0.0.1",
"dns1": "10.0.0.1",
"dns2": "(IP unset)",
"hostname": "ESP-AABB55"
},
"wifi": {
"ssid": "MyWiFi123",
"bssid": "01:23:45:67:89:AB",
"channel": 3,
"mac": "AA:BB:CC:DD:EE:FF",
"rssi": -69
},
"env": {
"t": 19.06119,
"h": 62.00809
}
}
Other Things
The ESP can be placed into a firmware upload mode by connecting RX to ground and then triggering the reed switch. In this mode the ESP will stay powered on while running a webserver where new firmware can be uploaded to.
So far after 7 months and 110 mail notifications the battery voltage has only dropped from 4.2V down to 3.9V, indicating that the device should last for at least another year or two and a further 200 notifications before needing to be recharged.
You can find all of the designs, firmware and things on my GitHub