• 欢迎大家分享资料!前往留言板评论即可!

Air800(GPRS+GPS模块)连接OneNet平台

合宙 模组资料网 1年前 (2021-05-15) 274次浏览 已收录 0个评论 扫描二维码
                    <h2 id="air800介绍" style="outline: 0px; padding: 0px; margin: 8px 0px 16px; font-size: 24px; color: rgb(79, 79, 79); font-weight: 700; line-height: 32px; word-break: break-all; font-family: -apple-system, " sf="" ui="" text",="" arial,="" "pingfang="" sc",="" "hiragino="" sans="" gb",="" "microsoft="" yahei",="" "wenquanyi="" micro="" hei",="" sans-serif;="" font-variant-ligatures:="" common-ligatures;"="">OneNet平台介绍<br></h2><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, " sf="" ui="" text",="" arial,="" "pingfang="" sc",="" "hiragino="" sans="" gb",="" "microsoft="" yahei",="" "wenquanyi="" micro="" hei",="" sans-serif;="" font-variant-ligatures:="" common-ligatures;"="">OneNET作为中国移动通信集团推出的一个专业物联网开放云平台,提供了丰富的智能硬件开发工具和可靠的服务,助力各类终端设备迅速接入网络,实现数据传输、数据存储、数据管理等完整的交互流程。</p><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, " sf="" ui="" text",="" arial,="" "pingfang="" sc",="" "hiragino="" sans="" gb",="" "microsoft="" yahei",="" "wenquanyi="" micro="" hei",="" sans-serif;="" font-variant-ligatures:="" common-ligatures;"="">支持公开协议包括EDP、MODBUS、MQTT以及HTTP等多种协议。详细资料参见:<a href="https://open.iot.10086.cn/doc" rel="nofollow noopener" target="_blank" style="outline: 0px; color: rgb(103, 149, 181); cursor: pointer; word-break: break-all;">https://open.iot.10086.cn/doc</a></p><h2 id="所需api" style="outline: 0px; padding: 0px; margin: 8px 0px 16px; font-size: 24px; color: rgb(79, 79, 79); font-weight: 700; line-height: 32px; word-break: break-all; font-family: -apple-system, " sf="" ui="" text",="" arial,="" "pingfang="" sc",="" "hiragino="" sans="" gb",="" "microsoft="" yahei",="" "wenquanyi="" micro="" hei",="" sans-serif;="" font-variant-ligatures:="" common-ligatures;"=""><a name="t2" style="outline: 0px; color: rgb(78, 161, 219); cursor: pointer; word-break: break-all;"></a>所需API</h2><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, " sf="" ui="" text",="" arial,="" "pingfang="" sc",="" "hiragino="" sans="" gb",="" "microsoft="" yahei",="" "wenquanyi="" micro="" hei",="" sans-serif;="" font-variant-ligatures:="" common-ligatures;"="">Luat封装了很多的实用API,所以在实现一些功能的时候就无需自己造轮子,直接调用其API即可</p><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, " sf="" ui="" text",="" arial,="" "pingfang="" sc",="" "hiragino="" sans="" gb",="" "microsoft="" yahei",="" "wenquanyi="" micro="" hei",="" sans-serif;="" font-variant-ligatures:="" common-ligatures;"=""><a href="http://wiki.openluat.com/doc/luatApi/#mqtt" rel="nofollow noopener" target="_blank" style="outline: 0px; color: rgb(103, 149, 181); cursor: pointer; word-break: break-all;">mqtt</a></p><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, " sf="" ui="" text",="" arial,="" "pingfang="" sc",="" "hiragino="" sans="" gb",="" "microsoft="" yahei",="" "wenquanyi="" micro="" hei",="" sans-serif;="" font-variant-ligatures:="" common-ligatures;"=""><a href="http://wiki.openluat.com/doc/luatApi/#pack" rel="nofollow noopener" target="_blank" style="outline: 0px; color: rgb(103, 149, 181); cursor: pointer; word-break: break-all;">pack</a></p><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, " sf="" ui="" text",="" arial,="" "pingfang="" sc",="" "hiragino="" sans="" gb",="" "microsoft="" yahei",="" "wenquanyi="" micro="" hei",="" sans-serif;="" font-variant-ligatures:="" common-ligatures;"=""><a href="http://wiki.openluat.com/doc/luatApi/#gps" rel="nofollow noopener" target="_blank" style="outline: 0px; color: rgb(103, 149, 181); cursor: pointer; word-break: break-all;">gps</a></p><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, " sf="" ui="" text",="" arial,="" "pingfang="" sc",="" "hiragino="" sans="" gb",="" "microsoft="" yahei",="" "wenquanyi="" micro="" hei",="" sans-serif;="" font-variant-ligatures:="" common-ligatures;"="">lbs</p><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, " sf="" ui="" text",="" arial,="" "pingfang="" sc",="" "hiragino="" sans="" gb",="" "microsoft="" yahei",="" "wenquanyi="" micro="" hei",="" sans-serif;="" font-variant-ligatures:="" common-ligatures;"=""><a href="http://wiki.openluat.com/doc/luatApi/#json" target="_blank" rel="noopener">json</a></p><h2 id="实现思路" style="outline: 0px; padding: 0px; margin: 8px 0px 16px; font-size: 24px; color: rgb(79, 79, 79); font-weight: 700; line-height: 32px; word-break: break-all; font-family: -apple-system, " sf="" ui="" text",="" arial,="" "pingfang="" sc",="" "hiragino="" sans="" gb",="" "microsoft="" yahei",="" "wenquanyi="" micro="" hei",="" sans-serif;="" font-variant-ligatures:="" common-ligatures;"=""><a name="t3" style="outline: 0px; color: rgb(78, 161, 219); cursor: pointer; word-break: break-all;"></a>实现思路</h2><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, " sf="" ui="" text",="" arial,="" "pingfang="" sc",="" "hiragino="" sans="" gb",="" "microsoft="" yahei",="" "wenquanyi="" micro="" hei",="" sans-serif;="" font-variant-ligatures:="" common-ligatures;"="">本例通过MQTT将Air800获取到的GPS坐标发送到OneNET平台并显示。</p><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, " sf="" ui="" text",="" arial,="" "pingfang="" sc",="" "hiragino="" sans="" gb",="" "microsoft="" yahei",="" "wenquanyi="" micro="" hei",="" sans-serif;="" font-variant-ligatures:="" common-ligatures;"="">MQTT协议是一个面向物联网应用的即时通信协议,使用TCP/IP提供网络连接,能够对负载内容实现消息屏蔽传输,开销小,可以有效降低网络流量。OneNET平台采用的是标准MQTT协议,所以使用合宙提供的MQTT API就能很方便的连上。只需要在OneNET上生成一个应用方可得到MQTT鉴权</p><pre class="prettyprint" name="code" style="outline: 0px; padding: 8px 16px 6px 56px; margin-bottom: 24px; font-family: Consolas, Inconsolata, Courier, monospace; font-size: 14px; position: relative; overflow-y: hidden; line-height: 22px; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); border-width: initial; border-style: none; border-color: initial; font-variant-ligatures: common-ligatures;"><code class="hljs  has-numbering" style="outline: 0px; font-family: Consolas, Inconsolata, Courier, monospace; font-size: 14px; display: block; padding: 0.5em; color: rgb(0, 0, 0); line-height: 22px; background-color: rgb(246, 248, 250); border-radius: 4px; overflow-x: auto; white-space: pre; word-wrap: normal; text-size-adjust: none; word-break: break-all;">Q1:MQTT连接鉴权时,Payload中ClientIdentifier;UserName;UserPassword分别填写什么?

