forked from ttn-zh/ic880a-gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.sh
executable file
·55 lines (44 loc) · 1.75 KB
/
start.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#! /bin/bash
# Reset iC880a PIN
SX1301_RESET_BCM_PIN=25
echo "$SX1301_RESET_BCM_PIN" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio$SX1301_RESET_BCM_PIN/direction
echo "0" > /sys/class/gpio/gpio$SX1301_RESET_BCM_PIN/value
sleep 0.1
echo "1" > /sys/class/gpio/gpio$SX1301_RESET_BCM_PIN/value
sleep 0.1
echo "0" > /sys/class/gpio/gpio$SX1301_RESET_BCM_PIN/value
sleep 0.1
echo "$SX1301_RESET_BCM_PIN" > /sys/class/gpio/unexport
# 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
# If there's a remote config, try to update it
if [ -d ../gateway-remote-config ]; then
# First pull from the repo
pushd ../gateway-remote-config/
git pull
git reset --hard
popd
# And then try to refresh the gateway EUI and re-link local_conf.json
# Same eth0/wlan0 fallback as on install.sh
GATEWAY_EUI_NIC="eth0"
if [[ `grep "$GATEWAY_EUI_NIC" /proc/net/dev` == "" ]]; then
GATEWAY_EUI_NIC="wlan0"
fi
if [[ `grep "$GATEWAY_EUI_NIC" /proc/net/dev` == "" ]]; then
echo "ERROR: No network interface found. Cannot set gateway ID."
exit 1
fi
GATEWAY_EUI=$(ip link show $GATEWAY_EUI_NIC | awk '/ether/ {print $2}' | awk -F\: '{print $1$2$3"FFFE"$4$5$6}')
GATEWAY_EUI=${GATEWAY_EUI^^} # toupper
echo "[TTN Gateway]: Use Gateway EUI $GATEWAY_EUI based on $GATEWAY_EUI_NIC"
INSTALL_DIR="/opt/ttn-gateway"
LOCAL_CONFIG_FILE=$INSTALL_DIR/bin/local_conf.json
if [ -e $LOCAL_CONFIG_FILE ]; then rm $LOCAL_CONFIG_FILE; fi;
ln -s $INSTALL_DIR/gateway-remote-config/$GATEWAY_EUI.json $LOCAL_CONFIG_FILE
fi
# Fire up the forwarder.
./poly_pkt_fwd