diff --git a/docs/en/LilyGo_LoRa_Series_Quick_Start_On_TTN.md b/docs/en/LilyGo_LoRa_Series_Quick_Start_On_TTN.md index 17e7c9a..04fbfcc 100644 --- a/docs/en/LilyGo_LoRa_Series_Quick_Start_On_TTN.md +++ b/docs/en/LilyGo_LoRa_Series_Quick_Start_On_TTN.md @@ -5,13 +5,11 @@ ## Index - [Required](#required) -- [Create a gateway on TTN](#create-a-gateway-on-ttn) - [Run sx1302_hal on the Raspberry Pi](#run-sx1302_hal-on-the-raspberry-pi) - - [Enable the SPI interface of the Raspberry Pi](#enable-the-spi-interface-of-the-raspberry-pi) - - [Download sx1302_hal source code and compile](#download-sx1302_hal-source-code-and-compile) - - [Configure global_conf](#configure-global_conf) - - [Run sx1302_hal](#run-sx1302_hal) - - [Check gateway connection status](#check-gateway-connection-status) + - [Deploy sx1302_hal](#deploy-sx1302hal) + - [Get relevant information](#get-relevant-information) +- [Create a gateway on TTN](#create-a-gateway-on-ttn) +- [Check gateway connection status](#check-gateway-connection-status) - [Create end device model on TTN](#create-end-device-model-on-ttn) - [Enter the create Application page](#enter-the-create-application-page) - [Create end device](#create-end-device) @@ -33,389 +31,57 @@ > > TTN Version: v3.15.1 -## Create a gateway on TTN - -1. Log in to https://console.cloud.thethings.network/ - -2. Select the cluster according to the frequency band supported by the gateway - -![cluster_picker](../static/cluster_picker.png) - -The frequency band supported by `T-SX1302` is `868MHZ`, here you need to select the `Europe1` cluster - -> ! Warning -> -> `Legacy V2 Console` is a server of TTN V2 version, it will be closed in December 2021, it is not recommended to use - -3. Create a gateway - -![create_gateways](../static/create_gateways.png) - -4. Configure gateway information - -It needs to fill in a unique `Gateway EUI`, if there is no better choice, you can use the MAC address of the Raspberry Pi - -![config_gateway_info](../static/config_gateway_info.png) - -5. Select frequency - -![slelct_frequenry](../static/slelct_frequenry.png) - ## Run sx1302_hal on the Raspberry Pi > NOTE > > The LoRaWAN gateway that has been connected to TTN, you can ignore this section -### Enable the SPI interface of the Raspberry Pi +### Deploy sx1302_hal -Open the /boot/config.txt file and write the following at the end of the file: - -``` -dtoverlay=spi0-1cs -``` - -### Download sx1302_hal source code and compile - -1. Download source code: +Execute [sx1302_hal.sh](../../tools/sx1302_hal.sh) on Raspberry Pi to automatically deploy sx1302_hal. ```shell -cd ~ -git clone https://github.com/Lora-net/sx1302_hal.git -cd sx1302_hal -git checkout V2.1.0 +sudo ./sx1302_hal.sh -f eu868 +sudo reboot ``` -2. Modify the source code - -Because `sx1302 hal` cannot read the temperature of `T-SX1302`, some codes in `libloragw/src/loragw_hal.c` need to be commented: - -```diff -diff --git a/libloragw/src/loragw_hal.c b/libloragw/src/loragw_hal.c -index ffc8ec0..504bb42 100644 ---- a/libloragw/src/loragw_hal.c -+++ b/libloragw/src/loragw_hal.c -@@ -1093,6 +1093,7 @@ int lgw_start(void) { - dbg_init_random(); - - if (CONTEXT_COM_TYPE == LGW_COM_SPI) { -+#if 0 - /* Find the temperature sensor on the known supported ports */ - for (i = 0; i < (int)(sizeof I2C_PORT_TEMP_SENSOR); i++) { - ts_addr = I2C_PORT_TEMP_SENSOR[i]; -@@ -1116,7 +1117,7 @@ int lgw_start(void) { - printf("ERROR: no temperature sensor found.\n"); - return LGW_HAL_ERROR; - } -- -+#endif - /* Configure ADC AD338R for full duplex (CN490 reference design) */ - if (CONTEXT_BOARD.full_duplex == true) { - err = i2c_linuxdev_open(I2C_DEVICE, I2C_PORT_DAC_AD5338R, &ad_fd); -@@ -1285,14 +1286,14 @@ int lgw_receive(uint8_t max_pkt, struct lgw_pkt_rx_s *pkt_data) { - nb_pkt_left = nb_pkt_fetched - max_pkt; - printf("WARNING: not enough space allocated, fetched %d packet(s), %d will be left in RX buffer\n", nb_pkt_fetched, nb_pkt_left); - } -- -+#if 0 - /* Apply RSSI temperature compensation */ - res = lgw_get_temperature(¤t_temperature); - if (res != LGW_I2C_SUCCESS) { - printf("ERROR: failed to get current temperature\n"); - return LGW_HAL_ERROR; - } -- -+#endif - /* 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++) { - /* Get packet and move to next one */ -``` - -Change the reset pin of `T-SX1302` to `GPIO7`: - -```diff -diff --git a/tools/reset_lgw.sh b/tools/reset_lgw.sh -index b58f0e9..56ff943 100755 ---- a/tools/reset_lgw.sh -+++ b/tools/reset_lgw.sh -@@ -12,7 +12,7 @@ - # GPIO mapping has to be adapted with HW - # - --SX1302_RESET_PIN=23 # SX1302 reset -+SX1302_RESET_PIN=7 # SX1302 reset - SX1302_POWER_EN_PIN=18 # SX1302 power enable - SX1261_RESET_PIN=22 # SX1261 reset (LBT / Spectral Scan) - AD5338R_RESET_PIN=13 # AD5338R reset (full-duplex CN490 reference design) -@@ -90,4 +90,4 @@ case "$1" in - ;; - esac -``` - -3. compile +### Get relevant information ```shell -make clean all -make install -make install_conf +pi@raspberrypi:~ $ cat .sx1302_hal/.output +Gateway EUI: B827EBFFFEFC7AF0 +Gateway Server address: eu1.cloud.thethings.network +Gateway Server port: 1700 ``` -### Configure global_conf +## Create a gateway on TTN -```shell -cd ~/sx1302_hal/bin -touch global_conf.json.sx1250.T-SX1302 -``` +1. Log in to https://console.cloud.thethings.network/ -Add the following content to `global_conf.json.sx1250.T-SX1302` : +2. Select the cluster according to the frequency band supported by the gateway. The frequency band supported by `T-SX1302` is `868MHZ`, here you need to select the `Europe1` cluster -```json -{ - "SX130x_conf": { - "com_type": "SPI", - "com_path": "/dev/spidev0.0", - "lorawan_public": true, - "clksrc": 0, - "antenna_gain": 0, /* antenna gain, in dBi */ - "full_duplex": false, - "precision_timestamp": { - "enable": false, - "max_ts_metrics": 255, - "nb_symbols": 1 - }, - "radio_0": { - "enable": true, - "type": "SX1250", - "freq": 867500000, - "rssi_offset": -215.4, - "rssi_tcomp": { - "coeff_a": 0, - "coeff_b": 0, - "coeff_c": 20.41, - "coeff_d": 2162.56, - "coeff_e": 0 - }, - "tx_enable": true, - "tx_freq_min": 863000000, - "tx_freq_max": 870000000, - "tx_gain_lut": [ - { - "rf_power": 12, - "pa_gain": 0, - "pwr_idx": 15 - }, - { - "rf_power": 13, - "pa_gain": 0, - "pwr_idx": 16 - }, - { - "rf_power": 14, - "pa_gain": 0, - "pwr_idx": 17 - }, - { - "rf_power": 15, - "pa_gain": 0, - "pwr_idx": 19 - }, - { - "rf_power": 16, - "pa_gain": 0, - "pwr_idx": 20 - }, - { - "rf_power": 17, - "pa_gain": 0, - "pwr_idx": 22 - }, - { - "rf_power": 18, - "pa_gain": 1, - "pwr_idx": 1 - }, - { - "rf_power": 19, - "pa_gain": 1, - "pwr_idx": 2 - }, - { - "rf_power": 20, - "pa_gain": 1, - "pwr_idx": 3 - }, - { - "rf_power": 21, - "pa_gain": 1, - "pwr_idx": 4 - }, - { - "rf_power": 22, - "pa_gain": 1, - "pwr_idx": 5 - }, - { - "rf_power": 23, - "pa_gain": 1, - "pwr_idx": 6 - }, - { - "rf_power": 24, - "pa_gain": 1, - "pwr_idx": 7 - }, - { - "rf_power": 25, - "pa_gain": 1, - "pwr_idx": 9 - }, - { - "rf_power": 26, - "pa_gain": 1, - "pwr_idx": 11 - }, - { - "rf_power": 27, - "pa_gain": 1, - "pwr_idx": 14 - } - ] - }, - "radio_1": { - "enable": true, - "type": "SX1250", - "freq": 868500000, - "rssi_offset": -215.4, - "rssi_tcomp": { - "coeff_a": 0, - "coeff_b": 0, - "coeff_c": 20.41, - "coeff_d": 2162.56, - "coeff_e": 0 - }, - "tx_enable": true - }, - "chan_multiSF_0": { - "enable": true, - "radio": 1, - "if": -400000 - }, - "chan_multiSF_1": { - "enable": true, - "radio": 1, - "if": -200000 - }, - "chan_multiSF_2": { - "enable": true, - "radio": 1, - "if": 0 - }, - "chan_multiSF_3": { - "enable": true, - "radio": 0, - "if": -400000 - }, - "chan_multiSF_4": { - "enable": true, - "radio": 0, - "if": -200000 - }, - "chan_multiSF_5": { - "enable": true, - "radio": 0, - "if": 0 - }, - "chan_multiSF_6": { - "enable": true, - "radio": 0, - "if": 200000 - }, - "chan_multiSF_7": { - "enable": true, - "radio": 0, - "if": 400000 - }, - "chan_Lora_std": { - "enable": true, - "radio": 1, - "if": -200000, - "bandwidth": 250000, - "spread_factor": 7, - "implicit_hdr": false, - "implicit_payload_length": 17, - "implicit_crc_en": false, - "implicit_coderate": 1 - }, - "chan_FSK": { - "enable": true, - "radio": 1, - "if": 300000, - "bandwidth": 125000, - "datarate": 50000 - } - }, - "gateway_conf": { - "gateway_ID": "b827ebFFFEfc7af0", - /* change with default server address/ports */ - "server_address": "eu1.cloud.thethings.network", - "serv_port_up": 1700, - "serv_port_down": 1700, - /* adjust the following parameters for your network */ - "keepalive_interval": 10, - "stat_interval": 30, - "push_timeout_ms": 100, - /* forward only valid packets */ - "forward_crc_valid": true, - "forward_crc_error": false, - "forward_crc_disabled": false, - /* GPS configuration */ - //"gps_tty_path": "/dev/ttyS0", - /* GPS reference coordinates */ - // "ref_latitude": 0.0, - //"ref_longitude": 0.0, - //"ref_altitude": 0, - /* Beaconing parameters */ - "beacon_period": 0, - "beacon_freq_hz": 869525000, - "beacon_datarate": 9, - "beacon_bw_hz": 125000, - "beacon_power": 14, - "beacon_infodesc": 0 - }, - "debug_conf": { - "ref_payload": [ - { - "id": "0xCAFE1234" - }, - { - "id": "0xCAFE2345" - } - ], - "log_file": "loragw_hal.log" - } -} -``` + ![cluster_picker](../static/cluster_picker.png) -Among them, `gateway_ID` is modified to `b827ebFFFEfc7af0` + > ! Warning + > + > `Legacy V2 Console` is a server of TTN V2 version, it will be closed in December 2021, it is not recommended to use -`server_address` is changed to `eu1.cloud.thethings.network` +3. Create a gateway -These information should be consistent with the Gateway information created on `TTN` + ![create_gateways](../static/create_gateways.png) -![lilygo_gateway_overview](../static/lilygo_gateway_overview.png) +4. Configure gateway information -> NOTE -> -> `serv_port_up` and `serv_port_down` are `1700` + Fill in the [Gateway EUI] obtained after deploying sx1302_hal (#get related information) -### Run sx1302_hal + ![config_gateway_info](../static/config_gateway_info.png) -```shell -cd ~/sx1302_hal/bin -./lora_pkt_fwd -c global_conf.json.sx1250.T-SX1302 -``` +5. Select frequency,Need to be consistent with the frequency band parameters of sx1302_hal.sh -### Check gateway connection status + ![slelct_frequenry](../static/slelct_frequenry.png) + +## Check gateway connection status Check if the gateway is successfully connected on TTN diff --git a/docs/zh/LilyGo_LoRa_Series_Quick_Start_On_TTN_zh.md b/docs/zh/LilyGo_LoRa_Series_Quick_Start_On_TTN_zh.md index 414716d..08e120f 100644 --- a/docs/zh/LilyGo_LoRa_Series_Quick_Start_On_TTN_zh.md +++ b/docs/zh/LilyGo_LoRa_Series_Quick_Start_On_TTN_zh.md @@ -5,13 +5,11 @@ ## 目录 - [测试环境](#测试环境) -- [在TTN上创建网关](#在ttn上创建网关) - [在树莓派上运行sx1302_hal](#在树莓派上运行sx1302_hal) - - [使能树莓派的SPI接口](#使能树莓派的spi接口) - - [下载sx1302_hal源码并编译](#下载sx1302_hal源码并编译) - - [修改配置文件](#修改配置文件) - - [运行sx1302_hal](#运行sx1302_hal) - - [检查网关连接状态](#检查网关连接状态) + - [部署sx1302_hal](#部署sx1302_hal) + - [获取相关信息](#获取相关信息) +- [在TTN上创建网关](#在TTN上创建网关) +- [检查网关连接状态](#检查网关连接状态) - [在TTN上创建终端设备模型](#在ttn上创建终端设备模型) - [进入创建APP页面](#进入创建app页面) - [创建终端设备模型](#创建终端设备模型) @@ -33,389 +31,57 @@ > > TTN Version: v3.15.1 -## 在TTN上创建网关 - -1. 登录到 https://console.cloud.thethings.network/ - -2. 根据网关支持频段选择对应的集群 - -![cluster_picker](../static/cluster_picker.png) - -`T-SX1302`对应的频段为 `868MHZ`, 这里需要选择 `Europe1` 集群 - -> ! Warning -> -> 其中 `Legacy V2 Console`为TTN V2版本的服务器, 它将在2021年12月份关闭, 不建议使用 - -3. 创建一个网关 - -![create_gateways](../static/create_gateways.png) - -4. 配置网关信息 - -其中需要填入一个唯一的`Gateway EUI`, 如果没有更好的选择,可以使用树莓派的MAC地址 - -![config_gateway_info](../static/config_gateway_info.png) - -5. 选择频率 - -![slelct_frequenry](../static/slelct_frequenry.png) - ## 在树莓派上运行sx1302_hal > NOTE > > 已有其他的也接入到TTN的LoRaWAN网关, 可以忽略该小节 -### 使能树莓派的SPI接口 +### 部署sx1302_hal -Open the `/boot/config.txt` file and write the following at the end of the file: - -``` -dtoverlay=spi0-1cs -``` - -### 下载sx1302_hal源码并编译 - -1. 下载源码: +在树莓派执行[sx1302_hal.sh](../../tools/sx1302_hal.sh),自动部署sx1302_hal。 ```shell -cd ~ -git clone https://github.com/Lora-net/sx1302_hal.git -cd sx1302_hal -git checkout V2.1.0 +sudo ./sx1302_hal.sh -f eu868 +sudo reboot ``` -2. 修改源码 - -因为 `sx1302_hal` 无法读取到 `T-SX1302` 的温度, 需要将 `libloragw/src/loragw_hal.c` 中的部分代码注释: - -```diff -diff --git a/libloragw/src/loragw_hal.c b/libloragw/src/loragw_hal.c -index ffc8ec0..504bb42 100644 ---- a/libloragw/src/loragw_hal.c -+++ b/libloragw/src/loragw_hal.c -@@ -1093,6 +1093,7 @@ int lgw_start(void) { - dbg_init_random(); - - if (CONTEXT_COM_TYPE == LGW_COM_SPI) { -+#if 0 - /* Find the temperature sensor on the known supported ports */ - for (i = 0; i < (int)(sizeof I2C_PORT_TEMP_SENSOR); i++) { - ts_addr = I2C_PORT_TEMP_SENSOR[i]; -@@ -1116,7 +1117,7 @@ int lgw_start(void) { - printf("ERROR: no temperature sensor found.\n"); - return LGW_HAL_ERROR; - } -- -+#endif - /* Configure ADC AD338R for full duplex (CN490 reference design) */ - if (CONTEXT_BOARD.full_duplex == true) { - err = i2c_linuxdev_open(I2C_DEVICE, I2C_PORT_DAC_AD5338R, &ad_fd); -@@ -1285,14 +1286,14 @@ int lgw_receive(uint8_t max_pkt, struct lgw_pkt_rx_s *pkt_data) { - nb_pkt_left = nb_pkt_fetched - max_pkt; - printf("WARNING: not enough space allocated, fetched %d packet(s), %d will be left in RX buffer\n", nb_pkt_fetched, nb_pkt_left); - } -- -+#if 0 - /* Apply RSSI temperature compensation */ - res = lgw_get_temperature(¤t_temperature); - if (res != LGW_I2C_SUCCESS) { - printf("ERROR: failed to get current temperature\n"); - return LGW_HAL_ERROR; - } -- -+#endif - /* 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++) { - /* Get packet and move to next one */ -``` - -将 `T-SX1302` 的复位引脚修改为 `GPIO7`: - -```diff -diff --git a/tools/reset_lgw.sh b/tools/reset_lgw.sh -index b58f0e9..56ff943 100755 ---- a/tools/reset_lgw.sh -+++ b/tools/reset_lgw.sh -@@ -12,7 +12,7 @@ - # GPIO mapping has to be adapted with HW - # - --SX1302_RESET_PIN=23 # SX1302 reset -+SX1302_RESET_PIN=7 # SX1302 reset - SX1302_POWER_EN_PIN=18 # SX1302 power enable - SX1261_RESET_PIN=22 # SX1261 reset (LBT / Spectral Scan) - AD5338R_RESET_PIN=13 # AD5338R reset (full-duplex CN490 reference design) -@@ -90,4 +90,4 @@ case "$1" in - ;; - esac -``` - -3. 编译 +### 获取相关信息 ```shell -make clean all -make install -make install_conf +pi@raspberrypi:~ $ cat .sx1302_hal/.output +Gateway EUI: B827EBFFFEFC7AF0 +Gateway Server address: eu1.cloud.thethings.network +Gateway Server port: 1700 ``` -### 修改配置文件 +## 在TTN上创建网关 -```shell -cd ~/sx1302_hal/bin -touch global_conf.json.sx1250.T-SX1302 -``` +1. 登录到 https://console.cloud.thethings.network/ -添加以下内容到 `global_conf.json.sx1250.T-SX1302`: +2. 根据网关支持频段选择对应的集群,`T-SX1302`对应的频段为 `868MHZ`, 这里需要选择 `Europe1` 集群 -```json -{ - "SX130x_conf": { - "com_type": "SPI", - "com_path": "/dev/spidev0.0", - "lorawan_public": true, - "clksrc": 0, - "antenna_gain": 0, /* antenna gain, in dBi */ - "full_duplex": false, - "precision_timestamp": { - "enable": false, - "max_ts_metrics": 255, - "nb_symbols": 1 - }, - "radio_0": { - "enable": true, - "type": "SX1250", - "freq": 867500000, - "rssi_offset": -215.4, - "rssi_tcomp": { - "coeff_a": 0, - "coeff_b": 0, - "coeff_c": 20.41, - "coeff_d": 2162.56, - "coeff_e": 0 - }, - "tx_enable": true, - "tx_freq_min": 863000000, - "tx_freq_max": 870000000, - "tx_gain_lut": [ - { - "rf_power": 12, - "pa_gain": 0, - "pwr_idx": 15 - }, - { - "rf_power": 13, - "pa_gain": 0, - "pwr_idx": 16 - }, - { - "rf_power": 14, - "pa_gain": 0, - "pwr_idx": 17 - }, - { - "rf_power": 15, - "pa_gain": 0, - "pwr_idx": 19 - }, - { - "rf_power": 16, - "pa_gain": 0, - "pwr_idx": 20 - }, - { - "rf_power": 17, - "pa_gain": 0, - "pwr_idx": 22 - }, - { - "rf_power": 18, - "pa_gain": 1, - "pwr_idx": 1 - }, - { - "rf_power": 19, - "pa_gain": 1, - "pwr_idx": 2 - }, - { - "rf_power": 20, - "pa_gain": 1, - "pwr_idx": 3 - }, - { - "rf_power": 21, - "pa_gain": 1, - "pwr_idx": 4 - }, - { - "rf_power": 22, - "pa_gain": 1, - "pwr_idx": 5 - }, - { - "rf_power": 23, - "pa_gain": 1, - "pwr_idx": 6 - }, - { - "rf_power": 24, - "pa_gain": 1, - "pwr_idx": 7 - }, - { - "rf_power": 25, - "pa_gain": 1, - "pwr_idx": 9 - }, - { - "rf_power": 26, - "pa_gain": 1, - "pwr_idx": 11 - }, - { - "rf_power": 27, - "pa_gain": 1, - "pwr_idx": 14 - } - ] - }, - "radio_1": { - "enable": true, - "type": "SX1250", - "freq": 868500000, - "rssi_offset": -215.4, - "rssi_tcomp": { - "coeff_a": 0, - "coeff_b": 0, - "coeff_c": 20.41, - "coeff_d": 2162.56, - "coeff_e": 0 - }, - "tx_enable": true - }, - "chan_multiSF_0": { - "enable": true, - "radio": 1, - "if": -400000 - }, - "chan_multiSF_1": { - "enable": true, - "radio": 1, - "if": -200000 - }, - "chan_multiSF_2": { - "enable": true, - "radio": 1, - "if": 0 - }, - "chan_multiSF_3": { - "enable": true, - "radio": 0, - "if": -400000 - }, - "chan_multiSF_4": { - "enable": true, - "radio": 0, - "if": -200000 - }, - "chan_multiSF_5": { - "enable": true, - "radio": 0, - "if": 0 - }, - "chan_multiSF_6": { - "enable": true, - "radio": 0, - "if": 200000 - }, - "chan_multiSF_7": { - "enable": true, - "radio": 0, - "if": 400000 - }, - "chan_Lora_std": { - "enable": true, - "radio": 1, - "if": -200000, - "bandwidth": 250000, - "spread_factor": 7, - "implicit_hdr": false, - "implicit_payload_length": 17, - "implicit_crc_en": false, - "implicit_coderate": 1 - }, - "chan_FSK": { - "enable": true, - "radio": 1, - "if": 300000, - "bandwidth": 125000, - "datarate": 50000 - } - }, - "gateway_conf": { - "gateway_ID": "b827ebFFFEfc7af0", - /* change with default server address/ports */ - "server_address": "eu1.cloud.thethings.network", - "serv_port_up": 1700, - "serv_port_down": 1700, - /* adjust the following parameters for your network */ - "keepalive_interval": 10, - "stat_interval": 30, - "push_timeout_ms": 100, - /* forward only valid packets */ - "forward_crc_valid": true, - "forward_crc_error": false, - "forward_crc_disabled": false, - /* GPS configuration */ - //"gps_tty_path": "/dev/ttyS0", - /* GPS reference coordinates */ - // "ref_latitude": 0.0, - //"ref_longitude": 0.0, - //"ref_altitude": 0, - /* Beaconing parameters */ - "beacon_period": 0, - "beacon_freq_hz": 869525000, - "beacon_datarate": 9, - "beacon_bw_hz": 125000, - "beacon_power": 14, - "beacon_infodesc": 0 - }, - "debug_conf": { - "ref_payload": [ - { - "id": "0xCAFE1234" - }, - { - "id": "0xCAFE2345" - } - ], - "log_file": "loragw_hal.log" - } -} -``` + ![cluster_picker](../static/cluster_picker.png) -其中, `gateway_ID` 修改为 `Gateway EUI` + > ! Warning + > + > 其中 `Legacy V2 Console`为TTN V2版本的服务器, 它将在2021年12月份关闭, 不建议使用 -`server_address` 修改为 `eu1.cloud.thethings.network` +3. 创建一个网关 -这些信息,要和 `TTN` 上创建的Gateway信息一致 + ![create_gateways](../static/create_gateways.png) -![lilygo_gateway_overview](../static/lilygo_gateway_overview.png) +4. 配置网关信息 -> NOTE -> -> `TTN` 的 `serv_port_up` 和 `serv_port_down` 为 `1700` + 填入部署sx1302_hal后获得的 [Gateway EUI](#获取相关信息) -### 运行sx1302_hal + ![config_gateway_info](../static/config_gateway_info.png) -```shell -cd ~/sx1302_hal/bin -./lora_pkt_fwd -c global_conf.json.sx1250.T-SX1302 -``` +5. 选择频率,需要部署 sx1302_hal 的频段参数保持一致 -### 检查网关连接状态 + ![slelct_frequenry](../static/slelct_frequenry.png) + +## 检查网关连接状态 在TTN上检查网关是否连接成功 @@ -437,7 +103,7 @@ cd ~/sx1302_hal/bin ![register_end_device](../static/register_end_device.png) -> NOTE +> NOTE > > `DevEUI`、`AppEUI`、`AppKey`选择自动生成即可 @@ -557,3 +223,4 @@ index 896be89..6b39f54 100644 | 版本 | 主要改动 | 日期 | 作者 | | ----- | -------- | ---------- | ------- | | 1.0.0 | 初始版本 | 2021/10/22 | liangyy | +| 1.1.0 | | 2022/11/29 | liangyy | diff --git a/tools/README.md b/tools/README.md new file mode 100644 index 0000000..1d1fa0c --- /dev/null +++ b/tools/README.md @@ -0,0 +1,68 @@ +# sx1302_hal.sh + +## Usage + +> NOTE +> +> This script requires administrator privileges. + +```shell +Script to automatically deploy packet_forwarder + +Usage: sudo ./sx1302_hal.sh [-s server] [-p port] [-f frequency] [--eui eui] [--verbose] [-o output] + sudo ./sx1302_hal.sh + ./sx1302_hal.sh -v + ./sx1302_hal.sh --help + +Option: + -s --server Gateway Server address. The default value is eu1.cloud.thethings.network. + -p --port Gateway Server port. The default value is 1700. + -f --frequency The frequency band of lorawan supports eu868, us915, as923. The default value is eu868. + -eui Gateway EUI. The default is produced by the mac address of eth0. + -o --output Output gateway information. + +Miscellaneous options: + --verbose Output extra information about the work being done. + + -v --version Output version info. + --help Output this help. + +Report bugs to lbquue@163.com. +``` + +## The Things Network + +The Things Network has the following three servers, just choose one of them. The port is 1700. + +Europe 1: + +``` +eu1.cloud.thethings.network +``` + + +North America 1: + +``` +nam1.cloud.thethings.network +``` + +Australia 1: + +``` +au1.cloud.thethings.network +``` + +## Test + +| Model | OS | Gateway | Status | +| ------------------------------------- | ---------------------------------------------- | --------------- | ------ | +| [Raspberry Pi 3 Model B Rev 1.2][1-1] | [Raspberry Pi OS Lite(64-bit) 2022-09-26][1-2] | [T-SX1302][1-3] | ✔ | + +[1-1]: https://www.raspberrypi.com/products/raspberry-pi-3-model-b/ +[1-2]: https://downloads.raspberrypi.org/raspios_lite_arm64/images/raspios_lite_arm64-2022-09-26/ +[1-3]: https://www.aliexpress.us/item/3256801172821554.html + +> NOTE +> +> Theoretically, other models of Raspberry Pi are also supported, welcome to submit test results! diff --git a/tools/sx1302_hal.sh b/tools/sx1302_hal.sh new file mode 100755 index 0000000..807c2a2 --- /dev/null +++ b/tools/sx1302_hal.sh @@ -0,0 +1,704 @@ +#!/bin/bash + +# Author: lbuque +# Github: https://github.com/Xinyuan-LilyGO/LilyGo-LoRa-Series + +RED="\033[31m" # Error message +GREEN="\033[32m" # Success message +YELLOW="\033[33m" # Warning message +BLUE="\033[36m" # Info message +PLAIN='\033[0m' + +# set -euxo pipefail + +readonly __version=0.1.0 + +readonly WORK_DIR=/home/pi/.sx1302_hal + +readonly sx1302_hal_name=sx1302_hal +readonly sx1302_hal_url=https://github.com/Lora-net/sx1302_hal/archive/refs/tags/V2.1.0.tar.gz +readonly sx1302_hal_version=2.1.0 + + +colorEcho() { + echo -e "${1}${@:2}${PLAIN}" +} + + +checkSystem() { + uid=$(id -u) + if [[ $uid -ne 0 ]]; then + colorEcho $RED " Please execute the script as root" # " 请以root身份执行该脚本" + exit 1 + fi + + res=$(command -v apt) + if [[ "$res" = "" ]]; then + colorEcho $RED "Unsupported Linux systems" + exit 1 + fi + + res=$(command -v systemctl) + if [[ "$res" = "" ]]; then + colorEcho $RED "The system version is too low, please upgrade to the latest version" + exit 1 + fi + + res=$(command -v wget) + if [[ "$res" = "" ]]; then + colorEcho $RED "Missing wget tool" + colorEcho $YELLOW "Try to install wget tool" + apt-get install wget + if [ $? != 0 ]; then + colorEcho $RED "Failed to install wget tool" + exit 1 + fi + fi + + res=$(command -v patch) + if [[ "$res" = "" ]]; then + colorEcho $RED "Missing patch tool" + colorEcho $YELLOW "Try to install patch tool" + apt-get install patch + if [ $? != 0 ]; then + colorEcho $RED "Failed to install patch tool" + exit 1 + fi + fi +} + + +prepare() { + if [ ! -d "$WORK_DIR" ]; then + mkdir -p $WORK_DIR + fi + + if [ ! -d "$WORK_DIR/dist" ]; then + mkdir -p $WORK_DIR/dist + fi + + if [ ! -d "$WORK_DIR/bin" ]; then + mkdir -p $WORK_DIR/bin + fi +} + + +download() { + sx1302_hal_archive=$WORK_DIR/dist/$sx1302_hal_name-$sx1302_hal_version.tar.gz + if [ ! -f $sx1302_hal_archive ]; then + wget $sx1302_hal_url -O $sx1302_hal_archive + fi + + if [ ! -d $WORK_DIR/$sx1302_hal_name-$sx1302_hal_version ]; then + tar -xvf $WORK_DIR/dist/$sx1302_hal_name-$sx1302_hal_version.tar.gz -C $WORK_DIR + fi +} + + +patching() { + if [ -f $WORK_DIR/$sx1302_hal_name-$sx1302_hal_version/.patch ]; then + return 0 + fi + + local readonly oragw_hal_c_patch=$(cat <> /boot/config.txt + fi + fi + echo $ret +} + + +getGatewayID() { + local readonly GWID_MIDFIX="FFFE" + local interface=`ifconfig | grep enx | awk '{print $1}'` + interface=${interface%%:*} + local readonly GWID_BEGIN=$(ip link show $interface | awk '/ether/ {print $2}' | awk -F\: '{print $1$2$3}') + local readonly GWID_END=$(ip link show $interface | awk '/ether/ {print $2}' | awk -F\: '{print $4$5$6}') + echo $GWID_BEGIN$GWID_MIDFIX$GWID_END +} + + +eu868Config() { + local readonly global_conf=$(cat < $WORK_DIR/bin/global_conf.json +} + + +us915Config() { + local readonly global_conf=$(cat < $WORK_DIR/bin/global_conf.json +} + + +as923Config() { + local readonly global_conf=$(cat < $WORK_DIR/bin/global_conf.json +} + + +daemon() { + local readonly lora_pkt_fwd_service_file=$(cat < /etc/systemd/system/lora_pkt_fwd.service + systemctl daemon-reload + systemctl enable lora_pkt_fwd.service + systemctl restart lora_pkt_fwd.service + # reboot +} + + +help() { + local readonly usage="Script to automatically deploy packet_forwarder + +Usage: sudo ./sx1302_hal.sh [-s server] [-p port] [-f frequency] [--eui eui] [--verbose] [-o output] + sudo ./sx1302_hal.sh + ./sx1302_hal.sh -v + ./sx1302_hal.sh --help + +Option: + -s --server Gateway Server address. The default value is eu1.cloud.thethings.network. + -p --port Gateway Server port. The default value is 1700. + -f --frequency The frequency band of lorawan supports eu868, us915, as923. The default value is eu868. + -eui Gateway EUI. The default is produced by the mac address of eth0. + -o --output Output gateway information. + +Miscellaneous options: + --verbose Output extra information about the work being done. + + -v --version Output version info. + --help Output this help. + +Report bugs to https://github.com/Xinyuan-LilyGO/LilyGo-LoRa-Series/issues." + echo -e "$usage" +} + + +version() { + local readonly version_info="sx1302_hal.sh $__version +Copyright (c) 2022 Shenzhen Xin Yuan Electronic Technology Co., Ltd +Written by lbuque" + echo -e "$version_info" +} + + +showInfo() { + echo + colorEcho $GREEN "packet_forwarder installed successfully!!! " + colorEcho $GREEN "===========================================" + colorEcho $GREEN "Installation path: $WORK_DIR" + colorEcho $GREEN "application path: $WORK_DIR/bin/lora_pkt_fwd" + colorEcho $GREEN "Configuration file path: $WORK_DIR/bin/global_conf.json" + colorEcho $GREEN "Systemctl file path: /etc/systemd/system/lora_pkt_fwd.service" + + colorEcho $GREEN "Gateway EUI: $1" + colorEcho $GREEN "Gateway Server address: $2" + colorEcho $GREEN "Gateway Server port: $3" + + if [ "$4" != "" ]; then + echo "Gateway EUI: $1" > $4 + echo "Gateway Server address: $2" >> $4 + echo "Gateway Server port: $3" >> $4 + fi +} + + +main() { + TEMP=`getopt -o s:p:f:o:v --long server:,port:,frequency:,eui:,output:,verbose,version,help -n $0 -- "$@"` + if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi + eval set -- "$TEMP" + local eui=`getGatewayID` + eui=${eui^^} + local server_address="eu1.cloud.thethings.network" + local server_port=1700 + local frequency_plan="eu868" + local output_file=$WORK_DIR/.output + while true ; do + case "$1" in + -s|--server) + server_address=$2 + shift 2 + ;; + -p|--port) + server_port=$2 + shift 2 + ;; + --eui) + eui=${$2^^} + shift 2 + ;; + -f|--frequency) + frequency_plan=$2 + case "$frequency_plan" in + eu868|us915|as923) + ;; + *) + colorEcho $RED "Wrong frequency plan($frequency_plan), Please choose eu868, us915, as923!" + exit 1 + ;; + esac + shift 2 + ;; + -o|--output) + output_file=$2 + shift 2 + ;; + --verbose) set -euxo pipefail ; shift ;; + -v|--version) version; exit 0 ;; + --help) help; exit 0 ;; + --) shift ; break ;; + *) echo "Internal error!" ; exit 1 ;; + esac + done + + checkSystem + prepare + download + patching + compile + install + ret=`raspiConfig` + case "$frequency_plan" in + eu868) + eu868Config $eui $server_address $server_port + ;; + us915) + us915Config $eui $server_address $server_port + ;; + as923) + as923Config $eui $server_address $server_port + ;; + *) + colorEcho $RED "Wrong frequency plan($frequency_plan), Please choose eu868, us915, as923!" + exit 1 + ;; + esac + daemon + showInfo $eui $server_address $server_port $output_file + if [ "$ret" = "0" ]; then + echo + colorEcho $BLUE "Take effect after restarting the system! ! !" + fi +} + +main $@