國立臺中教育大學資訊工程學系碩士論文
透過軟體中介層於物聯網環境下實現隨插即用式
使用者介面
A research on pluggable user interface in
IoT-enabled environment with middleware
指導教授: 徐國勛 教授
研究生: 黃大祐 撰
致謝
在碩士班的生涯中,我最感謝的人就是我的指導教授徐國勛教授,從老師的 身上我學到了太多東西,無論是專業知識或是做學問的態度與方法上都獲益匪 淺。也感謝我的口試委員,孔崇旭主任、李文廷教授、李信杰教授對我論文上的 指導及建議。以及感謝在台中教育大學求學期間,系上每個幫助過我的師長,李 宜軒、王讚彬、賴冠州、黃國展、李宗翰、林嬿雯、張林煌、顧維琪等教授,還 有系辦辦事員瑋珊。 再來要感謝軟體工程實驗室中的同儕,感謝祥紳、致謀常常陪我在實驗室一 起努力做研究到半夜。感謝繼玄時常督促我要好好做進度。感謝我的學長瑋辰、 冠霖在我剛進實驗室的時候教我如何成為一個研究生,以及旻遇、紹源在課業上 的經驗傳承。感謝我的學弟立青、承哲、冠宇、長諺在實驗室裡大小事務上的幫 助,還有旻映、昱豪、為中時常製造歡樂的拌嘴時光。 最後也是最重要的,感謝我的父母,如果沒有他們,不會有今天的我。願在 天上的父親能夠安息,願我的母親健康平安。摘要
近年來因為微型裝置的運算能力不斷提升,出現了物聯網 (IoT) 的概念,目 的是將具備智能運算的各種裝置,通過各種不同的通訊技術與網際網路連結, 使其能互相溝通並且互相操作 (Interoperability),使得異質系統 (heterogeneous systems) 間可以互相合作、共同完成一件工作,進而達到結合真實世界與數位 世界的目標。隨著各種物聯網的新型應用不斷開發下,伴隨而來的問題是,因 為 Things 的異質性 (heterogeneous) 過高,不同的裝置要被使用在同一個應用 上時,在通訊上的整合、操作指令上的傳遞都必須要被考慮進去,造成開發上 的困難。因此,目前在 IoT 整體的發展上,出現了許多關於、物聯網中介軟體 (IoT Middleware) 的研究,想要嘗試設計一個 Middleware 來簡化 IoT 應用程式 及服務的開發過程。本論文從 IoT 應用程式軟體開發者的角度出發,簡化過 去在開發上必須先從硬體的整合的難度,並基於裝置隨插即用的概念提出一個 Middleware 平台,除協助開發者對硬體進行連線外。當物聯網裝置被連上此平 台時,Middleware 會根據裝置上的使用者介面描述檔,為此裝置尋找合適的使 用者介面 bundle,並動態載入至平台中,讓開發者可以調用使用者介面至程式 中運行。供使用者對裝置進行操作。希望透過此方式,協助物聯網應用程式的開 發者,縮短軟硬體整合的時間,並改善以往須針對每個裝置去製作使用者介面的 缺點,利用第三方製作的使用者介面,提供使用者更多選擇,並且提高使用者介 面的再利用性。 關鍵詞 物聯網、中介軟體、使用者介面、隨插即用Abstract
In recent years, the computing capability of embedded devices increase continuously the concept of Internet of Things. With the development in IoT, there shows considerable researches on IoT Middleware trying to design a middleware to simplify the development process in IoT applica-tions. Most of these researches focused on how to integrate heterogeneous communication and message passing. Less exploration start from the perspective of software development. This research proposed a middle-ware platform aims to support softmiddle-ware programming in IoT application. When a device connects to this platform, the middleware will request a user interface bundle from the UI Bundle repository based on the UI de-scription on the device. The dynamic loading mechanism on this platform will install a suitable UI bundle for users to operate the connected device. This mechanism eliminates the effort on creating user interfaces for each device in an ad-hoc way and improves the reusability of the user interface. Finally, a set of API for utilizing this middleware are also provided in this thesis.
Keywords
目錄
第一章 緒論 ... 1 1.1 引言 . . . 1 1.2 動機 . . . 3 1.3 目的 . . . 5 第二章 背景知識與相關研究 ... 6 2.1 背景知識介紹 . . . 6 2.1.1 JSON . . . 6 2.1.2 OSGi . . . 7 2.1.3 OSGi on Android . . . 8 2.2 物聯網環境下的中介軟體相關研究 . . . 9 2.2.1 SOA-based . . . 9 2.2.2 Semantic Web-based . . . 9 2.2.3 VM in Gateway . . . 10 2.2.4 Combining XMPP in Communication . . . 11 2.2.5 Ad-Hoc way . . . 12 第三章 研究概述... 14 3.1 為物聯網應用的軟體開發者設計的中介軟體 . . . 14 3.2 與裝置可隨插即用的使用者介面 . . . 14 3.3 問題探討 . . . 15 第四章 系統分析與設計... 17 4.1 系統需求 . . . 17 4.1.1 Middleware . . . 17 4.1.2 Device Adaptor . . . 174.1.3 UI Repository . . . 20 4.2 系統架構 . . . 21 4.3 Class Diagram . . . 23 4.3.1 Middleware Host . . . 24 4.3.2 Communication Manager . . . 26 4.3.3 UI Match Maker . . . 27 4.3.4 Dynamic UI Loader . . . 28 第五章 案例研究... 29 5.1 實驗架構說明 . . . 29 5.2 使用硬體簡介 . . . 30
5.3 API of Proposed Middleware . . . 32
5.4 實驗系統展示 . . . 35
5.4.1 實驗系統畫面展示 . . . 36
第六章 結論與未來展望... 37
6.1 結論 . . . 37
表目錄
表 1 系統需求-Middleware . . . 18
表 2 系統需求-Device Adaptor . . . 19
表 3 系統需求-UI Repository . . . 19
圖目錄
圖 1 JSON Format Example . . . 6
圖 2 OSGi Framework . . . 7
圖 3 OSGi on Android . . . 8
圖 4 Overview . . . 14
圖 5 Device Communication Adaptor . . . 16
圖 6 Bundle Information Table . . . 20
圖 7 System Architecture . . . 21
圖 8 Sequence Diagram . . . 22
圖 9 Overall Class Diagram . . . 23
圖 10 Middleware Host Class Diagram . . . 24
圖 11 Communication Manager Class Diagram . . . 26
圖 12 UI Match Maker Class Diagram . . . 27
圖 13 Dynamic UI Loader Class Diagram . . . 28
圖 14 實驗架構圖 . . . 29
圖 15 DHT11 by Keyes . . . 30
圖 16 uartsBee V4.0 . . . 30
圖 17 WiFi Bee . . . 31
圖 18 API of Proposed Middleware . . . 32
圖 19 Method Detail - inStart . . . 33
圖 20 Method Detail - inStop . . . 33
圖 21 Method Detail - updateComm . . . 33
圖 22 Method Detail - requestUI . . . 34
圖 24 程式碼說明 . . . 35 圖 25 實驗展示-左. 啟動 Middleware; 中. 開始監聽; 右. 發現新裝置 . . 36 圖 26 實驗展示-左. 要求 UI 配對; 中. 選擇 UI bundle; 右. 動態載入 UI 36
第一章
緒論
1.1
引言
近 年 來 因 為 微 型 裝 置 的 運 算 能 力 不 斷 提 升, 出 現 了 物 聯 網 (Internet of Things) 的概念,目的是將具備智能運算的各種裝置,通過各種不同的通訊技術 與網際網路連結,使其能互相溝通並且互相操作 (Interoperability),使得異質系 統 (heterogeneous systems) 間可以互相合作、共同完成一件工作,進而達到結合 真實世界與數位世界的目標。 而 在 Internet of Things 的 幾 種 關 鍵 技 術 不 斷 的 進 步, 例 如 射 頻 識 別 技術 (Radio-frequency Identification)、無線感知網路 (Wireless Sensor Network) 、 嵌 入 式 技 術 (Embedded Intelligence)、奈 米 與 微 機 電 技 術 (Nanotechnology and Micro Electro Mechanical Systems),以及成本不斷降低的發展之下,現今 Internet of Things 在實務上已經有了不少應用,例如在物流、倉儲系統的管理 應用上 [1],可以提升物流處理中各個流程以及倉儲貨物的監控效率,減少運作 上的成本;或者是在居家安全的監控上,透過各種感測器,監控住家環境,包括 電路 [2]、溫度等等,並採取相對應的措施,以防範災害的發生;在醫療上,也 有透過裝設在病患身上的感測器,即時監控病患生理上的各項數值,並回傳到負責的醫療機構做分析等應用 [3]、[4],;在農業生產及銷售上,也有結合環境感測 的智慧型耕作系統 [5]、產銷履歷 [6] 的記載等應用;交通方面也有利用道路的監 控,智能交通號誌、分享交通資訊至各種交通工具上,達到改善交通狀況、提升 交通安全的目標 [7]、[8];在工業的安全上,也有利用小型感測器監控大型機具 的運作狀態,以降低機器故障時所帶來的危害等應用 [9]。
1.2
動機
隨著各式各樣在 Internet of Things 的新型應用不斷的開發下,伴隨而來 的問題是,因為 Things 的異質性 (heterogeneous) 過高,不同的裝置要被使用 在同一個應用上時,在通訊上的整合、操作指令上的傳遞都必須要被考慮進 去,造成開發上的困難。因此,目前在 IoT 整體的發展上,出現了許多關於 IoT Middleware 的研究,想要嘗試設計一個 Middleware 來簡化 IoT 應用程式 及服務的開發過程。[10] 中提到 IoT Middleware 應該是一個被放置在應用程 式端與實體的設備中間的一個抽象層 (abstract layer),目的是隱藏底層技術上 的細節、協助應用程式開發者專注於應用面的開發。在 [11] 中則提到了目前 在設計 IoT Middleware 的研究中所遭遇到的、待解決的問題,如互相操作性 (Interoperability)、延 展 性 (Scalability)、 硬 體 抽 象 化 (Abstraction Provision)、 自 發 性 的 交 互 動 作 (Spontaneous Interaction)、 不 固 定 的 基 礎 設 施 (Unfixed Infrastructure)、通訊上的多樣性 (Multiplicity) 以及安全和隱私 (Security and Privacy) 等。
目前在各種 IoT Middleware 的發展上尚未有統一的標準,不同的設計能 解決的問題範圍也不同。而現行的研究中,大部分都是從整合底層通訊的角度
出發來做 Middleware 的設計,如 [12] 提出一個基於 CoAP 協定的 Middleware, 使其掛載在每一個 IOT 的節點上,將每一個節點提供的服務視為一個資源, 透 過 RESTful web services 的 概 念 來 做 資 源 的 管 理 及 操 作,[13] 中 提 出 一 個 雙 gateway 的架構,分別處理底層裝置間的通訊以及與上層應用程式間的互 動,[14] 提出一個 SOA-based 的 Middleware,透過 Agent layer 來轉換各種無法 溝通的通訊協定,使其能溝通,[15] 提出將 XMPP 帶進 IoT 的通訊中可以搭起 異質裝置間的橋樑、免去使用 gateway 或類似角色的麻煩,[16] 則闡述在 IoT 的通訊中使用 XMPP 可以對安全性帶來多少提升,[17] 則是在 E-Health 實務中 將 XMPP-based 與 SOA-based 的 Middleware 拿來比較,判斷哪種比較適合在 此領域中應用。
也有不少如 [18–20] 的研究,提出 Semantic 的概念來設計 IoT Middleware 讓裝置具備提供 web service 的功能。還有少部分是依據特定領域用途來設計 的 Middleware,如 [21] 中探討想透過 RFID 的技術來追蹤商品從出貨後到被回 收這段時間的變化並從中分析有用的商業模式的這種用途下 IoT Middleware 須 具 備 的 功 能 面 向,[22] 則 是 探 討 工 業 製 造 上 所 使 用 的 IoT 環 境 所 需 要 的 Middleware 功能,[23] 則是在情境感知的領域中探討如何透過 IoT Middleware 來選取、排序不同應用下適合的感測器來達成應用程式的目標。
1.3
目的
對於軟體開發人員來說,應用程式軟體的開發者所需要的考慮的應該是 IoT Middleware 提供了什麼樣的介面能降低程式開發的複雜性、增加程式撰寫的效 率、快速建立一個能與裝置端互動的應用。在 [16] 提到支援提供使用者介面 User Interface Provision 在 IoT Middleware 是必要的,尤其是在現今智慧型行動 裝置被大量使用的情況下,使用者介面是能提供服務使用者與實體裝置互動的重 要橋梁,在過去,所有的 IoT 應用開發都必須為被使用到的裝置設計特定形式 的程式介面,很少人談到如何將現實世界中的實體裝置抽象化,使得程式開發人 員可以依據抽象後的描述來對這些裝置進行使用者介面的撰寫。為了簡化 IoT 裝置應用開發上的複雜性,並使 IoT 裝置達到隨插即用的功能,本論文提出一 個 Middleware 平台,設計一套 API(Application Programing Interface) 協助 IoT 應用程式的開發人員進行軟體開發,透過 API 與裝置連線、根據裝置上的使用 者介面描述檔,動態載入可讓使用者操作的使用者介面。
第二章
背景知識與相關研究
2.1
背景知識介紹
本章節將介紹幾種在實做中用到的技術相關背景知識。
2.1.1 JSON
圖 1: JSON Format Example
JSON(JavaScript Object Notation) [24] 是一種獨立於程式語言之外的文 字格式。因為它的易讀性與高相容性,使得它成為一種常用的數據交換格式。 JSON 字串有兩種模式,陣列與物件,分別用 [ ] 與 { } 來寫入資料。而資料內 容是成對的 name 與 value,用: 來區隔。其資料包含的值可以是數字、字串、布 林值或空值 (NULL)。圖 1是一個 JSON 的簡單範例,其中 conrents 陣列裡包含 了一個物件。由於它與 XML 相比為一個較輕量化的資料交換格式,所以本論文
中將使用 JSON 格式來儲存裝置的描述檔案傳送到 Middleware 中來做使用。
2.1.2 OSGi
圖 2: OSGi Framework
OSGi Alliance [25] 原本是由多家廠商組成的開放的標準化組織,目的是 讓提供服務的廠商能透過智慧家電設備的 Gateway 提供各種服務。經過多年的 發展,OSGi Alliance 官網將 OSGi 定義為一種技術,此技術是指一系列用於定 義 JAVA 動態化模組系統的標準。透過這些標準為大型的分散式系統與嵌入式 系統提供了一種模組化的架構,來減少軟體的複雜度。圖 2為 OSGi 框架,主 要分成安全層、模組層、生命週期層以及服務層,bundle 則是可以被動態載 入至 OSGi 框架中執行的應用程式。在本論文中將運用 bundle 可被動態載入 使用的特點,將 UI 包裝成 bundle 的型態,透過 OSGi 框架提供給 IoT 應用程 式的開發者使用。OSGi 框架在實做上有三個比較有名的專案,Apache Felix、 Equinox、Knopflerfish,本論文將使用 Apache Felix 來實做 Middlware 中 UI 動
態載入的功能
2.1.3 OSGi on Android
圖 3: OSGi on Android
在 本 論 文 中, 將 會 於 Android 的 平 台 上, 利 用 本 論 文 所 提 出 的 Middleware 實際建立一個應用來做為案例研究。而在 Android 平台下要使用 OSGi 載入 UI bundle 必須被 dexify 後才能被執行。原因是 Google Android 讓開 發者用 JAVA 開發 Android 上的應用程式,卻不是用 JVM 來執行程式,而是用 Dalvik VM 來執行,所以 bundle 必須含有可以被 Dalvik VM 判斷執行的.dex 檔 才能在 Android 上使用。圖 3說明了這個步驟,bundle 使用 JAVA 語言撰寫後, 編譯後被製作成.jar 型式的檔案,經過 Android 平台工具裡的 dx 工具產生.dex 檔,再利用 aapt 工具將.dex 檔包回 bundle 中,指令如圖 3中程式碼所示。
2.2
物聯網環境下的中介軟體相關研究
近 年 來 關 於 IoT Middleware 主 要 分 為 幾 個 方 向,SOA-based、semantic web、RFID& WSN、XMPP,也有一些是為了特定環境用途而發展的 Middle-ware,下面將分別就這幾項分類做介紹與探討:
2.2.1 SOA-based
The SOCRADES project [26] 使用 SOA 來使企業級的應用程序在廣泛的網 絡設備中進行數據交換,它提供高階的抽象類別,並具有 Web 的標準服務,且 提供設備認證和存取控制。。The Hydra middleware [27] 主要是透過 SOA 的架構 來達到情境感知的功能,在它的架構中,都是由應用程式層來做包括安全功能、 核心的元件如網路管理器、信任管理器及存取控制權限框架等。Wang 等人 [14] 提出了一個 SOA based 的 Agent 的概念,將所有異質網路協定,透過 Agent 層 轉變成同質性的網路,使其能溝通,並在其上建立了一個 gateway 層來解決一 些因為某些功能引起的如安全性方面的問題。
2.2.2 Semantic Web-based
Song 等人 [18] 用 semantic service 的概念,搜尋連線環境中的裝置後,用 OWL-S 來描述 Home area network 中的 device,將其變成一個 service 清單,再
透過組合任務的方式來操作這些裝置,目前已經成功在 Bluetooth 跟 UPnP 的 網 路 環 境 下 運 作。Perera 等 人 [23] 他 們 在 IoT 的 Middleware 上 提 出 來 一 個 context based framework 來描述 sensor 的特性,然後延伸出一個 Semantic Sensor Ontology,並提出了 CASSARAM 跟 CASSARA 這兩個工具讓使用者可 以依據需求來選擇選取 sensor 的優先順序。他們還提出了一套演算法 novel technique called Comparative Priority-based Heuristic Filtering,在他們的實驗 中有證明這個可以讓 sensor 在做索引的時候更快更有效率。Zhou 等人 [20] 則 是自行提出了一個三層架構的 IoT ontology,並用 semantic 的概念來對各層中 的元件作註記,他們提出的演算法可以快速地將 user demand, web services and resources data 等東西做分類及標註以方便資料傳輸時使用。
2.2.3 VM in Gateway
Azzara 等 人 在 歐 盟 的 一 個 名 為 ICSI 的 project [12] 中 提 出 了 一 個 WSN 的 Middleware solution,它們提出了一個由三個元件組成的 Middleware,包含 RESTful Web Service、Event Managers、Configuration Manager. 並將其掛載在 裝置端的 VM 上來實現一個 publish/subscribe model。Valente 等人提出了一個 叫做 MufFIN 的 Middleware 架構 [13],主要元件如下: 透過 1. Things gateway 與 devices 做通訊。2. WS-Gateway 透過 web service 跟上層的 application 做溝
通。3. Core 的部分提供 WEB 介面的實作。4. DFN 的部分可以管理客戶端 部屬到裝置上的模組,初始化模組後創造一個 publish-subscribe 的連結關係。 5. Subscriptions 是用來接受客戶端的訂閱並記錄客戶端的資訊。6. SOS 是利 用 OGC 定出來的 Sensor Observation Service standard 來識別 XML 的文件。7. DataAccess 是用來存取資料庫並提供資料給其他層使用。不過這個設計目前還 沒在實際的 IoT 環境底下做測試。
2.2.4 Combining XMPP in Communication
Kirsche 等 人 主 要 是 提 出 把 XMPP 帶 進 IoT 的 通 訊 環 境 裏 的 想 法 [15], 它們首先提出幾種目前 IoT 中較常見的通訊協定如 6LoWPAN、Constrained Application Protocol(CoAP) Message Queuing Telemetry Transport (MQTT) 並 探 討 他 們 目 前 能 做 到 的 功 能 以 及 其 優 缺 點。 然 後 提 到 兩 個 XMPP 實 作 在 嵌入式裝置上的專案 uXMPP and XMPPClient 並探討她現在的做法跟功能 性還有優缺點,並提到了用 XMPP 當作 IoT 的通訊協定的話可以不用用到 middleware or protocol gateways 來整合異質網路。Conzon 等人則提出了一個 VIRTUS Middleware [16],它是基於 XMPP 來設計的架構,他們的通訊完全是 使用 XMPP 來進行,好處是可以提供高安全性,並結合 OSGi 用來處理資料更 新與相依性的自動管理並簡化配置與佈署的過程。在此研究中把 device 分成三
種類型 1. Resource rich devices (like PC)、2. Resource-constrained devices (like Smartphones) 還有 3. Simple devices (like sensors or RFID reader),在前兩種裡 面都可以透過 XMPP 的 client library 來跟 server 連線再與其他節點做互動, 第三種則必須針對裝置特性個別做設計才能透過 XMPP 做資料傳輸。Bazzani 等人 [17] 則把 VIRTUS Middleware 進一步的應用再 E-Health 的領域中,並拿 SOA based 的 Middleware solutions 來跟 VIRTUS 做比較,結論是在 e-Health 這個領域,VIRTUS 比 SOA based 的好用。
2.2.5 Ad-Hoc way Villanueva 等人 [21] 提出了 RFID 的追蹤在產品倉儲、物流上的應用通常伴 隨著貨物賣出之後他的生命週期就結束了。而它們提出了一個商業模型,從追蹤 整個商品從生產到賣出到回收的整個生命週期,來從分析出對於商業利益有效 的資訊,所以它們必須要製作一個更大的 IoT 環境來達到他們的理想,所以它 們在這篇中探討各種 IoT Middleware 能夠幫助到它們的部分最後他們也了做了 一些實驗來確認他們所提出的理論可行性,不過離所謂的 global tracking system 應該還是有一大段的距離。Gusmeroli 等人在 IoT @ Work 這個專案 [22] 設計出 一個稱為 Event Notification Service – ENS 的 Middleware 架構,主要是應用在 製造業製造流程,它們希望可以發展出一個 self-configuration 的機制讓機器在運
作的過程中可以依照上層的指令自動轉換組態。ENS 的架構主要是利用 AMQP (Advanced Message Queuing Protocol) protocol(現由 OASIS 維護),這也是一個 類 SOA 的架構。
第三章
研究概述
圖 4: Overview3.1
為物聯網應用的軟體開發者設計的中介軟體
在探討了數個物聯網中介軟體後,我們發現,大部分的物聯網中介軟體著重 在異質網路的整合上,較少從應用軟體開發的角度出發,提供物聯網應用軟體開 發者可以增進開發效率的支援。因此,本研究提出一個中介軟體,協助開發者省 去整合硬體的時間、加速物聯網應用程式的開發。3.2
與裝置可隨插即用的使用者介面
在物聯網的應用中,使用者介面是提供服務使用者與實體裝置互動的重要橋 梁。過往在 IoT 裝置的應用開發上,需要針對不同用途之裝置,依其特性重新設計其使用者介面,才能在軟體的世界中顯示裝置所收集、感測到的資訊並對其 進行操作。但這些被開發出來的使用者介面,可重用性不高,且耗費許多開發時 間。所以本研究提出的中介軟體,將以可隨插即用的使用者介面為目的,協助開 發者取得使用者介面,載入到應用程式中使用。圖 4是我們的概述圖,應用程式 可以透過此中介軟體與物聯網環境中的硬體裝置建立連線,依據裝置上的描述檔 為其至第三方下載可使用的使用者介面,並載入使用者介面至應用程式中,使裝 置能夠隨插即用的與使用者介面結合。
3.3
問題探討
為了使我們的中介軟體滿足上述的功能,我們遭遇到了下列問題: 1. 裝置如何連線到中介軟體上 2. 如何達成裝置與使用者介面的配對 3. 使用者介面應該以什麼樣的方式存在才能供開發者直接載入至程式中使用 在問題 1 的解決方式上,由於在 IoT 的環境裡裝置的異質性過高,開發應 用時必需考慮到硬體操作介面以及通訊介面的整合。而對於軟體開發者來說,需 要的只是硬體被抽象化後在軟體世界裡面可以被操作的物件。所以我們引用了在 軟體設計樣式 (Design Pattern) 裡的一個 Adaptor Pattern 樣式的概念,實做一個轉接裝置 (Adaptor),如圖 5所示,利用 Adaptor 建立裝置與中介軟體之間的 連線,並賦予裝置與 Middleware 可以互相操作使用的能力。
圖 5: Device Communication Adaptor
而針對問題二我們將在裝置端附加使用者介面的描述檔,並利用 JSON 格 式來儲存這個描述,裝置與中介軟體建立連線後,中介軟體將依據使用者介面的 描述檔,為裝置搜尋可用的使用者介面。而為了解決問題 3,我們將在中介軟體 中引用 OSGi 這個軟體框架,由於 OSGi 的 bundle 是可以被動態載入,不需重 新編譯、安裝,即可在框架中被動態執行。我們利用這個特性將使用者介面包裝 成 bundle 的型態,中介軟體可以透過 OSGi 來動態載入使用者介面供開發者使 用,達到隨插即用的目的。
第四章
系統分析與設計
4.1
系統需求
由上述的研究概述中,我們將系統需求分成三大部分: 1.Middleware 如表 1所述。 2.Device Adaptor 如表 2所述。 3.UI Repository 如表 3所述。 4.1.1 Middleware Middleware 部分是整個系統的核心,其中包含了通訊連結、UI 配對以及動 態載入等模組,主要由 Host 來調用這些模組,同時 Host 也是提供開發者 API 的核心模組。4.1.2 Device Adaptor
Device Adaptor 是為了轉接裝置到中介軟體上所設置的硬體,根據需求我們 會在此建立 JSON 格式的 UI Description 供中介軟體配對 UI,建立 Middleware Connector, 使 用 WiFi 功 能 與 中 介 軟 體 建 立 連 線, 當 UI bundle 被 啟 用 後 Interaction Manager 會負責與 UI 間的互動。
表 1: 系統需求-Middleware
Middleware
FR101 Middleware Host
Host hosts all abstract device instances and serves as a bridge between application and the middleware. When Communication Manager notified a new device is connected, the Middleware Host creates a new abstract device instance and save the UI description received from device. Then it calls the UI Match Maker to find appropriate UI components and send back the list of UIs. The application developer can get the list and decide what they want to install.
FR102 Communication Manager
Communication Manager is responsible for establishing communication links between pluggable devices and middleware. It will notify the host to create an abstract device when a new device was connected to middleware and, It will receive the UI description that were sent from device.
FR103 UI Match Maker
UI Match Maker is responsible for find appropriate UI components ac-cording to the UI description from the UI repository. It saves profiles and locations of appropriate UI components to the abstract device. FR104 Dynamic UI Loader
Dynamic UI Loader aims to download UI component based on the de-veloper’s selection and installs it for applications to make it available on execution time of applications
表 2: 系統需求-Device Adaptor
Device Adaptor
FR201 UI Description
UI Description describes what the device is and stores the descrip-tion,profile of the user interface of the device. It supplies features of the device which was adapted to middleware for matching UI components in the middleware.
FR202 Middleware Connector
Enables various devices with communicating ability for establishing con-nection with the middleware.
FR203 Interaction Manager
After the application installed the UI, Interaction manager will help the device to interact with UI component matched by the middleware.
表 3: 系統需求-UI Repository
UI Repository
FR301 UI Manager
The UI manager provides the functionalities of storing and downloading UI components .
FR302 UI Repository
The middleware get the list of corresponding UI components,from the UI repository based on UI descriptions of devices.
FR303 UI Component
UI Component helps applications present the user interface for interact-ing with physical devices.
4.1.3 UI Repository
UI Repository 主要是記錄 UI bundle 相關資訊的資料庫,資料表範例如 6所 示。
4.2
系統架構
圖 7: System Architecture 依照上述的系統需求,我們設計出系統架構,如圖 7所示。Middleware Host 為 整 個 中 介 軟 體 的 主 要 模 組, 也 是 物 聯 網 應 用 程 式 開 發 者 撰 寫 程 式 時 的 主 要 入 口。 透 過 新 增 這 個 物 件 來 啟 動 整 個 中 介 軟 體。 啟 動 後, Communication Manager 將開始監聽是否有新的裝置被連上來,當有新裝置被 連線 Communication Manager 將要求裝至傳送 UI Description 到中介軟體上, 並通知 Middleware Host 新增一筆 Abstract Device 來記錄此裝置的內容。依 據 UI Description 要求 UI Match Maker 向 UI Repository 搜尋符合的 UI bundlelist。開發者此時可透過 Middleware Host 存取 UI bundle list 並選擇一個 UI bundle。選擇後 Dynamic UI Loader 將依據 list 上 bundle 的下載位址,下載 UI bundle 並安裝到實作的 OSGi 框架裡,最後開發者可以透過 Middleware Host 來 得到這個使用這介面的物件,並自行決定要將它使用在程式的哪個部分。圖 8說 明了應用程式、中介軟體、裝置以及 UI bundle repository 之間互動的順序
4.3
Class Diagram
圖 9: Overall Class Diagram
依照系統架構規劃 Class Diagram,分成 Middleware Host、Communica-tion Manager、UI Match Maker、Dynamic UI Loader 四個部分,整體架構如圖 9所示,其餘分別由圖 10、圖 11、圖 12、圖 13表示。類別圖中 Package 與系統 架構圖中的模組對應關係如表 4所示
表 4: Corresponding Module in Archetecture Module in Archetecture Response Package
Middleware Host com.dayo.middleware.host
Communication Manager com.dayo.middleware.commManager UI Match Maker com.dayo.Middleware.uiMatchMaker Dynamic UI Loader com.dayo.middleware.dynamicUiLoader
4.3.1 Middleware Host
圖 10: Middleware Host Class Diagram
Middleware Host 為本中介軟體的主要入口,在 JAVA 中可藉由 New 一 個 MWHost 物件來啟用整個中介軟體,啟用後 MWHost 將要求 Communication
Manager 開 始 監 聽 是 否 有 新 的 裝 置 連 線, 這 邊 實 作 了 一 個 Observer Pattern 的 Observer 來 觀 察 Communication Manager。 當 有 新 的 裝 置 連 線 後, 首 先 MWHost 會新增一個 AbstractDdevice 的物件並從 Communication Manager 擷 取裝置上的 UI Description 供其他模組使用。再來 MWHost 將要求 UI Match Maker 針對 UI Description 內的裝置型態來配對適合的 UI bundle,然後回傳 bundle 的 list 到 MWHost,開發者可利用 MWHost.requestUI() 來得到這個 list, 選定想要的 bundle name 將其當成參數傳進 getUIView() 中,MWHost 就會要 求 Dynamic UI Loader 至 UI bundle 儲存的位址下載 UI bundle 並將其安裝至 OSGi 的框架中,而後 Dynamic UI Loaderc 會 trace 出 UI bundle 註冊在 OSGi 裡的 View 物件,回傳給 MWHost 使用。
4.3.2 Communication Manager
圖 11: Communication Manager Class Diagram
Communication Manager 負責監控各種裝置連接至中介軟體的狀況,目 前只實作了 WiFi 的介面,利用 JAVA 的 Socket 來建立監聽的功能。當有新的 裝置被連上來時,CommListener 會要求裝置端傳送 UI Description 過來,然後 將 JSON 格式的 UI Description 解析之後存入 AbstractDevice 相對應的 tribute 中再將 AbstractDevice 回傳至 Middleware Host。
4.3.3 UI Match Maker
圖 12: UI Match Maker Class Diagram
UI Match Maker 負責為連上來的裝置做 UI 的配對,依據 UI Description 中 描 述 裝 置 型 態 的 參 數 向 UI Repository 要 求 資 料 比 對, 目 前 實 做 了 關 鍵 字比對。完成比對後將結果用 arrayList 存起來,裡面包含 0 到數個不等的 UIbundleObject 回傳給 MWHost 使用。UIbundleObject 主要包含該 UIbundle 儲存的位址,可供 Dynamic UI Loader 使用。
4.3.4 Dynamic UI Loader
圖 13: Dynamic UI Loader Class Diagram
Dynamic UI Loader 主要實做了一個 OSGi 的框架,利用 OSGi 可動態載 入 bundle 使用的優點,當開發者選定 UI bundle 後,Dynamic UI Loader 會至 UI bundle 的儲存位址下載回來安裝,UI bundle 被安裝並啟動後會在 OSGi 框架 內註冊一個 View 的服務,Dynamic UI Loader 會 trace 此服務然後將 UI bundle 內的 View 回傳至 MWHost,開發者可自行決定要在哪裡使用這個 View。
第五章
案例研究
本章節將於 Android 平台使用本論文所提出之中介軟體實做 IoT 應用程式, 我們將以實現一個可隨插即用的溫濕度感測器為例。 圖 14: 實驗架構圖5.1
實驗架構說明
圖 14為實驗的架構,我們在 Android 平台上建立一個 app 專案調用我們 的 middleware 監聽裝置連線,溫濕度感測器透過 arduino 與 wifi 模組建立的 Adaptor 來與 middleware 連線,連線後,middleware 將會替 Android 的 app 找 到可用的 UI,app 透過 middleware 得到 UI 後即可讓使用者操作。5.2
使用硬體簡介
圖 15: DHT11 by Keyes
感測器使用的是 Keyes 公司製造的模組化的 DHT11,可偵測兩種數值,溫度 與濕度,度量分別是 ◦C 與% 。
uartsBee 可用 USB 與 PC 連接,並可在上面燒錄 arduino 程式,搭配 WiFi 模
圖 16: uartsBee V4.0
圖 17: WiFi Bee
WiFi Bee 可賦予 uartsBee 無線傳輸的功能,透過設定能從無線基地台取得網 路連線。
5.3
API of Proposed Middleware
圖 18: API of Proposed Middleware
本論文提出一組 API,開發者於 JAVA 環境下匯入我們的 library 後, New 一個 MWHost 的物件即可調用我們的 middleware,API 列表如圖 18所示, Method Detail 如圖 19-23 所示
圖 19: Method Detail - inStart
圖 20: Method Detail - inStop
圖 22: Method Detail - requestUI
5.4
實驗系統展示
圖 24: 程式碼說明
圖 24是使用 Middleware 的程式範例,首先調用了 MWHost 物件 host 並啟動,監聽到新裝置後取得 bundle list,而後用 AlertDialog 讓使用者選取 bundle,最後調用 host.getUIView 並設定其成為內容畫面。實驗畫面如圖 25、 26所示。
5.4.1 實驗系統畫面展示
圖 25: 實驗展示-左. 啟動 Middleware; 中. 開始監聽; 右. 發現新裝置
第六章
結論與未來展望
6.1
結論
本研究主要貢獻為發展一套中介軟體,並設計一組 API 提供 IoT 軟體應用 程式的開發者, 透過這個 Middleware 與 IoT 裝置建立連線並取得第三方開發的 使用者介面動態載入使用,透過這樣的方式進行開發時,就不再像過去需要針對 式的對每個裝置製做特定的使用者介面,除了降低 IoT 應用程式的開發成本、 縮短開發過程外,還增加了使用者介面的可重用性。6.2
未來展望
在未來的發展上我們有以下三點方向: (1) 目前在 Middleware 的使用目標只實現在隨插即用的使用者介面上,未來希 望能夠再擴展更多對 IoT Device 的支援 (2) 目前實做出來的程式只支援單一裝置,未來希望能支援多個裝置並能組合多 裝置的服務。參考文獻
[1] P. fei Fan and G. zhao Zhou, “Analysis of the business model innovation of the technology of internet of things in postal logistics,” in 2011 IEEE 18Th Inter-national Conference on Industrial Engineering and Engineering Management, Sept 2011, pp. 532–536.
[2] W. Chen, “Application of internet of things for electric fire control,” in 2011 International Conference on Electrical and Control Engineering, Sept 2011, pp. 4741–4743.
[3] W. Zhao, C. Wang, and Y. Nakahira, “Medical application on internet of things,” in IET International Conference on Communication Technology and Application, January 2011, pp. 660–665.
[4] N. Rohokale, V.M. andPrasad and R. Prasad, “A cooperative internet of things (iot) for rural healthcare monitoring and control,” in 2nd International Confer-ence on Wireless Communication, Vehicular Technology, Information Theory and Aerospace Electronic Systems Technology, Feb-March 2011, pp. 1–6.
[5] L. Li, “Application of the internet of thing in green agricultural products supply chain management,” in International Conference on Intelligent Com-putation Technology and Automation, March 2011, pp. 1022–1025.
[6] Z. Feng, “Research on water-saving irrigation automatic control system based on internet of things,” in International Conference on Electric Information and Control Engineering, April 2011, pp. 2541–2544.
[7] L. Chunli, “Intelligent transportation based on the internet of things,” in 2nd International Conference on Consumer Electronics, Communications and Net-works, April 2012, pp. 360–362.
[8] Y. Cao, W. Li, and J. Zhang, “Real-time traffic information collecting and monitoring system based on the internet of things,” in 6th International Con-ference on Pervasive Computing and Applications, Oct 2011, pp. 45–49.
[9] X. Xu, Y. Zuo, and G. Wu, “Design of intelligent internet of things for equip-ment maintenance,” in International Conference on Intelligent Computation Technology and Automation, March 2011, pp. 509–511.
Comput. Netw., vol. 54, no. 15, pp. 2787–2805, Oct. 2010. [Online]. Available: http://dx.doi.org/10.1016/j.comnet.2010.05.010
[11] M. Chaqfeh and N. Mohamed, “Challenges in middleware solutions for the internet of things,” in International Conference on Collaboration Technologies and Systems, May 2012, pp. 21–26.
[12] A. Azzara, S. Bocchino, P. Pagano, G. Pellerano, and M. Petracca, “Mid-dleware solutions in wsn: the iot oriented approach in the icsi project,” in 21st International Conference on Software, Telecommunications and Com-puter Networks, Sept 2013, pp. 1–6.
[13] B. Valente and F. Martins, “A middleware framework for the internet of things,” in The Third International Conference on Advances in Future In-ternet, August 2011, pp. 139–144.
[14] Z. Wang, Y. Yang, L. Wang, and W. Wang, “A soa based iot communication middleware,” in International Conference on Mechatronic Science, Electric Engineering and Computer, Aug 2011, pp. 2555–2558.
internet of things,” in International Conference on Pervasive Computing and Communications Workshops, March 2012, pp. 455–458.
[16] D. Conzon, T. Bolognesi, P. Brizzi, A. Lotito, R. Tomasi, and M. Spirito, “The virtus middleware: an xmpp based architecture for secure iot communi-cations,” in 21st International Conference on Computer Communications and Networks, July-Aug 2012, pp. 1–6.
[17] M. Bazzani, D. Conzon, A. Scalera, M. Spirito, and C. Trainito, “Enabling the iot paradigm in e-health solutions through the virtus middleware,” in Trust, Security and Privacy in Computing and Communications (TrustCom), 2012 IEEE 11th International Conference on, June 2012, pp. 1954–1959.
[18] Z. Song, A. Cárdenas, and R. Masuoka, “Semantic middleware for the internet of things,” in Internet of Things, Nov-Dec 2010, pp. 1–8.
[19] C. Perera, A. Zaslavsky, P. Christen, M. Compton, and D. Georgakopou-los, “Context-aware sensor search, selection and ranking model for internet of things middleware,” in 14th International Conference on Mobile Data Man-agement, 2013, pp. 314–322.
[20] M. Zhou, H. Fan, and Y. Ma, “Semantic annotation method of iot middle-ware,” in Fourth International Conference on Intelligent Control and Infor-mation Processing, June 2013, pp. 495–498.
[21] F. Villanueva, D. Villa, F. Moya, M. Santofimia, and J. Lopez, “Internet of things architecture for an rfid-based product tracking business model,” in Innovative Mobile and Internet Services in Ubiquitous Computing (IMIS), 2012 Sixth International Conference on, July 2012, pp. 811–816.
[22] S. Gusmeroli, S. Piccione, and D. Rotondi, “Iot@work automation middleware system design and architecture,” in Emerging Technologies Factory Automa-tion (ETFA), 2012 IEEE 17th Conference on, Sept 2012, pp. 1–8.
[23] C. Perera, A. Zaslavsky, P. Christen, M. Compton, and D. Georgakopou-los, “Context-aware sensor search, selection and ranking model for internet of things middleware,” in Mobile Data Management (MDM), 2013 IEEE 14th International Conference on, vol. 1, June 2013, pp. 314–322.
[24] “Json,” in http://http://www.json.org/.
[26] “Socrades project,” in http://www.socrades.eu.