From 33d22addae4ef2e7d1de3e91b5d6ed7564d2e81e Mon Sep 17 00:00:00 2001 From: justmarvinn Date: Mon, 5 May 2025 23:26:44 +0200 Subject: [PATCH] hardware reset fixes --- README.md | 24 +++++++++++------------- healthcheck-timer | 6 +++--- install.sh | 4 ---- script | 37 +++++++++++++++++++++++++------------ service | 2 +- 5 files changed, 40 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index b438a59..ba0c998 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,11 @@ +## Dependencies + +### Ubuntu +```SHELL +sudo apt remove -y inetutils-ping +sudo apt install -y ppp iputils-ping +``` + ## Install ### Ubuntu @@ -9,27 +17,17 @@ curl -sSL "https://git.openergy.ru/LUCKFOX/SIM800C/raw/branch/main/install.sh" | - Start & enable on startup ```SHELL -sudo systemctl start sim800 -sudo systemctl enable sim800 sudo systemctl start sim800-healthcheck.timer sudo systemctl enable sim800-healthcheck.timer ``` -- Stop +- Stop & disable on startup ```SHELL -sudo systemctl stop sim800 sudo systemctl stop sim800-healthcheck.timer +sudo systemctl disable sim800-healthcheck.timer ``` -- Restart +- Restart immediately ```SHELL sudo systemctl restart sim800 ``` - -## Dependencies - -### Ubuntu -```SHELL -sudo apt remove -y inetutils-ping -sudo apt install -y ppp iputils-ping -``` diff --git a/healthcheck-timer b/healthcheck-timer index fbb5af6..e2f0383 100644 --- a/healthcheck-timer +++ b/healthcheck-timer @@ -2,11 +2,11 @@ [Unit] Description=SIM800 healthcheck timer -After=sim800.service +After=rc-local.service [Timer] -OnBootSec=1min -OnUnitActiveSec=1m +OnBootSec=2min +OnUnitActiveSec=2m [Install] WantedBy=timers.target diff --git a/install.sh b/install.sh index 04c6b70..503128b 100644 --- a/install.sh +++ b/install.sh @@ -24,7 +24,3 @@ curl -sSL "https://git.openergy.ru/LUCKFOX/SIM800C/raw/branch/main/healthcheck-s curl -sSL "https://git.openergy.ru/LUCKFOX/SIM800C/raw/branch/main/healthcheck-timer" > /etc/systemd/system/sim800-healthcheck.timer chmod +x /etc/init.d/sim800c -systemctl enable sim800 -systemctl start sim800 -systemctl enable sim800-healthcheck -systemctl start sim800-healthcheck diff --git a/script b/script index 59c18e5..a57db2b 100644 --- a/script +++ b/script @@ -2,34 +2,47 @@ # /etc/init.d/sim800c +INTERFACE_NAME=ppp0 +# see https://wiki.luckfox.com/Luckfox-Pico/Luckfox-Pico-GPIO for details +PIN_NUMBER=34 + case "$1" in start) - # echo "AT+CFUN=1,1" > /dev/ttyS3 - # sleep 3 - # echo "AT+IPR=115200" > /dev/ttyS3 - # sleep 1 + if ip link show $INTERFACE_NAME > /dev/null 2>&1; then + echo "Interface $INTERFACE_NAME already exists" + exit 1 + fi + + if [ ! -d "/sys/class/gpio/gpio{PIN_NUMBER}" ]; then + echo $PIN_NUMBER > /sys/class/gpio/export + fi + echo out > "/sys/class/gpio/gpio$PIN_NUMBER/direction" + echo 1 > "/sys/class/gpio/gpio$PIN_NUMBER/active_low" + echo 1 > "/sys/class/gpio/gpio$PIN_NUMBER/value" pon sim800c ;; stop) poff sim800c - # sleep 3 - # echo "+++" > /dev/ttyS3 - # sleep 3 - # echo "AT+CFUN=1,1" > /dev/ttyS3 - # sleep 3 + echo 0 > "/sys/class/gpio/gpio$PIN_NUMBER/value" + echo $PIN_NUMBER > /sys/class/gpio/unexport ;; restart|reload) $0 stop - sleep 1 + sleep 10 $0 start ;; healthcheck) - if ! ping -I ppp0 -c 5 -W 5 1.1.1.1 > /dev/null; then + # DNS names also available + PUBLIC_ADDR=1.1.1.1 + PACKET_COUNT=5 + TIMEOUT=10 + if ! ping -I $INTERFACE_NAME -c $PACKET_COUNT -W $TIMEOUT $PUBLIC_ADDR > /dev/null 2>&1; then echo "Healthcheck failed" - systemctl restart sim800 + systemctl restart sim800.service + # $0 restart exit 1 else echo "Healthcheck passed" diff --git a/service b/service index 98ed7ad..86bd732 100644 --- a/service +++ b/service @@ -6,9 +6,9 @@ After=rc-local.service [Service] Type=forking -# PIDFile=/run/ppp0.pid ExecStart=/etc/init.d/sim800c start ExecStop=/etc/init.d/sim800c stop +# PIDFile=/run/ppp0.pid # Restart=on-failure # RestartSec=5s