教程2b espiot democn v0免責(zé)公告_第1頁
教程2b espiot democn v0免責(zé)公告_第2頁
教程2b espiot democn v0免責(zé)公告_第3頁
教程2b espiot democn v0免責(zé)公告_第4頁
教程2b espiot democn v0免責(zé)公告_第5頁
已閱讀5頁,還剩12頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)

文檔簡介

TableTableof前 概 代碼結(jié) 工作模 調(diào)試工 curl指令使用的常見錯 局域網(wǎng)功 通用功 查詢版本信 設(shè)置連接參 局域網(wǎng)內(nèi)查找 智能插 查詢插座狀 設(shè)置插座狀 智能 查詢燈的狀 設(shè)置燈的狀 溫濕度傳感 廣域網(wǎng)功 Espressif 認(rèn) 智能插 智能 溫濕度傳感 用戶自定義反向控 ESP8266IoTSDK件平臺。本文主要介紹基于EspressifIoTSDK的嵌入式應(yīng)用開發(fā),在IoTDemo中,實現(xiàn)了三類產(chǎn)品:SDKWi-Fi、ESP8266物聯(lián)網(wǎng)平臺的所有網(wǎng)絡(luò)功能均在庫中實現(xiàn),對用戶不透明。用戶應(yīng)用的初始化功能可以在user_main.c中實現(xiàn)。voiduser_init(void)是上層程序的入口函數(shù),給用戶提供一個初始化接口,用戶可在該函數(shù)esp_iot_sdkexample文件夾中,提供IOT_Demo,AT,smart_config三種應(yīng)用示例,實際上,也可以在IOT_Demo中調(diào)用smart_configAPI,SDK提供相關(guān)API上層應(yīng)用均可調(diào)用。"usr"usrIoTDemouser_devicefind.c—UDP傳輸功能的示例,提供ESP8266設(shè)備查找功能;user_esp_platform.c—與Espressif云端服務(wù)器通信的示例;user_plug.c—智能插座的功能示例代碼;user_light.cPWM實現(xiàn)智能燈的功能示例代碼;user_humiture.cinclude目錄下為應(yīng)用程序相關(guān)頭文件,需要注意的是"user_config.h"文件,在該頭文件中可SENSOR_DEVICE(傳感器)又分為HUMITURE_SUB_DEVICE(溫濕度傳感器)和另需注意,以下頭文件中的宏定義指示用戶參數(shù)區(qū),用戶需根據(jù)編譯時選擇的flashmap自行調(diào)整,flashmap詳見文檔“2A-ESP8266IOT_SDK_User_Manual”user_esp_platform.h#defineESP_PARAM_START_SEC0x3Cuser_light.h中的#definePRIV_PARAM_START_SEC0x3Cuser_plug.h中的#definePRIV_PARAM_START_SEC0x3C"driver"IoTDemouser_esp_platform_init中設(shè)置初始工作模式為sotfAP+station共存的模式,用戶連入ESP8266softAP接口的局域網(wǎng),發(fā)指令讓ESP8266station接口連接可入外網(wǎng)的路由(AP),ESP8266softAPESP8266stationWiFi的狀況。ESP8266station接口連入路由后,自動連接Espressif云端服務(wù)器,對應(yīng)代碼user_esp_platform_check_ip。連接服務(wù)默認(rèn)加密模式為WPA/WPA2。station模式下,長按復(fù)位按鍵5秒,設(shè)備即復(fù)位并重啟恢復(fù)初始softAP+station共存模式,可Demo設(shè)備進行通訊時,可采用curl命令。可在鏈接(http://curl.haxx.se/download.html)進行指定版本的下載,后文中的curl指令請參照“Windowscurl”的示例。LinuxcurlCygwincurlcurl“Linux/Cygwincurl”的示例。curlcurlcurlcurltokencurl指令的工具(Linux/CygwinorWindows)softAPstationIPIPIOT_DEMO#defineSOFTAP_ENCRYPTsoftAP需要密碼進行連接(用戶如果無需密碼,則可將宏#defineSOFTAP_ENCRYPT關(guān)閉),密碼格式為:ESP8266_softAPMAC_PASSWORD,開發(fā)esp_iot_sdk\app\include\user_config.h#definePASSWORD例如"curl-Xcurl-XGET響應(yīng){"Version":"Device":"manufacture","Espressif}}ESP8266softAP+stationPCsoftAP提供的局域網(wǎng)(密碼如前述),通過PC發(fā)送curl指令設(shè)置。curlcurl-XPOST-H"Content-Type:application/json"-d"1234567890123456789012345678901234567890"}}}}'/config?Windowscurlcurl-XPOST-H"Content-Type:application/json"-d\"1234567890123456789012345678901234567890\"}}}}"