A: ClientIdentifier: 创建设备时得到的设备ID,为数字字串;

   UserName: 注册产品时,平台分配的产品ID,为数字字串; 

   UserPassword: 为设备的鉴权信息(即唯一设备编号,SN),或者为apiKey,为字符串。</code><ul class="pre-numbering" style="outline: 0px; padding-top: 8px; padding-bottom: 8px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-size: inherit; word-break: break-all; position: absolute; width: 48px; background-color: rgb(238, 240, 244); top: 0px; left: 0px; text-align: right;"><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">1</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">2</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">3</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">4</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">5</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">6</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">7</li></ul></pre><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, " sf="" ui="" text",="" arial,="" "pingfang="" sc",="" "hiragino="" sans="" gb",="" "microsoft="" yahei",="" "wenquanyi="" micro="" hei",="" sans-serif;="" font-variant-ligatures:="" common-ligatures;"="">OneNET平台优势之一可以利用数据点快速生成应用</p><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, " sf="" ui="" text",="" arial,="" "pingfang="" sc",="" "hiragino="" sans="" gb",="" "microsoft="" yahei",="" "wenquanyi="" micro="" hei",="" sans-serif;="" font-variant-ligatures:="" common-ligatures;"=""><img src="http://oldask.openluat.com/image/show/attachments-2018-09-MvPFGaTu5b9c730355901.png" class="img-responsive" style="color: rgb(0, 0, 0); font-size: 14px; text-align: start; width: 865.5px;"></p><div><br></div><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, " sf="" ui="" text",="" arial,="" "pingfang="" sc",="" "hiragino="" sans="" gb",="" "microsoft="" yahei",="" "wenquanyi="" micro="" hei",="" sans-serif;="" font-variant-ligatures:="" common-ligatures;"=""><img src="http://oldask.openluat.com/image/show/attachments-2018-09-5bFg4QYI5b9c7307e3436.png" class="img-responsive" style="color: rgb(0, 0, 0); font-size: 14px; text-align: start; width: 709.5px;"></p><div><br>要想让数据在OneNET平台上以数据点形式展现出来就得按照OneNET协议上传数据,使用OneNET平台的mqtt协议调试工具可以看到payload以json格式发送,并在json前面加0x01,0x00,0x20(这个字节为json长度),payload格式发送。</div><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, " sf="" ui="" text",="" arial,="" "pingfang="" sc",="" "hiragino="" sans="" gb",="" "microsoft="" yahei",="" "wenquanyi="" micro="" hei",="" sans-serif;="" font-variant-ligatures:="" common-ligatures;"="">json格式如下</p><pre class="prettyprint" name="code" style="outline: 0px; padding: 8px 16px 6px 56px; margin-bottom: 24px; font-family: Consolas, Inconsolata, Courier, monospace; font-size: 14px; position: relative; overflow-y: hidden; line-height: 22px; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); border-width: initial; border-style: none; border-color: initial; font-variant-ligatures: common-ligatures;"><code class="language-json hljs  has-numbering" style="outline: 0px; font-family: Consolas, Inconsolata, Courier, monospace; font-size: 14px; display: block; padding: 0.5em; color: rgb(0, 0, 0); line-height: 22px; background-color: rgb(246, 248, 250); border-radius: 4px; overflow-x: auto; white-space: pre; word-wrap: normal; text-size-adjust: none; word-break: break-all;">{
