文章目录

  • 架构
  • LoRa 芯片驱动调试
    • GPIO 模拟 SPI
    • 硬件SPI片选控制
  • LoRa转发模块移植
  • 有线口回传
  • 4G模块调试
    • 配置编译
    • PPP 拨号
    • QMI拨号
  • 参考
    • 基站端
    • 模组
    • LoRaWAN Server
    • Simulation
    • Semtech Starter Kit

这篇文章主要记录lora原型基站开发的过程,基站支持对接市场上默认的 LoRaWAN Server,支持有线口回传,支持4G回传。

架构

  • 步骤

    • CPU 移植运行 OpenWRT 系统,有线口正常,这块我是基于现成的,此处省略
    • 调试 SX1301 芯片驱动
    • 移植 Semtech 公司开源的 packet_forwarder 到 OpenWRT 平台,对接通用的 LoRaWAN Server
    • 调试移植4G模块驱动
  • 硬件组成:CPU 使用 SOC AR95xx 系列芯片,通过 SPI 接口跟基带芯片通信,LoRa 基带射频使用 Semtech 公司的多路芯片 SX1301 + SX1255,4G 模组使用龙尚 U8300
  • 软件:平台 OpenWRT ,版本 Attitude Adjustment 12.09,内核 3.3.8
  • 报文流程
    • AR95xx 通过 HAL 模块的 SPI 读写操作控制 SX1301 接收终端发送的报文,经过 packet forwarder 模块封装打包后走有线口、WIFI 或 4G 通路,通过UDP方式发送给后台 LoRaWAN Server。

LoRa 芯片驱动调试

AR9531 可以通过 USB 或 SPI 驱动 SX1301,USB方式需要FTDI转 SPI 芯片方式网上教程较多。由于板子限制,这里采用 SPI 方式,由于板子的 SPI 控制器已经用来驱动 flash,控制 SX1301 有两种方式:

  • GPIO 模拟 SPI 来控制(软 SPI )
  • 实际的硬件 SPI 通过片选控制

为提高调试效率,先修改Makefile的 cmdline 字段波特率,以串口 ttyS0 为例下面命令可以查找包含 ttyS0 对应行,使用 VIM 修改成 115200。

grep ttyS0 ./target/linux/ar71xx/image/Makefile

GPIO 模拟 SPI

参考
https://randomcoderdude.wordpress.com/2013/08/15/spi-over-gpio-in-openwrt/

  • GPIO 管脚使用

先确认 GPIO 管脚是否可用,是否能拉高拉低

cat /sys/kernel/debug/gpio  # 查看 GPIO 调试信息
cd /sys/class/gpio
echo 2 > export   # 把 GPIO 管脚 2 导出到用户空间
cd gpio2
echo out > direction   # 配置成输出
echo 0 > value   # 输入值 0
cat value    # 查看值是否改变
echo 1 > value  # 输入值 1
cat value

如果CPU用到对应 GPIO 口存在 JTAG 复用的话,芯片初始化 GPIO 时把 JTAG 关掉

//文件:linux-3.3.8/arch/mips/ath79/gpio.c
//函数:ath79_gpio_init
if (soc_is_qca953x())ath79_gpio_function_enable(AR934X_GPIO_FUNC_JTAG_DISABLE);
  • 移植编译内核模块

    OpenWRT 内核默认就已经有 GPIO 模拟 SPI 的驱动模块(spi-gpiospi-bitbang),另外有spi-dev 设备层通用驱动,用来导出到用户空间,编译内核前把这三个模块打开。spi-dev 模块问题是不大方便调试,建议下载移植 spi-gpio-custom 模块用于动态加载软 SPI 模块,根据对应 GPIO 管脚加载。

    # 参数说明
    * bus0    These four arguments can be arrays of
    * bus1    1-8 unsigned integers as follows:
    * bus2
    * bus3    <id>,<sck>,<mosi>,<miso>,<mode1>,<maxfreq1>,<cs1>,...
    * where:
    *
    * <id> ID to used as device_id for the corresponding bus (required)
    * <sck> GPIO pin ID to be used for bus SCK (required)
    * <mosi> GPIO pin ID to be used for bus MOSI (required*)
    * <miso> GPIO pin ID to be used for bus MISO (required*)
    * <modeX> Mode configuration for slave X in the bus (required)
    * (see /include/linux/spi/spi.h)
    * <maxfreqX> Maximum clock frequency in Hz for slave X in the bus (required)
    * <csX> GPIO pin ID to be used for slave X CS (required**)insmod spi-gpio-custom bus0=1,14,15,16,0,1000000,4  # 加载模块
    ls /dev/ | grep spidev1.0   # 确认 spidev 设备是否出现,存在则加载成功
    

