Compiling gateway connector from kersing's github

This commit is contained in:
JP Meijers 2017-02-24 23:01:00 +00:00
parent c361f88bba
commit df39d319cc
3 changed files with 87 additions and 122 deletions

23
Dockerfile Normal file
View 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"]

View File

@ -1,71 +1,47 @@
#! /bin/bash #! /bin/bash
# Stop on the first sign of trouble mkdir -p /opt/ttn-gateway/dev
set -e cd /opt/ttn-gateway/dev
echo "The Things Network Raspberry Pi Gateway Builder/Installer"
echo ""
# 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 git clone git://git.drogon.net/wiringPi
pushd wiringPi cd wiringPi
else cd ..
pushd wiringPi git clone https://github.com/kersing/lora_gateway.git
git reset --hard git clone https://github.com/kersing/paho.mqtt.embedded-c.git
git pull git clone https://github.com/kersing/ttn-gateway-connector.git
fi git clone https://github.com/kersing/protobuf-c.git
./build git clone https://github.com/kersing/packet_forwarder.git
popd git clone https://github.com/google/protobuf.git
# Build LoRa gateway app for this specific platform apt update
if [ ! -d lora_gateway ]; then apt install protobuf-compiler
git clone https://github.com/TheThingsNetwork/lora_gateway.git apt install libprotobuf-dev
pushd lora_gateway apt install libprotoc-dev
else apt install automake
pushd lora_gateway apt install libtool
git reset --hard apt install autoconf
git pull
fi cd lora_gateway/libloragw
sed -i -e 's/PLATFORM= kerlink/PLATFORM= imst_rpi/g' ./libloragw/library.cfg sed -i -e 's/PLATFORM= .*$/PLATFORM= imst_rpi/g' library.cfg
# Comment the following in or out as needed for hardware debugging sed -i -e 's/CFG_SPI= .*$/CFG_SPI= native/g' library.cfg
#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
make make
popd
# Build the packet forwarder cd ../../protobuf-c
if [ ! -d packet_forwarder ]; then ./autogen.sh
git clone https://github.com/TheThingsNetwork/packet_forwarder.git ./configure
pushd packet_forwarder make protobuf-c/libprotobuf-c.la
else mkdir bin
pushd packet_forwarder ./libtool install /usr/bin/install -c protobuf-c/libprotobuf-c.la `pwd`/bin
git pull
git reset --hard cd ../paho.mqtt.embedded-c/
fi
make make
popd make install
# Restore location back to where we were prior to starting the build cd ../ttn-gateway-connector
popd 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 cd ../packet_forwarder/mp_pkt_fwd/
cp $BUILD_DIR/packet_forwarder/reset_pkt_fwd.sh $INSTALL_DIR/set-gateway-id.sh make
cp $BUILD_DIR/packet_forwarder/poly_pkt_fwd/poly_pkt_fwd $INSTALL_DIR/ttn-gateway
echo "Build & Installation Completed." echo "Build & Installation Completed."

90
run.sh
View File

@ -2,7 +2,7 @@
# Exit if we're debugging and haven't yet built the gateway # 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" echo "ERROR: gateway executable not yet built"
exit 1 exit 1
fi fi
@ -59,6 +59,7 @@ if [[ $GW_REGION == "" ]]; then
echo "ERROR: GW_REGION required" echo "ERROR: GW_REGION required"
exit 1 exit 1
fi fi
GW_REGION=${GW_REGION^^}
echo GW_REGION: $GW_REGION echo GW_REGION: $GW_REGION
if [[ $GW_DESCRIPTION == "" ]]; then if [[ $GW_DESCRIPTION == "" ]]; then
@ -73,6 +74,18 @@ if [[ $GW_CONTACT_EMAIL == "" ]]; then
exit 1 exit 1
fi 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 "******************"
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_REF_ALTITUDE == "" ]]; then GW_REF_ALTITUDE="3"; fi
if [[ $GW_GPS == "" ]]; then GW_GPS="true"; 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 == "" ]] if [[ $GW_GPS_TTY_PATH == "" ]]
then then
@ -135,23 +133,6 @@ fi
if [[ $GW_FAKE_GPS == "" ]]; then GW_FAKE_GPS="false"; 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 # Synthesize local.conf JSON from env vars
echo -e "{\n\ echo -e "{\n\
@ -162,42 +143,26 @@ echo -e "{\n\
\t\t\"contact_email\": \"$GW_CONTACT_EMAIL\",\n\ \t\t\"contact_email\": \"$GW_CONTACT_EMAIL\",\n\
\t\t\"description\": \"$GW_DESCRIPTION\", \n\ \t\t\"description\": \"$GW_DESCRIPTION\", \n\
\t\t\"gps\": $GW_GPS,\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\"gps_tty_path\": \"$GW_GPS_TTY_PATH\",\n\
\t\t\"fake_gps\": $GW_FAKE_GPS,\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\"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\ \t}\n\
}" >./local_conf.json }" >./local_conf.json
# Set gateway_ID in local_conf.json to the gateway's MAC address # Set gateway_ID in local_conf.json to the gateway's MAC address
echo "******************" #echo "******************"
./set-gateway-id.sh start ./local_conf.json #./set-gateway-id.sh start ./local_conf.json
echo "******************" #echo "******************"
echo "" #echo ""
# Fire up the forwarder. # Fire up the forwarder.
@ -253,7 +218,8 @@ do
fi fi
echo "[TTN Gateway]: Starting packet forwarder..." 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 "****************** $CUSTOM_RESET_PIN"
echo "*** [TTN Gateway]: EXIT (retrying in 15s)" echo "*** [TTN Gateway]: EXIT (retrying in 15s)"
echo "******************" echo "******************"