SCADA-PiBot is a full-duplex monitoring and control system that integrates a SCADA system, Raspberry Pi, and Telegram bot to remotely monitor and manage a water treatment plant.
The system extracts real-time operational data from PLCs connected to the SCADA system and securely transmits it to an online database. A Cloudflare Tunnel is used to bypass the lack of a public IP and enable secure remote communication. Additionally, operators can send commands via a Telegram bot to interact with the system.
The system architecture consists of:
- SCADA System & PLCs β The primary automation and data acquisition layer.
- Raspberry Pi β Acts as an intermediary, collecting SCADA data and handling remote communication.
- Router (SIM-based) β Connects the system to the internet via a cellular network, enabling data transfer.
- Cloudflare Tunnel β Provides a secure way to access the Raspberry Pi remotely.
- VPS + Grafana β Stores SCADA logs in a database and visualizes them in real time.
- Telegram Bot β Allows operators to receive alerts and send remote commands.
β
SCADA Data Acquisition β Extracts real-time data from PLCs using Modbus.
β
Two-Way Telegram Bot Communication β Sends automated alerts and allows remote system control.
β
Cloudflare Tunnel for Secure Remote Access β Eliminates the need for a public IP.
β
Grafana Integration β Visualizes data on a VPS-hosted dashboard.
β
Automated Status Updates β Periodic reports on system health and network status via crontab.
β
Secure Communication β Prevents unauthorized access using authentication and encryption.
β
Data Logging & Storage β Sends SCADA readings to a remote database for analysis.
β
Edge Processing with Raspberry Pi β Reduces latency by processing alerts locally before sending data.
β
Router-Based Connectivity β Uses a SIM card for internet access, making it ideal for remote locations.
β
Scalable & Modular β Can be extended to support additional IoT sensors or security features.
SCADA-PiBot/
βββ scripts/
β βββ record_data.py # Logs temperature, humidity, and SCADA parameters
β βββ pre_reboot.py # Saves logs before reboot & notifies Telegram
β βββ post_reboot.py # Sends notification after reboot
β βββ data_collector.py # Collects SCADA data every 2 hours (based on crontab)
β βββ pi_status.py # Monitors system status & reports every 6 hours
β βββ telegram_bot.py # Manages Telegram bot interactions
β βββ modbus_reader.py # Extracts PLC data via Modbus protocol
β βββ cloudflare_tunnel.py # Handles secure communication via Cloudflare
βββ crontab_config.txt # Crontab settings for periodic automation
βββ README.md # Project documentation & setup guide
βββ .gitignore # Ignore unnecessary files (logs, cache, env, etc.)
βββ config.py # Configuration settings (API keys, paths, bot tokens)
βββ SCADA-Pi-Telegram.svg # System architecture diagram (for README display)
βββ requirements.txt # Python dependencies for easy setup
βββ LICENSE # License details for open-source usage
sudo apt update && sudo apt upgrade -y
sudo apt install python3 python3-pip
pip3 install requests telebot flask paho-mqtt
- Clone the Repository
git clone https://github.com/Homaei/SCADA-Pi-Telegram.git
cd SCADA-Pi-Telegram
- Set Up the Telegram Bot Create a Telegram bot using BotFather. Get the API Token and update config.py.
TELEGRAM_BOT_TOKEN = "your_bot_token"
AUTHORIZED_USERS = ["user_id1", "user_id2"]
- Set Up Cloudflare Tunnel Install Cloudflare Tunnel on Raspberry Pi:
curl -fsSL https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-arm -o cloudflared
chmod +x cloudflared
sudo mv cloudflared /usr/local/bin
Authenticate and create a tunnel:
cloudflared tunnel login
cloudflared tunnel create scada-pibot
Configure the tunnel for secure communication.
- Enable Crontab for Periodic Status Updates
crontab -e
Add the following line:
*/5 * * * * python3 /path/to/pi_status.py
π Usage Start the Monitoring System
python3 main.py
Interact with the Telegram Bot
+-------------+------------------------------------+
| Command | Description |
+-------------+------------------------------------+
| /status | Get Raspberry Pi system status |
| /scada_data | Fetch latest SCADA readings |
| /help | Show available commands |
+-------------+------------------------------------+
π Future Enhancements
π Improve SCADA Data Extraction (Direct Modbus/OPC-UA access).
π‘ Optimize Router Configuration (Intercept PLC traffic).
π Enhance Security Measures (VPN-based tunneling).
π Saving data to a PostgreSQL database on a VPS.
π Implement Data Visualization via Grafana.
π License This project is licensed under the MIT License.
π₯ Contributors