找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 7087|回復: 1
收起左側

arduino JSON庫和httppacket庫分享

[復制鏈接]
ID:404913 發(fā)表于 2018-10-2 18:51 | 顯示全部樓層 |閱讀模式
好多人找的arduinojson庫和httppacket庫文件包:
0.png

HTTP數(shù)據(jù)封裝Ardiuno SDK說明文檔

RestfulAPI包括資源的增、刪、改、查四類操作,其中刪、查操作不帶HTTP內(nèi)容,只有HTTP報頭。增、改操作有HTTP報頭,后面帶有JSON格式HTTP內(nèi)容。報頭數(shù)據(jù)URL帶有可選參數(shù),都是以“?”開始,以“&”分隔。下列操作的HTTP報文,紅色代表有URL可選參數(shù)。

HTTP報由報頭和HTTP內(nèi)容組成。HTTP內(nèi)容是JSON格式字符串,可以通過ArdiunoJSON庫實現(xiàn)HTTP內(nèi)容的封裝,本文檔主要說明HTTP包頭封裝的封裝方法和接口實現(xiàn)。

1.報文總結
1.1 查詢操作
//查看用戶
GET /user HTTP/1.1\r\n
api-key:<your_api_key>\r\n
Host:api.heclouds.com\r\n
\r\n

//查詢設備
GET /devices/<devices_id> HTTP/1.1\r\n
api-key:<your_api_key>\r\n
Host:api.heclouds.com\r\n
\r\n

GET /devices HTTP/1.1\r\n
api-key:<your_api_key>\r\n
Host:api.heclouds.com\r\n
\r\n

//查看數(shù)據(jù)流
GET /devices/<devices_id>/datastreams/<datastream_id> HTTP/1.1\r\n
api-key:<your_api_key>\r\n
Host:api.heclouds.com\r\n
\r\n

GET /devices/<devices_id>/datastreams?datastream_ids=temp,gps HTTP/1.1\r\n
api-key:<your_api_key>\r\n
Host:api.heclouds.com\r\n
\r\n

//查看數(shù)據(jù)點
GET /devices/<devices_id>/datapoints HTTP/1.1\r\n
api-key:<your_api_key>\r\n
Host:api.heclouds.com\r\n
\r\n

//查看觸發(fā)器
GET /triggers/<trigger_id> HTTP/1.1\r\n
api-key:<your_api_key>\r\n
Host:api.heclouds.com\r\n
\r\n

//查看API權限
GET /keys HTTP/1.1\r\n
api-key:<your_api_key>\r\n
Host:api.heclouds.com\r\n
\r\n

//查看二進制數(shù)據(jù)
GET /bindata/<index> HTTP/1.1\r\n
api-key:<your_api_key>\r\n
Host:api.heclouds.com\r\n
\r\n

//RestAPI日志查詢
GET /logs/<device_id> HTTP/1.1\r\n
api-key:<your_api_key>\r\n
Host:api.heclouds.com\r\n
\r\n

//歷史數(shù)據(jù)查詢
GET /datapoints HTTP/1.1\r\n
api-key:<your_api_key>\r\n
Host:api.heclouds.com\r\n
\r\n

1.2 新增操作
//新增設備
POST /devices HTTP/1.1\r\n
api-key:<your_api_key>\r\n
Host:api.heclouds.com\r\n
Content-Length: ***\r\n
\r\n
{"JASON"}

//新增數(shù)據(jù)流
POST /devices/<devices_id>/datastreams HTTP/1.1\r\n
api-key:<your_api_key>\r\n
Host:api.heclouds.com\r\n
Content-Length: ***\r\n
\r\n
{"JASON"}

//新增數(shù)據(jù)點
POST /devices/<devices_id>/datapoints HTTP/1.1\r\n
api-key:<your_api_key>\r\n
Host:api.heclouds.com\r\n
Content-Length: ***\r\n
\r\n
{"JASON"}

//新增觸發(fā)器
POST /triggers HTTP/1.1\r\n
api-key:<your_api_key>\r\n
Host:api.heclouds.com\r\n
Content-Length: ***\r\n
\r\n
{"JASON"}

//新增API權限
POST /keys HTTP/1.1\r\n
api-key:<your_api_key>\r\n
Host:api.heclouds.com\r\n
Content-Length: ***\r\n
\r\n
{"JASON"}

