参考
从零开始搭建一个LoRaWAN基站
准备
官方开源代码
https://github.com/Lora-net/sx1302_hal
git命令:
git clone https://github.com/Lora-net/sx1302_hal.git
厂家适配后的源码
因为官方源码中使用了一个温度传感器,而在此版设计中,并没有此传感器,所以需要将部分代码注释掉才能运行,这一步,M-GW1302S的厂家已经帮我们改好了。
https://gitee.com/rejeee/gw1302s
git命令:
git clone https://gitee.com/rejeee/gw1302s
准备工作
下载代码、编译、运行
git clone https://gitee.com/rejeee/gw1302s.git
cd gw1302s
target.cfg
中的TARGET_DIR
为TARGET_DIR=/home/pi/gw1302s/bin
make clean all
->此步骤会把代码编译成可执行文件
make install
-> 此步骤会用调用SCP将编译结果拷贝到TARGET_DIR所在目录,所以可能需要输入密码(此处是将scp的dst设为localhost,所以会拷贝到本地),若不想输密码,可参考README.md进行ssh秘钥拷贝,后续就无需输入密码了
make install_conf
->至此,源码就编译完成了,并且生成的已经在TARGET_DIR指定的目录下了
接下来我们需要配置global_conf.json
,配置得适用于我们的需要,此处我贡献一下我的global_conf.json
文件,其中配置基站的接收频点是通过配置两个SX1250的中心频点,外加8个偏移频点来进行的,如下图,我配置的为486.3~487.7的接收频点范围
{
"SX130x_conf": {
"spidev_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",
"single_input_mode": true,
"freq": 486600000,
"rssi_offset": -207.0,
"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": 470000000,
"tx_freq_max": 510000000,
"tx_gain_lut":[
{"rf_power": -6, "pa_gain": 0, "pwr_idx": 0},
{"rf_power": -3, "pa_gain": 0, "pwr_idx": 1},
{"rf_power": 0, "pa_gain": 0, "pwr_idx": 2},
{"rf_power": 3, "pa_gain": 1, "pwr_idx": 3},
{"rf_power": 6, "pa_gain": 1, "pwr_idx": 4},
{"rf_power": 10, "pa_gain": 1, "pwr_idx": 5},
{"rf_power": 11, "pa_gain": 1, "pwr_idx": 6},
{"rf_power": 12, "pa_gain": 2, "pwr_idx": 7},
{"rf_power": 13, "pa_gain": 1, "pwr_idx": 8},
{"rf_power": 14, "pa_gain": 2, "pwr_idx": 9},
{"rf_power": 16, "pa_gain": 2, "pwr_idx": 10},
{"rf_power": 20, "pa_gain": 3, "pwr_idx": 11},
{"rf_power": 23, "pa_gain": 3, "pwr_idx": 12},
{"rf_power": 25, "pa_gain": 3, "pwr_idx": 13},
{"rf_power": 26, "pa_gain": 3, "pwr_idx": 14},
{"rf_power": 27, "pa_gain": 3, "pwr_idx": 15}
]
},
"radio_1": {
"enable": true,
"type": "SX1250",
"single_input_mode": true,
"freq": 487400000,
"rssi_offset": -207.0,
"rssi_tcomp": {"coeff_a": 0, "coeff_b": 0, "coeff_c": 20.41, "coeff_d": 2162.56, "coeff_e": 0},
"tx_enable": false
},
"chan_multiSF_0": {"enable": true, "radio": 0, "if": -300000},
"chan_multiSF_1": {"enable": true, "radio": 0, "if": -100000},
"chan_multiSF_2": {"enable": true, "radio": 0, "if": 100000},
"chan_multiSF_3": {"enable": true, "radio": 0, "if": 300000},
"chan_multiSF_4": {"enable": true, "radio": 1, "if": -300000},
"chan_multiSF_5": {"enable": true, "radio": 1, "if": -100000},
"chan_multiSF_6": {"enable": true, "radio": 1, "if": 100000},
"chan_multiSF_7": {"enable": true, "radio": 1, "if": 300000},
"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": "AA555A0000000000",
/* change with default server address/ports */
"server_address": "your.lorawan.com",
"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,
/* 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"
}
}
至此,我们就拥有一台自己DIY的LoRaWAN基站了!!
global_conf.json配置
这个配置文件是lora_pkt_fwd
程序运行的所有配置参数,其中有几点是我们平时会比较常用到的:
radio_0.freq==486600000,radio_1.freq==487400000
,这就是radio_0
和radio_1
的中心频点,下面会根据设置的8个频点的偏移情况来开启8个接收信道,具体体现在"chan_multiSF_0": {"enable": true, "radio": 0, "if": -300000},
"chan_multiSF_1": {"enable": true, "radio": 0, "if": -100000},
"chan_multiSF_2": {"enable": true, "radio": 0, "if": 100000},
"chan_multiSF_3": {"enable": true, "radio": 0, "if": 300000},
"chan_multiSF_4": {"enable": true, "radio": 1, "if": -300000},
"chan_multiSF_5": {"enable": true, "radio": 1, "if": -100000},
"chan_multiSF_6": {"enable": true, "radio": 1, "if": 100000},
"chan_multiSF_7": {"enable": true, "radio": 1, "if": 300000},
我们以第一条为例
chan_multiSF_X
,指的是这个频点是可以接收多个SF的,这种频点最多可以有8个,这是由硬件决定的
enable:true
表示这个频点开启
"radio":0
,表明此信道的中心频点是radio_0的中心频点
"if": -300000
,表明此信道在中心频点上偏移-300000Hz
故此条配置的含义是:
此频点可接收多个SF
此频点为radio_0.freq-300000=486600000-300000=486300000=486.3MHz
设置基站的ID
gateway_conf.gateway_ID
即是
如何设置基站的LoRaWAN NS指向
gateway_conf.server_address
为NS的地址
gateway_conf.serv_port_up
为NS的上行端口
gateway_conf.serv_port_down
为NS的下行端口
如何设置基站的发射功率
基站的发射功率
首先是要有个radio的tx_enable是true的,即表示通过此芯片发送下行,这个和硬件- 有关,不过大部分情况下都是radio_0(大家都参考的原厂的参考设计)
tx_freq_min
,tx_freq_max
设置的是发射的最大,最小频点范围
tx_gain_lut
是tx power的一个具体配置表,也就是说,当基站收到NS的下发命令时,会按照指定功率进行下发,若指定的功率不在这个表里面,那么可能就不会进行下发了,此表为什么这配我也不清楚,一般情况下不要去改动它