2016-03-21 19:36:55 +00:00
|
|
|
#! /bin/bash
|
|
|
|
|
2016-03-21 21:20:50 +00:00
|
|
|
# Configure the global and local configuration files via the environment
|
|
|
|
|
2016-03-22 04:10:53 +00:00
|
|
|
echo "******************"
|
|
|
|
echo "*** Configuration:"
|
|
|
|
echo "******************"
|
2016-03-21 21:20:50 +00:00
|
|
|
|
2016-03-22 17:45:40 +00:00
|
|
|
if [[ $GATEWAY_REGION == "" ]]; then
|
|
|
|
echo "ERROR: NO GATEWAY_REGION FOUND IN ENVIRONMENT"
|
2016-03-22 18:09:32 +00:00
|
|
|
while true; do sleep 10; done
|
2016-03-22 17:45:40 +00:00
|
|
|
fi
|
|
|
|
echo GATEWAY_REGION: $GATEWAY_REGION
|
|
|
|
|
2016-03-21 21:20:50 +00:00
|
|
|
if [[ $GATEWAY_NAME == "" ]]; then
|
|
|
|
echo "ERROR: NO GATEWAY_NAME FOUND IN ENVIRONMENT"
|
2016-03-22 18:09:32 +00:00
|
|
|
while true; do sleep 10; done # don't exit in resin
|
|
|
|
exit 1
|
2016-03-21 21:20:50 +00:00
|
|
|
fi
|
|
|
|
echo GATEWAY_NAME: $GATEWAY_NAME
|
|
|
|
|
|
|
|
if [[ $GATEWAY_EMAIL == "" ]]; then
|
|
|
|
echo "ERROR: NO GATEWAY_EMAIL FOUND IN ENVIRONMENT"
|
2016-03-22 18:09:32 +00:00
|
|
|
while true; do sleep 10; done # don't exit in resin
|
|
|
|
exit 1
|
2016-03-21 21:20:50 +00:00
|
|
|
fi
|
|
|
|
echo GATEWAY_EMAIL: $GATEWAY_EMAIL
|
|
|
|
|
|
|
|
if [[ $GATEWAY_LAT == "" ]]; then
|
|
|
|
echo "ERROR: NO GATEWAY_LAT (latitude) FOUND IN ENVIRONMENT"
|
2016-03-22 18:09:32 +00:00
|
|
|
while true; do sleep 10; done # don't exit in resin
|
|
|
|
exit 1
|
2016-03-21 21:20:50 +00:00
|
|
|
fi
|
|
|
|
echo GATEWAY_LAT: $GATEWAY_LAT
|
|
|
|
|
|
|
|
if [[ $GATEWAY_LON == "" ]]; then
|
|
|
|
echo "ERROR: NO GATEWAY_LON (longitude) FOUND IN ENVIRONMENT"
|
2016-03-22 18:09:32 +00:00
|
|
|
while true; do sleep 10; done # don't exit in resin
|
|
|
|
exit 1
|
2016-03-21 21:20:50 +00:00
|
|
|
fi
|
|
|
|
echo GATEWAY_LON: $GATEWAY_LON
|
|
|
|
|
|
|
|
if [[ $GATEWAY_ALT == "" ]]; then
|
|
|
|
echo "ERROR: NO GATEWAY_ALT (altitude) FOUND IN ENVIRONMENT"
|
2016-03-22 18:09:32 +00:00
|
|
|
while true; do sleep 10; done # don't exit in resin
|
2016-03-21 21:20:50 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
echo GATEWAY_ALT: $GATEWAY_ALT
|
|
|
|
|
2016-03-22 04:10:53 +00:00
|
|
|
echo "******************"
|
2016-03-21 21:20:50 +00:00
|
|
|
echo ""
|
|
|
|
|
2016-03-22 17:45:40 +00:00
|
|
|
# load the region-appropriate global conf
|
|
|
|
|
2016-03-22 18:45:20 +00:00
|
|
|
if curl --fail https://raw.githubusercontent.com/rayozzie/ttn-gateway-conf/master/$GATEWAY_REGION-global_conf.json --output ./global_conf.json
|
2016-03-22 17:45:40 +00:00
|
|
|
then
|
2016-03-22 18:45:20 +00:00
|
|
|
echo Successfully loaded $GATEWAY_REGION-global_conf.json from TTN repo
|
2016-03-22 18:09:32 +00:00
|
|
|
else
|
2016-03-22 17:45:40 +00:00
|
|
|
echo "******************"
|
2016-03-22 18:09:32 +00:00
|
|
|
echo "ERROR: GATEWAY_REGION not found"
|
2016-03-22 17:45:40 +00:00
|
|
|
echo "******************"
|
2016-03-22 18:09:32 +00:00
|
|
|
while true; do sleep 10; done # don't exit in resin
|
2016-03-22 17:45:40 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# create local.conf
|
|
|
|
|
2016-03-22 19:09:41 +00:00
|
|
|
echo -e "{\n\
|
|
|
|
\t\"gateway_conf\": {\n\
|
2016-03-22 18:45:20 +00:00
|
|
|
\t\t\"gateway_ID\": \"0000000000000000\",\n\
|
|
|
|
\t\t\"ref_latitude\": $GATEWAY_LAT,\n\
|
|
|
|
\t\t\"ref_longitude\": $GATEWAY_LON,\n\
|
|
|
|
\t\t\"ref_altitude\": $GATEWAY_ALT,\n\
|
|
|
|
\t\t\"contact_email\": \"$GATEWAY_EMAIL\",\n\
|
|
|
|
\t\t\"description\": \"$GATEWAY_NAME\" \n\
|
|
|
|
\t}\n\
|
|
|
|
}" >./local_conf.json
|
2016-03-21 21:20:50 +00:00
|
|
|
|
2016-03-21 19:36:55 +00:00
|
|
|
# Reset gateway ID based on MAC
|
2016-03-21 22:58:37 +00:00
|
|
|
|
2016-03-22 04:10:53 +00:00
|
|
|
echo "******************"
|
|
|
|
../packet_forwarder/reset_pkt_fwd.sh start ./local_conf.json
|
|
|
|
echo "******************"
|
2016-03-21 22:58:37 +00:00
|
|
|
echo ""
|
|
|
|
|
2016-03-21 19:36:55 +00:00
|
|
|
# Test the connection, wait if needed.
|
|
|
|
while [[ $(ping -c1 google.com 2>&1 | grep " 0% packet loss") == "" ]]; do
|
|
|
|
echo "[TTN Gateway]: Waiting for internet connection..."
|
|
|
|
sleep 30
|
|
|
|
done
|
|
|
|
|
|
|
|
# Fire up the forwarder.
|
|
|
|
while true
|
|
|
|
do
|
|
|
|
echo "[TTN Gateway]: Starting packet forwarder..."
|
|
|
|
./poly_pkt_fwd
|
2016-03-22 04:10:53 +00:00
|
|
|
echo "******************"
|
2016-03-22 04:21:11 +00:00
|
|
|
echo "*** [TTN Gateway]: EXIT (retrying in 15s)"
|
2016-03-22 04:10:53 +00:00
|
|
|
echo "******************"
|
2016-03-21 19:36:55 +00:00
|
|
|
sleep 15
|
|
|
|
done
|