///新增二進制數(shù)據(jù)
POST /bindata HTTP/1.1\r\n
api-key:<your_api_key>\r\n
Host:api.heclouds.com\r\n
Content-Length: ***\r\n
\r\n
{"JASON"}


1.3 更新操作
//更新設備
PUT /devices/<devices_id> HTTP/1.1\r\n
api-key:<your_api_key>\r\n
Host:api.heclouds.com\r\n
Content-Length: ***\r\n
\r\n
{"JASON"}

//更新數(shù)據(jù)流
PUT /devices/<devices_id>/datastreams/<datastream_id> HTTP/1.1\r\n
api-key:<your_api_key>\r\n
Host:api.heclouds.com\r\n
Content-Length: ***\r\n
\r\n
{"JASON"}

//更新觸發(fā)器
PUT /triggers/<trigger_id> HTTP/1.1\r\n
api-key:<your_api_key>\r\n
Host:api.heclouds.com\r\n
Content-Length: ***\r\n
\r\n
{"JASON"}

//更新API權限
PUT /keys/<key_string> HTTP/1.1\r\n
api-key:<your_api_key>\r\n
Host:api.heclouds.com\r\n
Content-Length: ***\r\n
\r\n
{"JASON"}

//發(fā)送數(shù)據(jù)到edp設備
POST /cmds/<device_id> HTTP/1.1\r\n
api-key:<your_api_key>\r\n
Host:api.heclouds.com\r\n
Content-Length: ***\r\n
\r\n
{"JASON"}

1.4 刪除操作
//刪除設備
DELETE /devices/<devices_id> HTTP/1.1\r\n
api-key:<your_api_key>\r\n
Host:api.heclouds.com\r\n
\r\n

//刪除數(shù)據(jù)流
DELETE /devices/<devices_id>/datastreams/<datastream_id>  HTTP/1.1\r\n
api-key:<your_api_key>\r\n
Host:api.heclouds.com\r\n
\r\n

//刪除數(shù)據(jù)點
DELETE /devices/<devices_id>/datapoints HTTP/1.1\r\n
api-key:<your_api_key>\r\n
Host:api.heclouds.com\r\n
\r\n

//刪除觸發(fā)器
DELETE /triggers/<trigger_id> HTTP/1.1\r\n
api-key:<your_api_key>\r\n
Host:api.heclouds.com\r\n
\r\n

//刪除API權限
DELETE /keys/<key_string> HTTP/1.1\r\n
api-key:<your_api_key>\r\n
Host:api.heclouds.com\r\n
\r\n

//刪除二進制數(shù)據(jù)
DELETE /bindata/<index> HTTP/1.1\r\n
api-key:<your_api_key>\r\n
Host:api.heclouds.com\r\n
\r\n


2SDK對外接口說明

/**********************************************************************
*  功能描述: 設置http包頭主機地址字符串
*  @param param1   char* hostAddr  服務器地址字符串指針

*  @return void

**********************************************************************/
void HttpPacketHead::setHostAddress(char* hostAddr)

/**********************************************************************
*  功能描述: 更新單個URL參數(shù)
*  @param param1   char* key      參數(shù)名字字符串指針
*  @param param2   char* value    參數(shù)的值字符串指針

*  @return void

**********************************************************************/
void HttpPacketHead::updateUrlParameterWith(char* key, char* value)

/**********************************************************************
*  功能描述: 清除所有之前設置的URL參數(shù)
*  @param void

*  @return void

**********************************************************************/
void HttpPacketHead::clearUrlParameter(void)

/**********************************************************************
*  功能描述:刪除一個之前已經(jīng)存在的URL參數(shù),如果沒有這
*                        個參數(shù) 不做任何操作
*  @param char* key   參數(shù)名稱

*  @return void

**********************************************************************/
void HttpPacketHead::removeUrlParameter(char* key)

/**********************************************************************
*  功能描述:添加一個url 參數(shù)http包中,如果存在該參數(shù),
*                       不做任何操作.
*  @param1 char* key       參數(shù)名稱
*  @param2 char* value     參數(shù)值

*  @return  void

**********************************************************************/
void HttpPacketHead::addUrlParameter(char* key, char* value)

/**********************************************************************
*  功能描述:設置http包中要要訪問的設備id
*  @param1 char* Dev_Id       設備ID 字符串

*  @return  void

**********************************************************************/
void HttpPacketHead::setDevId(char* Dev_Id)

