This project monitors internet connectivity by pinging multiple targets, logs the status in an SQLite database, and automatically triggers a modem power cycle via Tapo P100 Smart Plug if consecutive failures are detected. It also provides a dashboard to visualize the network status over time using a Dash web app.
- Monitor Internet Connectivity: Pings a list of IPs (e.g.,
8.8.8.8
,1.1.1.1
) and logs success/failure in SQLite. - Automatic Power Cycle: If the internet is down for 5 consecutive checks, it triggers a power cycle of a TP-Link Tapo smart plug (controlling the modem).
- Dash Dashboard: A web interface to visualize internet status logs using Dash, showing connectivity success rate, latency, and packet loss over time.
- Redis Caching: Used in the Dash app for performance optimization.
- Cooldown Logic: Ensures the power cycle isn’t retriggered within a specified cooldown period (10 minutes).
- Tapo p100 Smart Plug: Utilises Tapo Smart Plug for power cycling modem.
internet-monitoring/
├── check_internet.sh # Script that checks the internet and triggers the power cycle
├── power_cycle_nbn.py # Python script for power cycling the modem via Tapo smart plug
├── power_cycle_nbn_override.py # Pytho script to manually trigger power cycling of Tapo smart plug
├── requirements.txt # Python dependencies for the power cycle script (pytapo)
├── internet_status_dashboard.py # Dash web app to visualize network logs
├── README.md
├── setup.sh # Automated setup script
└── logs/ # Directory for logs, state files, and db
git clone https://github.com/famesjranko/local-network-monitor-dashboard.git
cd local-network-monitor-dashboard
chmod +x setup.sh
sudo ./setup.sh
This script will:
- Create necessary directories.
- Move relevant files into the project directory.
- Set up a Python virtual environment and install dependencies.
- Injects tapo p100 credentials
email
,password
,device_ip
,device_name
into scripts (via user input) - Install and configure Redis (can set cache size max in script)
- Create and enable systemd service and timer files for the internet check and Dash app.
Check the status of the services to ensure they are running correctly:
sudo systemctl status check_internet.timer
sudo systemctl status dash_app.service
And navigate to http://<your-server-ip>:8050
in a browser to access the dashboard.
First, clone this repository and navigate to the directory:
git clone https://github.com/famesjranko/local-network-monitor-dashboard.git
cd local-network-monitor-dashboard
-
Create a virtual environment to manage Python dependencies:
python3 -m venv venv source venv/bin/activate
-
Install dependencies for both the power cycle script and the Dash app:
pip install -r scripts/requirements.txt pip install -r dash_app/requirements.txt
-
Install Redis on your system:
sudo apt-get update sudo apt-get install redis-server
-
Start Redis and enable it to run at startup:
sudo systemctl start redis-server sudo systemctl enable redis-server
-
Set the Redis port (if using a port other than the default
6379
):-
Open the Redis configuration file:
sudo nano /etc/redis/redis.conf
-
Find the
port
setting and modify it if necessary:port 6379 # Change this if needed
-
Save the file and restart Redis:
sudo systemctl restart redis-server
-
-
Limit Redis memory usage (optional):
-
Open the configuration file:
sudo nano /etc/redis/redis.conf
-
Set the maximum memory Redis can use (e.g., 100MB):
maxmemory 100mb
-
Choose an eviction policy to remove the least recently used keys when Redis reaches the memory limit:
maxmemory-policy allkeys-lru
-
Save the file and restart Redis:
sudo systemctl restart redis-server
-
Check that Redis is running correctly by using the following command:
redis-cli ping
You should see the response PONG
if Redis is running.
This script pings predefined targets (e.g., 8.8.8.8
) and logs internet status in the SQLite database (internet_status.db
). If the internet is down for 5 consecutive checks, it triggers the power cycle of the modem via the Python script.
-
Edit Target IPs: You can edit the target IPs in the
TARGETS
array incheck_net.sh
if needed. -
Database and Log Paths: The logs are stored in the
logs/
directory. The SQLite database (internet_status.db
) stores the ping results.
This script communicates with a TP-Link Tapo smart plug to power cycle the modem. You can find more information about the Tapo P100 smart plug here.
-
Tapo Credentials: Update the
email
,password
, anddevice_ip
in the script with your Tapo credentials and device IP address. -
Cooldown Period: The script includes a cooldown period (default: 10 minutes) to avoid repeated power cycling. The cooldown is tracked via the
logs/cooldown.txt
file.
To automate the running of the internet check script and the Dash app, you can set up systemd services and timers.
You can use systemd
to run the internet check script every minute.
-
Create a Timer: Save the following as
/etc/systemd/system/check_internet.timer
[Unit] Description=Runs Check Internet Connectivity Every Minute [Timer] # Run every minute OnCalendar=*:0/1 AccuracySec=1s Persistent=true [Install] WantedBy=timers.target
-
Create the Service: Save the following as
/etc/systemd/system/check_internet.service
[Unit] Description=Check Internet Connectivity [Service] Type=oneshot ExecStart=/bin/bash /path/to/project/check_internet.sh StandardOutput=append:/path/to/project/logs/check_internet-script.log StandardError=append:/path/to/project/logs/check_internet-script_error.log [Install] WantedBy=multi-user.target
-
Enable the Timer:
sudo systemctl daemon-reload sudo systemctl enable --now check_internet.timer
You can also set up the Dash app to run automatically on system startup.
-
Create the Service: Save the following as
/etc/systemd/system/dash_app.service
[Unit] Description=Dash App for Internet Status Monitoring After=network.target redis-server.service [Service] User=<your-username> WorkingDirectory=/path/to/project/ ExecStart=/path/to/project/venv/bin/python3 /path/to/project/internet_status_dashboard.py Restart=always RestartSec=10 Environment=PYTHONUNBUFFERED=1 [Install] WantedBy=multi-user.target
-
Enable the Dash App Service:
sudo systemctl daemon-reload sudo systemctl enable dash_app.service sudo systemctl start dash_app.service
-
To check if the internet check service is running properly:
sudo systemctl status check_internet.service
-
To check if the Dash app service is running:
sudo systemctl status dash_app.service
The Dash app provides a web interface to monitor network connectivity and manually trigger power cycling.
-
Run the Dash App:
cd /path/to/project/ python3 internet_status_dashboard.py
-
Access the App: Navigate to
http://<your-server-ip>:8050
in a browser to access the dashboard.
-
The Internet Check:
- The
check_interet.sh
script runs every minute via the systemd timer. - It pings 3 target IPs. If all fail for 5 consecutive attempts, it triggers the modem power cycle via the Tapo smart plug.
- Each result is logged in an SQLite database, and details like packet loss, latency, and success rate are recorded.
- The
-
The Power Cycle:
- The
power_cycle_nbn.py
script communicates with a Tapo smart plug to power cycle the modem. - A cooldown period of 10 minutes ensures that consecutive power cycles do not happen too soon.
- The
-
The Dashboard:
- The Dash web app provides a graphical view of the network history and current connection satus, and a power cycle button for the tapo plug.
It shows metrics like success rates, latency, and packet loss.
- You can manually trigger a power cycle from the dashboard by clicking the Power Cycle NBN Plug button.
- Logs: All logs are stored in the
logs/
directory, and can be useful for debugging. - Database: The SQLite database (
internet_status.db
) stores all the ping data for the dashboard and logs.