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 or MMDVM log files to extract relevant information.
- Monitors DStar/MMDVM 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
.envfile 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 (only for dstar gateway log monitoring)
GW_ADDRESS=172.16.0.1
# Ignore the time server messages?
GW_IGNORE_TIME_MESSAGES=True-
Choose the script you want to use to run the bot:
main-dstargateway.py: Run the bot which monitors the Dstar Gateway log file (for gateways running ICOM hardware).main-mmdvm.py: Run the bot which monitors the MMDVM log file (for gateways running MMDVM hardware).
-
Rename the chosen script to
main.py- For example, if you want to use the Dstar Gateway log monitoring script:
mv main-dstargateway.py main.pyThe bot can be launched using the following command:
./main.shThe 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>&1main.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-botlibrary. -
Environment Variables:
The bot uses environment variables (TG_BOTTOKENandTG_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.envfile.
Install them using:
pip install -r requirements.txtAs 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.