Here an updated init.d script for broadcasting the output of ArduPilot to the whole network.
It should support auto recognition of the proper broadcasting IP adress of the interface “wlan0”.
#!/bin/sh
### BEGIN INIT INFO
# Provides: ArduProxy
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Multiplexes the UDP socket connection of ArduPilot
# Description: If using the RPi as a WiFi access point, we want all connected computers to get the state of the vehicle.
### END INIT INFO
NAME=ArduProxy
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin
DIR=/usr/bin
BIN=socat
DAEMON=$DIR/$BIN
CONFF="/etc/network/interfaces"
DESC="ArduProxy @ Navio+"
PORT="14550"
PIDFILE=/var/run/$NAME.pid
# Check for missing binaries (socat)
test -x $DAEMON || { echo "$BIN not installed";
if [ "$1" = "stop" ]; then exit 0;
else exit 5; fi; }
# Check for existence of a network interfaces configuration file
test -r $CONFF || { echo "$CONFF not existing";
if [ "$1" = "stop" ]; then exit 0;
else exit 6; fi; }
# Get the network adress of the interface wlan0
NETWORK=$(awk -v par="wlan0" '
/^iface/ && $2==par {f=1}
f && /^\s*address/ {ip=$2; sub(".1$", ".255", ip); print ip; f=0}' $CONFF)
# If IP was found, prepare option parameter for 'socat'
# else exit this script
if [ "$NETWORK" = "" ]; then echo "Error: no address for interface wlan0 was defined."; exit 0; fi
OPTIONS="UDP4-LISTEN:$PORT,fork UDP4-DATAGRAM:$NETWORK:$PORT,broadcast"
# Load some functions for the process administration
. /lib/lsb/init-functions
do_start() {
log_daemon_msg "Starting system $DAEMON $ARGS daemon"
/sbin/start-stop-daemon --start --pidfile $PIDFILE \
-b --make-pidfile \
--exec $DAEMON -- $OPTIONS
log_end_msg $?
}
do_stop() {
log_daemon_msg "Stopping system $DAEMON $ARGS daemon"
/sbin/start-stop-daemon --stop --pidfile $PIDFILE --verbose
log_end_msg $?
}
case "$1" in
start)
do_start
;;
stop)
log_daemon_msg "Stopping system $DAEMON $ARGS daemon"
do_stop
;;
restart|reload|force-reload)
do_stop
do_start
;;
status)
status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $?
;;
*)
echo "Usage: /etc/init.d/$USER {start|stop|restart|status}"
exit 1
;;
esac
exit 0