硬件SPI片选控制

待完善,主要修订代码 dev-m25p80.c,

+static struct ath79_spi_controller_data ath79_spi_cdata0 =
+{
+  .cs_type = ATH79_SPI_CS_TYPE_INTERNAL,
+  .cs_line = 0,
+};
+
+static struct ath79_spi_controller_data ath79_spi_cdata1 =
+{
+  .cs_type = ATH79_SPI_CS_TYPE_GPIO,
+  .cs_line = 2,
+   .is_flash = false
+};
+
+static struct spi_board_info ath79_spi_info_multi[] = {
+  {
+      .bus_num    = 0,
+      .chip_select    = 0,
+      .max_speed_hz   = 25000000,
+      .modalias   = "m25p80",
+      .controller_data = &ath79_spi_cdata0,
+  },
+  {
+      .bus_num    = 0,
+      .chip_select    = 1,
+      .max_speed_hz   = 25000000,
+      .modalias   = "spidev",
+      .controller_data = &ath79_spi_cdata1,
+  }
+};
+
+void __init ath79_register_m25p80_multidev(struct flash_platform_data *pdata)
+{
+  multi_pdata = pdata;
+  add_mtd_concat_notifier();
+  ath79_spi_data.bus_num = 0;
+  ath79_spi_data.num_chipselect = 2;
+  ath79_spi_cdata0.is_flash = false;
+  ath79_spi_info_multi[0].platform_data = pdata;
+  ath79_register_spi(&ath79_spi_data, ath79_spi_info_multi, 2);
+}

LoRa转发模块移植

  • 编译移植 LoRa 报文转发模块

    下载编译 packet_forwarderlora_gateway 模块,lora_gateway 编译时生成 .a 库文件,供 packet_forwarder 模块调用运行报文转发程序,根据自己系统修改下 Makefile,编译完生成 lora_pkt_fwd 可执行文件以及其他测试程序。

    https://github.com/Lora-net/packet_forwarder

    https://github.com/Lora-net/lora_gateway

    Note:模块 v3.0.0 版本对接 LoRaWAN Server 使用了自定义的 GWMP 协议版本 2,不兼容版本 1,对接时要注意两边版本一致

  • 编写 packet_forwarder 起机脚本,包含了加载软 SPI 模块,复位 SX1301(手册要求),更新 local_conf 网关 MAC,启动 LoRa 转发模块,参考如下

