简介
硬件
LoraWAN网关硬件上需要一个网关模组,比如SX1301、SX1302等,我使用的是SX1302,某鱼入手还是挺便宜的还带树莓派转接板,到手后就直接可以用了,连接图如下:
开发板和模块的通讯
SPI -- 与SX1302通讯,使用的是SPI3.0;
I2C -- 与温度传感器通讯,使用的是I2C-3;
串口 -- 接收GPS数据,使用的是ttyS8;
还有需要一个GPIO口,接到了板子的83引脚;
涉及到的系统配置
修改/boot/uEnv/uEnvLubanCatZW.txt
下面是设备树插件部分的内容,开启了一下相关的硬件:
dtoverlay=/dtb/overlay/rk356x-lubancat-gmac1-disabled-overlay.dtbo
dtoverlay=/dtb/overlay/rk356x-lubancat-i2c3-m0-overlay.dtbo
dtoverlay=/dtb/overlay/rk3566-lubancat-0-spi3-m1-gpio-cs-overlay.dtbo
dtoverlay=/dtb/overlay/rk356x-lubancat-spi3-m1-overlay.dtbo
dtoverlay=/dtb/overlay/rk356x-lubancat-uart8-m0-overlay.dtbo
软件
软件上需要用到SX1302的hal库,chirpstack的bridge软件包和chirpstack服务器软件包。
安装依赖
-
通过以下命令安装mosquitto
-
通过以下命令安装PostgreSQL配置
安装:
sudo apt install postgresql
配置:
sudo -u postgres psql
create role chirpstack with login password 'chirpstack';
create database chirpstack with owner chirpstack;
\c chirpstack
create extension pg_trgm;
\q
上面的账号密码及数据库名字都可以自定义,在下面配置chirpstack时保持一致就行。
-
通过以下命令安装redis-server
sudo apt install redis-server
-
安装emqx
可以选择docker部署或者直接安装emqx服务。
直接安装参考Ubuntu 安装 EMQX 5.0 文档
docker部署参考Docker 部署 EMQX 5.0 文档
sx1302_hal
可以在github上面下载到:
地址是:https://github.com/Lora-net/sx1302_hal.git
使用的是release版本,V2.1.0
里面需要修改的文件有:
#define I2C_DEVICE "/dev/i2c-3"
复制tools/reset_lgw.sh到sx1302的根目录
修改如下
SX1302_RESET_PIN=83
SX1302_POWER_EN_PIN=18
SX1261_RESET_PIN=22
AD5338R_RESET_PIN=13
WAIT_GPIO() {
sleep 0.1
}
init() {
echo "$SX1302_RESET_PIN" > /sys/class/gpio/export; WAIT_GPIO
echo "out" > /sys/class/gpio/gpio$SX1302_RESET_PIN/direction; WAIT_GPIO
}
reset() {
echo "CoreCell reset through GPIO$SX1302_RESET_PIN..."
echo "1" > /sys/class/gpio/gpio$SX1302_RESET_PIN/value; WAIT_GPIO
echo "0" > /sys/class/gpio/gpio$SX1302_RESET_PIN/value; WAIT_GPIO
}
复制packet_forwarder下的global_conf.json.sx1250.CN490到sx1302根目录,然后重命名为global_conf.json。修改为如下:
{
"SX130x_conf": {
"com_type": "SPI",
"com_path": "/dev/spidev3.0",
"lorawan_public": true,
"clksrc": 0,
"antenna_gain": 0,
"full_duplex": false,
"fine_timestamp": {
"enable": false,
"mode": "all_sf"
},
"radio_0": {
"enable": true,
"type": "SX1250",
"single_input_mode": true,
"freq": 470600000,
"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": 500000000,
"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": 1, "pwr_idx": 7},
{"rf_power": 13, "pa_gain": 1, "pwr_idx": 8},
{"rf_power": 14, "pa_gain": 1, "pwr_idx": 9},
{"rf_power": 16, "pa_gain": 1, "pwr_idx": 10},
{"rf_power": 20, "pa_gain": 1, "pwr_idx": 11},
{"rf_power": 23, "pa_gain": 1, "pwr_idx": 12},
{"rf_power": 25, "pa_gain": 1, "pwr_idx": 13},
{"rf_power": 26, "pa_gain": 1, "pwr_idx": 14},
{"rf_power": 27, "pa_gain": 1, "pwr_idx": 15}
]
},
"radio_1": {
"enable": true,
"type": "SX1250",
"single_input_mode": true,
"freq": 471400000,
"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_All": {"spreading_factor_enable": [ 5, 6, 7, 8, 9, 10, 11, 12 ]},
"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",
"server_address": "localhost",
"serv_port_up": 1700,
"serv_port_down": 1700,
"keepalive_interval": 10,
"stat_interval": 30,
"push_timeout_ms": 100,
"forward_crc_valid": true,
"forward_crc_error": false,
"forward_crc_disabled": false,
"gps_tty_path": "/dev/ttyS8",
"ref_latitude": 0.0,
"ref_longitude": 0.0,
"ref_altitude": 0,
"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"
}
}
最后通过下面命令启动:
sudo ./packet_forwarder/lora_pkt_fwd -c global_conf.json
chirpstack_gateway_bridge
可以去chirpstack官网下载,地址如下:
chirpstack-gateway-bridge下载地址
下载deb安装包进行安装,安装完成后修改配置文件:/etc/chirpstack-gateway-bridge/chirpstack-gateway-bridge.toml,内容如下:
marshaler="json"
主要为了调试的时候可以更直观的看到数据,也可以不改,只要与后面的chirpstack配置对应就行。
通过一下命令启动
sudo systemctl start chirpstack-gateway-bridge
chirpstack
也在chirpstack官网下载,地址如下:
ChirpStack下载地址
复制配置文件,从/etc/chirpstack中的chirpstack.toml和region_cn470_0.toml复制到~/.config/chirpstack(没有目录就创建),修改配置文件:
chirpstack.toml:
[network]
net_id="000000"
enabled_regions=[
"cn470_0",
]
[api]
bind="0.0.0.0:28080"
secret="you-must-replace-this"
[integration]
enabled=["mqtt"]
[integration.mqtt]
server="tcp://localhost:1883/"
json=true
region_cn470_0.toml:
[regions.gateway.backend.mqtt]
event_topic="gateway/+/event/+"
command_topic="gateway/{{gateway_id}}/command/{{command}}"
server="tcp://localhost:1883"
username=""
password=""
运行chirpstack:
chirpstack -c ~/.config/chirpstack
至此,安装部署已经完成,接下去是通过控制面板来添加、配置lorawan。请参考下一节吧。