"<span class="hljs-attribute" style="outline: 0px; font-size: inherit; word-break: break-all;">datastreams</span>": <span class="hljs-value" style="outline: 0px; font-size: inherit; word-break: break-all;">[
    {
        "<span class="hljs-attribute" style="outline: 0px; font-size: inherit; word-break: break-all;">id</span>": <span class="hljs-value" style="outline: 0px; font-size: inherit; word-break: break-all;"><span class="hljs-string" style="outline: 0px; color: rgb(0, 153, 0); font-size: inherit; word-break: break-all;">"temperature"</span></span>, //数据流名称或数据流模板名称
        "<span class="hljs-attribute" style="outline: 0px; font-size: inherit; word-break: break-all;">datapoints</span>": <span class="hljs-value" style="outline: 0px; font-size: inherit; word-break: break-all;">[
           {
              "<span class="hljs-attribute" style="outline: 0px; font-size: inherit; word-break: break-all;">at</span>": <span class="hljs-value" style="outline: 0px; font-size: inherit; word-break: break-all;"><span class="hljs-string" style="outline: 0px; color: rgb(0, 153, 0); font-size: inherit; word-break: break-all;">"2013-04-22T00:35:43"</span></span>, //上传数据点时间,可选。如果为空,则设备云会取当前时间。

//如果存在其格式必须为”YYYY-MM-DDThh:mm:ss”的形式(例如:2015-03-22T22:31:12)
“value
“: 42 //上传数据点值
},
{
at“: “2013-04-22T00:55:43”,
value“: 84 //上传数据点值
}
]
},
{
id“: “key”, //数据流名称或数据流模板名称
datapoints“: [
{
at“: “2013-04-22T00:35:43”,//上传数据点时间,可选。
value“: {…}//上传数据点值
},
{
at“: “2013-04-22T00:35:43”,
value“: {…}//上传数据点值
}
]
},
{…}
]
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32

