3.1. Architecture
The hardware of the HEM platform comprises multiple device categories.
Though the traditional HEM platform disaggregates devices in terms of connecting, sensing, actuating and communicating, today’s advances in the embedded system allow having all these functionalities in one package within the HAN known as a network node. Our platform uses the popular Arduino AVR&ARM and ESP32 hardware as central slave processing units.
Gateway: Communication within IoTivity middleware is mainly IP-based based (Wi-Fi and ethernet). The gateway thus offers protocol translation from the Local COAP based HAN to HTTP/S-based cloud connectivity either as BaaS or SaaS providing the platform with pub-sub (Live-Query) mechanism.
Computing: The devices that store, process, and analyze data within the platform. Low-level computation is performed at the HAN servers or nodes. However, high-level computation and storage are distributed between the local gateway and the Back4App BaaS infrastructure for performance and processing disaggregation.
Figure 2 shows the hardware architecture used for a two-way communication, data acquisition, processing, and storage within the proposed platform. As described in
Section 1, our novel platform incorporates all state-of-art, open-source IoT Enabling technologies for higher-end HEM deployment.
Each node can be interacted with outside the Local COAP Network. However, miniaturization and cost-effectiveness require the gateway to primarily handle computations and all non-local resources and data requests while acting as a proxy server for the local node to remote clients.
3.2. Software Architecture
Several technologies facilitating IoT application development and deployment for smart homes are adopted to guide experimental development. Adopting state-of-the-art solutions, we focus on open-source software technology to alleviate the complexity of proprietary software and the related cost.
For the sensing and actuating and resource server node, the firmware leverages open real-time operating system (RTOS), namely Contiki OS, a bundle whose memory footprint is scaled to fully run-on different Arduino architecture (AVR & ARM), thus adding more consistency, scalability, modularity, and compactness to the local server firmware.
3.2.1. HAN Middleware
Our platform will handle local networks’ interoperability, scalability, and device management complexities using the OCF-IoTivity framework, a communications framework for IoT enabling smooth peer-to-peer connectivity amongst devices irrespective of the underlying OS or protocol satisfying several requisites of the Internet of Things [
8].
Therefore, IoTivity eases the home area network management by handling resource discovery, device management, protocol conversion, and security requirement for the platform. IoTivity-Lite, the OCF release for the constrained devices was recently released primarily for hardware within category 3 (
Figure 1). Thus, an adaptation or port was developed to support lower category devices on IoTivity-Lite.
3.2.2. IoTivity-Lite Arduino Port
To maintain low cost within the platform, we decided to port the IoTivity-Lite framework to lower category devices (category 1 & 2). In this regard, we targeted the popular Arduino MCU and the Espressif ESP32 Wi-Fi MCU. However, the port of the IoTivity framework relies on an OS running on the MCU.
Based on the literature review on RTOS and the state-of-art, we considered two OS, mainly FreeRTOS and Contiki OS. These RTOS are popular for low power, low-cost MCU. However, we used the Contiki OS on the Arduino MCU because of its low memory footprint and simplicity in developing firmware that is seamless to IoTivity-Lite integration using Contiki OS itself within its stack. In the case of the ESP32 (~500 Kbytes of RAM), we adapted an Initial IoTivity port based on the FreeRTOS OS.
3.2.3. Gateway to Local HAN Server Interaction
The OCF IoTivity group avails a JavaScript port of the IoTivity stack running on the Node engine or IoTivity-node for the high-level device. Using the IoT-rest-API-server, a NodeJS REST server for HTTP-based communication leveraging IoTivity-node as a client for the local CoAP network devices.
Thus, we used the IoTivity-node empowered IoT-rest-API-server on the gateway device (Raspberry PI) to manage discovery and resources access within the IoTivity-Lite network.
3.2.4. Cloud Tools and Infrastructure
In this work, the Cloud is mainly used as a Backend-as-a-Service (BaaS), offering the pub-sub mechanism (Live Query) subscriptions service on the platform data. It provides storage, backend service related to computation, and Home Automation (HA) services. We used Parse, an open-source server providing a RESTful API for a plethora of devices and OS on the different programming languages (the JavaScript API was used).
Parse server is flexible and can be hosted and migrated from one cloud platform to another. Though Google Cloud and Amazon are the most popular in terms of Cloud Hosting, there are no native Parse server environments and lack important Parse BaaS tools. In this regard, we used the back4App Cloud platform to provide computing, storage (mango DB), server management, Live-Query, Cloud background Jobs and third-party login (i.e., Facebook), and mobile push notification (mainly Android) all as BaaS for an IoT platform centered on a mobile or web application.
3.3. Communication Architecture
In this work, the Cloud is mainly used as a Backend-as-a-Service (BaaS), offering the pub-sub mechanism (Live Query) offering subscriptions service on the platform data. It provides storage, backend service related to computation, and feedback Home Automation (HA) services. We used Parse, an open-source server providing a RESTful API for a plethora of devices and OS for the different programming languages (We use the JavaScript API).
Parse server is flexible and can be hosted and migrated from one cloud platform to another. Though Google Cloud and Amazon are the most popular in terms of Cloud Hosting, there are no native Parse server environments and important Parse BaaS tools are lacking. In this regard, we used the back 4AppCloud platform to provide computing, storage (Mango DB), server management, Live-Query, Cloud background Jobs and third-party login (i.e., Facebook), and mobile push notification (mainly Android) all as BaaS for an IoT platform centered on a mobile or web application.
The IoT-rest-API-server provides the gateway with HTTP/HTTPS access to IoTivity-Lite HAN slave servers when powered on. Next, the “main server” process initializes connectivity to the cloud BaaS infrastructures on Back4App cloud. On the cloud BaaS, we create an App, databases table, namely, “Loads” storing appliances data, “SmartHomes” storing all registered smart home data, “DRM” storing DRM data for each smart home (
Figure 3). We implemented an “owning” relationship amongst the different classes to scale this deployment to multiple smart homes.
Figure 3. Platform databases structure and connections on Back4App BaaS.
This mechanism scales the system by enabling many owners in the “User” table to own a specific “smart home” that owns many different appliances in the “Loads” table and a specific “DRM” object (
Figure 4). Moreover, this method allows us not to create a class/table for each smart home context, thus keeping all related data together, easing development and maintenance. Following a user login/signup process, the “main server” starts a pub-sub subscription to the related “smart home”, DRM, and Loads resources on the cloud platform using the Parse Server Live Query mechanism (
Figure 4).
Figure 4. Local and cloud configuration and communication in the platform.
This connection is realized by authenticating the user and defining the “smart home” against the username. This tool is part of the Back4App BaaS services and is user-configurable by adding the classes (holding database entries/objects) that will be part of the subscription services. It enables each client endpoint to receive events on the entry in the subscription list.
The events emitted within the subscription are the “create” and “update” events received in real-time by the subscribed client alongside meta-data regarding the specific entry being created/updated. We initialized the Parse server Live Query mechanism using our Back4App application ID, JavaScript Key, and its Master Key for authentication purposes.
A useful feature of the Parse server on the Back4App platform is the cloud code functionality. This tool enables the developer to run NodeJS functions directly on the Back4App cloud. This step immediately makes the cloud code functions available to the IoT platform. Cloud code functionality offers energy utilities a backdoor to implement incentives and management programs (Utility DRM portal). After configuration, the gateway server initiates a login/signup sequence with the cloud user authentication services.
Next, the gateway server initiates the local DBs (“Monitor” and “Loads” tables are created if not existing already). For offline storage we used MySQL DB engine. This storage is synchronized with an initial DB query to the online storage which returns the provisioned number of loads. This process is two-fold.
First, the gateway server sends a DB query for the number of known and provisioned appliances. Then, it retrieves those from the local storage that can store newly discovered appliances. Secondly, a resource discovery request is sent to the IoT-rest-API-server service. This server generates a multicast request on the IoTivity COAP network to retrieve all resources. Subsequently, each appliance in the local DB is updated after submitting GET requests for their properties (state, power, and current).
Lately, the remote DB appliance properties are also updated. After initialization, an observation service on the IoTivity network using the OBSERVE mechanism is started, and resource properties are regularly updated.
When a mobile client using the energy app participates in the platform information exchange, first, the app establishes a connection to the cloud backend and starts a client subscription (
Figure 5). After the client successfully completes login/signup, Parse server BaaS security features are used on the client and the home gateway to provide two-way secured data communication. All GET requests are submitted as Parse GET queries for each mobile client to access the related homes databases.
Figure 5. Communication flow with remote/local Android smartphone app.
Lastly, the remote DB appliance properties are also updated. After initialization, an observation service on the IoTivity network using the OBSERVE mechanism is started and resource properties are regularly updated.
When a mobile client uses energy, the app participates in the platform information exchange. First, the app establishes a connection to the cloud backend and starts a client subscription (
Figure 5). The client successfully login/signup as an authenticated user. The system uses the Back4App Parse security features on the client and the home gateway side to provide secured data communication in both ways. All GET requests are submitted as Parse GET queries for each mobile client to access the related homes databases.
A PUT request is forwarded to the Parse server on the cloud platform. As the gateway server is in Live Query mode, those requests are received as update events. The gateway server thus generates an HTTP POST request to the IoT-rest-API-server which generates a CoAP POST (i.e., /api/oic/ktn/kettle? di =’’) with the new state (i.e., state: true/false) that turn the corresponding appliance on/off. Using the Parse Live query mechanism (observation), the smartphone App listens to updates on appliances’ power properties from the gateway server’s observer process and updates the App front-end.