This project is a Python-based Telegram bot that monitors DStar logs and sends updates to a specified Telegram chat. It uses the python-telegram-bot
library to interact with Telegram and parses DStar log files to extract relevant information.
- Monitors DStar log files for new entries.
- Parses log entries and formats them into readable messages.
- Sends updates to a Telegram chat using a bot.
- Configurable via environment variables.
- Python 3.7 or higher
- A Telegram bot token (create one using BotFather).
- A Telegram chat ID where the bot will send messages.
- Access to the DStar log files on your Pi-Star system.
- Clone the repository to your Pi-Star system:
git clone https://github.com/iu2frl/pistar-lastheard-telegram
cd pistar-lastheard-telegram
- Create a
.env
file in the project directory and add the following environment variables:
# Telegram bot token
TG_BOTTOKEN=<your-telegram-bot-token>
# Target chat where to send messages
TG_CHATID=<your-telegram-chat-id>
# Address of the RP2C device
GW_ADDRESS=172.16.0.1
# Ignore the time server messages?
GW_IGNORE_TIME_MESSAGES = True
The bot can be launched using the following command:
./main.sh
The script will:
- Create and activate a virtual environment (if not already created).
- Install the required dependencies.
- Start the bot and monitor the DStar logs.
To run the script at boot, add an entry in cron:
@reboot cd /home/pi-star/lastheard && ./main.sh > /tmp/lastheard.txt 2>&1
main.py
: The main script that contains the bot logic and log monitoring functionality.main.sh
: A shell script to set up the environment and run the bot.requirements.txt
: A list of Python dependencies required for the project.
-
Log Monitoring:
The bot reads the latest DStar log file and extracts the last line. It parses the log line using a regex pattern to extract fields like timestamp, callsigns, and repeaters. -
Telegram Integration:
The bot formats the parsed log entry into an HTML message and sends it to the specified Telegram chat using thepython-telegram-bot
library. -
Environment Variables:
The bot uses environment variables (TG_BOTTOKEN
andTG_CHATID
) to configure the Telegram bot token and chat ID.
Tip
If using the main.sh
script, all dependencies and virtual environment are created automatically
The project requires the following Python libraries:
python-telegram-bot
: For interacting with the Telegram Bot API.dotenv
: For loading environment variables from a.env
file.
Install them using:
pip install -r requirements.txt
As Pi-Star starts the device in read-only mode, I suggest commenting out the pip install ...
line in main.sh
to avoid errors due to read-only mode
The bot uses Python's logging
module to log events and errors. Logs are displayed in the console for easy debugging.
Feel free to submit issues or pull requests to improve the project.
This project is licensed under the GNU GPL v3 License. See the LICENSE
file for details.