Receive a Pushnotification when someone opens your Mailbox (Postbox)
- @a-mnich
- @crnnr
- ESP32
- Reed switch
- Resistor (300 Ohm - other resistances should work too though)
- Raspberry Pi (Zero)
- Mqtt Broker (can also be installed on the Raspberry Pi)
- Replace the code as necessary and described below
- Wire up the ESP
- Upload MailAlertingClient.ino to ESP
- Setup RapberryPi
- OPTIONAL: Install Mosquitto MQTT Broker on RasberryPi)
- Copy receiverService.py to /home/pi/ directory
- Install pip dependencies
- Copy MailboxReceiverService.service to /etc/systemd/system/
- Make script executable (chmod)
- Set neccesary enviroment variables
- Reload systemd & enable service
- Clone the repo
- Replace variable values:
Client/MailAlertingClient.ino
Variable | Default Value | Description |
---|---|---|
wifiSSID | SSID of your Wifi where MQTT Broker is accessible | |
wifiPassword | Password of your Wifi | |
MQTT_BROKER_IP | IP of your MQTT Broker (If you run the MQTT Broker on the Raspberry Pi this will be the same IP as the Raspberry IP) | |
MQTT_BROKER_PORT | 1883 | Port of the MQTT broker. |
MQTT_CLIENT_NAME | maclient | Client name which the ESP will use to publish |
Variable | Default Value | Description |
---|---|---|
MQTT_BROKER_IP | IP of your MQTT Broker (If you run the MQTT Broker on the Raspberry Pi this will be the same IP as the Raspberry IP). | |
MQTT_BROKER_PORT | 1883 | Port of the MQTT broker. |
DEVICES_FOR_NOTIFICATION | None | V2Ids of Devices, which should receive a notification on Mailbox open. You can target specific devices by setting this to a arry of ids e.g. ['AB12'] . The default setting will publish to all Devices. |
DEVICES_FOR_IMPLICIT_NOTIFICATION | None | V2Ids of Devices, which should receive a notification on a implicit Mailbox open. This is send when the receiver Service receives two closed states without an open state in between. You can target specific devices by setting this to a arry of ids e.g. ['AB12'] . The default setting will publish to all Devices. |
MAILBOX_OPEN_TEXT | Mailbox was opened | Text which should get pushed to the devices on Mailbox open. |
MAILBOX_STATE_MISSED_TEXT | Mailbox was opened (explicit open state missed) | Text which should get pushed to the devices on implicit Mailbox open. This is send when the receiver Service receives two closed states without an open state in between. |
PUSH_NOTIFIER_USER_NAME | UserName of your PushNotifier Account (Please set this as environment variable!) | |
PUSH_NOTIFIER_PASSWORD | Password of your PushNotifier Account (Please set this as environment variable!) | |
PUSH_NOTIFIER_PACKAGE_NAME | Packagename of your PushNotifier App | |
PUSH_NOTIFIER_API_KEY | APIKey of your PushNotifier Account (Please set this as environment variable!) |
- https://docs.espressif.com/projects/arduino-esp32/en/latest/installing.html
- https://github.com/knolleary/pubsubclient
- Optional: If using a third party ESP board you might have to install drivers for the board manually
- Connect a reed switch to the 3V3 PIN and the G13 (GPIO 13) pin.
- Connect the G13 switch with the resistor to any GND (ground) pin.
- https://projects.raspberrypi.org/en/projects/raspberry-pi-setting-up
- python 3 (Usualy included with the OS)
- https://pypi.org/project/paho-mqtt/
- https://pypi.org/project/pushnotifier/
- Optional: If you want to host the MQTT broker on the Raspberry Pi https://mosquitto.org/download/
Install Python dependencies
> pip install paho-mqtt
> pip install pushnotifier
Setup systemd to automatically start the receiverService.py
> sudo chmod 744 MailboxReceiverService.service
> sudo chmod +x MailboxReceiverService.service
> sudo systemctl daemon-reload
> sudo systemctl enable MailboxReceiverService.service
> sudo systemctl start MailboxReceiverService.service
NOTE: To Debug the systemd setup you can use
sudo systemctl status MailboxReceiverService.service
for the general status andjournalctl -e -u MailboxReceiverService
for more detailed logs
This was introduced as a security practice to keep credentials out of script files.
You can set an environment variable temporarily for your current terminal session using the export
command:
export PUSH_NOTIFIER_USERNAME="your_username"
export PUSH_NOTIFIER_PASSWORD="your_password"
export PUSH_NOTIFIER_APIKEY="your_api_key"
To set environment variables for a user permanently, you can add the export commands to the user's profile file. For a typical user, you can add them to the ~/.bashrc or ~/.bash_profile file
echo 'export PUSH_NOTIFIER_USERNAME="your_username"' >> ~/.bashrc
echo 'export PUSH_NOTIFIER_PASSWORD="your_password"' >> ~/.bashrc
echo 'export PUSH_NOTIFIER_APIKEY="your_api_key"' >> ~/.bashrc