diff --git a/Dockerfile.template b/Dockerfile.template index 3d3f8f7..af638d4 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 @@ -16,6 +10,18 @@ COPY . . # Compile our source code 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* ./ # Launch our binary on container startup. CMD ["bash", "start.sh"] 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. diff --git a/README.md b/README.md index 5dc2560..c0103a8 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 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 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,17 @@ 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) * 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) + +or + +* [RAK 2245 pi hat](https://store.rakwireless.com/products/rak2245-pi-hat) + ### Software * A TTN account ([sign up here](https://console.thethingsnetwork.org)) @@ -50,7 +58,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. @@ -91,8 +109,9 @@ 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``` +**`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. diff --git a/balena.yml b/balena.yml index ccd337c..2d10011 100644 --- a/balena.yml +++ b/balena.yml @@ -4,3 +4,4 @@ applicationEnvironmentVariables: - GW_RESET_PIN: 11 - SPI_SPEED: 2000000 - TC_URI: wss://lns.eu.thethings.network:443 + - MODEL: RAK2245 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 ------------------------------------------------------------------ */ 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/examples/corecell/reset_lgw.sh b/examples/corecell/reset_lgw.sh index 0136d72..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() { @@ -29,8 +29,8 @@ init() { } reset() { - echo "CoreCell reset through GPIO$SX1302_RESET_PIN..." - echo "CoreCell power enable through GPIO$SX1302_POWER_EN_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 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/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 diff --git a/start.sh b/start.sh index 0278622..5881d27 100644 --- a/start.sh +++ b/start.sh @@ -17,33 +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 + ./start_rak2245.sh + + fi + if [ $MODEL = "RAK2287" ];then + ./start_rak2287.sh + fi +fi -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/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 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