m5310模组数据上传至onenet_NBIOT模组M5310接入中国移动物联网开放平台示例文档
<time>:?-t?設備存活時間,標示終端和
OneNET 平臺之間連接的存活周
期,設置范圍為
10s~86400s;
:?-u 設置
PUT 和 POST 指令分片長度,范圍 0~6,指示分片長度
為 2^(4+u),缺省值為
5;
:?-g
設置GET指令分片長度,范圍0~6,指示分片長度為2^(4+g),
缺省值為 5;
: -x 設置觸發分片操作的最大長度,范圍
0~2,指示閾值為
2^(4+x),缺省值為
2。
如 無 特殊 需求,建議分片參數 block1 和 和
block2?設置
為缺省值,block2th?設
置為 為 1 。
這種方法適用于采用串口調試助手調試M5310模組。
(2)使用相關算法生成注冊碼:
#include
"memory.h"
#include
"string.h"
#include
"stdio.h"
#include
"stdlib.h"
#include
"string.h"
typedef enum
{
MIPL_DEBUG_LEVEL_NONE
= 0,
MIPL_DEBUG_LEVEL_RXL,
MIPL_DEBUG_LEVEL_RXL_RXD,
MIPL_DEBUG_LEVEL_TXL_TXD,
}
MIPL_DEBUG_LEVEL_E;
typedef unsigned char
uint8;
typedef unsigned short
uint16;
typedef unsigned
uint32;
#define
MIPL_BOOT?1
#define
MIPL_ENCRYPT?0
#define
MIPL_DEBUG?MIPL_DEBUG_LEVEL_NONE
#define
MIPL_PORT?0
#define
MIPL_KEEP_ALIVE?3000
#define
MIPL_BLOCK1?5
#define
MIPL_BLOCK2?5
#define
MIPL_BLOCK2TH?1
#define
MIPL_URI?"coap:\/\/183.230.40.39:5683"
#define
MIPL_ENDPOINT?"862018102915220;460040236709122"
typedef
struct
{
uint8
boot;
uint8
encrypt;
MIPL_DEBUG_LEVEL_E
debug;
uint16
port;
uint32
keep_alive;
size_t
uri_len;
char*
uri;
size_t
ep_len;
char*
ep;
uint8
block1;?//COAP option
BLOCK1(PUT or POST),0-6.
2^(4+n)?bytes
uint8
block2;?//COAP option
BLOCK2(GET),0-6.
2^(4+n)?bytes
uint8
block2th;?//max size to
trigger block-wise operation,0-2. 2^(8+n) bytes
} MIPL_T;
void mipl_generate(char *buf,
size_t buflen, MIPL_T *mipl);
int
main(void)
{
char
config[1024];
MIPL_T
m5310_mipl_t;
m5310_mipl_t.block1
= MIPL_BLOCK1;
m5310_mipl_t.block2
= MIPL_BLOCK2;
m5310_mipl_t.block2th
= MIPL_BLOCK2TH;
m5310_mipl_t.boot
= MIPL_BOOT;
m5310_mipl_t.debug
= MIPL_DEBUG;
m5310_mipl_t.encrypt
= MIPL_ENCRYPT;
m5310_mipl_t.ep_len
= strlen((char*)MIPL_ENDPOINT);
m5310_mipl_t.ep
= (char*)MIPL_ENDPOINT;
m5310_mipl_t.keep_alive
= MIPL_KEEP_ALIVE;
m5310_mipl_t.port
= MIPL_PORT;
m5310_mipl_t.uri
= (char*)MIPL_URI;
m5310_mipl_t.uri_len
= strlen((char*)MIPL_URI);
mipl_generate(config,
sizeof(config), &m5310_mipl_t);
while(1);
return
0;
}
void output_buffer(unsigned
char *buffer, int length,int index, int flag)
{
int i =
0;
while( i <
length )
{
printf(
"X", buffer[i++] );
}
printf(",%d,%d\r\n",index,flag);
}
void mipl_generate(char *buf,
size_t buflen, MIPL_T *mipl)
{
uint32 offset
= 0;
int mipl_num
= 0;
char mode =
0;
memset(buf,
0, buflen);
mode =
((mipl->boot & 0x1) << 4) | (mipl->encrypt &
0x1);
memcpy(buf +
offset, &mode, 1);
offset++;
memcpy(buf +
offset, &mipl->debug, 1);
offset++;
memcpy(buf +
offset, &mipl->port, 2);
offset +=
2;
memcpy(buf+offset,
&mipl->keep_alive, 4);
offset +=
4;
memcpy(buf +
offset, &mipl->uri_len, 2);
offset +=
2;
memcpy(buf +
offset, mipl->uri, mipl->uri_len);
offset +=
mipl->uri_len;
memcpy(buf +
offset, &mipl->ep_len, 2);
offset +=
2;
memcpy(buf +
offset, mipl->ep, mipl->ep_len);
offset +=
mipl->ep_len;
*(buf +
offset) = mipl->block1;
offset++;
*(buf +
offset) = mipl->block2;
offset++;
*(buf +
offset) = mipl->block2th;
offset++;
mipl_num =
0;
while(offset
> 1024)//每條+MIPLCONF命令最多輸入1024字節配置數據
{
printf("AT+MIPLCONF=%d,",1024);
output_buffer( (unsigned char *)(buf + (mipl_num >>
10)),1024,mipl_num + 1,0);//index從1起始
mipl_num++;
offset -=
1024;
}
printf("AT+MIPLCONF=%d,",offset);
output_buffer(
(unsigned char *)(buf + (mipl_num >> 10)),offset,mipl_num +
1,1);//結束
}
這種方法適用于通過MCU控制M5310模組。
將生成的注冊碼發送到M5310:
AT+MIPLCONF=71,10000000B80B00001900636F61703A2F2F3138332E3233302E34302E33393A353638331F003836323031383130323931353232303B343630303430323336373039313232050501,1,1
0
OK
0為
4、?訂閱Object
組 配置
命令格式:AT+MIPLADDOBJ=,,
objectid代表的類型可參考IPSO
資源模型,http://www.openmobilealliance.or ...
/LwM2MRegistry.html。
如發送:AT+MIPLADDOBJ=0,3303,0
5、模組側發起登錄
AT+MIPLOPEN=0,15
上述指令中,30
代表登錄超時時間;如果超過該時間,模組還未接收到平臺的登錄響應,模組則會上報登錄失敗的通知。
登錄結果上報:
模組上報登錄請求,服務器收到登錄請求數據之后,會根據數據內容,返回本次登錄結果;如果登錄失敗,或者登錄超時,模組都會上報登錄失敗的響應。
登錄成功上報打印如下:
+MIPLOPEN:0,1
登錄失敗上報打印如下:
+MIPLOPEN:0,0
需要注意的是, 如果在注冊碼中的
debug參數設置為非0,則在登錄過程中,除了上報登錄信息之外,還會應顯示對應debug
等級的數據內容。
模組登錄成功后,平臺會下發Observer 消息和
Discover 消息;模組收到這兩條消息之后,會自動處理,無需用戶另行處理:
同時OneNET會顯示設備在線:
6、向OneNET平臺發送數據
命令格式:AT+MIPLNOTIFY=,,,,,,[,]
這里使用不帶ackid方法上報:
AT+MIPLNOTIFY=0,3303,0,5700,4,"24.5"
OK
查看上報的數據:
參數說明:
:資源ID,請參考IPSO
資源模型,http://www.openmobilealliance.or ...
/LwM2MRegistry.html。
:
1?2?3?4?5?6
string?opaque?integer?float?bool?hex_str
五、命令總結
1、上電檢查流程
(1) AT
//判斷模組是否上電開機成功
(2) AT+CSQ
//信號質量檢查
(3) AT+CEREG? //判斷 PS
域附著狀態,標識位返回 1 或 5 表示附著正常
(4) AT+CGATT? //檢查模組 PS
附著狀態
2、模組側設備創建及資源訂閱,登錄流程
(1) AT+MIPLCONF=72,1003000……….
3033393639050501,1,1//設置模組側設備注冊碼
(2)
AT+MIPLADDOBJ=0,3200,0?//訂閱
Object 3200 資源設置
(3)
AT+MIPLNOTIFY=0,3200,0,5505,6," E309C82FE6 ",1 //訂閱 Resource 5500
資源設置
(4) AT+MIPLOPEN=0,30 //設備登錄到
OneNET 平臺
3、OneNET?數據收發流程
(1)
AT+MIPLNOTIFY=0,3200,0,5505,6," E309C82FE6 ",1
//數據上傳
(2)
AT+MIPLREAD=0,60204,3200,0,5505," E309C82FE6
",1?//Read
操作回復流程
(3) AT+MIPLWRITE=0,62069,1
//Write 操作回復流程
(4) AT+MIPLEXECUTE=0,46081,1
//Execute 操作回復流程
4、模組側設備注銷流程
(1)
AT+MIPLCLOSE=0?//登錄注銷流程
(2) AT+MIPLDELOBJ=0,3200,0
//模組側訂閱資源列表釋放
(3) AT+MIPLDEL=0
//模組側通信實例刪除
六、IPSO 資源模型示例
更多請參考:OMA LightweightM2M (LwM2M) Object and
Resource Registry
總結
以上是生活随笔為你收集整理的m5310模组数据上传至onenet_NBIOT模组M5310接入中国移动物联网开放平台示例文档的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: excel2010设置列宽为像素_vba
- 下一篇: unix到底有啥用_观点|什么是Unix