項(xiàng)目介紹
本項(xiàng)目是ESP32+SX1302,做成LoRaWAN 多通道GW,支持packet-forward
開發(fā)環(huán)境
- IDF:V5.2.1
- IDE:VSCode+ESP-IDF插件
PCBA示意圖
固件燒錄
接線
1.燒錄程序時(shí)接這個(gè)口,ESP32燒程序是先讓設(shè)備進(jìn)入燒錄模式(先按住BOOT0按鍵,然后按下EN按鍵,此時(shí)ESP32重啟,進(jìn)入燒錄模式,然后松開BOOT0按鍵,ESP32停留在燒錄模式)
Note:
- 如果使用ESP-PROG,板上帶有自動(dòng)進(jìn)入boot模式的功能,燒錄時(shí)可以不用按按鍵進(jìn)入boot模式
燒錄軟件
1.下載flash_download_tool_3.9.6_2
2.選擇芯片和下載方式
3.配置下載地址和bin文件,點(diǎn)擊start開始下載
配置
WEB 配置
設(shè)備上電會(huì)進(jìn)入AP模式
設(shè)備內(nèi)置一個(gè)web端,可用于對(duì)設(shè)備進(jìn)行配置
設(shè)備首次上電WIFI會(huì)進(jìn)入AP模塊,AP模式下設(shè)備配置如下
# AP模式下WIFI配置
SSID:LoRaGW-xxxxxx
password:loragwwifi
xxxxxx為SN的后6位
WEB端地址:192.168.4.1
用戶需要再配置網(wǎng)關(guān)的區(qū)域、頻點(diǎn)、網(wǎng)關(guān)ID、packet-forward轉(zhuǎn)發(fā)地址,網(wǎng)關(guān)ID默認(rèn)會(huì)根據(jù)MAC地址自動(dòng)生成,可以不用修改
網(wǎng)關(guān)的頻點(diǎn)是通過(guò)修改radio0和radio1來(lái)實(shí)現(xiàn)的,8個(gè)頻點(diǎn)和radio0,radio1的映射,不同地區(qū)會(huì)不一樣
CN470(通常radio0與radio1相差800KHZ,默認(rèn)radio=470600000Hz,radio1=471400000Hz)
freq0 = RADIO0-300KHz,默認(rèn)為470.3MHz
freq1 = RADIO0-100KHz,默認(rèn)為470.5MHz
freq2 = RADIO0+100KHz,默認(rèn)為470.7MHz
freq3 = RADIO0+300KHz,默認(rèn)為470.9MHz
freq4 = RADIO1-300KHz,默認(rèn)為471.1MHz
freq5 = RADIO1-100KHz,默認(rèn)為471.3MHz
freq6 = RADIO1+100KHz,默認(rèn)為471.5MHz
freq7 = RADIO1+300KHz,默認(rèn)為471.7MHz
EU868(默認(rèn)radio=867500000Hz,radio1=868500000Hz)
freq0 = RADIO1-400KHz 默認(rèn)為868.1MHz
freq1 = RADIO1-200KHz 默認(rèn)為868.3MHz
freq2 = RADIO1 默認(rèn)為868.5MHz
freq3 = RADIO0-400KHz 默認(rèn)為867.1MHz
freq4 = RADIO0-200KHz 默認(rèn)為867.3MHz
freq5 = RADIO0 默認(rèn)為867.5MHz
freq6 = RADIO0+200KHz 默認(rèn)為867.7MHz
freq7 = RADIO0+400KHz 默認(rèn)為867.9MHz
US915(默認(rèn)radio=904300000Hz,radio1=905000000Hz) //US915_1
freq0 = RADIO0-400KHz 默認(rèn)為903.9MHz
freq1 = RADIO0-200KHz 默認(rèn)為904.1MHz
freq2 = RADIO0 默認(rèn)為904.3MHz
freq3 = RADIO0+200KHz 默認(rèn)為904.5MHz
freq4 = RADIO1-300KHz 默認(rèn)為904.7MHz
freq5 = RADIO1-100KHz 默認(rèn)為904.9MHz
freq6 = RADIO1+100KHz 默認(rèn)為905.1MHz
freq7 = RADIO1+300KHz 默認(rèn)為905.3MHz
chan_LoRa_Std = radio0+300Khz,默認(rèn)為904.6MHz
命令行配置
設(shè)備支持命令行進(jìn)行配置,請(qǐng)使用putty或XSHELL進(jìn)行
- 串口配置為115200,8,N,1
ESXP1302_GW >
ESXP1302_GW > help
pkt_fwd [-h] [--restore] [--host=< UDP Host >] [--port=< UDP Port >] [--gwid=< gateway id >]
ESP32 packet forwarder based on sx1302_hal
--restore clean NVS config
-h, --help print help
--host=< UDP Host > UDP Host
--port=< UDP Port > UDP Port
--gwid=< gateway id > Gateway Id
ifconfig
printf network status
reboot
reboot the system
help [< string >]
Print the summary of all registered commands if no arguments are given,
otherwise print summary of given command.
< string > Name of command
如上,可通過(guò)設(shè)備pkt_fwd命令進(jìn)行設(shè)置
- pkt_fwd,用于配置設(shè)備pkt_fwd相關(guān)的信息
- ifconfig,用于查看所有網(wǎng)卡的信息
ESXP1302_GW > ESXP1302_GW > ifconfig =========ifconfig=========== --------if:ppp prio:20-------- link: NET_UP ip: 10.145.122.176 mask: 255.255.255.255 gw: 10.64.64.64 dns1: 218.85.157.99 dns2: 218.85.157.99 IMEI: 860761079936981 IMSI: 460115210945489 ICCID: 89860322245923849833 CSQ/BER: 23/0 --------if:eth prio:50-------- link: LINK_DOWN/NET_DOWN MAC: 66:e8:33:49:ba:47 ip: 0.0.0.0 mask: 0.0.0.0 gw: 0.0.0.0 dns1: 218.85.157.99 dns2: 218.85.157.99 --------if:ap prio:10-------- MAC: 64:e8:33:49:ba:45 ip: 192.168.4.1 ssid: esp32 pswd: esp32wifi =========ifconfig end===========
- reboot,用于設(shè)備重啟
- help,查看幫助說(shuō)明
LoRaWAN NS
測(cè)試用NS,域名:lora.ansitw.com,IP:106.52.124.231
WEB端地址:106.52.124.231:8080
包轉(zhuǎn)發(fā)地址:
- CN470 :106.52.124.231:1700
- EU868 :106.52.124.231:1701
- US915_0 :106.52.124.231:1702
- US915_1 :106.52.124.231:1703
?
網(wǎng)關(guān)測(cè)試
發(fā)送測(cè)試
test_hal_tx -r 1250 -f 506.5 -s 12 --pwid 22 -n 10
-r:指定射頻前端芯片為1250
-f:發(fā)送的頻點(diǎn)(MHz)
-s:SF
–pwid 22:
接收測(cè)試
test_hal_rx -r 1250 -a 475.5 -b 476.5
WEB配置
總體概述
- GW Info,網(wǎng)關(guān)信息查看
- Configuration,網(wǎng)關(guān)配置查看和修改
- Maintenance,維護(hù)頁(yè)(設(shè)備升級(jí)、恢復(fù)出廠設(shè)備)
配置
- WIFI STA,支持WIFI接入點(diǎn)方式連接網(wǎng)絡(luò)
- Management MQTT,用來(lái)配置管理通道的MQTT參數(shù)
- 支持ThingsBoard
- 支持標(biāo)準(zhǔn)MQTT
驗(yàn)收測(cè)試方法
- 燒錄程序,可正常燒錄
- 燒錄后,重新上電,RUN指示燈,0.5s間隔閃爍
- 連接設(shè)備的WIFI熱點(diǎn)(ssid:LoRaGW-xxxxxx 密碼:loragwwifi),瀏覽器輸入(http://192.168.4.1),可看到設(shè)備的配置頁(yè)面
- 測(cè)試以太網(wǎng),將設(shè)備接入路由器,設(shè)備能以DHCP方式獲取到IP,說(shuō)明以太網(wǎng)功能正常
- 設(shè)備聯(lián)網(wǎng)后,SX1302和GNSS模塊啟動(dòng),將設(shè)備的GWID(GWID默認(rèn)為SN)錄入到NS服務(wù)器,可在NS服務(wù)器上看到網(wǎng)關(guān)上線,說(shuō)明SX1302功能正常
- 插入4G SIM,拔掉網(wǎng)線,4G正常獲取到IP地址,說(shuō)明4G功能正常
- 將GNSS放到室外有GNSS信號(hào)的地方,可以獲取到經(jīng)緯度和海拔,說(shuō)明GNSS功能正常
- 至此,各硬件功能都驗(yàn)證完成,測(cè)試通過(guò)
網(wǎng)關(guān)配置通道
標(biāo)準(zhǔn)MQTT通道
配置通道通過(guò)MQTT進(jìn)行數(shù)據(jù)交互,其中設(shè)備發(fā)往服務(wù)器的通道稱為上行通道,服務(wù)器發(fā)往設(shè)備的通道稱為下行通道
其中:
- 上行Topic:up/gw/{SN}/0
- 下行Topic:dn/gw/{SN}/0
例如網(wǎng)關(guān)的SN:64e833fffe5909d8,那么上下行通道分別為
- 上行Topic:up/gw/64e833fffe5909d8/0
- 下行Topic:dn/gw/64e833fffe5909d8/0
網(wǎng)關(guān)會(huì)周期性地通過(guò)上行通道發(fā)送周期心跳包
服務(wù)器也可以通過(guò)下行通道,向網(wǎng)關(guān)下發(fā)數(shù)據(jù)
周期包
{
"pkt": "periodUplink",
"GWInfo": {
"SN": "64e833fffe5909d8",
"SoftwareVersion": "V1.0.1",
"HardwareVersion": "V1.0.0"
},
"Staus": {
"GPSValid": true,
"Latitude": 24.000000,
"Longitude": 120.000000,
"Altitude": 0.000000,
"Cellular": {},
"Ethernet": {},
"WIFI": {
"Link": "NET_UP",
"IPMode": "DHCP",
"MAC": "64:e8:33:59:09:d8",
"IP": "192.169.4.12",
"Mask": "255.255.255.0",
"GW": "192.169.4.1",
"DNS1": "192.169.4.1",
"DNS2": "192.169.4.1"
}
},
"Configuration": {
"STA": {
"Enable": false,
"SSID": "",
"Password": ""
},
"Management": {
"MQTT": {
"Enable": true,
"URL": "mqtt://broker.emqx.io",
"ClientID": "64e833fffe5909d8",
"UplinkTopic": "up/gw/64e833fffe5909d8/0",
"DownlinkTopic": "dn/gw/64e833fffe5909d8/0"
}
},
"LoRaWAN": {
"Region": "cn470",
"Radio0": "470600000",
"Radio1": "enable",
"NsHost": "lora.ansitw.com",
"NsPort": "1700",
"GatewayID": "64e833fffe5909d8"
}
}
}
更改網(wǎng)關(guān)配置
直接修改Configuration中的內(nèi)容,下發(fā)下來(lái)即可
{
"pkt": "downlink",
"Configuration": {
"STA": {
"Enable": false,
"SSID": "",
"Password": ""
},
"Management": {
"MQTT": {
"Enable": true,
"URL": "mqtt://broker.emqx.io",
"ClientID": "64e833fffe5909d8",
"UplinkTopic": "up/gw/64e833fffe5909d8/0",
"DownlinkTopic": "dn/gw/64e833fffe5909d8/0"
}
},
"LoRaWAN": {
"Region": "cn470",
"Radio0": "470600000",
"Radio1": "enable",
"NsHost": "lora.ansitw.com",
"NsPort": "1700",
"GatewayID": "64e833fffe5909d8"
}
}
}
回復(fù):
{
"pkt": "downlinkRespone",
“result”:"success"
}
重啟
{
"pkt": "downlink",
"cmd": {
"reboot": true
}
}
回復(fù)
{
"pkt": "downlinkRespone",
“result”:"success"
}
升級(jí)
{
"pkt": "downlink",
"cmd": {
"upgrade": "http://192.169.4.53/esp32_sx1302.bin"
}
}
回復(fù)(收到升級(jí)命令)
{
"pkt": "downlinkRespone",
“result”:"success"
}
ThingsBoard MQTT通道
配置通道通過(guò)MQTT進(jìn)行數(shù)據(jù)交互,網(wǎng)關(guān)發(fā)送數(shù)據(jù)給云平臺(tái)稱為uplink,云平臺(tái)發(fā)送命令給網(wǎng)關(guān)稱為downlink
有兩條鏈路:
- 網(wǎng)關(guān)主動(dòng)發(fā)送數(shù)據(jù)
- telemetry_uplink
- 設(shè)備每隔一段時(shí)間會(huì)發(fā)送心跳包
- 設(shè)備在上電和配置信息更改時(shí),會(huì)發(fā)送配置信息
- telemetry_uplink
- 云平臺(tái)發(fā)送命令給網(wǎng)關(guān)
- request_downlink,云平臺(tái)發(fā)送命令給網(wǎng)關(guān)
- respone_uplink,網(wǎng)關(guān)回復(fù)數(shù)據(jù)給云平臺(tái)
其中:
- telemetry_uplink_topic:v1/devices/me/telemetry //支持修改,支持修改的字符串中有
審核編輯 黃宇
-
SX1302
+關(guān)注
關(guān)注
1文章
4瀏覽量
8131 -
lorawan
+關(guān)注
關(guān)注
3文章
312瀏覽量
23785 -
ESP32
+關(guān)注
關(guān)注
17文章
951瀏覽量
16992
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論