本例中的json格式为

<code class="language-json hljs  has-numbering" style="outline: 0px; font-family: Consolas, Inconsolata, Courier, monospace; font-size: 14px; display: block; padding: 0.5em; color: rgb(0, 0, 0); line-height: 22px; background-color: rgb(246, 248, 250); border-radius: 4px; overflow-x: auto; white-space: pre; word-wrap: normal; text-size-adjust: none; word-break: break-all;">{
    "<span class="hljs-attribute" style="outline: 0px; font-size: inherit; word-break: break-all;">datastreams</span>": <span class="hljs-value" style="outline: 0px; font-size: inherit; word-break: break-all;">[
        {
            "<span class="hljs-attribute" style="outline: 0px; font-size: inherit; word-break: break-all;">id</span>": <span class="hljs-value" style="outline: 0px; font-size: inherit; word-break: break-all;"><span class="hljs-string" style="outline: 0px; color: rgb(0, 153, 0); font-size: inherit; word-break: break-all;">"gps"</span></span>,
            "<span class="hljs-attribute" style="outline: 0px; font-size: inherit; word-break: break-all;">datapoints</span>": <span class="hljs-value" style="outline: 0px; font-size: inherit; word-break: break-all;">[
                {
                    "<span class="hljs-attribute" style="outline: 0px; font-size: inherit; word-break: break-all;">at</span>": <span class="hljs-value" style="outline: 0px; font-size: inherit; word-break: break-all;"><span class="hljs-string" style="outline: 0px; color: rgb(0, 153, 0); font-size: inherit; word-break: break-all;">""</span></span>,
                    "<span class="hljs-attribute" style="outline: 0px; font-size: inherit; word-break: break-all;">value</span>": <span class="hljs-value" style="outline: 0px; font-size: inherit; word-break: break-all;">{
                        "<span class="hljs-attribute" style="outline: 0px; font-size: inherit; word-break: break-all;">lon</span>": <span class="hljs-value" style="outline: 0px; font-size: inherit; word-break: break-all;"><span class="hljs-number" style="outline: 0px; color: rgb(0, 102, 102); font-size: inherit; word-break: break-all;">106.584</span></span>,
                        "<span class="hljs-attribute" style="outline: 0px; font-size: inherit; word-break: break-all;">lat</span>": <span class="hljs-value" style="outline: 0px; font-size: inherit; word-break: break-all;"><span class="hljs-number" style="outline: 0px; color: rgb(0, 102, 102); font-size: inherit; word-break: break-all;">29.5707</span></span>,
                        "<span class="hljs-attribute" style="outline: 0px; font-size: inherit; word-break: break-all;">ele</span>": <span class="hljs-value" style="outline: 0px; font-size: inherit; word-break: break-all;"><span class="hljs-number" style="outline: 0px; color: rgb(0, 102, 102); font-size: inherit; word-break: break-all;">100</span>
                    </span>}
                </span>}
            ]
        </span>}
    ]
</span>}</code><ul class="pre-numbering" style="outline: 0px; padding-top: 8px; padding-bottom: 8px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-size: inherit; word-break: break-all; position: absolute; width: 48px; background-color: rgb(238, 240, 244); top: 0px; left: 0px; text-align: right;"><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">1</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">2</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">3</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">4</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">5</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">6</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">7</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">8</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">9</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">10</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">11</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">12</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">13</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">14</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">15</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">16</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">17</li></ul>

可以看到对应不同的数据点,只需要修改“id”和“datapoints”。

部分代码

所以将GPS数据发送到OneNET平台上,最关键点将获取到的GPS数据打包为OneNET数据点格式

