SIM800C/script
2025-05-05 23:26:44 +02:00

59 lines
1.1 KiB
Bash

#!/bin/bash
# /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)
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
echo 0 > "/sys/class/gpio/gpio$PIN_NUMBER/value"
echo $PIN_NUMBER > /sys/class/gpio/unexport
;;
restart|reload)
$0 stop
sleep 10
$0 start
;;
healthcheck)
# 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.service
# $0 restart
exit 1
else
echo "Healthcheck passed"
exit 0
fi
;;
*)
echo "Usage: $0 {start|stop|restart|healthcheck}"
exit 1
esac
exit 0