Skip to main content

Monitor configurable MQTT topics and forward the messages to ntfy.sh topics.

Project description

NSP Ntfy

GitHub Actions Workflow Status Coveralls Sonar Quality Gate PyPI - Version GitHub License

Overview

NSP-NTFY is a bridge between Night Sky Pi's MQTT messages and ntfy.sh push notifications. When Night Sky Pi detects events (like satellite passes or ISS visibility), it can publish these to a local MQTT broker. NSP-NTFY subscribes to these events and forwards them as push notifications to your devices via ntfy.sh, allowing you to receive real-time astronomy alerts without exposing your local network.

Table of Contents

Prerequisites

Before deploying NSP-NTFY, ensure you have the following prerequisites configured:

Python

NSP-NTFY is written in Python and has been tested with the following Python versions:

  • Python 3.12

MQTT Broker

Night Sky Pi has the ability to publish events to an MQTT broker. The intent of this is so that other modules can react to the events to complete additional actions. Initially this broker will only run locally therefore only allow clients that reside on the same device as intended. Firstly we need to install MQTT on the Raspberry Pi.

sudo apt update && sudo apt upgrade
sudo apt install -y mosquitto
sudo apt install -y mosquitto-clients # Optional for testing locally
sudo systemctl enable mosquitto.service
sudo reboot # Just something I like to do, this is optional as well

Installation

Installing NSP-NTFY is straightforward using pip:

# Install from PyPI
pip install nsp-ntfy

# Or install development version directly from GitHub
pip install git+https://github.com/joe-mccarthy/nsp-ntfy.git

Configuration

NSP Configuration

First, ensure your Night Sky Pi is configured to publish MQTT messages. These settings are in the Night Sky Pi configuration file:

"device" : {
    "mqtt" : {
        "enabled": true,
        "host": "127.0.0.1"
    }
}

NSP-NTFY Configuration

Create a configuration file for NSP-NTFY (nsp-ntfy-config.json):

{
  "mqtt": {
    "broker": "127.0.0.1",
    "port": 1883,
    "username": "",
    "password": "",
    "topic": "nsp/notifications/#"
  },
  "ntfy": {
    "server": "https://ntfy.sh",
    "topic": "your-unique-topic-name",
    "priority": "default",
    "tags": ["satellite", "astronomy"]
  },
  "logging": {
    "level": "INFO",
    "file": "/var/log/nsp-ntfy.log"
  }
}

Configuration options explained:

  • MQTT Settings:

    • broker: Address of your MQTT broker (default: 127.0.0.1)
    • port: MQTT broker port (default: 1883)
    • username & password: Credentials if your broker requires authentication
    • topic: MQTT topic pattern to subscribe to (default: "nsp/notifications/#")
  • NTFY Settings:

    • server: NTFY server URL (default: https://ntfy.sh)
    • topic: Your unique notification topic - keep this private as anyone with this name can send/receive notifications
    • priority: Default notification priority (default, min, low, high, urgent)
    • tags: Default tags to include with notifications
  • Logging Settings:

    • level: Logging level (DEBUG, INFO, WARNING, ERROR)
    • file: Log file path

Usage

Running as a Service

It's recommended that NSP-NTFY is run as a service. This ensures that it doesn't stop if a user logs off and continues running after system restarts.

sudo nano /etc/systemd/system/nsp-ntfy.service

Next step is to update the service definition to the correct paths and running as the correct user:

[Unit]
Description=nsp-ntfy
After=network.target

[Service]
Type=Simple
# update this to be your current user
User=username 
# the location of the nsp-ntfy to work within
WorkingDirectory=/home/username/
# update these paths to be the location of the nsp-ntfy.sh 
# update argument to where you previously copied the json configuration.
ExecStart=nsp-ntfy /home/username/nsp-ntfy-config.json /home/username/nsp-config.json 
Restart=on-failure

[Install]
WantedBy=multi-user.target

Next is to enable and start the service.

sudo systemctl daemon-reload
sudo systemctl start nsp-ntfy
sudo systemctl enable nsp-ntfy

Manual Execution

To run NSP-NTFY manually, execute the following command:

nsp-ntfy /path/to/nsp-ntfy-config.json /path/to/nsp-config.json

Notification Examples

Here are some examples of notifications you might receive:

  • Satellite Pass: "Satellite XYZ will be visible at 10:15 PM for 5 minutes."
  • ISS Visibility: "The ISS will be visible at 9:30 PM for 6 minutes."
  • Astronomy Alert: "Meteor shower peak tonight at 11:00 PM."

Troubleshooting

If you encounter issues, check the following:

  1. Logs: Review the log file specified in the configuration (/var/log/nsp-ntfy.log).
  2. MQTT Broker: Ensure the MQTT broker is running and accessible.
  3. Configuration: Verify the configuration files for any errors.
  4. Service Status: Check the status of the NSP-NTFY service:
sudo systemctl status nsp-ntfy

Contributing

Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".

Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nsp_ntfy-2.0.2.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nsp_ntfy-2.0.2-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file nsp_ntfy-2.0.2.tar.gz.

File metadata

  • Download URL: nsp_ntfy-2.0.2.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for nsp_ntfy-2.0.2.tar.gz
Algorithm Hash digest
SHA256 1679b3c95abb40c70e882422439bed58288141cdfc8205b0a405fde9147a71ce
MD5 f8d52ec8643d57f964efb061a86c5986
BLAKE2b-256 2ef1afe08b5752d3e99f676df32d2191ecbf72c6f9d18ea833e0e4c66e1347b4

See more details on using hashes here.

Provenance

The following attestation bundles were made for nsp_ntfy-2.0.2.tar.gz:

Publisher: publish.yml on joe-mccarthy/nsp-ntfy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nsp_ntfy-2.0.2-py3-none-any.whl.

File metadata

  • Download URL: nsp_ntfy-2.0.2-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for nsp_ntfy-2.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 134dafb80a2a33e379717b9965f6c804094c03d30931ca35fc31a918c756e63e
MD5 e2b8b438d371bf1139acf09eacf3834b
BLAKE2b-256 cec49e29285cf75043e3cd2090d28cfd00a23022280e870ed5854376e5247b0d

See more details on using hashes here.

Provenance

The following attestation bundles were made for nsp_ntfy-2.0.2-py3-none-any.whl:

Publisher: publish.yml on joe-mccarthy/nsp-ntfy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page