<code class="language-lua hljs  has-numbering" style="outline: 0px; font-family: Consolas, Inconsolata, Courier, monospace; font-size: 14px; display: block; padding: 0.5em; color: rgb(0, 0, 0); line-height: 22px; background-color: rgb(246, 248, 250); border-radius: 4px; overflow-x: auto; white-space: pre; word-wrap: normal; text-size-adjust: none; word-break: break-all;"><span class="hljs-keyword" style="outline: 0px; color: rgb(0, 0, 136); font-size: inherit; word-break: break-all;">local</span> <span class="hljs-function" style="outline: 0px; font-size: inherit; word-break: break-all;"><span class="hljs-keyword" style="outline: 0px; color: rgb(0, 0, 136); font-size: inherit; word-break: break-all;">function</span> <span class="hljs-title" style="outline: 0px; color: rgb(0, 153, 0); font-size: inherit; word-break: break-all;">msgPack</span><span class="hljs-params" style="outline: 0px; color: rgb(79, 79, 79); font-size: inherit; word-break: break-all;">()</span></span>
  <span class="hljs-comment" style="outline: 0px; color: rgb(136, 0, 0); font-size: inherit; word-break: break-all;">--打包json</span>
  <span class="hljs-keyword" style="outline: 0px; color: rgb(0, 0, 136); font-size: inherit; word-break: break-all;">local</span> torigin = 
  {
    datastreams = 
    {{
      id = <span class="hljs-string" style="outline: 0px; color: rgb(0, 153, 0); font-size: inherit; word-break: break-all;">"gps"</span>,
      datapoints = 
      {{
        at = <span class="hljs-string" style="outline: 0px; color: rgb(0, 153, 0); font-size: inherit; word-break: break-all;">""</span>,
        value = 
        {
          lon = bgps.returnBlng(),      <span class="hljs-comment" style="outline: 0px; color: rgb(136, 0, 0); font-size: inherit; word-break: break-all;">--得到获取到的经度</span>
          lat = bgps.returnBlat(),      <span class="hljs-comment" style="outline: 0px; color: rgb(136, 0, 0); font-size: inherit; word-break: break-all;">--得到获取到的纬度</span>
          ele = <span class="hljs-string" style="outline: 0px; color: rgb(0, 153, 0); font-size: inherit; word-break: break-all;">"100"</span>
        }
      }}
    }}
  }
  <span class="hljs-keyword" style="outline: 0px; color: rgb(0, 0, 136); font-size: inherit; word-break: break-all;">local</span> msg = json.encode(torigin)      <span class="hljs-comment" style="outline: 0px; color: rgb(136, 0, 0); font-size: inherit; word-break: break-all;">--对json进行编码</span>
  <span class="hljs-keyword" style="outline: 0px; color: rgb(0, 0, 136); font-size: inherit; word-break: break-all;">local</span> len = msg.len(msg)
  buf = pack.pack(<span class="hljs-string" style="outline: 0px; color: rgb(0, 153, 0); font-size: inherit; word-break: break-all;">"bbbA"</span>, <span class="hljs-number" style="outline: 0px; color: rgb(0, 102, 102); font-size: inherit; word-break: break-all;">0x01</span>,<span class="hljs-number" style="outline: 0px; color: rgb(0, 102, 102); font-size: inherit; word-break: break-all;">0x00</span>,len,msg)    <span class="hljs-comment" style="outline: 0px; color: rgb(136, 0, 0); font-size: inherit; word-break: break-all;">--打包数据流字节头</span>
<span class="hljs-keyword" style="outline: 0px; color: rgb(0, 0, 136); font-size: inherit; word-break: break-all;">end</span></code><ul class="pre-numbering" style="outline: 0px; padding-top: 8px; padding-bottom: 8px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-size: inherit; word-break: break-all; position: absolute; width: 48px; background-color: rgb(238, 240, 244); top: 0px; left: 0px; text-align: right;"><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">1</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">2</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">3</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">4</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">5</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">6</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">7</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">8</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">9</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">10</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">11</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">12</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">13</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">14</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">15</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">16</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">17</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">18</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">19</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">20</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">21</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">22</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">23</li></ul>

GPS读取数据处理

<code class="language-lua hljs  has-numbering" style="outline: 0px; display: block; padding: 0.5em; line-height: 22px; background-color: rgb(246, 248, 250); border-radius: 4px; overflow-x: auto; word-wrap: normal; text-size-adjust: none; word-break: break-all;"><span class="hljs-comment" style="outline: 0px; word-break: break-all;"><font color="#880000" face="Consolas, Inconsolata, Courier, monospace"><span style="font-size: 14px; font-variant-ligatures: common-ligatures; white-space: pre;">--- 模块功能:GPS功能测试.
-- @author openLuat
-- @module gps.testGps
-- @license MIT
-- @copyright openLuat
-- @release 2018.03.23