token4016進制數(shù)的字符串。ESP8266tokenEspressifCloud激活、認(rèn)證;用戶使用同一個隨機tokenEspressifCloud申請該設(shè)備的控制權(quán)限。因此,隨機token與ESP8266設(shè)備是一一對應(yīng)的關(guān)系,不能與其他設(shè)備共用?!癱urlcurl-XPOST-HContent-Type:application/json-d"1234567890123456789012345678901234567890"}}}}'/config?Windowscurlcurl-XPOST-H"Content-Type:application/json"-d\",\"token\":\”1234567890123456789012345678901234567890\”}}}}"ESP8266stationcurlcurlcurl-XGET返回status說明如下curlcurl-XPOSTcurl-XPOSTcurl-XPOSTcurlcurl-XPOST-H"Content-Type:application/json"-d{"Connect_Softap":{"authmode":"OPEN","channel":6,"ssid":"ESP_IOT_SOFTAP","password":""}}}}'/config?command=wifiWindowscurlcurl-XPOST-H"Content-Type:application/json"-d\",\"password\":\"\"}}}}"注意authmode支持OPEN,WPAPSK,WPA2PSK,password8WiFisoftAP+stationAPPPCESP8266softAPcurlESP8266station連接路由。過程中可以查詢station的連接狀態(tài)。ESP8266station連上路由后,向服務(wù)器認(rèn)證,通過后,ESP8266station之后,ESP8266station模式。當(dāng)網(wǎng)絡(luò)連接斷開,嘗試重連無效,ESP8266softAPstation模式。此時可以重新從步驟2進行連接。另,esp_iot_sdk_v0.9.2及之后版本,支持網(wǎng)絡(luò)連接失敗時,自動切換已記錄的AP進行連接,由宏定義#defineAP_CACHE控制此功能開關(guān)。局域網(wǎng)內(nèi)查找PC1025UDPESP8266設(shè)備的查找,發(fā)送廣播“AreYouEspressifIOTSmartDevice?”,ESP82661025UDP廣播包進行響應(yīng)響應(yīng)I’mI’mI’m其中xx:xx:xx:xx:xx:xx為設(shè)備MAC地址,yyy.yyy.yyy.yyy為設(shè)備IP地址。curlcurl-XGET{"Response":{"Response":"status":}}curl-XPOST-H"Content-Type:application/json"-d'{"Response":{"status":1}}'curl-XPOST-H"Content-Type:application/json"-d'{"Response":{"status":1}}'Windowscurl-XPOST-H"Content-Type:application/json"-d"{\"Response\":{\"status\":1}}"curl-XPOST-H"Content-Type:application/json"-d"{\"Response\":{\"status\":1}}"curlcurl-XGET{"freq":{"freq":100,"rgb":{"red":"green":"blue":}}其中,freq取值范圍為1~500;red、green、blue取值范圍為0~255curl-XPOST-H"Content-Type:application/json"-d'{"freq":100,"rgb":{"red":200,"green":0,"blue":0}}'curl-XPOST-H"Content-Type:application/json"-d'{"freq":100,"rgb":{"red":200,"green":0,"blue":0}}'http://ip/config?command=lightWindowscurl-XPOST-H"Content-Type:application/json"-d"{\"freq\":100,\"rgb\":{\"red\":200,\"green\":0,\"blue\":0}}"curl-XPOST-H"Content-Type:application/json"-d"{\"freq\":100,\"rgb\":{\"red\":200,\"green\":0,\"blue\":0}}"http://ip/config?command=light其中,freq取值范圍為1~500;red、green、blue取值范圍為0~255EspressifCloud注意后述“設(shè)備”后述“PC”指用戶可通過PCmaster-device-ESP8266設(shè)備憑借它作為身份認(rèn)證,享受EspressifCloud提供的云端服務(wù),master-device-key.bin需要向EspressifCloud申請,燒錄到SPIflash。ESP8266curlssid、passwordtokenEspressifCloudEspressifCloud(IP地址8,端口8000TCP{"path":{"path":"/v1/device/activate/","method":"POST","meta":{"Authorization":"tokenHERE_IS_THE_MASTER_DEVICE_KEY"},"body":{"encrypt_method":"PLAIN","bSSID":"18:fe:34:70:12:00","token":"1234567890123456789012345678901234567890"}}12345678901234567890123456789012345678903.1.2{"status":{"status":200,"device":{device},"key":{key},"token":EspressifCloudcurl-XPOST-H"Authorization:tokencurl-XPOST-H"Authorization:tokenc8922638bb6ec4c18fcf3e44ce9955f19fa3ba12"-d'{"token":"1234567890123456789012345678901234567890"}'/v1/Windowscurl-XPOST-H"Authorization:tokencurl-XPOST-H"Authorization:tokenc8922638bb6ec4c18fcf3e44ce9955f19fa3ba12"-d"{\"token\":\"1234567890123456789012345678901234567890\"}"/響應(yīng){"status":200,{"status":200,"key":{"updated":"2014-05-1221:22:03","user_id":1,"product_id":0,"name":"deviceactivatesharetoken","created":"2014-05-1221:22:03","source_ip":"*","visibly":1,"id":149,"datastream_tmpl_id":0,"token":"e474bba4b8e11b97b91019e61b7a018cdbaa3246","access_methods":"*","is_owner_key":1,"scope":3, "device_id":29,"activate_status":1,"datastream_id":0,"expired_at":"2288-02-22c8922638bb6ec4c18fcf3e44ce9955f19fa3ba12為userkey(用戶身份ID)的舉例,需填入用戶實際的userkey值,在EspressifCloud注冊用戶時獲得。步驟如下:EspressifCloude474bba4b8e11b97b91019e61b7a018cdbaa3246為返回的設(shè)備ownerkey,在PC側(cè)使用ownerkey對設(shè)備進行控制。EspressifCloud(IP地址8,端口8000)TCP包,{"nonce":{"nonce":560192812,"path":"/v1/device/identify","method":"GET",{"Authorization":"tokenTCP包的作用是,ESP8266EspressifCloudESP8266設(shè)備重新連接EspressifCloud都需要向服務(wù)器發(fā)送這樣一包數(shù)據(jù)。其中“nonce”是一組隨機整數(shù),token后面是設(shè)備的master-device-key。EspressifCloud認(rèn)證設(shè)備持有的確實是服務(wù)器發(fā)布的master-device-key后,會向設(shè)備回復(fù)一個響應(yīng){"device":{"device":{"productbatch_id":0,"last_active":"2014-06-1910:06:58",12335,"activate_status":1,"serial":"334a8481","id":130,"bSSID":34:97:d5:33","last_pull":"2014-06-1910:06:58","last_push":"2014-06-10:06:58","location":"","metadata":"18:fe:34:97:d5:33temperature","status":2,"updated":"2014-06-1910:06:58","description":"device-description-79eba060","activated_at":"2014-06-1910:06:58","visibly":1,"is_private":"product_id":1,"name":"device-name-79eba060","created":"2014-05-28"is_frozen":0,"key_id":387},"nonce":560192812,"message":identified","status":PINGEspressifCloud(IP地址:8,端口:8000)TCP{"path":"/v1/ping/",{"path":"/v1/ping/","method":"POST","meta":{"Authorization":"token響應(yīng){"status":{"status":200,"message":"pingsuccess","datetime":"2014-06-19"nonce":PINGESP8266GET命令時,表示設(shè)備需要將自身的狀態(tài)上傳至服務(wù)器,服務(wù)器發(fā)給設(shè)備的GET命令格式如下所示:{"body":{},{"body":{},"nonce":33377242,"is_query_device":true,"get":{},"token":"e474bba4b8e11b97b91019e61b7a018cdbaa3246","meta":{"Authorization":"tokene474bba4b8e11b97b91019e61b7a018cdbaa3246"},"path":"/v1/datastreams/plug-status/datapoint/","post":{},"method":"GET"}響應(yīng){"status":200,{"status":200,"datapoint":{"x":0},"nonce":33377242,"is_query_device":ESP8266POST命令時,表示設(shè)備需要改變自身狀態(tài)。服務(wù)器相關(guān)的{"body":{"datapoint":{"x":1}},{"body":{"datapoint":{"x":1}},"nonce":620580862,"is_query_device":true,"get":{},"token":"e474bba4b8e11b97b91019e61b7a018cdbaa3246","meta":{"Authorization":"tokene474bba4b8e11b97b91019e61b7a018cdbaa3246"},"path":"/v1/datastreams/plug-status/datapoint/","post":{},"method":"POST","deliver_to_device":true}ESP8266智能插座完成控制動作后,向服務(wù)器發(fā)送一個更新狀態(tài)成功的響應(yīng),格式如下,響應(yīng)回復(fù)的nonce值必須與云端服務(wù)器之前發(fā)送的控制命令中的nonce值一致,以表示每次控制和響應(yīng)相互對響應(yīng){"status":200,{"status":200,"datapoint":{"x":1},"nonce":620580862,"deliver_to_device":curl-XGET-H"Content-Type:application/json"-H"Authorization:tokene474bba4b8e11b97b91019e61b7a018cdbaa3246curl-XGET-H"Content-Type:application/json"-H"Authorization:tokene474bba4b8e11b97b91019e61b7a018cdbaa3246"/v1/datastreams/響應(yīng){"status":200,"nonce":11432809,"datapoint":{"x":1},"deliver_to_device":{"status":200,"nonce":11432809,"datapoint":{"x":1},"deliver_to_device":curl-XPOST-H"Content-Type:application/json"-H"Authorization:tokencurl-XPOST-H"Content-Type:application/json"-H"Authorization:tokene474bba4b8e11b97b91019e61b7a018cdbaa3246"–d'{"datapoint":{"x":1}}'http://Windowscurl-XPOST-H"Content-Type:application/json"-H"Authorization:tokencurl-XPOST-H"Content-Type:application/json"-H"Authorization:tokene474bba4b8e11b97b91019e61b7a018cdbaa3246"–d"{\"datapoint\":{\"x\":1}}"http://響應(yīng){"status":200,{"status":200,"nonce":11432809,"datapoint":{"x":1},"deliver_to_device":ESP8266GET命令時,表示設(shè)備需要將自身的狀態(tài)上傳至服務(wù)器,服務(wù)器發(fā)給設(shè)備的GET命令格式如下所示:{"body":{},{"body":{},"nonce":8968711,"is_query_device":true,"get":{},"token":"e474bba4b8e11b97b91019e61b7a018cdbaa3246","meta":{"Authorization":"tokene474bba4b8e11b97b91019e61b7a018cdbaa3246"},"path":"/v1/datastreams/light/datapoint/","post":{},"method":"GET"}響應(yīng){"nonce":{"nonce":5619936,"datapoint":{"x":100,"y":200,"z":0,"k":0,"l":"deliver_to_device":ESP8266POST命令時,表示設(shè)備需要改變自身狀態(tài)。服務(wù)器相關(guān)的{"body":{"datapoint":{"y":200,{"body":{"datapoint":{"y":200,"x":100,"k":0,"z":0,"l":50}},"nonce":5619936,"is_query_device":true,"get":{},"token":"e474bba4b8e11b97b91019e61b7a018cdbaa3246","meta":{"Authorization":"tokene474bba4b8e11b97b91019e61b7a018cdbaa3246"},"path":"/v1/datastreams/light/datapoint/","post":{},"method":"POST"響應(yīng){"nonce":{"nonce":5619936,"datapoint":{"x":100,"y":200,"z":0,"k":0,"l":"deliver_to_device":其中,X表示頻率,取值范圍1~500;Y(red),Z(green),K(blue)調(diào)節(jié)智能燈的顏色,取值范圍0~255;L為保留參數(shù)。curl-XGET-H"Content-Type:application/json"-H"Authorization:tokene474bba4b8e11b97b91019e61b7a018cdbaa3246curl-XGET-H"Content-Type:application/json"-H"Authorization:tokene474bba4b8e11b97b91019e61b7a018cdbaa3246"/v1/datastreams/響應(yīng){"nonce":{"nonce":5619936,"datapoint":{"x":100,"y":200,"z":0,"k":0,"l":"deliver_to_device":curl-XPOST-H"Content-Type:application/json"-H"Authorization:tokencurl-XPOST-H"Content-Type:application/json"-H"Authorization:tokene474bba4b8e11b97b91019e61b7a018cdbaa3246"–d'{"datapoint":{"x":100,"y":200,"z":0,"k":0,"l":50}}'/v1/datastreams/light/Windowscurl-XPOST-H"Content-Type:application/json"-H"Authorization:tokencurl-XPOST-H"Content-Type:application/json"-H"Authorization:tokene474bba4b8e11b97b91019e61b7a018cdbaa3246"–d"{\"datapoint\":{\"x\":100,\"y\":200,\"z\":0,\"k\":0,\"l\":50}}"/v1/datastreams/light/響應(yīng){"nonce":{"nonce":5619936,"datapoint":{"x":100,"y":200,"z":0,"k":0,"l":"deliver_to_device":其中,X表示頻率,取值范圍1~500;Y(red),Z(green),K(blue)調(diào)節(jié)智能燈的顏色,取值范圍0~255;L為保留參數(shù)。{"nonce":1,{"nonce":1,"path":"/v1/datastreams/tem_hum/datapoint/","method":"POST","body":{"datapoint":{"x":35,"y":32}},"meta":{"Authorization":"token響應(yīng)

X表示溫度值,Y{"status":200,{"status":200,"datapoint":{"updated":"2014-05-1418:42:54","2014-05-1418:42:54","visibly":1,"datastream_id":16,"at":"2014-05-18:42:54","y":32,"x":35,"id":PCAPIownerkey查詢最新數(shù)據(jù)curl-XGET-H"Content-Type:application/json"-H"Authorization:tokencurl-XGET-H"Content-Type:application/json"-H"Authorization:tokene474bba4b8e11b97b91019e61b7a018cdbaa3246"/v1/datastreams/注意:ownerkey“remotedeviceisdisconnectorbusy”,是正常情況,因為溫濕查詢歷史數(shù)據(jù)curl-XGET-H"Content-Type:application/json"-H"Authorization:tokencurl-XGET-H"Content-Type:application/json"-H"Authorization:tokene474bba4b8e11b97

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論