/**********************************************************************
*  功能描述:設置http包中要要訪問的數(shù)據(jù)流ID
*  @param1 char* StreamId      數(shù)據(jù)流ID 字符串

*  @return  void

**********************************************************************/
void HttpPacketHead::setDataStreamId(char* StreamId)

/**********************************************************************
*  功能描述:設置http包中要要訪問的觸發(fā)器ID
*  @param1 char* TrigId      觸發(fā)器ID 字符串

*  @return  void

**********************************************************************/
void HttpPacketHead::setTriggerId(char* TrigId)

/**********************************************************************
*  功能描述:設置http包中要要訪問的bin文件索引
*  @param1 char* Idx    文件索引

*  @return  void

**********************************************************************/
void HttpPacketHead::setBinIdx(char* Idx)

/**********************************************************************
*  功能描述:添加一個API key,只有在API 更新操作中才會設置.
*  @param1 char* key    key字符串

*  @return  void

**********************************************************************/
void HttpPacketHead::addAPIKey(char* key)

/**********************************************************************
*  功能描述:設置訪問設備所需的密鑰.
*  @param1 char* key    key字符串

*  @return  void

**********************************************************************/
void HttpPacketHead::setAccessKey(char* key)

/**********************************************************************
*  功能描述:產(chǎn)生http 數(shù)據(jù)報頭,僅限POST、PUT操作
*  @param1 OPS_TYPE     operType          操作類型
*  @param2 RESRC_TYPE  type                資源類型
*  @param3 char* jsonData            http內(nèi)容json結構

*  @return  RET_ERR      產(chǎn)生數(shù)據(jù)包失敗,可能因為參數(shù)傳入不當

              RET_OK     產(chǎn)生數(shù)據(jù)包成功

**********************************************************************/
intHttpPacketHead::createCmdPacket(OPS_TYPE operType, RESRC_TYPE type, char* jsonData)


/**********************************************************************

int HttpPacketHead::createCmdPacket(OPS_TYPE operType, RESRC_TYPEtype)

*  功能描述:產(chǎn)生http 數(shù)據(jù)報頭,僅限D(zhuǎn)ELETE、GET操作
*  @param1 OPS_TYPE     operType          操作類型
*  @param2 RESRC_TYPE  type                資源類型

*  @return  RET_ERR      產(chǎn)生數(shù)據(jù)包失敗,可能因為參數(shù)傳入不當

              RET_OK      產(chǎn)生數(shù)據(jù)包成功
**********************************************************************/

3.資源類型說明
    TYPE_USER                       用戶
    TYPE_DEV                  設備
    TYPE_DATASTREAM                 數(shù)據(jù)流
    TYPE_DATAPOINT                    數(shù)據(jù)點
    TYPE_TRIGGER                     觸發(fā)器
    TYPE_APIKEY                      API-KEY
    TYPE_BINDATA                     二進制數(shù)據(jù)
    TYPE_APILOG              API日志  
    TYPE_HISTORYDATA             歷史數(shù)據(jù)

4. 操作類型說明
POST                                 新增
    PUT                                        更新
    GET                                       查詢
    DELETE                               刪除

5. 約束限制
1)一個HTTP報報頭最大不能超過300字節(jié);
2)一個HTTPURL可選參數(shù)個數(shù)不超過7個;
3)一個HTTP報所有URL參數(shù)字符串總長度不超過150字節(jié)。

6. 編程舉例
Ardiuno代碼段:

  HttpPacketHead packet;

packet.setHostAddress("api.heclouds.com");//設置主機地址

packet.setDevId("70290");//設置設備ID

packet.setAccessKey("<Your access api-key>");//設置訪問密鑰

packet.addUrlParameter("datastream_ids", "temp");//添加URL參數(shù)

packet.addUrlParameter("datastream_ids", "gps");//添加URL參數(shù)

packet.createCmdPacket(GET, TYPE_DATASTREAM);//產(chǎn)生查詢數(shù)據(jù)流的報頭

  Serial.print(packet.content);


輸出為:
GET /devices/70290/datastreams/?datastream_ids=temp,gps HTTP/1.1
api-key:<Your access api-key>
Host:api.heclouds.com
具體使用方法請參照示例程序。

全部資料51hei下載地址:
ArdiunoHttpSDK.rar (1.12 MB, 下載次數(shù): 100)

回復

使用道具 舉報

ID:139761 發(fā)表于 2019-2-6 17:00 | 顯示全部樓層
感謝感謝
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復 返回頂部 返回列表