#!/bin/sh /etc/rc.commonSTART=101
STOP=102
insmod_gpio_custom=true
reset_lora_chip=true
reset_cmd="reset_lgw.sh"
upgw_cmd="update_gwid.sh"
cmd="lora_pkt_fwd"
mod="spi-gpio-custom"
configFile="local_conf.json"
gpio_spi_dev="/dev/spidev1.0" # gpio simulated driver
hard_spi_dev="/dev/spidev0.1" # alternative: controlled by hardware spi controller
pid_file="/var/run/$cmd.pid"
stdout_log="/tmp/$cmd.log"
#stderr_log="/tmp/$cmd.err"
sck_pin=14
mosi_pin=15
miso_pin=16
mode=0
max_freq=10000000
cs_pin=4get_pid() {ps | grep -v grep | grep "$cmd" | awk '{print $1}'
}is_running() {ps | grep -v grep | grep "$cmd" > /dev/null [ $? = 0 ]
}start() {if is_running; thenecho "Already started"elseif [ \( ! -e "$gpio_spi_dev" \) -a \( ! -e "$hard_spi_dev" \) ]; thenecho "insmod custom gpio based spi"insmod $mod bus0=1,$sck_pin,$mosi_pin,$miso_pin,$mode,$max_freq,$cs_pin  # 可以在代码里加载好fiif [ "$reset_lora_chip" = true ]; thenecho "Reset SX1301"chmod +x /etc/lora/"$reset_cmd"/etc/lora/"$reset_cmd" start  fiecho "update gateway id"chmod +x /etc/lora/"$upgw_cmd"/etc/lora/"$upgw_cmd" /etc/lora/"$configFile"echo "Starting $cmd"/usr/sbin/"$cmd" # >> "$stdout_log" 2>> "$stdout_log" &echo "$!" > "$pid_file"if ! is_running; thenecho "Unable to start, see $stdout_log"exit 1elseecho "Successfully started, see $stdout_log"fifi
}stop() {if is_running; thenecho -n "Stopping $cmd.."kill `get_pid`for i in {1..60}doif ! is_running; thenbreakfiecho -n "."sleep 1doneechosleep 1if [ "$reset_lora_chip" = true ]; then/etc/lora/$reset_cmd stop fiif [ -e "$gpio_spi_dev" ]; thenecho "rmmod custom gpio based spi"rmmod $mod fiif is_running; thenecho "Not stopped; may still be shutting down or shutdown may have failed"exit 1elseecho "Stopped"if [ -f "$pid_file" ]; thenrm "$pid_file"fifielseecho "Not running"fi
}restart() {stop "$@"start "$@"
}status() {if is_running; thenecho "Running"elseecho "Stopped"exit 1fi
}EXTRA_COMMANDS="status"
EXTRA_HELP="  status Print the status of lora packet-forward"
/etc/init.d/packet_forwarder start  # 启动
  • 运行测试程序

Note: 运行测试程序前需先加载 spi-gpio-custom 模块,可以启动一下 /etc/init.d/packet_forwarder start 关掉,或者手动加载模块

# 发送功率测试,参数根据要求配置
util_tx_continuous -f 433.3 -r 1255 --mod LORA --sf 7 --bw 125
# 接收灵敏度测试
util_rx_test -c /etc/lora/freq_conf_433.json
  • 对接 LoRaWAN Server

    只是原型的话推荐接入 Loriot.io 社区进行调试期间试用, https://cn1dashboard.loriot.io/login,也可以自己到 github 上查找开源相关自己搭建一个。

有线口回传

参考 https://wiki.openwrt.org/doc/uci/network

注意与 4G 回传二选一来配置,ping 不通时,注意查看路由表默认路由是否是4G端口 route -e,DNS 要配,LoRa 报文转发模块默认会解析 server 域名。

uci set network.lan.proto=static  # 静态IP
uci set network.lan.ipaddr=xxx.xxx.xxx.xxx
uci set network.lan.gateway=xxx.xxx.xxx.xxx
uci set network.lan.dns=xxx.xxx.xxx.xxx
uci set network.lan.netmask=255.255.255.0
uci commit

或者通过改配置文件 /etc/config/network

config interface 'lan'option ifname 'eth0 eth1 ath0'option type 'bridge'  # 桥模式option force_link '1'option proto 'static'option ipaddr 'xxx.xxx.xxx.xxx'option netmask '255.255.255.0' option gateway 'xxx.xxx.xxx.xxx'option dns 'xxx.xxx.xxx.xxx' 

重启网络生效

/etc/init.d/network restart

4G模块调试

