Compiling gateway connector from kersing's github
This commit is contained in:
parent
c361f88bba
commit
df39d319cc
23
Dockerfile
Normal file
23
Dockerfile
Normal file
@ -0,0 +1,23 @@
|
||||
FROM resin/raspberrypi-buildpack-deps
|
||||
|
||||
# Enable systemd, as Resin requires this
|
||||
#ENV INITSYSTEM on
|
||||
|
||||
# Make the hardware type available as a runtime env var
|
||||
ENV RESIN_ARCH %%RESIN_ARCH%%
|
||||
ENV RESIN_MACHINE_NAME %%RESIN_MACHINE_NAME%%
|
||||
|
||||
# Version number of gateway software.
|
||||
# (Incrementing this simply forces Docker to flush its cache
|
||||
# and thus forces a full rebuild. Not used outside of Dockerfile.)
|
||||
ENV TTN_GATEWAY_SOFTWARE 51
|
||||
|
||||
# Copy the build and run environment
|
||||
COPY . /opt/ttn-gateway/
|
||||
WORKDIR /opt/ttn-gateway/
|
||||
|
||||
# Build the gateway (or comment this out if debugging on-device)
|
||||
RUN ./dev/build.sh && rm -rf ./dev
|
||||
|
||||
# Start it up
|
||||
CMD ["sh", "-c", "./run.sh"]
|
96
dev/build.sh
96
dev/build.sh
@ -1,71 +1,47 @@
|
||||
#! /bin/bash
|
||||
|
||||
# Stop on the first sign of trouble
|
||||
set -e
|
||||
mkdir -p /opt/ttn-gateway/dev
|
||||
cd /opt/ttn-gateway/dev
|
||||
git clone git://git.drogon.net/wiringPi
|
||||
cd wiringPi
|
||||
cd ..
|
||||
git clone https://github.com/kersing/lora_gateway.git
|
||||
git clone https://github.com/kersing/paho.mqtt.embedded-c.git
|
||||
git clone https://github.com/kersing/ttn-gateway-connector.git
|
||||
git clone https://github.com/kersing/protobuf-c.git
|
||||
git clone https://github.com/kersing/packet_forwarder.git
|
||||
git clone https://github.com/google/protobuf.git
|
||||
|
||||
echo "The Things Network Raspberry Pi Gateway Builder/Installer"
|
||||
echo ""
|
||||
apt update
|
||||
apt install protobuf-compiler
|
||||
apt install libprotobuf-dev
|
||||
apt install libprotoc-dev
|
||||
apt install automake
|
||||
apt install libtool
|
||||
apt install autoconf
|
||||
|
||||
# Build in a temp folder that we'll completely purge after build,
|
||||
# and install into the linux folder where apps reside.
|
||||
|
||||
INSTALL_DIR="/opt/ttn-gateway"
|
||||
if [ ! -d "$INSTALL_DIR" ]; then mkdir $INSTALL_DIR; fi
|
||||
|
||||
BUILD_DIR="$INSTALL_DIR/dev"
|
||||
if [ ! -d "$BUILD_DIR" ]; then mkdir $BUILD_DIR; fi
|
||||
|
||||
# Switch to where we'll do the builds
|
||||
pushd $BUILD_DIR
|
||||
|
||||
# Build WiringPi so that we can do Raspberry Pi I/O
|
||||
if [ ! -d wiringPi ]; then
|
||||
git clone git://git.drogon.net/wiringPi
|
||||
pushd wiringPi
|
||||
else
|
||||
pushd wiringPi
|
||||
git reset --hard
|
||||
git pull
|
||||
fi
|
||||
./build
|
||||
popd
|
||||
|
||||
# Build LoRa gateway app for this specific platform
|
||||
if [ ! -d lora_gateway ]; then
|
||||
git clone https://github.com/TheThingsNetwork/lora_gateway.git
|
||||
pushd lora_gateway
|
||||
else
|
||||
pushd lora_gateway
|
||||
git reset --hard
|
||||
git pull
|
||||
fi
|
||||
sed -i -e 's/PLATFORM= kerlink/PLATFORM= imst_rpi/g' ./libloragw/library.cfg
|
||||
# Comment the following in or out as needed for hardware debugging
|
||||
#sed -i -e 's/DEBUG_SPI= 0/DEBUG_SPI= 1/g' ./libloragw/library.cfg
|
||||
#sed -i -e 's/DEBUG_REG= 0/DEBUG_REG= 1/g' ./libloragw/library.cfg
|
||||
#sed -i -e 's/DEBUG_HAL= 0/DEBUG_HAL= 1/g' ./libloragw/library.cfg
|
||||
#sed -i -e 's/DEBUG_AUX= 0/DEBUG_AUX= 1/g' ./libloragw/library.cfg
|
||||
#sed -i -e 's/DEBUG_GPS= 0/DEBUG_GPS= 1/g' ./libloragw/library.cfg
|
||||
cd lora_gateway/libloragw
|
||||
sed -i -e 's/PLATFORM= .*$/PLATFORM= imst_rpi/g' library.cfg
|
||||
sed -i -e 's/CFG_SPI= .*$/CFG_SPI= native/g' library.cfg
|
||||
make
|
||||
popd
|
||||
|
||||
# Build the packet forwarder
|
||||
if [ ! -d packet_forwarder ]; then
|
||||
git clone https://github.com/TheThingsNetwork/packet_forwarder.git
|
||||
pushd packet_forwarder
|
||||
else
|
||||
pushd packet_forwarder
|
||||
git pull
|
||||
git reset --hard
|
||||
fi
|
||||
cd ../../protobuf-c
|
||||
./autogen.sh
|
||||
./configure
|
||||
make protobuf-c/libprotobuf-c.la
|
||||
mkdir bin
|
||||
./libtool install /usr/bin/install -c protobuf-c/libprotobuf-c.la `pwd`/bin
|
||||
|
||||
cd ../paho.mqtt.embedded-c/
|
||||
make
|
||||
popd
|
||||
make install
|
||||
|
||||
# Restore location back to where we were prior to starting the build
|
||||
popd
|
||||
cd ../ttn-gateway-connector
|
||||
cp config.mk.in config.mk
|
||||
make
|
||||
cp bin/libttn-gateway-connector.so /usr/lib/
|
||||
|
||||
# Copy things needed at runtime to where they'll be expected
|
||||
cp $BUILD_DIR/packet_forwarder/reset_pkt_fwd.sh $INSTALL_DIR/set-gateway-id.sh
|
||||
cp $BUILD_DIR/packet_forwarder/poly_pkt_fwd/poly_pkt_fwd $INSTALL_DIR/ttn-gateway
|
||||
cd ../packet_forwarder/mp_pkt_fwd/
|
||||
make
|
||||
|
||||
echo "Build & Installation Completed."
|
||||
|
90
run.sh
90
run.sh
@ -2,7 +2,7 @@
|
||||
|
||||
# Exit if we're debugging and haven't yet built the gateway
|
||||
|
||||
if [ ! -f "ttn-gateway" ]; then
|
||||
if [ ! -f "/opt/ttn-gateway/dev/packet_forwarder/mp_pkt_fwd/mp_pkt_fwd" ]; then
|
||||
echo "ERROR: gateway executable not yet built"
|
||||
exit 1
|
||||
fi
|
||||
@ -59,6 +59,7 @@ if [[ $GW_REGION == "" ]]; then
|
||||
echo "ERROR: GW_REGION required"
|
||||
exit 1
|
||||
fi
|
||||
GW_REGION=${GW_REGION^^}
|
||||
echo GW_REGION: $GW_REGION
|
||||
|
||||
if [[ $GW_DESCRIPTION == "" ]]; then
|
||||
@ -73,6 +74,18 @@ if [[ $GW_CONTACT_EMAIL == "" ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ $GW_ID == "" ]]; then
|
||||
echo "ERROR: GW_ID required"
|
||||
echo "See https://www.thethingsnetwork.org/docs/gateways/registration.html#via-gateway-connector"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ $GW_KEY == "" ]]; then
|
||||
echo "ERROR: GW_KEY required"
|
||||
echo "See https://www.thethingsnetwork.org/docs/gateways/registration.html#via-gateway-connector"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "******************"
|
||||
echo ""
|
||||
|
||||
@ -107,21 +120,6 @@ if [[ $GW_REF_LONGITUDE == "" ]]; then GW_REF_LONGITUDE="4.884232"; fi
|
||||
if [[ $GW_REF_ALTITUDE == "" ]]; then GW_REF_ALTITUDE="3"; fi
|
||||
|
||||
if [[ $GW_GPS == "" ]]; then GW_GPS="true"; fi
|
||||
if [[ $GW_BEACON == "" ]]; then GW_BEACON="false"; fi
|
||||
if [[ $GW_MONITOR == "" ]]; then GW_MONITOR="false"; fi
|
||||
if [[ $GW_UPSTREAM == "" ]]; then GW_UPSTREAM="true"; fi
|
||||
if [[ $GW_DOWNSTREAM == "" ]]; then GW_DOWNSTREAM="true"; fi
|
||||
if [[ $GW_GHOSTSTREAM == "" ]]; then GW_GHOSTSTREAM="false"; fi
|
||||
if [[ $GW_RADIOSTREAM == "" ]]; then GW_RADIOSTREAM="true"; fi
|
||||
if [[ $GW_STATUSSTREAM == "" ]]; then GW_STATUSSTREAM="true"; fi
|
||||
|
||||
if [[ $GW_KEEPALIVE_INTERVAL == "" ]]; then GW_KEEPALIVE_INTERVAL="10"; fi
|
||||
if [[ $GW_STAT_INTERVAL == "" ]]; then GW_STAT_INTERVAL="30"; fi
|
||||
if [[ $GW_PUSH_TIMEOUT_MS == "" ]]; then GW_PUSH_TIMEOUT_MS="100"; fi
|
||||
|
||||
if [[ $GW_FORWARD_CRC_VALID == "" ]]; then GW_FORWARD_CRC_VALID="true"; fi
|
||||
if [[ $GW_FORWARD_CRC_ERROR == "" ]]; then GW_FORWARD_CRC_ERROR="false"; fi
|
||||
if [[ $GW_FORWARD_CRC_DISABLED == "" ]]; then GW_FORWARD_CRC_DISABLED="false"; fi
|
||||
|
||||
if [[ $GW_GPS_TTY_PATH == "" ]]
|
||||
then
|
||||
@ -135,23 +133,6 @@ fi
|
||||
|
||||
if [[ $GW_FAKE_GPS == "" ]]; then GW_FAKE_GPS="false"; fi
|
||||
|
||||
if [[ $GW_GHOST_ADDRESS == "" ]]; then GW_GHOST_ADDRESS="127.0.0.1"; fi
|
||||
if [[ $GW_GHOST_PORT == "" ]]; then GW_GHOST_PORT="1918"; fi
|
||||
|
||||
if [[ $GW_MONITOR_ADDRESS == "" ]]; then GW_MONITOR_ADDRESS="127.0.0.1"; fi
|
||||
if [[ $GW_MONITOR_PORT == "" ]]; then GW_MONITOR_PORT="2008"; fi
|
||||
|
||||
if [[ $GW_SSH_PATH == "" ]]; then GW_SSH_PATH="/usr/bin/ssh"; fi
|
||||
if [[ $GW_SSH_PORT == "" ]]; then GW_SSH_PORT="22"; fi
|
||||
|
||||
if [[ $GW_HTTP_PORT == "" ]]; then GW_HTTP_PORT="80"; fi
|
||||
|
||||
if [[ $GW_NGROK_PATH == "" ]]; then GW_NGROK_PATH="/usr/bin/ngrok"; fi
|
||||
|
||||
if [[ $GW_SYSTEM_CALLS == "" ]]; then GW_SYSTEM_CALLS="[\"df -m\",\"free -h\",\"uptime\",\"who -a\",\"uname -a\"]"; fi
|
||||
|
||||
if [[ $GW_PLATFORM == "" ]]; then GW_PLATFORM="*"; fi
|
||||
|
||||
# Synthesize local.conf JSON from env vars
|
||||
|
||||
echo -e "{\n\
|
||||
@ -162,42 +143,26 @@ echo -e "{\n\
|
||||
\t\t\"contact_email\": \"$GW_CONTACT_EMAIL\",\n\
|
||||
\t\t\"description\": \"$GW_DESCRIPTION\", \n\
|
||||
\t\t\"gps\": $GW_GPS,\n\
|
||||
\t\t\"beacon\": $GW_BEACON,\n\
|
||||
\t\t\"monitor\": $GW_MONITOR,\n\
|
||||
\t\t\"upstream\": $GW_UPSTREAM,\n\
|
||||
\t\t\"downstream\": $GW_DOWNSTREAM,\n\
|
||||
\t\t\"ghoststream\": $GW_GHOSTSTREAM,\n\
|
||||
\t\t\"radiostream\": $GW_RADIOSTREAM,\n\
|
||||
\t\t\"statusstream\": $GW_STATUSSTREAM,\n\
|
||||
\t\t\"keepalive_interval\": $GW_KEEPALIVE_INTERVAL,\n\
|
||||
\t\t\"stat_interval\": $GW_STAT_INTERVAL,\n\
|
||||
\t\t\"push_timeout_ms\": $GW_PUSH_TIMEOUT_MS,\n\
|
||||
\t\t\"forward_crc_valid\": $GW_FORWARD_CRC_VALID,\n\
|
||||
\t\t\"forward_crc_error\": $GW_FORWARD_CRC_ERROR,\n\
|
||||
\t\t\"forward_crc_disabled\": $GW_FORWARD_CRC_DISABLED,\n\
|
||||
\t\t\"gps_tty_path\": \"$GW_GPS_TTY_PATH\",\n\
|
||||
\t\t\"fake_gps\": $GW_FAKE_GPS,\n\
|
||||
\t\t\"ghost_address\": \"$GW_GHOST_ADDRESS\",\n\
|
||||
\t\t\"ghost_port\": $GW_GHOST_PORT,\n\
|
||||
\t\t\"monitor_address\": \"$GW_MONITOR_ADDRESS\",\n\
|
||||
\t\t\"monitor_port\": $GW_MONITOR_PORT,\n\
|
||||
\t\t\"ssh_path\": \"$GW_SSH_PATH\",\n\
|
||||
\t\t\"ssh_port\": $GW_SSH_PORT,\n\
|
||||
\t\t\"http_port\": $GW_HTTP_PORT,\n\
|
||||
\t\t\"ngrok_path\": \"$GW_NGROK_PATH\",\n\
|
||||
\t\t\"system_calls\": $GW_SYSTEM_CALLS,\n\
|
||||
\t\t\"platform\": \"$GW_PLATFORM\",\n\
|
||||
\t\t\"ipinfo\": $IPINFO,\n\
|
||||
\t\t\"gateway_ID\": \"0000000000000000\"\n\
|
||||
\t\t\"servers\": [\n\
|
||||
\t\t{\
|
||||
\t\t\t\"serv_type\": \"ttn\",\n\
|
||||
\t\t\t\"serv_address\": \"router.$GW_REGION.thethings.network\",\n\
|
||||
\t\t\t\"serv_gw_id\": \"$GW_ID\",\n\
|
||||
\t\t\t\"serv_gw_key\": \"$GW_KEY\",\n\
|
||||
\t\t\t\"serv_enabled\", true
|
||||
\t\t}],\
|
||||
\t}\n\
|
||||
}" >./local_conf.json
|
||||
|
||||
# Set gateway_ID in local_conf.json to the gateway's MAC address
|
||||
|
||||
echo "******************"
|
||||
./set-gateway-id.sh start ./local_conf.json
|
||||
echo "******************"
|
||||
echo ""
|
||||
#echo "******************"
|
||||
#./set-gateway-id.sh start ./local_conf.json
|
||||
#echo "******************"
|
||||
#echo ""
|
||||
|
||||
|
||||
# Fire up the forwarder.
|
||||
@ -253,7 +218,8 @@ do
|
||||
fi
|
||||
|
||||
echo "[TTN Gateway]: Starting packet forwarder..."
|
||||
./ttn-gateway
|
||||
cp /opt/ttn-gateway/dev/packet_forwarder/mp_pkt_fwd/mp_pkt_fwd mp_pkt_fwd
|
||||
./mp_pkt_fwd
|
||||
echo "****************** $CUSTOM_RESET_PIN"
|
||||
echo "*** [TTN Gateway]: EXIT (retrying in 15s)"
|
||||
echo "******************"
|
||||
|
Loading…
Reference in New Issue
Block a user