From 6aa191791686f279ffb13a907a7bd29827f13401 Mon Sep 17 00:00:00 2001 From: mpous Date: Fri, 18 Sep 2020 17:05:36 +0200 Subject: [PATCH 01/16] Corecell build --- Dockerfile.template | 3 ++- setup.gmk | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Dockerfile.template b/Dockerfile.template index 3d3f8f7..c3cfbd0 100644 --- a/Dockerfile.template +++ b/Dockerfile.template @@ -15,7 +15,8 @@ WORKDIR /usr/src/app COPY . . # Compile our source code -RUN make platform=rpi variant=std arch=%%BALENA_ARCH%% +#RUN make platform=rpi variant=std arch=%%BALENA_ARCH%% +RUN make platform=corecell variant=std arch=%%BALENA_ARCH%% # Launch our binary on container startup. CMD ["bash", "start.sh"] diff --git a/setup.gmk b/setup.gmk index 58fbb1f..8a05246 100644 --- a/setup.gmk +++ b/setup.gmk @@ -45,6 +45,7 @@ ARCH.linux.default = x86_64-linux-gnu ARCH.linuxV2.default = x86_64-linux-gnu ARCH.linuxpico.default = x86_64-linux-gnu ARCH.corecell.default = arm-linux-gnueabihf +ARCH.corecell.aarch64 = aarch64-linux-gnu ARCH.rpi.armv7hf = arm-linux-gnueabihf ARCH.rpi.aarch64 = aarch64-linux-gnu ARCH.kerlink.default = arm-klk-linux-gnueabi From 6c604c37aaf878f462dfd2bb60ed6b417ce67dd3 Mon Sep 17 00:00:00 2001 From: mpous Date: Fri, 18 Sep 2020 20:02:58 +0200 Subject: [PATCH 02/16] More changes corecell --- examples/corecell/reset_lgw.sh | 13 +++++++------ start.sh | 13 ++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/examples/corecell/reset_lgw.sh b/examples/corecell/reset_lgw.sh index 0136d72..2332e05 100755 --- a/examples/corecell/reset_lgw.sh +++ b/examples/corecell/reset_lgw.sh @@ -21,16 +21,17 @@ WAIT_GPIO() { init() { # setup GPIOs echo "$SX1302_RESET_PIN" > /sys/class/gpio/export; WAIT_GPIO - echo "$SX1302_POWER_EN_PIN" > /sys/class/gpio/export; WAIT_GPIO + #echo "$SX1302_POWER_EN_PIN" > /sys/class/gpio/export; WAIT_GPIO # set GPIOs as output echo "out" > /sys/class/gpio/gpio$SX1302_RESET_PIN/direction; WAIT_GPIO - echo "out" > /sys/class/gpio/gpio$SX1302_POWER_EN_PIN/direction; WAIT_GPIO + #echo "out" > /sys/class/gpio/gpio$SX1302_POWER_EN_PIN/direction; WAIT_GPIO } reset() { echo "CoreCell reset through GPIO$SX1302_RESET_PIN..." echo "CoreCell power enable through GPIO$SX1302_POWER_EN_PIN..." + echo "SX1302 reset through GPIO$SX1302_RESET_PIN..." # write output for SX1302 CoreCell power_enable and reset echo "1" > /sys/class/gpio/gpio$SX1302_POWER_EN_PIN/value; WAIT_GPIO @@ -45,10 +46,10 @@ term() { then echo "$SX1302_RESET_PIN" > /sys/class/gpio/unexport; WAIT_GPIO fi - if [ -d /sys/class/gpio/gpio$SX1302_POWER_EN_PIN ] - then - echo "$SX1302_POWER_EN_PIN" > /sys/class/gpio/unexport; WAIT_GPIO - fi + #if [ -d /sys/class/gpio/gpio$SX1302_POWER_EN_PIN ] + #then + # echo "$SX1302_POWER_EN_PIN" > /sys/class/gpio/unexport; WAIT_GPIO + #fi } case "$1" in diff --git a/start.sh b/start.sh index 0278622..c6bf68c 100644 --- a/start.sh +++ b/start.sh @@ -22,19 +22,19 @@ declare -a pinToGPIO pinToGPIO=( -1 -1 -1 2 -1 3 -1 4 14 -1 15 17 18 27 -1 22 23 -1 24 10 -1 9 25 11 8 -1 7 0 1 5 -1 6 12 13 -1 19 16 26 20 -1 21) -cd examples/live-s2.sm.tc +cd examples/corecell # Default to TTN server TC_URI=${TC_URI:-"wss://lns.eu.thethings.network:443"} -TC_TRUST=${TC_TRUST:-$(curl https://letsencrypt.org/certs/trustid-x3-root.pem.txt)} +TC_TRUST=${TC_TRUST:-$(curl https://letsencrypt.org/certs/lets-encrypt-x3-cross-signed.pem.txt)} -GW_RESET_PIN=${GW_RESET_PIN:-11} +GW_RESET_PIN=${GW_RESET_PIN:-22} GW_RESET_GPIO=${GW_RESET_GPIO:-${pinToGPIO[$GW_RESET_PIN]}} # Setup TC files from environment -echo $TC_URI > tc.uri -echo "$TC_TRUST" > tc.trust +echo $TC_URI > ./lns-ttn/tc.uri +echo "$TC_TRUST" > ./lns-ttn/tc.trust # Reset gateway echo "Resetting gateway concentrator on GPIO $GW_RESET_GPIO" @@ -45,5 +45,4 @@ echo 1 > /sys/class/gpio/gpio$GW_RESET_GPIO/value echo 0 > /sys/class/gpio/gpio$GW_RESET_GPIO/value echo $GW_RESET_GPIO > /sys/class/gpio/unexport -RADIODEV=/dev/spidev0.0 ../../build-rpi-std/bin/station - +./start-station.sh -l ./lns-ttn From c3e6d96392bbe9ecbef5e1c2fecfc260962b5a66 Mon Sep 17 00:00:00 2001 From: mpous Date: Mon, 21 Sep 2020 22:06:05 +0200 Subject: [PATCH 03/16] the corecell way --- Dockerfile.template | 2 +- examples/corecell/reset_lgw.sh | 19 ++++++------ examples/corecell/start-station.sh | 1 - start-corecell.sh | 47 ++++++++++++++++++++++++++++++ start.sh | 15 +++++----- 5 files changed, 64 insertions(+), 20 deletions(-) create mode 100644 start-corecell.sh diff --git a/Dockerfile.template b/Dockerfile.template index c3cfbd0..65b0740 100644 --- a/Dockerfile.template +++ b/Dockerfile.template @@ -19,4 +19,4 @@ COPY . . RUN make platform=corecell variant=std arch=%%BALENA_ARCH%% # Launch our binary on container startup. -CMD ["bash", "start.sh"] +CMD ["bash", "start-corecell.sh"] diff --git a/examples/corecell/reset_lgw.sh b/examples/corecell/reset_lgw.sh index 2332e05..d8c9c59 100755 --- a/examples/corecell/reset_lgw.sh +++ b/examples/corecell/reset_lgw.sh @@ -11,7 +11,7 @@ # GPIO mapping has to be adapted with HW # -SX1302_RESET_PIN=23 +SX1302_RESET_PIN=17 SX1302_POWER_EN_PIN=18 WAIT_GPIO() { @@ -21,17 +21,16 @@ WAIT_GPIO() { init() { # setup GPIOs echo "$SX1302_RESET_PIN" > /sys/class/gpio/export; WAIT_GPIO - #echo "$SX1302_POWER_EN_PIN" > /sys/class/gpio/export; WAIT_GPIO + echo "$SX1302_POWER_EN_PIN" > /sys/class/gpio/export; WAIT_GPIO # set GPIOs as output echo "out" > /sys/class/gpio/gpio$SX1302_RESET_PIN/direction; WAIT_GPIO - #echo "out" > /sys/class/gpio/gpio$SX1302_POWER_EN_PIN/direction; WAIT_GPIO + echo "out" > /sys/class/gpio/gpio$SX1302_POWER_EN_PIN/direction; WAIT_GPIO } reset() { - echo "CoreCell reset through GPIO$SX1302_RESET_PIN..." - echo "CoreCell power enable through GPIO$SX1302_POWER_EN_PIN..." - echo "SX1302 reset through GPIO$SX1302_RESET_PIN..." + echo "RAK2287 reset through GPIO$SX1302_RESET_PIN..." + echo "RAK2287 power enable through GPIO$SX1302_POWER_EN_PIN..." # write output for SX1302 CoreCell power_enable and reset echo "1" > /sys/class/gpio/gpio$SX1302_POWER_EN_PIN/value; WAIT_GPIO @@ -46,10 +45,10 @@ term() { then echo "$SX1302_RESET_PIN" > /sys/class/gpio/unexport; WAIT_GPIO fi - #if [ -d /sys/class/gpio/gpio$SX1302_POWER_EN_PIN ] - #then - # echo "$SX1302_POWER_EN_PIN" > /sys/class/gpio/unexport; WAIT_GPIO - #fi + if [ -d /sys/class/gpio/gpio$SX1302_POWER_EN_PIN ] + then + echo "$SX1302_POWER_EN_PIN" > /sys/class/gpio/unexport; WAIT_GPIO + fi } case "$1" in diff --git a/examples/corecell/start-station.sh b/examples/corecell/start-station.sh index 5317c19..dc28d0f 100755 --- a/examples/corecell/start-station.sh +++ b/examples/corecell/start-station.sh @@ -78,7 +78,6 @@ fi STATION_BIN="../../build-corecell-$variant/bin/station" - if [ -f "$STATION_BIN" ]; then printf "Using variant=$variant, lns_config='$lns_config'\n" printf "$GREEN Starting Station ... $NC\n" diff --git a/start-corecell.sh b/start-corecell.sh new file mode 100644 index 0000000..92cb632 --- /dev/null +++ b/start-corecell.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash + +TAG_KEY="EUI" +TTN_EUI=$(cat /sys/class/net/eth0/address | sed -r 's/[:]+//g' | sed -e 's#\(.\{6\}\)\(.*\)#\1FFFE\2#g') + +echo $TTN_EUI + +ID=$(curl -sX GET "https://api.balena-cloud.com/v5/device?\$filter=uuid%20eq%20'$BALENA_DEVICE_UUID'" \ +-H "Content-Type: application/json" \ +-H "Authorization: Bearer $BALENA_API_KEY" | \ +jq ".d | .[0] | .id") + +TAG=$(curl -sX POST \ +"https://api.balena-cloud.com/v5/device_tag" \ +-H "Content-Type: application/json" \ +-H "Authorization: Bearer $BALENA_API_KEY" \ +--data "{ \"device\": \"$ID\", \"tag_key\": \"$TAG_KEY\", \"value\": \"$TTN_EUI\" }" > /dev/null) + + +# declare map of hardware pins to GPIO on Raspberry Pi +declare -a pinToGPIO +pinToGPIO=( -1 -1 -1 2 -1 3 -1 4 14 -1 15 17 18 27 -1 22 23 -1 24 10 -1 9 25 11 8 -1 7 0 1 5 -1 6 12 13 -1 19 16 26 20 -1 21) + +cd examples/corecell + +# Default to TTN server +TC_URI=${TC_URI:-"wss://lns.eu.thethings.network:443"} +TC_TRUST=${TC_TRUST:-$(curl https://letsencrypt.org/certs/lets-encrypt-x3-cross-signed.pem.txt)} + + +GW_RESET_PIN=${GW_RESET_PIN:-22} +GW_RESET_GPIO=${GW_RESET_GPIO:-${pinToGPIO[$GW_RESET_PIN]}} + +# Setup TC files from environment +echo $TC_URI > ./lns-ttn/tc.uri +echo "$TC_TRUST" > ./lns-ttn/tc.trust + +# Reset gateway +#echo "Resetting gateway concentrator on GPIO $GW_RESET_GPIO" +#echo $GW_RESET_GPIO > /sys/class/gpio/export +#echo out > /sys/class/gpio/gpio$GW_RESET_GPIO/direction +#echo 0 > /sys/class/gpio/gpio$GW_RESET_GPIO/value +#echo 1 > /sys/class/gpio/gpio$GW_RESET_GPIO/value +#echo 0 > /sys/class/gpio/gpio$GW_RESET_GPIO/value +#echo $GW_RESET_GPIO > /sys/class/gpio/unexport + +./start-station.sh -l ./lns-ttn diff --git a/start.sh b/start.sh index c6bf68c..92cb632 100644 --- a/start.sh +++ b/start.sh @@ -21,7 +21,6 @@ TAG=$(curl -sX POST \ declare -a pinToGPIO pinToGPIO=( -1 -1 -1 2 -1 3 -1 4 14 -1 15 17 18 27 -1 22 23 -1 24 10 -1 9 25 11 8 -1 7 0 1 5 -1 6 12 13 -1 19 16 26 20 -1 21) - cd examples/corecell # Default to TTN server @@ -37,12 +36,12 @@ echo $TC_URI > ./lns-ttn/tc.uri echo "$TC_TRUST" > ./lns-ttn/tc.trust # Reset gateway -echo "Resetting gateway concentrator on GPIO $GW_RESET_GPIO" -echo $GW_RESET_GPIO > /sys/class/gpio/export -echo out > /sys/class/gpio/gpio$GW_RESET_GPIO/direction -echo 0 > /sys/class/gpio/gpio$GW_RESET_GPIO/value -echo 1 > /sys/class/gpio/gpio$GW_RESET_GPIO/value -echo 0 > /sys/class/gpio/gpio$GW_RESET_GPIO/value -echo $GW_RESET_GPIO > /sys/class/gpio/unexport +#echo "Resetting gateway concentrator on GPIO $GW_RESET_GPIO" +#echo $GW_RESET_GPIO > /sys/class/gpio/export +#echo out > /sys/class/gpio/gpio$GW_RESET_GPIO/direction +#echo 0 > /sys/class/gpio/gpio$GW_RESET_GPIO/value +#echo 1 > /sys/class/gpio/gpio$GW_RESET_GPIO/value +#echo 0 > /sys/class/gpio/gpio$GW_RESET_GPIO/value +#echo $GW_RESET_GPIO > /sys/class/gpio/unexport ./start-station.sh -l ./lns-ttn From 4d8c4c1fe015ec9ea6c10fe3e9ab3e44a0b9646e Mon Sep 17 00:00:00 2001 From: mpous Date: Mon, 21 Sep 2020 22:20:23 +0200 Subject: [PATCH 04/16] Corecell last changes --- README.md | 9 +++++---- examples/corecell/lns-ttn/station.conf | 3 +-- start-corecell.sh | 3 ++- start.sh | 8 +++++--- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 5dc2560..738569c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# LoRa Basics™ Station using balena.io and RAK2245 +# LoRa Basics™ Station using balena.io and RAK2287 -This project deploys a TTN LoRa gateway with Basics Station Packet Forward protocol with balena. It runs on a Raspberry Pi or balenaFin with a RAK2245 Pi Hat. +This project deploys a TTN LoRa gateway with Basics Station Packet Forward protocol with balena. It runs on a Raspberry Pi or balenaFin with a RAK2287 concentrator with a Pi Hat. ## Introduction @@ -15,7 +15,8 @@ The Basics Station protocol enables the LoRa gateways with a reliable and secure ### Hardware * Raspberry Pi 4 or [balenaFin](https://www.balena.io/fin/) -* [RAK 2245 pi hat](https://store.rakwireless.com/products/rak2245-pi-hat) +* [RAK 2287 Concentrator](https://store.rakwireless.com/products/rak2287-lpwan-gateway-concentrator-module) +* [RAK 2287 Pi Hat](https://store.rakwireless.com/products/rak2287-pi-hat) * SD card in case of the RPi 4 ### Software @@ -91,7 +92,7 @@ Variable Name | Value | Description | Default **`GW_ID`** | `STRING` | TTN Gateway EUI | (EUI) **`GW_KEY`** | `STRING` | Unique TTN Gateway Key | (Key pasted from TTN console) **`GW_RESET_PIN`** | `STRING` | Pin number that resets | 11 -**`SPI_SPEED`** | `STRING` | The Raspberry Pi and RAK2245 uses SPI to communicate and needs to use a specific speed | 2000000 +**`SPI_SPEED`** | `STRING` | The Raspberry Pi and RAK2287 uses SPI to communicate and needs to use a specific speed | 2000000 **`TC_URI`** | `STRING` | basics station TC URI to get connected. If you are in the EU region use ```wss://lns.{eu-us-in-au}.thethings.network:443``` | ```wss://lns.eu.thethings.network:443``` diff --git a/examples/corecell/lns-ttn/station.conf b/examples/corecell/lns-ttn/station.conf index 4618940..ceaf9b2 100644 --- a/examples/corecell/lns-ttn/station.conf +++ b/examples/corecell/lns-ttn/station.conf @@ -49,5 +49,4 @@ "log_size": 10000000, "log_rotate": 3 } -} - +} \ No newline at end of file diff --git a/start-corecell.sh b/start-corecell.sh index 92cb632..b3a23ac 100644 --- a/start-corecell.sh +++ b/start-corecell.sh @@ -25,7 +25,8 @@ cd examples/corecell # Default to TTN server TC_URI=${TC_URI:-"wss://lns.eu.thethings.network:443"} -TC_TRUST=${TC_TRUST:-$(curl https://letsencrypt.org/certs/lets-encrypt-x3-cross-signed.pem.txt)} +#TC_TRUST=${TC_TRUST:-$(curl https://letsencrypt.org/certs/lets-encrypt-x3-cross-signed.pem.txt)} +TC_TRUST=${TC_TRUST:-$(curl https://letsencrypt.org/certs/trustid-x3-root.pem.txt)} GW_RESET_PIN=${GW_RESET_PIN:-22} diff --git a/start.sh b/start.sh index 92cb632..02e1f58 100644 --- a/start.sh +++ b/start.sh @@ -21,12 +21,12 @@ TAG=$(curl -sX POST \ declare -a pinToGPIO pinToGPIO=( -1 -1 -1 2 -1 3 -1 4 14 -1 15 17 18 27 -1 22 23 -1 24 10 -1 9 25 11 8 -1 7 0 1 5 -1 6 12 13 -1 19 16 26 20 -1 21) -cd examples/corecell + +cd examples/live-s2.sm.tc # Default to TTN server TC_URI=${TC_URI:-"wss://lns.eu.thethings.network:443"} -TC_TRUST=${TC_TRUST:-$(curl https://letsencrypt.org/certs/lets-encrypt-x3-cross-signed.pem.txt)} - +TC_TRUST=${TC_TRUST:-$(curl https://letsencrypt.org/certs/trustid-x3-root.pem.txt)} GW_RESET_PIN=${GW_RESET_PIN:-22} GW_RESET_GPIO=${GW_RESET_GPIO:-${pinToGPIO[$GW_RESET_PIN]}} @@ -44,4 +44,6 @@ echo "$TC_TRUST" > ./lns-ttn/tc.trust #echo 0 > /sys/class/gpio/gpio$GW_RESET_GPIO/value #echo $GW_RESET_GPIO > /sys/class/gpio/unexport +#RADIODEV=/dev/spidev0.0 ../../build-rpi-std/bin/station ./start-station.sh -l ./lns-ttn + From 3436e0d52badf4ca23ddc4c970466284b1b4b6cb Mon Sep 17 00:00:00 2001 From: mpous Date: Mon, 21 Sep 2020 22:24:19 +0200 Subject: [PATCH 05/16] Corecell last changes --- start-corecell.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/start-corecell.sh b/start-corecell.sh index b3a23ac..92cb632 100644 --- a/start-corecell.sh +++ b/start-corecell.sh @@ -25,8 +25,7 @@ cd examples/corecell # Default to TTN server TC_URI=${TC_URI:-"wss://lns.eu.thethings.network:443"} -#TC_TRUST=${TC_TRUST:-$(curl https://letsencrypt.org/certs/lets-encrypt-x3-cross-signed.pem.txt)} -TC_TRUST=${TC_TRUST:-$(curl https://letsencrypt.org/certs/trustid-x3-root.pem.txt)} +TC_TRUST=${TC_TRUST:-$(curl https://letsencrypt.org/certs/lets-encrypt-x3-cross-signed.pem.txt)} GW_RESET_PIN=${GW_RESET_PIN:-22} From dba36b1522008b135f9f92de4117c7fc7027bf75 Mon Sep 17 00:00:00 2001 From: mpous Date: Mon, 21 Sep 2020 22:31:27 +0200 Subject: [PATCH 06/16] Corecell last changes --- deps/lgw1302/V1.0.5-corecell.patch | 390 +++++++++++++++++++++++++++++ 1 file changed, 390 insertions(+) diff --git a/deps/lgw1302/V1.0.5-corecell.patch b/deps/lgw1302/V1.0.5-corecell.patch index 27caa24..1a9df99 100644 --- a/deps/lgw1302/V1.0.5-corecell.patch +++ b/deps/lgw1302/V1.0.5-corecell.patch @@ -298,3 +298,393 @@ index 77c3d4d..487283f 100644 /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ int timestamp_counter_mode(bool enable_precision_ts, uint8_t max_ts_metrics, uint8_t nb_symbols) { +diff --git a/libloragw/Makefile b/libloragw/Makefile +index 262167a..439b23a 100644 +--- a/libloragw/Makefile ++++ b/libloragw/Makefile +@@ -85,7 +85,7 @@ $(OBJDIR)/%.o: src/%.c $(INCLUDES) inc/config.h | $(OBJDIR) + + ### static library + +-libloragw.a: $(OBJDIR)/loragw_spi.o $(OBJDIR)/loragw_i2c.o $(OBJDIR)/loragw_aux.o $(OBJDIR)/loragw_reg.o $(OBJDIR)/loragw_sx1250.o $(OBJDIR)/loragw_sx125x.o $(OBJDIR)/loragw_sx1302.o $(OBJDIR)/loragw_cal.o $(OBJDIR)/loragw_debug.o $(OBJDIR)/loragw_hal.o $(OBJDIR)/loragw_stts751.o $(OBJDIR)/loragw_gps.o $(OBJDIR)/loragw_sx1302_timestamp.o $(OBJDIR)/loragw_sx1302_rx.o ++libloragw.a: $(OBJDIR)/loragw_spi.o $(OBJDIR)/loragw_i2c.o $(OBJDIR)/loragw_aux.o $(OBJDIR)/loragw_reg.o $(OBJDIR)/loragw_sx1250.o $(OBJDIR)/loragw_sx125x.o $(OBJDIR)/loragw_sx1302.o $(OBJDIR)/loragw_cal.o $(OBJDIR)/loragw_debug.o $(OBJDIR)/loragw_hal.o $(OBJDIR)/loragw_gps.o $(OBJDIR)/loragw_sx1302_timestamp.o $(OBJDIR)/loragw_sx1302_rx.o + $(AR) rcs $@ $^ + + ### test programs +diff --git a/libloragw/inc/loragw_stts751.h b/libloragw/inc/loragw_stts751.h +deleted file mode 100644 +index b1a898a..0000000 +--- a/libloragw/inc/loragw_stts751.h ++++ /dev/null +@@ -1,58 +0,0 @@ +-/* +- / _____) _ | | +-( (____ _____ ____ _| |_ _____ ____| |__ +- \____ \| ___ | (_ _) ___ |/ ___) _ \ +- _____) ) ____| | | || |_| ____( (___| | | | +-(______/|_____)_|_|_| \__)_____)\____)_| |_| +- (C)2019 Semtech +- +-Description: +- Basic driver for ST ts751 temperature sensor +- +-License: Revised BSD License, see LICENSE.TXT file include in the project +-*/ +- +- +-#ifndef _LORAGW_STTS751_H +-#define _LORAGW_STTS751_H +- +-/* -------------------------------------------------------------------------- */ +-/* --- DEPENDANCIES --------------------------------------------------------- */ +- +-#include /* C99 types */ +-#include /* bool type */ +- +-#include "config.h" /* library configuration options (dynamically generated) */ +- +-/* -------------------------------------------------------------------------- */ +-/* --- INTERNAL SHARED TYPES ------------------------------------------------ */ +- +-/* -------------------------------------------------------------------------- */ +-/* --- INTERNAL SHARED FUNCTIONS -------------------------------------------- */ +- +-/* -------------------------------------------------------------------------- */ +-/* --- PUBLIC CONSTANTS ----------------------------------------------------- */ +- +-#define I2C_PORT_TEMP_SENSOR_0 0x39 /* STTS751-0DP3F */ +-#define I2C_PORT_TEMP_SENSOR_1 0x3B /* STTS751-1DP3F */ +- +-/* -------------------------------------------------------------------------- */ +-/* --- PUBLIC FUNCTIONS ----------------------------------------------------- */ +- +-/** +-@brief TODO +-@param TODO +-@return TODO +-*/ +-int stts751_configure(int i2c_fd, uint8_t i2c_addr); +- +-/** +-@brief TODO +-@param TODO +-@return TODO +-*/ +-int stts751_get_temperature(int i2c_fd, uint8_t i2c_addr, float * temperature); +- +-#endif +- +-/* --- EOF ------------------------------------------------------------------ */ +diff --git a/libloragw/src/loragw_hal.c b/libloragw/src/loragw_hal.c +index 3b00c09..66d5c97 100644 +--- a/libloragw/src/loragw_hal.c ++++ b/libloragw/src/loragw_hal.c +@@ -41,7 +41,7 @@ License: Revised BSD License, see LICENSE.TXT file include in the project + #include "loragw_sx1250.h" + #include "loragw_sx125x.h" + #include "loragw_sx1302.h" +-#include "loragw_stts751.h" ++ + #include "loragw_debug.h" + + /* -------------------------------------------------------------------------- */ +@@ -181,8 +181,8 @@ static lgw_context_t lgw_context = { + FILE * log_file = NULL; + + /* I2C temperature sensor handles */ +-static int ts_fd = -1; +-static uint8_t ts_addr = 0xFF; ++//static int ts_fd = -1; ++//static uint8_t ts_addr = 0xFF; + + /* -------------------------------------------------------------------------- */ + /* --- PRIVATE FUNCTIONS DECLARATION ---------------------------------------- */ +@@ -719,22 +719,23 @@ int lgw_start(void) { + dbg_init_gpio(); + #endif + ++// + /* Try to configure temperature sensor STTS751-0DP3F */ +- ts_addr = I2C_PORT_TEMP_SENSOR_0; +- i2c_linuxdev_open(I2C_DEVICE, ts_addr, &ts_fd); +- err = stts751_configure(ts_fd, ts_addr); +- if (err != LGW_I2C_SUCCESS) { +- i2c_linuxdev_close(ts_fd); +- ts_fd = -1; +- /* Not found, try to configure temperature sensor STTS751-1DP3F */ +- ts_addr = I2C_PORT_TEMP_SENSOR_1; +- i2c_linuxdev_open(I2C_DEVICE, ts_addr, &ts_fd); +- err = stts751_configure(ts_fd, ts_addr); +- if (err != LGW_I2C_SUCCESS) { +- printf("ERROR: failed to configure the temperature sensor\n"); +- return LGW_HAL_ERROR; +- } +- } ++// ts_addr = I2C_PORT_TEMP_SENSOR_0; ++// i2c_linuxdev_open(I2C_DEVICE, ts_addr, &ts_fd); ++// err = stts751_configure(ts_fd, ts_addr); ++// if (err != LGW_I2C_SUCCESS) { ++// i2c_linuxdev_close(ts_fd); ++// ts_fd = -1; ++// /* Not found, try to configure temperature sensor STTS751-1DP3F */ ++// ts_addr = I2C_PORT_TEMP_SENSOR_1; ++// i2c_linuxdev_open(I2C_DEVICE, ts_addr, &ts_fd); ++// err = stts751_configure(ts_fd, ts_addr); ++// if (err != LGW_I2C_SUCCESS) { ++// printf("ERROR: failed to configure the temperature sensor\n"); ++// return LGW_HAL_ERROR; ++// } ++// } + + /* set hal state */ + CONTEXT_STARTED = true; +@@ -762,10 +763,10 @@ int lgw_stop(void) { + lgw_disconnect(); + + DEBUG_MSG("INFO: Closing I2C\n"); +- err = i2c_linuxdev_close(ts_fd); +- if (err != 0) { +- printf("ERROR: failed to close I2C device (err=%i)\n", err); +- } ++ //err = i2c_linuxdev_close(ts_fd); ++ //if (err != 0) { ++ // printf("ERROR: failed to close I2C device (err=%i)\n", err); ++ //} + + CONTEXT_STARTED = false; + return LGW_HAL_SUCCESS; +@@ -778,7 +779,9 @@ int lgw_receive(uint8_t max_pkt, struct lgw_pkt_rx_s *pkt_data) { + uint8_t nb_pkt_fetched = 0; + uint16_t nb_pkt_found = 0; + uint16_t nb_pkt_left = 0; +- float current_temperature, rssi_temperature_offset; ++ //float current_temperature, rssi_temperature_offset; ++ float current_temperature = 30.0; ++ float rssi_temperature_offset; + + /* Check that AGC/ARB firmwares are not corrupted, and update internal counter */ + /* WARNING: this needs to be called regularly by the upper layer */ +@@ -802,11 +805,11 @@ int lgw_receive(uint8_t max_pkt, struct lgw_pkt_rx_s *pkt_data) { + } + + /* Apply RSSI temperature compensation */ +- res = stts751_get_temperature(ts_fd, ts_addr, ¤t_temperature); +- if (res != LGW_I2C_SUCCESS) { +- printf("ERROR: failed to get current temperature\n"); +- return LGW_HAL_ERROR; +- } ++ //res = stts751_get_temperature(ts_fd, ts_addr, ¤t_temperature); ++ //if (res != LGW_I2C_SUCCESS) { ++ // printf("ERROR: failed to get current temperature\n"); ++ // return LGW_HAL_ERROR; ++ //} + + /* Iterate on the RX buffer to get parsed packets */ + for (nb_pkt_found = 0; nb_pkt_found < ((nb_pkt_fetched <= max_pkt) ? nb_pkt_fetched : max_pkt); nb_pkt_found++) { +@@ -982,10 +985,10 @@ int lgw_get_eui(uint64_t* eui) { + + int lgw_get_temperature(float* temperature) { + CHECK_NULL(temperature); +- +- if (stts751_get_temperature(ts_fd, ts_addr, temperature) != LGW_I2C_SUCCESS) { +- return LGW_HAL_ERROR; +- } ++ *temperature = 30.0; ++ //if (stts751_get_temperature(ts_fd, ts_addr, temperature) != LGW_I2C_SUCCESS) { ++ // return LGW_HAL_ERROR; ++ //} + + return LGW_HAL_SUCCESS; + } +diff --git a/libloragw/src/loragw_stts751.c b/libloragw/src/loragw_stts751.c +deleted file mode 100644 +index c417dc2..0000000 +--- a/libloragw/src/loragw_stts751.c ++++ /dev/null +@@ -1,186 +0,0 @@ +-/* +- / _____) _ | | +-( (____ _____ ____ _| |_ _____ ____| |__ +- \____ \| ___ | (_ _) ___ |/ ___) _ \ +- _____) ) ____| | | || |_| ____( (___| | | | +-(______/|_____)_|_|_| \__)_____)\____)_| |_| +- (C)2019 Semtech +- +-Description: +- Basic driver for ST ts751 temperature sensor +- +-License: Revised BSD License, see LICENSE.TXT file include in the project +-*/ +- +- +-/* -------------------------------------------------------------------------- */ +-/* --- DEPENDANCIES --------------------------------------------------------- */ +- +-#include /* C99 types */ +-#include /* bool type */ +-#include /* printf fprintf */ +- +-#include "loragw_i2c.h" +-#include "loragw_stts751.h" +- +-/* -------------------------------------------------------------------------- */ +-/* --- PRIVATE MACROS ------------------------------------------------------- */ +- +-#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) +-#if DEBUG_I2C == 1 +- #define DEBUG_MSG(str) fprintf(stderr, str) +- #define DEBUG_PRINTF(fmt, args...) fprintf(stderr,"%s:%d: "fmt, __FUNCTION__, __LINE__, args) +- #define CHECK_NULL(a) if(a==NULL){fprintf(stderr,"%s:%d: ERROR: NULL POINTER AS ARGUMENT\n", __FUNCTION__, __LINE__);return LGW_REG_ERROR;} +-#else +- #define DEBUG_MSG(str) +- #define DEBUG_PRINTF(fmt, args...) +- #define CHECK_NULL(a) if(a==NULL){return LGW_REG_ERROR;} +-#endif +- +-/* -------------------------------------------------------------------------- */ +-/* --- PRIVATE CONSTANTS ---------------------------------------------------- */ +- +-#define STTS751_REG_TEMP_H 0x00 +-#define STTS751_REG_STATUS 0x01 +-#define STTS751_STATUS_TRIPT BIT(0) +-#define STTS751_STATUS_TRIPL BIT(5) +-#define STTS751_STATUS_TRIPH BIT(6) +-#define STTS751_REG_TEMP_L 0x02 +-#define STTS751_REG_CONF 0x03 +-#define STTS751_CONF_RES_MASK 0x0C +-#define STTS751_CONF_RES_SHIFT 2 +-#define STTS751_CONF_EVENT_DIS BIT(7) +-#define STTS751_CONF_STOP BIT(6) +-#define STTS751_REG_RATE 0x04 +-#define STTS751_REG_HLIM_H 0x05 +-#define STTS751_REG_HLIM_L 0x06 +-#define STTS751_REG_LLIM_H 0x07 +-#define STTS751_REG_LLIM_L 0x08 +-#define STTS751_REG_TLIM 0x20 +-#define STTS751_REG_HYST 0x21 +-#define STTS751_REG_SMBUS_TO 0x22 +- +-#define STTS751_REG_PROD_ID 0xFD +-#define STTS751_REG_MAN_ID 0xFE +-#define STTS751_REG_REV_ID 0xFF +- +-#define STTS751_0_PROD_ID 0x00 +-#define STTS751_1_PROD_ID 0x01 +-#define ST_MAN_ID 0x53 +- +-/* -------------------------------------------------------------------------- */ +-/* --- PRIVATE VARIABLES ---------------------------------------------------- */ +- +-/* -------------------------------------------------------------------------- */ +-/* --- INTERNAL SHARED VARIABLES -------------------------------------------- */ +- +-/* -------------------------------------------------------------------------- */ +-/* --- PRIVATE FUNCTIONS ---------------------------------------------------- */ +- +-/* -------------------------------------------------------------------------- */ +-/* --- PUBLIC FUNCTIONS DEFINITION ------------------------------------------ */ +- +-int stts751_configure(int i2c_fd, uint8_t i2c_addr) { +- int err; +- uint8_t val; +- +- /* Check Input Params */ +- if (i2c_fd <= 0) { +- printf("ERROR: invalid I2C file descriptor\n"); +- return LGW_I2C_ERROR; +- } +- +- DEBUG_PRINTF("INFO: configuring STTS751 temperature sensor on 0x%02X...\n", i2c_addr); +- +- /* Get product ID and test which sensor is mounted */ +- err = i2c_linuxdev_read(i2c_fd, i2c_addr, STTS751_REG_PROD_ID, &val); +- if (err != 0) { +- DEBUG_PRINTF("ERROR: failed to read I2C device 0x%02X (err=%i)\n", i2c_addr, err); +- return LGW_I2C_ERROR; +- } +- switch (val) { +- case STTS751_0_PROD_ID: +- DEBUG_MSG("INFO: Product ID: STTS751-0\n"); +- break; +- case STTS751_1_PROD_ID: +- DEBUG_MSG("INFO: Product ID: STTS751-1\n"); +- break; +- default: +- printf("ERROR: Product ID: UNKNOWN\n"); +- return LGW_I2C_ERROR; +- } +- +- /* Get Manufacturer ID */ +- err = i2c_linuxdev_read(i2c_fd, i2c_addr, STTS751_REG_MAN_ID, &val); +- if (err != 0) { +- DEBUG_PRINTF("ERROR: failed to read I2C device 0x%02X (err=%i)\n", i2c_addr, err); +- return LGW_I2C_ERROR; +- } +- if (val != ST_MAN_ID) { +- printf("ERROR: Manufacturer ID: UNKNOWN\n"); +- return LGW_I2C_ERROR; +- } else { +- DEBUG_PRINTF("INFO: Manufacturer ID: 0x%02X\n", val); +- } +- +- /* Get revision number */ +- err = i2c_linuxdev_read(i2c_fd, i2c_addr, STTS751_REG_REV_ID, &val); +- if (err != 0) { +- DEBUG_PRINTF("ERROR: failed to read I2C device 0x%02X (err=%i)\n", i2c_addr, err); +- return LGW_I2C_ERROR; +- } +- DEBUG_PRINTF("INFO: Revision number: 0x%02X\n", val); +- +- /* Set conversion resolution to 12 bits */ +- err = i2c_linuxdev_write(i2c_fd, i2c_addr, STTS751_REG_CONF, 0x8C); /* TODO: do not hardcode the whole byte */ +- if (err != 0) { +- DEBUG_PRINTF("ERROR: failed to write I2C device 0x%02X (err=%i)\n", i2c_addr, err); +- return LGW_I2C_ERROR; +- } +- +- /* Set conversion rate to 1 / second */ +- err = i2c_linuxdev_write(i2c_fd, i2c_addr, STTS751_REG_RATE, 0x04); +- if (err != 0) { +- DEBUG_PRINTF("ERROR: failed to write I2C device 0x%02X (err=%i)\n", i2c_addr, err); +- return LGW_I2C_ERROR; +- } +- +- return LGW_I2C_SUCCESS; +-} +- +-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ +- +-int stts751_get_temperature(int i2c_fd, uint8_t i2c_addr, float * temperature) { +- int err; +- uint8_t high_byte, low_byte; +- int8_t h; +- +- /* Check Input Params */ +- if (i2c_fd <= 0) { +- printf("ERROR: invalid I2C file descriptor\n"); +- return LGW_I2C_ERROR; +- } +- +- /* Read Temperature LSB */ +- err = i2c_linuxdev_read(i2c_fd, i2c_addr, STTS751_REG_TEMP_L, &low_byte); +- if (err != 0) { +- printf("ERROR: failed to read I2C device 0x%02X (err=%i)\n", i2c_addr, err); +- return LGW_I2C_ERROR; +- } +- +- /* Read Temperature MSB */ +- err = i2c_linuxdev_read(i2c_fd, i2c_addr, STTS751_REG_TEMP_H, &high_byte); +- if (err != 0) { +- printf("ERROR: failed to read I2C device 0x%02X (err=%i)\n", i2c_addr, err); +- return LGW_I2C_ERROR; +- } +- +- h = (int8_t)high_byte; +- *temperature = ((h << 8) | low_byte) / 256.0; +- +- DEBUG_PRINTF("Temperature: %f C (h:0x%02X l:0x%02X)\n", *temperature, high_byte, low_byte); +- +- return LGW_I2C_SUCCESS; +-} +- +-/* --- EOF ------------------------------------------------------------------ */ From f511eca6101013f84a26715caffe65faaa33fcdf Mon Sep 17 00:00:00 2001 From: Rahul Thakoor Date: Tue, 22 Sep 2020 14:55:41 +0400 Subject: [PATCH 07/16] Add support for both RAK2245 and RAK2287 via env vars Change-type: major Signed-off-by: Rahul Thakoor --- Dockerfile.template | 25 +++++++++++++--------- start-corecell.sh | 47 ---------------------------------------- start.sh | 52 ++++++++++++++++++++++++++++++--------------- 3 files changed, 50 insertions(+), 74 deletions(-) delete mode 100644 start-corecell.sh diff --git a/Dockerfile.template b/Dockerfile.template index 65b0740..42e5a84 100644 --- a/Dockerfile.template +++ b/Dockerfile.template @@ -1,12 +1,6 @@ -FROM balenalib/%%BALENA_MACHINE_NAME%%-debian:stretch +FROM balenalib/%%BALENA_MACHINE_NAME%%-debian:buster-build as builder +# Install build tools and remove layer cache afterwards -# Install build tools and remove layer cache afterwards -RUN apt-get -q update && apt-get install -yq --no-install-recommends \ - build-essential \ - git \ - && apt-get clean && rm -rf /var/lib/apt/lists/* - -RUN install_packages jq # Switch to working directory for our app WORKDIR /usr/src/app @@ -15,8 +9,19 @@ WORKDIR /usr/src/app COPY . . # Compile our source code -#RUN make platform=rpi variant=std arch=%%BALENA_ARCH%% +RUN make platform=rpi variant=std arch=%%BALENA_ARCH%% RUN make platform=corecell variant=std arch=%%BALENA_ARCH%% + +FROM balenalib/%%BALENA_MACHINE_NAME%%-debian:buster + +RUN install_packages jq + +WORKDIR /usr/src/app + +COPY --from=builder /usr/src/app/ ./ + +COPY start.sh ./ + # Launch our binary on container startup. -CMD ["bash", "start-corecell.sh"] +CMD ["bash", "start.sh"] diff --git a/start-corecell.sh b/start-corecell.sh deleted file mode 100644 index 92cb632..0000000 --- a/start-corecell.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env bash - -TAG_KEY="EUI" -TTN_EUI=$(cat /sys/class/net/eth0/address | sed -r 's/[:]+//g' | sed -e 's#\(.\{6\}\)\(.*\)#\1FFFE\2#g') - -echo $TTN_EUI - -ID=$(curl -sX GET "https://api.balena-cloud.com/v5/device?\$filter=uuid%20eq%20'$BALENA_DEVICE_UUID'" \ --H "Content-Type: application/json" \ --H "Authorization: Bearer $BALENA_API_KEY" | \ -jq ".d | .[0] | .id") - -TAG=$(curl -sX POST \ -"https://api.balena-cloud.com/v5/device_tag" \ --H "Content-Type: application/json" \ --H "Authorization: Bearer $BALENA_API_KEY" \ ---data "{ \"device\": \"$ID\", \"tag_key\": \"$TAG_KEY\", \"value\": \"$TTN_EUI\" }" > /dev/null) - - -# declare map of hardware pins to GPIO on Raspberry Pi -declare -a pinToGPIO -pinToGPIO=( -1 -1 -1 2 -1 3 -1 4 14 -1 15 17 18 27 -1 22 23 -1 24 10 -1 9 25 11 8 -1 7 0 1 5 -1 6 12 13 -1 19 16 26 20 -1 21) - -cd examples/corecell - -# Default to TTN server -TC_URI=${TC_URI:-"wss://lns.eu.thethings.network:443"} -TC_TRUST=${TC_TRUST:-$(curl https://letsencrypt.org/certs/lets-encrypt-x3-cross-signed.pem.txt)} - - -GW_RESET_PIN=${GW_RESET_PIN:-22} -GW_RESET_GPIO=${GW_RESET_GPIO:-${pinToGPIO[$GW_RESET_PIN]}} - -# Setup TC files from environment -echo $TC_URI > ./lns-ttn/tc.uri -echo "$TC_TRUST" > ./lns-ttn/tc.trust - -# Reset gateway -#echo "Resetting gateway concentrator on GPIO $GW_RESET_GPIO" -#echo $GW_RESET_GPIO > /sys/class/gpio/export -#echo out > /sys/class/gpio/gpio$GW_RESET_GPIO/direction -#echo 0 > /sys/class/gpio/gpio$GW_RESET_GPIO/value -#echo 1 > /sys/class/gpio/gpio$GW_RESET_GPIO/value -#echo 0 > /sys/class/gpio/gpio$GW_RESET_GPIO/value -#echo $GW_RESET_GPIO > /sys/class/gpio/unexport - -./start-station.sh -l ./lns-ttn diff --git a/start.sh b/start.sh index 02e1f58..0674465 100644 --- a/start.sh +++ b/start.sh @@ -21,29 +21,47 @@ TAG=$(curl -sX POST \ declare -a pinToGPIO pinToGPIO=( -1 -1 -1 2 -1 3 -1 4 14 -1 15 17 18 27 -1 22 23 -1 24 10 -1 9 25 11 8 -1 7 0 1 5 -1 6 12 13 -1 19 16 26 20 -1 21) - -cd examples/live-s2.sm.tc +if [ -z ${MODEL} ] ; + then + echo -e "\033[91mWARNING: MODEL variable not set.\n Set the model of the gateway you are using." + balena-idle + else + if [ $MODEL = "RAK2245" ];then + cd examples/live-s2.sm.tc + fi + if [ $MODEL = "RAK2287" ];then + cd examples/corecell + fi +fi # Default to TTN server TC_URI=${TC_URI:-"wss://lns.eu.thethings.network:443"} TC_TRUST=${TC_TRUST:-$(curl https://letsencrypt.org/certs/trustid-x3-root.pem.txt)} - GW_RESET_PIN=${GW_RESET_PIN:-22} GW_RESET_GPIO=${GW_RESET_GPIO:-${pinToGPIO[$GW_RESET_PIN]}} -# Setup TC files from environment -echo $TC_URI > ./lns-ttn/tc.uri -echo "$TC_TRUST" > ./lns-ttn/tc.trust - -# Reset gateway -#echo "Resetting gateway concentrator on GPIO $GW_RESET_GPIO" -#echo $GW_RESET_GPIO > /sys/class/gpio/export -#echo out > /sys/class/gpio/gpio$GW_RESET_GPIO/direction -#echo 0 > /sys/class/gpio/gpio$GW_RESET_GPIO/value -#echo 1 > /sys/class/gpio/gpio$GW_RESET_GPIO/value -#echo 0 > /sys/class/gpio/gpio$GW_RESET_GPIO/value -#echo $GW_RESET_GPIO > /sys/class/gpio/unexport + +if [ $MODEL = "RAK2245" ];then + # Setup TC files from environment + echo $TC_URI > tc.uri + echo "$TC_TRUST" > tc.trust + + # Reset gateway + echo "Resetting gateway concentrator on GPIO $GW_RESET_GPIO" + echo $GW_RESET_GPIO > /sys/class/gpio/export + echo out > /sys/class/gpio/gpio$GW_RESET_GPIO/direction + echo 0 > /sys/class/gpio/gpio$GW_RESET_GPIO/value + echo 1 > /sys/class/gpio/gpio$GW_RESET_GPIO/value + echo 0 > /sys/class/gpio/gpio$GW_RESET_GPIO/value + echo $GW_RESET_GPIO > /sys/class/gpio/unexport + RADIODEV=/dev/spidev0.0 ../../build-rpi-std/bin/station +fi +if [ $MODEL = "RAK2287" ];then + # Setup TC files from environment + echo $TC_URI > ./lns-ttn/tc.uri + echo "$TC_TRUST" > ./lns-ttn/tc.trust -#RADIODEV=/dev/spidev0.0 ../../build-rpi-std/bin/station -./start-station.sh -l ./lns-ttn + ./start-station.sh -l ./lns-ttn +fi +balena-idle From 836fcea48c4f34e75a75c229135ec686a593d944 Mon Sep 17 00:00:00 2001 From: mpous Date: Tue, 22 Sep 2020 13:31:19 +0200 Subject: [PATCH 08/16] README and balena.yml update --- README.md | 23 +++++++++++++++++++---- balena.yml | 3 +++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 738569c..f1b2061 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# LoRa Basics™ Station using balena.io and RAK2287 +# LoRa Basics™ Station using balena.io and RAK2245 and RAK 2287 -This project deploys a TTN LoRa gateway with Basics Station Packet Forward protocol with balena. It runs on a Raspberry Pi or balenaFin with a RAK2287 concentrator with a Pi Hat. +This project deploys a TTN LoRa gateway with Basics Station Packet Forward protocol with balena. It runs on a Raspberry Pi or balenaFin with a RAK2245 and RAK2287 concentrator with a Pi Hat. ## Introduction @@ -15,9 +15,14 @@ The Basics Station protocol enables the LoRa gateways with a reliable and secure ### Hardware * Raspberry Pi 4 or [balenaFin](https://www.balena.io/fin/) +* SD card in case of the RPi 4 + * [RAK 2287 Concentrator](https://store.rakwireless.com/products/rak2287-lpwan-gateway-concentrator-module) * [RAK 2287 Pi Hat](https://store.rakwireless.com/products/rak2287-pi-hat) -* SD card in case of the RPi 4 + +or + +* [RAK 2245 pi hat](https://store.rakwireless.com/products/rak2245-pi-hat) ### Software @@ -63,6 +68,15 @@ If that does not work, go to the terminal box and click "Select a target", then Copy the result and you are ready to register your gateway with this EUI. +#### Define your MODEL + +In case that your LoRa concentrator is a RAK2287, it's important to change the Device Variable with the correct MODEL. + +1. Go to balenaCloud dashboard and get into your LoRa gateway device site. +2. Click "Device Variables" button on the left menu and change the MODEL variable to RAK2287. + +That enables a fleet of LoRa gateways with both RAK2245 and RAK2287 together under the same app. + ### Configure your The Things Network gateway @@ -93,7 +107,8 @@ Variable Name | Value | Description | Default **`GW_KEY`** | `STRING` | Unique TTN Gateway Key | (Key pasted from TTN console) **`GW_RESET_PIN`** | `STRING` | Pin number that resets | 11 **`SPI_SPEED`** | `STRING` | The Raspberry Pi and RAK2287 uses SPI to communicate and needs to use a specific speed | 2000000 -**`TC_URI`** | `STRING` | basics station TC URI to get connected. If you are in the EU region use ```wss://lns.{eu-us-in-au}.thethings.network:443``` | ```wss://lns.eu.thethings.network:443``` +**`TC_URI`** | `STRING` | basics station TC URI to get connected. If you are in the EU region use ```wss://lns.{eu-us-in-au}.thethings.network:443``` | ```wss://lns.eu.thethings.network:443`` +**`MODEL`** | `STRING` | ```RAK2245``` or ```RAK2287``` At this moment your The Things Network gateway should be up and running. Check on the TTN console if it shows the connected status. diff --git a/balena.yml b/balena.yml index ccd337c..39836fa 100644 --- a/balena.yml +++ b/balena.yml @@ -4,3 +4,6 @@ applicationEnvironmentVariables: - GW_RESET_PIN: 11 - SPI_SPEED: 2000000 - TC_URI: wss://lns.eu.thethings.network:443 + - MODEL: RAK2245 + - REGION: eu + From 3f24b3edf303be0b9cca274c0f5fd70e121dcb2c Mon Sep 17 00:00:00 2001 From: Marc Pous Date: Tue, 22 Sep 2020 13:32:06 +0200 Subject: [PATCH 09/16] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f1b2061..5cc5c00 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# LoRa Basics™ Station using balena.io and RAK2245 and RAK 2287 +# LoRa Basics™ Station using balena.io and RAK2245 or RAK 2287 This project deploys a TTN LoRa gateway with Basics Station Packet Forward protocol with balena. It runs on a Raspberry Pi or balenaFin with a RAK2245 and RAK2287 concentrator with a Pi Hat. From 44f6122b8fa1cce5cb9ba93c3f9d2d6bc495b97e Mon Sep 17 00:00:00 2001 From: Marc Pous Date: Tue, 22 Sep 2020 13:36:35 +0200 Subject: [PATCH 10/16] Update README.md --- README.md | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 5cc5c00..3f92713 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,17 @@ If you are a balena CLI expert, feel free to use balena CLI. ## Configure the Gateway -### Before configure your LoRa gateway +### Define your MODEL + +In case that your LoRa concentrator is a ```RAK2287```, it's important to change the Device Variable with the correct MODEL. The default MODEL on the balena Application is the ```RAK2245```. + +1. Go to balenaCloud dashboard and get into your LoRa gateway device site. +2. Click "Device Variables" button on the left menu and change the MODEL variable to ```RAK2287```. + +That enables a fleet of LoRa gateways with both ```RAK2245``` and ```RAK2287``` together under the same app. + + +### Get the EUI of the LoRa Gateway The LoRa gateways are manufactured with a unique 64 bits (8 bytes) identifier, called EUI, which can be used to register the gateway on The Things Network. To get the EUI from your board it’s important to know the Ethernet MAC address of it. The TTN EUI will be the Ethernet mac address (6 bytes), which is unique, expanded with 2 more bytes (FFFE). This is a standard way to increment the MAC address from 6 to 8 bytes. @@ -68,15 +78,6 @@ If that does not work, go to the terminal box and click "Select a target", then Copy the result and you are ready to register your gateway with this EUI. -#### Define your MODEL - -In case that your LoRa concentrator is a RAK2287, it's important to change the Device Variable with the correct MODEL. - -1. Go to balenaCloud dashboard and get into your LoRa gateway device site. -2. Click "Device Variables" button on the left menu and change the MODEL variable to RAK2287. - -That enables a fleet of LoRa gateways with both RAK2245 and RAK2287 together under the same app. - ### Configure your The Things Network gateway From c2d680f90923e3d2ce65b06d1fc30b9400d3f8f9 Mon Sep 17 00:00:00 2001 From: Marc Pous Date: Tue, 22 Sep 2020 13:37:33 +0200 Subject: [PATCH 11/16] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3f92713..2e136a0 100644 --- a/README.md +++ b/README.md @@ -58,10 +58,10 @@ If you are a balena CLI expert, feel free to use balena CLI. ### Define your MODEL -In case that your LoRa concentrator is a ```RAK2287```, it's important to change the Device Variable with the correct MODEL. The default MODEL on the balena Application is the ```RAK2245```. +In case that your LoRa concentrator is a ```RAK2287```, it's important to change the Device Variable with the correct ```MODEL```. The default ```MODEL``` on the balena Application is the ```RAK2245```. 1. Go to balenaCloud dashboard and get into your LoRa gateway device site. -2. Click "Device Variables" button on the left menu and change the MODEL variable to ```RAK2287```. +2. Click "Device Variables" button on the left menu and change the ```MODEL``` variable to ```RAK2287```. That enables a fleet of LoRa gateways with both ```RAK2245``` and ```RAK2287``` together under the same app. From 8a438d4821f56212e6cc881eae8e7462c8761a44 Mon Sep 17 00:00:00 2001 From: Marc Pous Date: Tue, 22 Sep 2020 13:39:34 +0200 Subject: [PATCH 12/16] Update README.md --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2e136a0..e8c2ef6 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# LoRa Basics™ Station using balena.io and RAK2245 or RAK 2287 +# LoRa Basics™ Station using balena.io with RAK2245 or RAK 2287 concentrators This project deploys a TTN LoRa gateway with Basics Station Packet Forward protocol with balena. It runs on a Raspberry Pi or balenaFin with a RAK2245 and RAK2287 concentrator with a Pi Hat. @@ -17,6 +17,8 @@ The Basics Station protocol enables the LoRa gateways with a reliable and secure * Raspberry Pi 4 or [balenaFin](https://www.balena.io/fin/) * SD card in case of the RPi 4 +#### LoRa Concentrators + * [RAK 2287 Concentrator](https://store.rakwireless.com/products/rak2287-lpwan-gateway-concentrator-module) * [RAK 2287 Pi Hat](https://store.rakwireless.com/products/rak2287-pi-hat) @@ -108,7 +110,7 @@ Variable Name | Value | Description | Default **`GW_KEY`** | `STRING` | Unique TTN Gateway Key | (Key pasted from TTN console) **`GW_RESET_PIN`** | `STRING` | Pin number that resets | 11 **`SPI_SPEED`** | `STRING` | The Raspberry Pi and RAK2287 uses SPI to communicate and needs to use a specific speed | 2000000 -**`TC_URI`** | `STRING` | basics station TC URI to get connected. If you are in the EU region use ```wss://lns.{eu-us-in-au}.thethings.network:443``` | ```wss://lns.eu.thethings.network:443`` +**`TC_URI`** | `STRING` | basics station TC URI to get connected. If you are in the EU region use ```wss://lns.{eu-us-in-au}.thethings.network:443``` | ```wss://lns.eu.thethings.network:443``` **`MODEL`** | `STRING` | ```RAK2245``` or ```RAK2287``` From 856329eace7c9a9ade280312f999597962ec6be4 Mon Sep 17 00:00:00 2001 From: Marc Pous Date: Tue, 22 Sep 2020 13:40:08 +0200 Subject: [PATCH 13/16] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e8c2ef6..c0103a8 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ Variable Name | Value | Description | Default **`GW_RESET_PIN`** | `STRING` | Pin number that resets | 11 **`SPI_SPEED`** | `STRING` | The Raspberry Pi and RAK2287 uses SPI to communicate and needs to use a specific speed | 2000000 **`TC_URI`** | `STRING` | basics station TC URI to get connected. If you are in the EU region use ```wss://lns.{eu-us-in-au}.thethings.network:443``` | ```wss://lns.eu.thethings.network:443``` -**`MODEL`** | `STRING` | ```RAK2245``` or ```RAK2287``` +**`MODEL`** | `STRING` | ```RAK2245``` or ```RAK2287``` | ```RAK2245``` At this moment your The Things Network gateway should be up and running. Check on the TTN console if it shows the connected status. From a46c95212fbbe41358018609921f8359518e72ad Mon Sep 17 00:00:00 2001 From: Marc Pous Date: Tue, 22 Sep 2020 14:20:48 +0200 Subject: [PATCH 14/16] Update balena.yml --- balena.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/balena.yml b/balena.yml index 39836fa..2d10011 100644 --- a/balena.yml +++ b/balena.yml @@ -4,6 +4,4 @@ applicationEnvironmentVariables: - GW_RESET_PIN: 11 - SPI_SPEED: 2000000 - TC_URI: wss://lns.eu.thethings.network:443 - - MODEL: RAK2245 - - REGION: eu - + - MODEL: RAK2245 From 77cfd66622efd88a032e02c27d09b6a63b7b03d8 Mon Sep 17 00:00:00 2001 From: Rahul Thakoor Date: Tue, 22 Sep 2020 16:26:00 +0400 Subject: [PATCH 15/16] Use separate start scripts Change-type: patch Signed-off-by: Rahul Thakoor --- Dockerfile.template | 2 +- start.sh | 39 ++++----------------------------------- start_rak2245.sh | 32 ++++++++++++++++++++++++++++++++ start_rak2287.sh | 16 ++++++++++++++++ 4 files changed, 53 insertions(+), 36 deletions(-) create mode 100755 start_rak2245.sh create mode 100755 start_rak2287.sh diff --git a/Dockerfile.template b/Dockerfile.template index 42e5a84..af638d4 100644 --- a/Dockerfile.template +++ b/Dockerfile.template @@ -21,7 +21,7 @@ WORKDIR /usr/src/app COPY --from=builder /usr/src/app/ ./ -COPY start.sh ./ +COPY start* ./ # Launch our binary on container startup. CMD ["bash", "start.sh"] diff --git a/start.sh b/start.sh index 0674465..5881d27 100644 --- a/start.sh +++ b/start.sh @@ -17,51 +17,20 @@ TAG=$(curl -sX POST \ --data "{ \"device\": \"$ID\", \"tag_key\": \"$TAG_KEY\", \"value\": \"$TTN_EUI\" }" > /dev/null) -# declare map of hardware pins to GPIO on Raspberry Pi -declare -a pinToGPIO -pinToGPIO=( -1 -1 -1 2 -1 3 -1 4 14 -1 15 17 18 27 -1 22 23 -1 24 10 -1 9 25 11 8 -1 7 0 1 5 -1 6 12 13 -1 19 16 26 20 -1 21) if [ -z ${MODEL} ] ; then echo -e "\033[91mWARNING: MODEL variable not set.\n Set the model of the gateway you are using." balena-idle else + echo "Using MODEL: $MODEL" if [ $MODEL = "RAK2245" ];then - cd examples/live-s2.sm.tc + ./start_rak2245.sh + fi if [ $MODEL = "RAK2287" ];then - cd examples/corecell + ./start_rak2287.sh fi fi -# Default to TTN server -TC_URI=${TC_URI:-"wss://lns.eu.thethings.network:443"} -TC_TRUST=${TC_TRUST:-$(curl https://letsencrypt.org/certs/trustid-x3-root.pem.txt)} -GW_RESET_PIN=${GW_RESET_PIN:-22} -GW_RESET_GPIO=${GW_RESET_GPIO:-${pinToGPIO[$GW_RESET_PIN]}} - - -if [ $MODEL = "RAK2245" ];then - # Setup TC files from environment - echo $TC_URI > tc.uri - echo "$TC_TRUST" > tc.trust - - # Reset gateway - echo "Resetting gateway concentrator on GPIO $GW_RESET_GPIO" - echo $GW_RESET_GPIO > /sys/class/gpio/export - echo out > /sys/class/gpio/gpio$GW_RESET_GPIO/direction - echo 0 > /sys/class/gpio/gpio$GW_RESET_GPIO/value - echo 1 > /sys/class/gpio/gpio$GW_RESET_GPIO/value - echo 0 > /sys/class/gpio/gpio$GW_RESET_GPIO/value - echo $GW_RESET_GPIO > /sys/class/gpio/unexport - RADIODEV=/dev/spidev0.0 ../../build-rpi-std/bin/station -fi -if [ $MODEL = "RAK2287" ];then - # Setup TC files from environment - echo $TC_URI > ./lns-ttn/tc.uri - echo "$TC_TRUST" > ./lns-ttn/tc.trust - - ./start-station.sh -l ./lns-ttn -fi -balena-idle diff --git a/start_rak2245.sh b/start_rak2245.sh new file mode 100755 index 0000000..1e31464 --- /dev/null +++ b/start_rak2245.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +cd examples/live-s2.sm.tc + +# declare map of hardware pins to GPIO on Raspberry Pi +declare -a pinToGPIO +pinToGPIO=( -1 -1 -1 2 -1 3 -1 4 14 -1 15 17 18 27 -1 22 23 -1 24 10 -1 9 25 11 8 -1 7 0 1 5 -1 6 12 13 -1 19 16 26 20 -1 21) + +# Default to TTN server +TC_URI=${TC_URI:-"wss://lns.eu.thethings.network:443"} +TC_TRUST=${TC_TRUST:-$(curl https://letsencrypt.org/certs/trustid-x3-root.pem.txt)} + + +GW_RESET_PIN=${GW_RESET_PIN:-11} +GW_RESET_GPIO=${GW_RESET_GPIO:-${pinToGPIO[$GW_RESET_PIN]}} + +# Setup TC files from environment +echo $TC_URI > tc.uri +echo "$TC_TRUST" > tc.trust + +# Reset gateway +echo "Resetting gateway concentrator on GPIO $GW_RESET_GPIO" +echo $GW_RESET_GPIO > /sys/class/gpio/export +echo out > /sys/class/gpio/gpio$GW_RESET_GPIO/direction +echo 0 > /sys/class/gpio/gpio$GW_RESET_GPIO/value +echo 1 > /sys/class/gpio/gpio$GW_RESET_GPIO/value +echo 0 > /sys/class/gpio/gpio$GW_RESET_GPIO/value +echo $GW_RESET_GPIO > /sys/class/gpio/unexport + +RADIODEV=/dev/spidev0.0 ../../build-rpi-std/bin/station + +balena-idle diff --git a/start_rak2287.sh b/start_rak2287.sh new file mode 100755 index 0000000..c8552bf --- /dev/null +++ b/start_rak2287.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +cd examples/corecell + +# Default to TTN server +TC_URI=${TC_URI:-"wss://lns.eu.thethings.network:443"} +TC_TRUST=${TC_TRUST:-$(curl https://letsencrypt.org/certs/trustid-x3-root.pem.txt)} + + +# Setup TC files from environment +echo $TC_URI > ./lns-ttn/tc.uri +echo "$TC_TRUST" > ./lns-ttn/tc.trust + +./start-station.sh -l ./lns-ttn + +balena-idle From 27098a5210a0c0d15c9e415a89974e498e60a5b3 Mon Sep 17 00:00:00 2001 From: Marc Pous Date: Tue, 22 Sep 2020 14:34:58 +0200 Subject: [PATCH 16/16] Delete README-balena.md Outdated README balena version --- README-balena.md | 103 ----------------------------------------------- 1 file changed, 103 deletions(-) delete mode 100644 README-balena.md diff --git a/README-balena.md b/README-balena.md deleted file mode 100644 index 5b0533d..0000000 --- a/README-balena.md +++ /dev/null @@ -1,103 +0,0 @@ -# LoRa Basics™ Station using balena.io and RAK2245 - -This project deploys a TTN LoRa gateway with Basics Station Packet Forward protocol with balena. It runs on a Raspberry Pi or balenaFin with a RAK2245 Pi Hat. - - -## Introduction - -Deploy a The Things Network (TTN) LoRa gateway running the basics station Semtech Packet Forward protocol. We are using balena.io and RAK to reduce fricition for the LoRa gateway fleet owners. - -The Basics Station protocol enables the LoRa gateways with a reliable and secure communication between the gateways and the cloud and it is becoming the standard Packet Forward protocol used by most of the LoRaWAN operators. - - -## Getting started - -### Hardware - -* Raspberry Pi 4 or [balenaFin](https://www.balena.io/fin/) -* [RAK 2245 pi hat](https://store.rakwireless.com/products/rak2245-pi-hat) -* SD card in case of the RPi 4 - -### Software - -* A TTN account ([sign up here](https://console.thethingsnetwork.org) -* A balenaCloud account ([sign up here](https://dashboard.balena-cloud.com/) -* [balenaEtcher](https://balena.io/etcher) - -Once all of this is ready, you are able to deploy this repository following instructions below. - -## Deploy the code - -### Via [Balena Deploy](https://www.balena.io/docs/learn/deploy/deploy-with-balena-button/) - -Running this project is as simple as deploying it to a balenaCloud application. You can do it in just one click by using the button below: - -[![](https://www.balena.io/deploy.png)](https://dashboard.balena-cloud.com/deploy?repoUrl=https://github.com/balena-io-playground/basicstation) - -Follow instructions, click Add a Device and flash an SD card with that OS image dowloaded from balenaCloud. Enjoy the magic 🌟Over-The-Air🌟! - - -### Via [Balena-Cli](https://www.balena.io/docs/reference/balena-cli/) - -If you are a balena CLI expert, feel free to use balena CLI. - -- Sign up on [balena.io](https://dashboard.balena.io/signup) -- Create a new application on balenaCloud. -- Clone this repository to your local workspace. -- Using [Balena CLI](https://www.balena.io/docs/reference/cli/), push the code with `balena push ` -- See the magic happening, your device is getting updated 🌟Over-The-Air🌟! - - -## Configure the Gateway - -### Before configure your LoRa gateway - -The LoRa gateways are manufactured with a unique 64 bits (8 bytes) identifier, called EUI, which can be used to register the gateway on The Things Network. To get the EUI from your board it’s important to know the Ethernet MAC address of it. The TTN EUI will be the Ethernet mac address (6 bytes), which is unique, expanded with 2 more bytes (FFFE). This is a standard way to increment the MAC address from 6 to 8 bytes. - -To get the EUI, copy the TAG of the device which will be generated automatically when the device gets provisioned on balenaCloud. - -If that does not work, go to the terminal box and click "Select a target", then “HostOS”. Once you are inside the shell, type: - -```cat /sys/class/net/eth0/address | sed -r 's/[:]+//g' | sed -e 's#\(.\{6\}\)\(.*\)#\1FFFE\2#g' ``` - -Copy the result and you are ready to register your gateway with this EUI. - - -### Configure your The Things Network gateway - -1. Sign up at [The Things Network console](https://console.thethingsnetwork.org/). -2. Click Gateways button. -3. Click the "Register gateway" link. -4. Check “I’m using the legacy packet forwarder” checkbox. -5. Paste the EUI from the Ethernet mac address of the board (calculated above) -6. Complete the form and click Register gateway. - - -### Balena LoRa Basics Station Service Variables - -Once successfully registered, copy the The Things Network gateway KEY to configure your board variables on balenaCloud. - -1. Go to balenaCloud dashboard and get into your LoRa gateway device site. -2. Click "Device Variables" button on the left menu and add these variables. - -Most of the variables have been generated automatically when the Application has been created with the Deploy with Balena button. However it's important to introduce the `GW_ID`and `GW_KEY`from the The Things Network console. - - -Variable Name | Value | Description | Default ------------- | ------------- | ------------- | ------------- -**`GW_GPS`** | `STRING` | Enables GPS | true or false -**`GW_ID`** | `STRING` | TTN Gateway EUI | (EUI) -**`GW_KEY`** | `STRING` | Unique TTN Gateway Key | (Key pasted from TTN console) -**`GW_RESET_PIN`** | `STRING` | Pin number that resets | 11 -**`SPI_SPEED`** | `STRING` | The Raspberry Pi and RAK2245 uses SPI to communicate and needs to use a specific speed | 20000000 -**`TC_URI`** | `STRING` | basics station TC URI to get connected | ```wss://lns.eu.thethings.network:443``` - - -At this moment your The Things Network gateway should be up and running. Check on the TTN console if it shows the connected status. - - -## Attribution - -- This is an adaptation of the [Semtech Basics Station repository](https://github.com/lorabasics/basicstation). Documentation [here](https://doc.sm.tc/station). -- This is in part working thanks of the work of Jose Marcelino from RAK Wireless and Marc Pous from balena.io. -- This is in part based on excellent work done by the Balena.io Hardware Hackers team.