Giter VIP home page Giter VIP logo

mail-alerting's Introduction

mail-alerting

Receive a Pushnotification when someone opens your Mailbox (Postbox)

Special Thanks

  • @a-mnich
  • @crnnr

What you'll need

  • 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)

How to Setup

  1. Replace the code as necessary and described below
  2. Wire up the ESP
  3. Upload MailAlertingClient.ino to ESP
  4. Setup RapberryPi
  5. OPTIONAL: Install Mosquitto MQTT Broker on RasberryPi)
  6. Copy receiverService.py to /home/pi/ directory
  7. Install pip dependencies
  8. Copy MailboxReceiverService.service to /etc/systemd/system/
  9. Make script executable (chmod)
  10. Set neccesary enviroment variables
  11. Reload systemd & enable service

Code

  1. Clone the repo
  2. 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!)

ESP Setup

Dependencies

Wiring

  1. Connect a reed switch to the 3V3 PIN and the G13 (GPIO 13) pin.
  2. Connect the G13 switch with the resistor to any GND (ground) pin.

Raspberry Pi Setup

Dependencies

Raspberry Pi Setup

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 and journalctl -e -u MailboxReceiverService for more detailed logs

Setting environment variables

This was introduced as a security practice to keep credentials out of script files.

Temporary Environment Variables

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"

Permanent Environment Variables for user

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

mail-alerting's People

Contributors

michamican avatar crnnr avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.