参考
https://wiki.openwrt.org/doc/recipes/3gdongle
http://blog.csdn.net/qianguozheng/article/details/50543704
4G网卡的拨号方式有三种: PPP (PPP over EV-DO, CDMA, UMTS or GPRS),QMI (USB modems using QMI protocol),NCM (USB modems using NCM rotocol)

配置编译

使用驱动程序及工具,通过 make menuconfig 里要打开如下模块。

  • 工具
    comgt
  • USB HCI
    kmod-usb2 (aka EHCI)
    kmod-usb-ohci
    kmod-usb-uhci (for example VIA chips)
  • 虚拟串口通信用
    kmod-usb-serial, and kmod-usb-serial-option, and kmod-usb-serial-wwan, or kmod-usb-acm
  • 依赖库
    kmod-usb-core, already in 10.03 RC3 Image
    chat, dependency of comgt
    ppp, dependency of chat, already in 10.03 RC3 Image
    kmod-usb-serial, dependency of kmod-usb-serial-option

option 驱动加载后,出现 5 个 ttyUSB,PPP 拨号使用 ttyUSB1,AT 命令查询 ttyUSB2,数据通路走 PPP 或 QMI 拨号,两者都要修订代码 option_ids 增加 id,芯片初始化要注册USB控制器

//文件:linux-3.3.8/arch/mips/ath79/mach-ap120-h.c
//函数:static void __init xxx_setup(void)
ath79_register_usb();
//文件:linux-3.3.8/drivers/usb/serial/option.c
{ USB_DEVICE(LONGSUNG_VENDOR_ID, LONGSUNG_U8300_PRODUCT_ID)},  /* add for longsung U8300 LTE modem */

PPP 拨号

速率支持不是最高,当前状态下够用,3.3.8 内核配置完就可支持,通过 UCI 命令配置

uci set wan.ifname=ppp0
uci set wan.device=/dev/ttyUSB1
uci set wan.apn=3gnet
uci set wan.service=umts
uci set wan.dialnumber=*99#
uci set wan.proto=3g
uci set wan.defaultroute=1

或者修改 /etc/config/network 增加 ppp0 的 wan 口

config interface 'wan'option ifname 'ppp0'option device '/dev/ttyUSB1'option apn    '3gnet'  # 根据运营商变化注:联通apn:3gnet 电信apn:ctnet 移动apn:cmnet/cmwapoption service 'umts'  option dialnumber '*99#'   # 联通dialnumber:3G为*99# 电信:3G为#777 移动为:*99***1# LTE为:*99#option proto '3g'option defaultroute '1'

/etc/init.d/network restart 重启网络
ifconfig 查看是否出现 3G 端口

QMI拨号

跟 PPP 拨号二选一, 修改代码跳过第四接口不让其被 option 驱动检测到,加载 GobiNet 模块驱动该口,支持 4G,更高速率,使用时 PPP 拨号要关掉

//文件:drivers/usb/serial/option.c
//函数: static int option_probe(struct usb_serial *serial, const struct usb_device_id *id)
if (cpu_to_le16(serial->dev->descriptor.idVendor) == LONGSUNG_VENDOR_ID &&cpu_to_le16(serial->dev->descriptor.idProduct) == LONGSUNG_U8300_PRODUCT_ID &&serial->interface->cur_altsetting->desc.bInterfaceNumber == 4) {printk(KERN_INFO"Discover the 4th interface for U8300 NDIS\n");return -ENODEV;
}

Gobi 芯片是高通开发的移动宽带 modem,3.3.8 内核需自己移植 GobiNet 驱动,3.4 内核以上系统自身有带 qmi_wwan 驱动,用户空间工具 ofono, uqmi and libqmi,感兴趣的可以看下 https://sigquit.wordpress.com/2014/06/11/qmiwwan-or-gobinet/

