標籤:
今天開始我的畢業設計,基於HTML5的智能家居手機用戶端設計。挑剔了好久,終於找到我可以使用國外開源項目智能家居核心,通過restful(我也不是很懂,畢竟我只是電子資訊學院愛好網路)。
REST描述了一個架構樣式的網路系統,比如 web 應用程式。在目前主流的三種Web服務互動方案中,REST相比於SOAP(Simple Object Access protocol,簡易物件存取通訊協定 (SOAP))以及XML-RPC更加簡單明了,無論是對URL的處理還是對Payload的編碼,REST都傾向於用更加簡單輕量的方法設計和實現。值得注意的是REST並沒有一個明確的標準,而更像是一種設計的風格。
首先我選定openhab作為伺服器端,雖然它內建手機用戶端,但是由於我比較喜歡它,我還是想給它做一個手機用戶端,由於使用HTML技術我也可以使用phonegap用一套代碼製作各個平台使用的手機用戶端。
首先看看openhab輸出的xml格式:http://192.168.0.19:8080/rest
得到:
This XML file does not appear to have any style information associated with it. The document tree is shown below.<openhab><link type="items">http://192.168.0.19:8080/rest/items</link><link type="sitemaps">http://192.168.0.19:8080/rest/sitemaps</link></openhab>
可以看出它包含一個sitemap的選項可以尋找到所有網站地圖;通過items可以找到所有item(由於篇幅原因,item有所精簡)
This XML file does not appear to have any style information associated with it. The document tree is shown below.<items><item><type>GroupItem</type><name>All</name><state>Undefined</state><link>http://192.168.0.19:8080/rest/items/All</link></item><item><type>GroupItem</type><name>gGF</name><state>Undefined</state><link>http://192.168.0.19:8080/rest/items/gGF</link></item><item><type>GroupItem</type><name>FF_Corridor</name><state>OFF</state><link>http://192.168.0.19:8080/rest/items/FF_Corridor</link></item><item><type>GroupItem</type><name>Lights</name><state>ON</state><link>http://192.168.0.19:8080/rest/items/Lights</link></item><item><type>GroupItem</type><name>Heating</name><state>ON</state><link>http://192.168.0.19:8080/rest/items/Heating</link></item><item><type>GroupItem</type><name>Temperature</name><state>20.12500000</state><link>http://192.168.0.19:8080/rest/items/Temperature</link></item><item><type>GroupItem</type><name>Windows</name><state>OPEN</state><link>http://192.168.0.19:8080/rest/items/Windows</link></item><item><type>DimmerItem</type><name>Light_GF_Living_Table</name><state>0</state><link>http://192.168.0.19:8080/rest/items/Light_GF_Living_Table</link></item><item><type>SwitchItem</type><name>Light_GF_Toilet_Ceiling</name><state>OFF</state><link>http://192.168.0.19:8080/rest/items/Light_GF_Toilet_Ceiling</link></item></items>
由此可以看出,openhab的REST輸出是一個xml檔案,所以我們只需要解析xml就好了。
—————————————本文由本人在部落格園首發,在開源智能家居論壇有帖,轉寄請保留此連結———————————————
基於Html5的智能家居手機用戶端設計(一)——找到openhab的rest