module(...,package.seeall)

require"gps"
require"agps"
require"lbsLoc"
require"common"

local Rlat = ""
local Rlng = ""
--[[
功能  :发送查询位置请求
参数  :无
返回值:无
]]
local function reqLbsLoc()
    reqAddr = not reqAddr
    lbsLoc.request(getLocCb,reqAddr)
end

--[[
功能  :获取基站对应的经纬度后的回调函数
参数  :
        result:number类型,0表示成功,1表示网络环境尚未就绪,2表示连接服务器失败,3表示发送数据失败,4表示接收服务器应答超时,5表示服务器返回查询失败;为0时,后面的3个参数才有意义
        lat:string类型,纬度,整数部分3位,小数部分7位,例如031.2425864
        lng:string类型,经度,整数部分3位,小数部分7位,例如121.4736522
        addr:string类型,UCS2大端编码的位置字符串。调用lbsLoc.request时传入的第二个参数为true时,才返回本参数
返回值:无
]]
function getLocCb(result,lat,lng,addr)
    --log.info("testLbsLoc.getLocCb",result,lat,lng,result==0 and common.ucs2beToGb2312(addr) or "")
    --获取经纬度成功
    if result==0 then
        Rlat = lat
        Rlng = lng
        log.info("testLbsLoc success",Rlat,Rlng)
    else
        Rlat = ""
        Rlng = ""
    end
    
end


function printGps()
    if gps.isFix() then
        local tLocation = gps.getLocation()
        Rlat = tLocation.lat
        Rlng = tLocation.lng
        log.info("testGps.printGps success",
        gps.isOpen(),gps.isFix(),
        tLocation.lngType,tLocation.lng,tLocation.latType,tLocation.lat,
        gps.getAltitude(),
        speed,
        gps.getCourse(),
        gps.getViewedSateCnt(),
        gps.getUsedSateCnt())
    else
        reqLbsLoc()
    end
    return Rlat,Rlng

end

local function test1Cb(tag)
    log.info("testGps.test1Cb",tag)
    --printGps()
end


--设置GPS+BD定位
--如果不调用此接口,默认也为GPS+BD定位
--gps.setAerialMode(1,1,0,0)

--设置仅gps.lua内部处理NEMA数据
--如果不调用此接口,默认也为仅gps.lua内部处理NEMA数据
--如果gps.lua内部不处理,把NMEA数据通过回调函数cb提供给外部程序处理,参数设置为1,nmeaCb
--如果gps.lua和外部程序都处理,参数设置为2,nmeaCb
-- gps.setNmeaMode(2,nmeaCb)

-- test(testIdx)
gps.open(gps.DEFAULT,{tag="TEST1",cb=test1Cb})
--sys.timerLoopStart(printGps,20000)</span><span style="font-variant-ligatures: common-ligatures; white-space: pre;"><br></span></font></span></code><ul class="pre-numbering" style="color: rgb(0, 0, 0); font-family: Consolas, Inconsolata, Courier, monospace; font-size: inherit; font-variant-ligatures: common-ligatures; outline: 0px; padding-top: 8px; padding-bottom: 8px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; word-break: break-all; position: absolute; width: 48px; background-color: rgb(238, 240, 244); top: 0px; left: 0px; text-align: right;"><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">1</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">2</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">3</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">4</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">5</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">6</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">7</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">8</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">9</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">10</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">11</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">12</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">13</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">14</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">15</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">16</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">17</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">18</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">19</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">20</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">21</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">22</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">23</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">24</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">25</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">26</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">27</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">28</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">29</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">30</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">31</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">32</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">33</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">34</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">35</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">36</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">37</li><li style="outline: 0px; padding: 0px 8px; margin: 0px; font-size: inherit; list-style: none; word-break: break-all; color: rgb(153, 153, 153);">38
<br class="Apple-interchange-newline"></li></ul>


完整代码:https://github.com/lenghonglin/openLuat_Air800/tree/master/OneNet


转载请注明原文链接:Air800(GPRS+GPS模块)连接OneNet平台
喜欢 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址