#加载模块
insmod /lib/modules/3.3.8/GobiNet.ko
#读返回结果
cat /dev/ttyUSB2 &
#拨号
echo -e 'at$qcrmcall=1,1\r\n' > /dev/ttyUSB2
#查看出现4g用接口
ifconfig #查询网络服务类型
echo -en "at+psrat\r" > /dev/ttyUSB2
#查询手机功能
echo -e "at+cfun?\r" > /dev/ttyUSB2
#查询pin是否正常识别或是否有pin码
echo -e "at+cpin?\r" > /dev/ttyUSB2
#查询运营商
echo -e "at+cops?\r" > /dev/ttyUSB2
#返回IMSI号
echo -en "at+cimi\r" > /dev/ttyUSB2
#查询IMEI号
echo -e "at+cgsn\r" > /dev/ttyUSB2
#查询集成电路卡识别码
echo -e "at+iccid\r" > /dev/ttyUSB2
#查询信号质量,返回rssi,rxlevel
echo -e "at+csq\r" > /dev/ttyUSB2
#断开连接
echo -e 'at$qcrmcall=0,1\r\n' > /dev/ttyUSB2

参考

除了前面提到了,下面罗列一些关于 LoRaWAN 系统搭建可能会用到的代码链接。

基站端

  • Low-cost LoRa gateway with SX1272 and Raspberry

  • https://github.com/CongducPham/LowCostLoRaGw

  • This is a fork with the needed modifications to be able to use lora_gateway with a Multitech MTAC-LORA (MultiConnect mCard) board instead of a IoT Starter Kit platform.
    https://github.com/mirakonta/lora_gateway

模组

  • Semtech 开源的节点实现代码,MCU基于STM32L151CB,射频SX1272
    https://github.com/Lora-net/LoRaMac-node

  • IBM 开源的节点实现代码,BSD License,支持ClassA、B
    https://www.research.ibm.com/labs/zurich/ics/lrsc/lmic.html

LoRaWAN Server

lorawan server开源实现,MIT授权,可以参考实现

  • go语言 the things network社区,15年10月就开始做了,比较完整
    https://github.com/TheThingsNetwork/ttn
    V1版本源码:https://github.com/TheThingsNetwork/ttn/tree/v1-staging
    TTN官网:https://www.thethingsnetwork.org
    TTN架构:https://www.thethingsnetwork.org/wiki/Backend/Overview
    ttnctl CLI:https://www.thethingsnetwork.org/docs/current/cli/
    后台:https://account.thethingsnetwork.org

  • go语言,16年2月开始做的,跟TTN很像
    https://github.com/brocaar/loraserver/

  • erlang语言,适合小型网络使用,只有1个人在开发
    https://github.com/gotthardp/lorawan-server

Simulation

https://sites.google.com/a/wesdec.be/mweyn/lpwan

Semtech Starter Kit

http://semtechlorakit.blogspot.jp/

