Homaei / SCADA-Pi-Telegram

This is a remote monitoring system that integrates a Raspberry Pi, SCADA system, and Telegram bot to enable full-duplex communication for real-time status updates and command execution. The system allows data extraction from PLC-connected SCADA systems in a water treatment plant and transmits it securely to an online database or server.

Repository from Github https://github.comHomaei/SCADA-Pi-TelegramRepository from Github https://github.comHomaei/SCADA-Pi-Telegram

πŸ“Œ Project Overview

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.

✨ Key Features

βœ… 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

πŸ“‘ System Architecture

SCADA-Pi-Telegram Architecture


βš™οΈ Installation & Setup

1. Install Required Packages on Raspberry Pi

sudo apt update && sudo apt upgrade -y
sudo apt install python3 python3-pip
pip3 install requests telebot flask paho-mqtt
  1. Clone the Repository
git clone https://github.com/Homaei/SCADA-Pi-Telegram.git
cd SCADA-Pi-Telegram
  1. 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"]
  1. 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.

  1. 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

About

This is a remote monitoring system that integrates a Raspberry Pi, SCADA system, and Telegram bot to enable full-duplex communication for real-time status updates and command execution. The system allows data extraction from PLC-connected SCADA systems in a water treatment plant and transmits it securely to an online database or server.

License:GNU General Public License v3.0


Languages

Language:Python 100.0%