LoRa网关与服务器通信——PROTOCOL

一、PROTOCOL文档消息类型介绍

官话 Basic communication protocol between Lora gateway and server

此文档定义了LoRa网关与服务器之间的通信协议
  1. Introduction
    The protocol between the gateway and the server is purposefully very basic and
    for demonstration purpose only, or for use on private and reliable networks.
    重点词汇:private 由此可见LoRa网关在私有网络部署环境是有可用价值的。

  2. Upstream protocol (跳着讲是因为我不会)

    1. PUSH_DATA packet 网关通过IP协议传送至NS端,属于上行链路网关至NS段。该包的数据结构如下:

      0 : protocol version = 2 一个字节的协议版本号
      1-2 : random token 两个字节的随机Token
      3 : PUSH_DATA identifier 0x00 一个字节的消息ID
      4-11 : Gateway unique identifier (MAC address) 八个字节的网关ID
      12-end : JSON object, starting with {, ending with } 其余的为JSON格式的消息体

      json
      {
      	"rxpk":[ {...}, ...]
      }
      
      {"rxpk":[
      	{
      		"time":"2013-03-31T16:21:17.528002Z",
      		"tmst":3512348611,
      		"chan":2,
      		"rfch":0,
      		"freq":866.349812,
      		"stat":1,
      		"modu":"LORA",
      		"datr":"SF7BW125",
      		"codr":"4/6",
      		"rssi":-35,
      		"lsnr":5.1,
      		"size":32,
      		"data":"-DS4CGaDCdG+48eJNM3Vai-zDpsR71Pn9CPA9uCON84"
      	},{
      		"time":"2013-03-31T16:21:17.530974Z",
      		"tmst":3512348514,
      		"chan":9,
      		"rfch":1,
      		"freq":869.1,
      		"stat":1,
      		"modu":"FSK",
      		"datr":50000,
      		"rssi":-75,
      		"size":16,
      		"data":"VEVTVF9QQUNLRVRfMTIzNA=="
      	},{
      		"time":"2013-03-31T16:21:17.532038Z",
      		"tmst":3316387610,
      		"chan":0,
      		"rfch":0,
      		"freq":863.00981,
      		"stat":1,
      		"modu":"LORA",
      		"datr":"SF10BW125",
      		"codr":"4/7",
      		"rssi":-38,
      		"lsnr":5.5,
      		"size":32,
      		"data":"ysgRl452xNLep9S1NTIg2lomKDxUgn3DJ7DE+b00Ass"
      	}
      ]}
      


      该JSON数组可能会包含stat字段,上报网关经纬度状态,海拔状态,接收包状态。

      json
      {"stat":{
      	"time":"2014-01-12 08:59:28 GMT",
      	"lati":46.24000,
      	"long":3.25230,
      	"alti":145,
      	"rxnb":2,
      	"rxok":2,
      	"rxfw":2,
      	"ackr":100.0,
      	"dwnb":2,
      	"txnb":2
      }}
      
  3. Downstream protocol

    {
    	"txpk": {...}
    }
    
    1. PULL_DATA packet心跳包,网关会隔一段时间给NS服务器发送一帧,数据为空,NS可根据心跳包接收情况判断网管的在线状态(网关端没有遗言机制)可在网关端设置时间。
      将心跳包划为下行链路我一直很迷。

    2. PULL_RESP NS服务器主动下发指令。

      {"txpk":{
      	"imme":true,
      	"freq":864.123456,
      	"rfch":0,
      	"powe":14,
      	"modu":"LORA",
      	"datr":"SF11BW125",
      	"codr":"4/6",
      	"ipol":false,
      	"size":32,
      	"data":"H3P3N2i9qc4yt7rK7ldqoeCVJGBybzPY5h1Dd7P7p8v"
      }}
      

      powe字段为网关发射功率,NS可设置。

    3. 网关报错类型
      在这里插入图片描述
      网关拒绝发送的原因如上表,其中TOO_LATE,TOO_EARLY,COLLISION_PACKET都与网关内部时针有极大的关联。见名知意TOO_EARLY,为NS定义的tmst 早于网关计算的发射时间,即节点接收窗口开启时间。TOO_LATE为NS定义的tmst 晚于网关计算的发射时间,网关判断该tmst发送的数据不能被节点接收。COLLISION_PACKET网关在NS定义的tmst下已经有发送的数据帧,如果同时发送都会发送失败。TX_FREQ、TX_POWER为频点和发射功率与网关配置不符。其余错误暂未接触。

了解此文档是LoRa物联网平台的开始。(后边会唠唠华为的OC平台)

展开阅读全文

没有更多推荐了,返回首页