OpenWRT系统(二) - LoRa基站开发相关推荐

  1. android系统二次开发,Andorid系统二次开发界面

    Andorid系统二次开发界面 给大家介绍完外观,下面我们一起再来看下魅族MX的系统界面.本次魅族MX仍然采用的是Andorid操作系统,并且加入了二次开发界面.UI界面整体上保持了和M9的特色,不过 ...

  2. wincc报表日报表实例_工作系统二次开发二Python加工原膜切割日报表数据实例

    #工作系统二次开发二Python加工原膜切割日报表数据实例 #当查询一个或多个工作令后在表格展示数据前按要求对数据进行二次处理,处理要求看如下 #1.加工单号和母卷物料编号相同则把除第一行外的领料有关 ...

  3. 二次开发_企业ERP系统二次开发问题的探讨分析

    新朋友点上方蓝字"ERP之家"快速关注 导读:根据笔者多年在企业中实施及推进ERP,概的实战经验,阐述了ERP系统二次开发的必然性和二次发开的成因及存在的风险,提出如何合理地规避二 ...

  4. 方维订餐系统二次开发,将商户的所有图片调到商铺详情里面

    方维订餐系统二次开发,将商户的所有图片调到商铺详情里面 方维订餐系统将商户的所有图片调到商铺详情里面,在上一篇已经解决了,这里有另外一种方法: 在store_view.html 加入下面一句 < ...

  5. 方维团购系统二次开发,项目经验

    方维团购系统二次开发,项目经验 基于方维团购4.2系统上进行二次开发 在保留方维系统绝大部分现有功能下,二次开发内容包含以下几大部分: 1. 会员账号系统 2. 资金返现返券系统(代金券.账户余额.返 ...

  6. 聚播微信多开客服系统二次开发SDK服务端接口

    聚播微信多开客服系统二次开发SDK服务端接口 case HeartBeatReq: {// 客户端发送的心跳包heartBeatReqHandler.handleMsg(ctx, msgVo);bre ...

  7. 思途cms php文件说明,思途旅游CMS系统二次开发说明文档(v5.0).pdf

    思途旅游CMS系统二次开发说明文档(V5.0) 思途旅游CMS系统二次开发说明文档(V5.0) 思途CMS系统5.0版本相比之前 v3.0/v4.0的版本相比,主要变化在于前端PC网页和手机采用koh ...

  8. 双千兆网口路由器方案开发板香橙派R1 Plus LTS连接USB无线网卡测试说明(OpenWRT 系统)

    说明:使用的OpenWRT 系统是OrangePi官方适配的,如果其他第三方固件,需要自己实测下.支持的无线网卡列表如下.其中 RTL8723BU 和 MT7601U 都是 只支持 Station M ...

  9. SpringBoot实现Java高并发秒杀系统之Service层开发(二)

    继上一篇文章:SpringBoot实现Java高并发秒杀系统之DAO层开发 我们创建了SpringBoot项目并熟悉了秒杀系统的表设计,下面我们将讲解一下秒杀系统的核心部分:Service业务层的开发 ...

最新文章

  1. 拼接(  read----contigs)和组装(contigs---Scaffolds)
  2. 使用 VS2013 Update 4 编译 Notepad++ 6.8.1
  3. Python函数中的变量和函数返回值
  4. 0010服务器无对应信息,查看云服务器信息
  5. java hibernate 插入数据_[Java教程]hibernate 返回新插入数据的Id
  6. python代码大全中文注释_零基础小白必看篇:Python代码注释规范代码实例解析操作(收藏)...
  7. Linux 服务器高级编程ET LT代码
  8. java中set怎么建int型_使用Array.setInt来填充Java中的数组
  9. 2017.9.25 社交网络 思考记录
  10. 域名抢注php程序_“丁真”被抢注,蹭热点这门生意,能成就好品牌?
  11. java enum转ini_JAVA中用XML实现INI文件格式的解决方
  12. JAVA王思聪吃热狗程序_易语言制作王校长吃热狗游戏的源码
  13. LwM2M(轻量级M2M)协议
  14. 磁珠 符号_贴片磁珠规格
  15. Linux系统中sit0是做什么的
  16. Excel如何批量删除工作表全部图片?
  17. Smarty入门教程一----Smarty的安装
  18. 变软的苹果,正在复制腾讯
  19. 草莓采摘机器人——ROS导航(一) ROS Kinetic + Handsfree系统安装以及环境配置
  20. javascript CryptoJS 进行HmacSHA1加密

热门文章

  1. SmartX 超融合支撑 Rhapsody 医疗集成引擎运行效率实测详解 | 场景测评
  2. 《数据库系统》学习笔记
  3. 图扑数字孪生煤矿开采系统,打造采煤“硬实力”
  4. 大数据面试之kafka重点(二)
  5. 文件夹加入到sys.path
  6. Excel中文本数字单元格批量转换(不影响公式单元格)
  7. ubuntu php 开启pdo扩展
  8. zadig.exe不是有效的Win32程序
  9. 了解以下几点,让你的精灵4RTK应用更专业
  10. 三菱fx3u使用st语言adprw指令通过485-adp-mb模块与台达变频器进行通信