Simple script to reboot your Tenda4g09 router as soon as it looses connection to LTE. Relies on tenda4g09 Python library.
Can be used with docker or directly (eg. on a raspberry pi).
Simple script to reboot your Tenda4g09 router as soon as it looses connection to LTE. Relies on tenda4g09 Python library.
Can be used with docker or directly (eg. on a raspberry pi).
version: "3.3" | |
services: | |
tenda: | |
build: . | |
environment: | |
TENDA_HOST: 192.168.0.1 | |
TENDA_PASSWORD: somepassword | |
labels: | |
# Force reboot every day at two am | |
ofelia.enabled: "true" | |
ofelia.job-exec.datecron.schedule: "0 0 2 * *" | |
ofelia.job-exec.datecron.command: "python3 /reboot.py" | |
ofelia: | |
image: mcuadros/ofelia:latest | |
command: daemon --docker | |
volumes: | |
- /var/run/docker.sock:/var/run/docker.sock:ro | |
- ./logs:/logs | |
labels: | |
ofelia.save-folder: "/logs" | |
depends_on: | |
- tenda |
FROM python:3-alpine | |
RUN pip install tenda4g09 | |
COPY ./run.py /run.py | |
COPY ./reboot.py /reboot.py | |
CMD ["/usr/local/bin/python3", "-u", "/run.py"] |
import os | |
from tenda4g09 import Tenda4G09 | |
tenda = Tenda4G09(os.environ['TENDA_HOST']) | |
success = False | |
# Try as may times as necessary | |
while not success: | |
success = tenda.login(os.environ['TENDA_PASSWORD']) | |
if success: | |
success = tenda.reboot() | |
print("Reboot OK" if success else "Reboot ERROR! Retrying...") | |
else: | |
print("Login error! Retrying...") |
import os, time | |
from tenda4g09 import Tenda4G09 | |
tenda = Tenda4G09(os.environ['TENDA_HOST']) | |
while True: | |
if tenda.login(os.environ['TENDA_PASSWORD']): | |
while True: | |
ret, status = tenda.status() | |
if not ret: | |
# logging in when someone else is using the api (eg. in the webinterface) will kicj that other someoue out | |
# -> Sleep a while to keep the webinterface usable | |
print("Cannot get status. Assuming someone else is using the api and sleeping for 10 minutes before logging in again.") | |
time.sleep(60*10) | |
break | |
elif status["simInfo"]["internetStatus"] == "1": | |
print("Internet OK :D") | |
else: | |
print("Internet ERROR!") | |
print("Reboot OK" if tenda.reboot() else "Reboot ERROR") | |
# Check every 5 seconds | |
time.sleep(5) |