IoTivity Cloud-Enabled Platform for Energy Management Applications

: In developing countries today, population growth and the penetration of higher standard of living appliances in homes has resulted in a rapidly increasing residential load. In South Africa, the recent rolling blackouts and electricity price increase only highlighted this reality, calling for sustainable measures to reduce overall consumption and peak load. The dawn of the smart grid concept, embedded systems, and ICTs have paved the way for novel Home Energy Management Systems (HEMS) design. In this regard, the Internet of Things (IoT), an enabler for intelligent and efﬁcient energy management systems, is the subject of increasing attention for optimizing HEMS design and mitigating its deployment cost constraints. In this work, we propose an IoT platform for residential energy management applications focusing on interoperability, low cost, technology availability, and scalability. We addressed the backend complexities of IoT Home Area Networks (HAN) using the Open Consortium Foundation (OCF) IoTivity-Lite middleware. To augment the quality, servicing, reduce the cost, and the development complexities, this work leverages open-source cloud technologies from Back4App as Backend-as-a-Service (BaaS) to provide consumers and utilities with a data communication platform within an experimental study illustrating time and space agnostic “mind-changing” energy feedback, Demand Response Management (DRM) under a peak shaving algorithm yielded peak load reduction around 15% of the based load, and appliance operation control using a HEM App via an Android smartphone.


Introduction
The growing energy consumption in South Africa constitutes a significant impediment to energy supply sustainability. This situation is particularly alarming in domestic areas, which make up a growing share of peak loads and energy wastage. The recent rolling blackouts and electricity price increase only highlighted this reality and calls for sustainable measures to reduce overall consumption [1]. But in such context, the cost and complexities of grid interventions in the residential sector has limited energy utility initiatives to an awareness and educational campaign and flash addresses on digital media to address energy wastage [2].
However, the growing demand emphasized the limitation of these interventions. Therefore, it is necessary for the grid to extend its technological tools to residential buildings. HEMS provides consumers with feedback on appliances or equipment operation and offers an automation platform for implementing energy management strategies [3]. However, traditional HEMS suffer several design and architectural limitations. Indeed, constraints related to device interoperability, data granularity, system reusability and scalability, computing power, and hardware cost have impeded HEMS performance and restricted their penetration in households [4].
Nevertheless, the advent of IoT, cloud computing, and related technologies mitigate these factors and open novel opportunities in HEM design and deployment. Furthermore, the size reduction of embedded systems, and the proliferation of networking equipment IoT 2022, 3 74 in living spaces offers the opportunity to build sophisticated and cost-effective home area networks (HAN).
Focusing on the "everything connects to each other" principle, IoT bridges the semantic gap regarding the ubiquity of IoT network devices [5]. It mitigates the cost and device resources limitations and cost factors that restrict HEM real-world applications. However, IoT is not a stand-alone paradigm. Rather, it is an assortment of several technologies working together. In recent times the interaction between IoT devices and the surrounding environment has expanded and generated an enormous amount of data to be handled [6].
The resource-limited nature of IoT demands expensive hardware and software to store the bulk amount of data [7]. To avoid these limitations, data communications in IoT leverage cloud-based computing infrastructures to accommodate big data requirements, provide protocols translation, data abstraction, and higher computing power ( Figure 1) [8]. Lately, numerous research ventures have focused on combining cloud computing and IoT to provide users improved services accessible anywhere at the same time.
IoT 2022, 2, Nevertheless, the advent of IoT, cloud computing, and related technologies mitig these factors and open novel opportunities in HEM design and deployment. Furthermo the size reduction of embedded systems, and the proliferation of networking equipme in living spaces offers the opportunity to build sophisticated and cost-effective home a networks (HAN).
Focusing on the "everything connects to each other" principle, IoT bridges the mantic gap regarding the ubiquity of IoT network devices [5]. It mitigates the cost a device resources limitations and cost factors that restrict HEM real-world applicatio However, IoT is not a stand-alone paradigm. Rather, it is an assortment of several te nologies working together. In recent times the interaction between IoT devices and t surrounding environment has expanded and generated an enormous amount of data be handled [6].
The resource-limited nature of IoT demands expensive hardware and software store the bulk amount of data [7]. To avoid these limitations, data communications in I leverage cloud-based computing infrastructures to accommodate big data requiremen provide protocols translation, data abstraction, and higher computing power (Figure [8]. Lately, numerous research ventures have focused on combining cloud computing a IoT to provide users improved services accessible anywhere at the same time. As stated in [9], the cloud "promises high reliability, scalability, and autonomy" future IoT applications. That is, cloud-based platforms support connectivity to thin Such platforms make anything accessible in a time and space agnostic manner, thus voring user-friendliness and performance through backend services (computing, stora connectivity) or BaaS [10]. Currently, research on IoT middleware has shown that I middleware can greatly alleviate issues related to device interoperability, network sca bility, and device management within HAN networks. Thus, IoT middleware favor re world HEM applications. As stated in [7], middleware in the IoT shall address intern and things issues, handle semantics gap, context awareness, device discovery, mana device resources, big data, and privacy.

State of the Art
IoT is a novel ICT paradigm showing promise in various studies regarding IoT pl forms for HEM. The authors in [11] designed and implemented a home automation s tem that leverages IoT to control most household appliances over an easily adaptable w interface. The planned system offers great flexibility by using Wi-Fi technology to conn its spread-out sensing devices to a home automation server. Such an implementation g is to decrease the system deployment cost and facilitate future system upgrades and configuration.
Nevertheless, this setup is archaic and incurs a scalability issue added to the fact th the connection to the home gateway via its IP requires the restrictive private DNS in ma developing contexts as this suggests a payable subscription to some ISP. Here the Clo is used as SaaS to forward an email notification to users. However, the non-real-time n ture and textual format of email limit the depth of feedback and analytics that can be do on the consumption data. As stated in [9], the cloud "promises high reliability, scalability, and autonomy" for future IoT applications. That is, cloud-based platforms support connectivity to things. Such platforms make anything accessible in a time and space agnostic manner, thus favoring userfriendliness and performance through backend services (computing, storage, connectivity) or BaaS [10]. Currently, research on IoT middleware has shown that IoT middleware can greatly alleviate issues related to device interoperability, network scalability, and device management within HAN networks. Thus, IoT middleware favor real-world HEM applications. As stated in [7], middleware in the IoT shall address internet and things issues, handle semantics gap, context awareness, device discovery, manage device resources, big data, and privacy.

State of the Art
IoT is a novel ICT paradigm showing promise in various studies regarding IoT platforms for HEM. The authors in [11] designed and implemented a home automation system that leverages IoT to control most household appliances over an easily adaptable web interface. The planned system offers great flexibility by using Wi-Fi technology to connect its spread-out sensing devices to a home automation server. Such an implementation goal is to decrease the system deployment cost and facilitate future system upgrades and reconfiguration.
Nevertheless, this setup is archaic and incurs a scalability issue added to the fact that the connection to the home gateway via its IP requires the restrictive private DNS in many developing contexts as this suggests a payable subscription to some ISP. Here the Cloud is used as SaaS to forward an email notification to users. However, the non-real-time nature and textual format of email limit the depth of feedback and analytics that can be done on the consumption data.
In [12], the authors propose an IoT platform targeting residential consumers leveraging smartphone and cloud technologies to offer Smart grid empowered energy management (DRM signal) and home automation as services. To this end, the authors proposed a UHG transmitting collected data to the cloud via the network layer using Openfire as middleware on the Gateway to provide the pub-sub mechanism to push information to subscribers. This architecture alleviates the need for a private DNS at the consumers' side and significantly mitigates implementation constraints and cost.
Nonetheless, the XMPP is TCP-oriented (heavyweight) and expensive for lower-end devices. Moreover, it is unrecognized by the IETF standard for IoT. The Openfire server essentially lacks functionalities such as discovery and provisioning, and security is not supported on lower-end devices, thus increasing the cost. In [8], software architecture is proposed for efficient and secure energy management within the smart grid. At the heart of their platform is the IoT gateway (raspberry-PI) running on the Eclipse Kura framework, a free and scalable framework built on Java/OSGi used as middleware to offer hardware interoperability.
Moreover, cloud connectivity within the platform is enabled using Mosquito MQTT, pushing the stream of smart meter data to a message broker at the edge for analytics and knowledge extraction, and later forwarding the aggregated data securely to the cloud, preserving privacy. In this work, less attention is given to HAN devices management, resources provisioning, device discovery, and security. Furthermore, the middleware being used required higher category hardware (see Figure 1) that can run the Java Virtual machine (JVM). This has the drawback of mitigating the expected miniaturization of IoT implementation, increasing cost, and limiting scalability in developing contexts.
In [13], a fog computing-based platform for energy management focusing on interoperability, scalability, adaptability, and local and remote monitoring while leveraging open-source software/hardware enabled users to implement energy management with the customized control-as-services. The authors focused on facilitating the deployment of their platform in residential places by mitigating the cost associated with computing and communications devices software stacks. Thus, they focused on using popular, open-source hardware within their HAN. In this regard, The Raspberry PI acts as a home gateway and TelsoB mote running TinyOS communicating over Zigbee.
To support device-to-device communication, security, and device management, the author used the Devices Profile for Web Services (DPWS) middleware to abstract the management of HAN devices and provide web connectivity. However, the web interface provided relies on local router DNS info. This limits operation on the local network and increases the cost of implementation when an ISP subscription is required for remote control operations.
In [14], the authors proposed an energy management cloud platform based on the SaaS cloud model to enhance interoperability via the use of a universal smart energy management gateway based on a free Internet of Things (IoT) framework named IoTivity. The author used the IoTivity middleware to abstract from the monolithic, ad hoc implementation that locks traditional HEMS to a private protocol or mechanism, limiting the choice and spectrum of possible HAN. Therefore, a completed architecture that handles the platform requirement for data communication and device management from appliances on the HAN to services provided in the cloud was provided. However, because IoTivity is a CoAP based framework, the authors proposed a REST framework for bridging CoAP to HTPP to access their dedicated cloud infrastructure.
In [15], the authors proposed a framework for energy management applications running on a home gateway offering energy services for multi-homes running on Azure Cloud using dedicated 3rd party providers. Each home is incorporate a gateway (Intel (R) Core (TM) i3-2100 CPU) powered with Microsoft Lab of Things (Homes) middleware. The authors provided an Android mobile terminal and web dashboard using a publish/subscribe MQTT model and Azure push notification for front-end requirements. Nevertheless, being a gateway dedicated middleware, IoT limits the miniaturization of IoT HAN devices, thus increasing implementation costs.

Research Challenges and Concept Overview Section
In summary, the implementation of the HEM platform poses the following major issue: Middleware offering hardware abstraction, device management and discovery, connectivity, scalability, adaptability, services customization, and security. • Cloud platform either as SaaS or BaaS to export processing and add computing power, remote connectivity, and services.

•
Cost of implementing, hardware availability, and protocol stack.

Research Contributions
To address the above-mentioned challenges, our novel platform for HEM employs: • Open-source middleware using free and accepted IoT protocol stack and scalable to lower-end hardware to provide disaggregated interoperability, scalability, adaptability, HAN device management, discovery provisioning, and seamless device-to-device (D2D) connectivity and security. • Leverage, ubiquitous, low-cost and low-power embedded devices as HAN node, enhancing technology availability and penetration in a developing context.

•
Open-source cloud computing and storage as Software-as-a-Service and BaaS offsetting heavy computation and storage to cloud infrastructure as well as providing service for two-way connectivity via subscriptions mechanisms and free APIs to both local gateways and mobile devices for end-users providing integration and control that is both time and space agnostic.

Cloud-Enabled IoTivity Platform
Novel platforms for HEM should incorporate the features and requirements defined in Section 1 in order to be economical and affordable for the common consumer, and thus increase their penetration in living spaces. A cloud-enabled energy management platform based on the Backend-as-a-Service (BaaS) model built around the OCF IoTivity framework is proposed. The platform's architecture centers on standard protocols and open-source services and software. Figure 2 below, depicts an overview of the proposed architecture. We thus present a three-layer architecture consisting of a HAN gathering consumption data and controlling appliances. Next a home gateway to manage HAN devices and to handle cloud connectivity. Finally, a Cloud layer for computing, data storage, and remote services over the thirdparty tools and a smartphone App as user front-end for enhanced feedback. Additionally, the Cloud provides an interface to smart grid services as these are made available by utilities providers.

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, highlevel 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.

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, highlevel 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.

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 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.

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.

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.

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.

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.

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.

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 thirdparty 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.
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. 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" 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). 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 userconfigurable 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. 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). 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 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.
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.
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. 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. 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.

Experimental Results of Case Study
To evaluate the performance of our cloud-based IoTivity platform in addressing the challenges of HEM design, we implemented an experimental setup. Leveraging an energy application on an Android smartphone tested the platform's performance in providing real-time energy monitoring and home automation (HA). We then implemented a peak load management DRM algorithm to manage consumption at home. The HEM platform was deployed for the resistive load (appliance) as shown in Figure 6.
The detailed specification for the hardware used is listed in Table 1 below.

Experimental Results of Case Study
To evaluate the performance of our cloud-based IoTivity platform in addressing the challenges of HEM design, we implemented an experimental setup. Leveraging an energy application on an Android smartphone tested the platform's performance in providing real-time energy monitoring and home automation (HA). We then implemented a peak load management DRM algorithm to manage consumption at home. The HEM platform was deployed for the resistive load (appliance) as shown in Figure 6. The detailed specification for the hardware used is listed in Table 1 below. The HAN's devices or motes are designed and manufactured as plug-and-play shields (Figure 7). These shields provide the sensing and actuating interface to existing home appliances via non-invasive and safe electronics devices a DAQ shield on each mote is embedded with sensing and actuating electronics for 1Vrms CT sensor signal output and 30A AC actuating relays.
Communication within the HAN for the Arduino-based mote is Hardwire (Ethernet using the Wiznet 5500 ethernet shield), whereas Wi-Fi is used the ESP32 based motes.
The AVR-based mote is augmented with an external memory bank to improve its performance in handling the secured deployment of the IoTivity-Lite stack. The firmware running on the HAN devices (Arduino and ESP32) comprises the IoTivity-Lite server code and the low-level sensing and actuating code interfacing to the device's ADC and GPIO registers to control the mote actuation devices. This code is used by the higher-level server firmware within the GET and PUT methods.
The firmware calculates from the sensed current and voltage the power properties of each appliance connected to a mote based on the Arduino or ESP32 MCU. This computation is based on the algorithm that samples the current and voltage transformers for 25 The HAN's devices or motes are designed and manufactured as plug-and-play shields ( Figure 7). These shields provide the sensing and actuating interface to existing home appliances via non-invasive and safe electronics devices a DAQ shield on each mote is embedded with sensing and actuating electronics for 1Vrms CT sensor signal output and 30A AC actuating relays.
IoT 2022, 2,11 cycles (at 50Hz) or 500 ms to calculate the different Root Mean Square (RMS) power accumulated to compute the power consumption. We used a 10 bits ADC setting on Arduino AVR and 12 bits on ARM and ESP32.

Experimental Results
In this section, we present the case study results focusing on the observation of all scenarios executed to establish our platform performance. Using the setup in Figure 4, we test the feedback and home automation scenario within the platform. That is, we present the response from the IoTivity-Lite HAN server device. That is, the Arduino and ESP32 slaves' response to resource requests.
Then, we show the underlying software services handling the smart-home local and remote connectivity. In this regard, describing the different initialization steps via curtailed logs of each of the services running on our raspberry PI local home server. Secondly, we present feedback results, i.e., home consumption in real-time, and enhanced visualization anytime, anywhere via the energy app.
Thirdly, we demonstrate home automation using the energy app to turn home appliances on/off. Lastly, we detailed the DRM scenario condition and assumption and show the result of our peak shaving algorithm.
The firmware burnt on the HAN resource server runs the IoTivity-Lite core ported to the AVR and ARM Arduino Arch. In Figure 8 below, we see the initialization logs for the devices, which request a local IP address within the 192.168.0.1 subnet, initializing the IoTivity core, and starting a listening server on IPv4 port 56789 for Arduino devices. The ESP32 slaves use both IPv4 and IPv6 listening sockets provided by the IoTivity-Lite stack. Communication within the HAN for the Arduino-based mote is Hardwire (Ethernet using the Wiznet 5500 ethernet shield), whereas Wi-Fi is used the ESP32 based motes.
The AVR-based mote is augmented with an external memory bank to improve its performance in handling the secured deployment of the IoTivity-Lite stack. The firmware running on the HAN devices (Arduino and ESP32) comprises the IoTivity-Lite server code and the low-level sensing and actuating code interfacing to the device's ADC and GPIO registers to control the mote actuation devices. This code is used by the higher-level server firmware within the GET and PUT methods.
The firmware calculates from the sensed current and voltage the power properties of each appliance connected to a mote based on the Arduino or ESP32 MCU. This computation is based on the algorithm that samples the current and voltage transformers for 25 cycles (at 50 Hz) or 500 ms to calculate the different Root Mean Square (RMS) power accumulated to compute the power consumption. We used a 10 bits ADC setting on Arduino AVR and 12 bits on ARM and ESP32.

Experimental Results
In this section, we present the case study results focusing on the observation of all scenarios executed to establish our platform performance. Using the setup in Figure 4, we test the feedback and home automation scenario within the platform. That is, we present the response from the IoTivity-Lite HAN server device. That is, the Arduino and ESP32 slaves' response to resource requests.
Then, we show the underlying software services handling the smart-home local and remote connectivity. In this regard, describing the different initialization steps via curtailed logs of each of the services running on our raspberry PI local home server. Secondly, we present feedback results, i.e., home consumption in real-time, and enhanced visualization anytime, anywhere via the energy app.
Thirdly, we demonstrate home automation using the energy app to turn home appliances on/off. Lastly, we detailed the DRM scenario condition and assumption and show the result of our peak shaving algorithm.
The firmware burnt on the HAN resource server runs the IoTivity-Lite core ported to the AVR and ARM Arduino Arch. In Figure 8 below, we see the initialization logs for the devices, which request a local IP address within the 192.168.0.1 subnet, initializing the IoTivity core, and starting a listening server on IPv4 port 56789 for Arduino devices. The ESP32 slaves use both IPv4 and IPv6 listening sockets provided by the IoTivity-Lite stack.

Experimental Results
In this section, we present the case study results focusing on the observation of scenarios executed to establish our platform performance. Using the setup in Figure 4, test the feedback and home automation scenario within the platform. That is, we pres the response from the IoTivity-Lite HAN server device. That is, the Arduino and ESP slaves' response to resource requests.
Then, we show the underlying software services handling the smart-home local a remote connectivity. In this regard, describing the different initialization steps via c tailed logs of each of the services running on our raspberry PI local home server. Second we present feedback results, i.e., home consumption in real-time, and enhanced visu zation anytime, anywhere via the energy app.
Thirdly, we demonstrate home automation using the energy app to turn home app ances on/off. Lastly, we detailed the DRM scenario condition and assumption and sh the result of our peak shaving algorithm.
The firmware burnt on the HAN resource server runs the IoTivity-Lite core por to the AVR and ARM Arduino Arch. In Figure 8 below, we see the initialization logs the devices, which request a local IP address within the 192.168.0.1 subnet, initializing IoTivity core, and starting a listening server on IPv4 port 56789 for Arduino devices. T ESP32 slaves use both IPv4 and IPv6 listening sockets provided by the IoTivity-Lite sta

Feedback via Energy App
For the energy monitoring scenario, we evaluated the platform's ability to prov space-agnostic and real-time feedback. The firmware loaded in all slaves allows these vices to serve the client with resources data handling those as GET/POST requests. T

Feedback via Energy App
For the energy monitoring scenario, we evaluated the platform's ability to provide space-agnostic and real-time feedback. The firmware loaded in all slaves allows these devices to serve the client with resources data handling those as GET/POST requests. The IoT-rest-API-server provisioned devices and resources on the IoTivity-Lite local network after issuing a multicast request on the endpoint (localhost: 8000/ioc/res).
A client can thus request local resources to issue HTTP requests to the REST server. Figure 9 shows logs of GET requests received from the slaves, followed by the IoTivity-Lite stack processing of the request and a response (74 bytes of resource data) to the client on 192.168.0.111:59264.
A client can thus request local resources to issue HTTP requests to the REST serv Figure 9 shows logs of GET requests received from the slaves, followed by the IoTivi Lite stack processing of the request and a response (74 bytes of resource data) to the clie on 192.168.0.111:59264. Using a Sony Xperia Z5 smartphone we tested Energy feedback on our platform u ing the IoTSmartApp as shown in Figure 10 below.
The energy consumption is presented in engaging visual tools both graphic and te tual with compelling colors (red under the consumption curve). The evaluation show that feedback can be dispatched via the platform within ~3 s from HAN to the Back4A BaaS then to the smartphone App ( Figure 10). Using a Sony Xperia Z5 smartphone we tested Energy feedback on our platform using the IoTSmartApp as shown in Figure 10 below.
Using a Sony Xperia Z5 smartphone we tested Energy feedback on our platform using the IoTSmartApp as shown in Figure 10 below.
The energy consumption is presented in engaging visual tools both graphic and textual with compelling colors (red under the consumption curve). The evaluation shows that feedback can be dispatched via the platform within ~3 s from HAN to the Back4App BaaS then to the smartphone App ( Figure 10).

Home Automation via Energy App
We evaluated the platform's ability to provide space agnostic on/off control of the home appliances under consideration. In Figure 11, a POST interaction is performed whenever the client request and update an appliance status (On/Off).
After updating the state of an appliance from a POST request, the resource server sends a 39 bytes acknowledgment response to the requesting client at 192.168.0.111:8000.  The energy consumption is presented in engaging visual tools both graphic and textual with compelling colors (red under the consumption curve). The evaluation shows that feedback can be dispatched via the platform within~3 s from HAN to the Back4App BaaS then to the smartphone App ( Figure 10).

Home Automation via Energy App
We evaluated the platform's ability to provide space agnostic on/off control of the home appliances under consideration. In Figure 11, a POST interaction is performed whenever the client request and update an appliance status (On/Off). Using a Sony Xperia Z5 smartphone we tested Energy feedback on our platform using the IoTSmartApp as shown in Figure 10 below.
The energy consumption is presented in engaging visual tools both graphic and textual with compelling colors (red under the consumption curve). The evaluation shows that feedback can be dispatched via the platform within ~3 s from HAN to the Back4App BaaS then to the smartphone App ( Figure 10).

Home Automation via Energy App
We evaluated the platform's ability to provide space agnostic on/off control of the home appliances under consideration. In Figure 11, a POST interaction is performed whenever the client request and update an appliance status (On/Off).
After updating the state of an appliance from a POST request, the resource server sends a 39 bytes acknowledgment response to the requesting client at 192.168.0.111:8000. Figure 11. HAN server POST response. Figure 11. HAN server POST response.
After updating the state of an appliance from a POST request, the resource server sends a 39 bytes acknowledgment response to the requesting client at 192.168.0.111:8000.
In Figure 12, we present feedback about home automation via our IotSmartApp. This experimentation targets an iron-rated 1200 W within the tested setup. On Figure 12a the iron is off, thus its state is false (the lamp is grey). On Figure 12b the iron is turned on (lamp is yellow), the consumption (power) at that instant was recorded as 1.16 kW. In Figure 6, can practically be seen the Arduino server connected to the physical appliance control circuit in an activated (red light is on).
In Figure 12, we present feedback about home automation via our IotSmartApp. This experimentation targets an iron-rated 1200 W within the tested setup. On Figure 12a the iron is off, thus its state is false (the lamp is grey). On Figure 12b the iron is turned on (lamp is yellow), the consumption (power) at that instant was recorded as 1.16 KW. In Figure 6, can practically be seen the Arduino server connected to the physical appliance control circuit in an activated (red light is on).

DRM via Energy App
We implemented a DRM algorithm for peak load management as a service that aims to demonstrate the impact of our platform on residential load efficiency. We followed related works around HEM to define our experimental model.
To demonstrate the performance of their IoT architecture for residential load, the author in [15] implemented an experiment based on a maximum allowable peak threshold of 33 KW. The author's algorithm controls light bulbs at each house at peak time, slotting a 24-h time duration into 8640 time periods. That is their smart grid simulation detected the total demand every 10 s. The author in [13], implemented a smart transformer controlas-a-service over fog computing, limiting the load of each home at 4 KW. The algorithm monitors the status of the power source and activates a DR signal when overload by cycling all homes and shedding load in a home that has exceeded the 4 KW thresholds. In both studies, the demonstrated DRM does not consider user preferences. In [16], the authors introduced three-level priority scheduling for home appliances so users can switch on home appliances subject to their satisfaction level and preferences. Peak load DRM depends on mathematical models. The case study considers regularly operated or fixed home appliances and develops an algorithm based on appliances operation priority settings and equations from works proposed in [17,18].
The DRM algorithm used a default value of 5 KW based on the literature. Figure 13 depicts the experimental platform and its two-way data transmission.

DRM via Energy App
We implemented a DRM algorithm for peak load management as a service that aims to demonstrate the impact of our platform on residential load efficiency. We followed related works around HEM to define our experimental model.
To demonstrate the performance of their IoT architecture for residential load, the author in [15] implemented an experiment based on a maximum allowable peak threshold of 33 kW. The author's algorithm controls light bulbs at each house at peak time, slotting a 24-h time duration into 8640 time periods. That is their smart grid simulation detected the total demand every 10 s. The author in [13], implemented a smart transformer controlas-a-service over fog computing, limiting the load of each home at 4 kW. The algorithm monitors the status of the power source and activates a DR signal when overload by cycling all homes and shedding load in a home that has exceeded the 4 kW thresholds. In both studies, the demonstrated DRM does not consider user preferences. In [16], the authors introduced three-level priority scheduling for home appliances so users can switch on home appliances subject to their satisfaction level and preferences. Peak load DRM depends on mathematical models. The case study considers regularly operated or fixed home appliances and develops an algorithm based on appliances operation priority settings and equations from works proposed in [17,18].
The DRM algorithm used a default value of 5 kW based on the literature. Figure 13 depicts the experimental platform and its two-way data transmission.
The algorithm runs with an electricity price per unit considering a household in the research context (City of Cape Town) with consumption equal to or above 600 kWh/month. Municipality regulation rated the power consumption unit at 278.46 c/kWh (City of Cape Town, 2019).
The developed energy app is used to test the DRM scenario. In Figure 14, configuration windows are proposed to the user to set up the current DRM algorithm threshold, reset the smart home's appliance IDs, and activate/de-activate the DRM service running on the gateway server. When the user activates the DRM service, both the new status and threshold are passed to the listening home server via the Parse Live Query mechanism. The algorithm output for analysis was logged and plotted to appreciate the benefit of the peak-saving algorithm. The maximum allowable peak demand is 5 kW with a 10% positive margin (5.5 kW) based on appliances properties and priority setting in Table 2 above. We calculate the average power and energy cost, and maximum peak power. This data is made available as statistical info to each smart home user. The guiding Equations (A1)-(A3) digitized for the DRM algorithm are detailed in Appendix A. In Figure 14 below, configuration windows are proposed to the user to manage the DRM algorithm threshold (using the knob), reset the smart home s appliance IDs, and activate/de-activate (via the switch widgets) the DRM service running on the home server. The algorithm runs with an electricity price per unit considering a household in the research context (City of Cape Town) with consumption equal to or above 600 Kwh/month. Municipality regulation rated the power consumption unit at 278.46 c/kWh (City of Cape Town, 2019).
The developed energy app is used to test the DRM scenario. In Figure 14, configuration windows are proposed to the user to set up the current DRM algorithm threshold, reset the smart home's appliance IDs, and activate/de-activate the DRM service running on the gateway server. When the user activates the DRM service, both the new status and threshold are passed to the listening home server via the Parse Live Query mechanism. The algorithm output for analysis was logged and plotted to appreciate the benefit of the peak-saving algorithm. The maximum allowable peak demand is 5 kW with a 10% positive margin (5.5 kW) based on appliances properties and priority setting in Table 2 above. We calculate the average power and energy cost, and maximum peak power. This data is made available as statistical info to each smart home user. The guiding Equations (A1)-(A3) digitized for the DRM algorithm are detailed in Appendix A. In Figure 14 below, configuration windows are proposed to the user to manage the DRM algorithm threshold (using the knob), reset the smart home's appliance IDs, and activate/de-activate (via the switch widgets) the DRM service running on the home server.  We sampled appliance consumption at 10 min duration. However, a 5 min timeframe was used for peak simulation, running the algorithm at a 10 s interval then normalizing the resultThe grey and blue curve of Figure 15 denotes the load profile with and without the demand management, respectively, whereas the brown and green curves represent the peak cost of consumption with and without demand management.The red line shows the maximum allowable demand threshold (about 5.5 KW). When the demand exceeds the peak limit, the DRM service turns some appliances off according to the priority assigned. We can see the DRM load profile (brown curve) peak is lowered and the valleys are filled as expected of a peak shaving algorithm.  We sampled appliance consumption at 10 min duration. However, a 5 min timeframe was used for peak simulation, running the algorithm at a 10 s interval then normalizing the resultThe grey and blue curve of Figure 15 denotes the load profile with and without the demand management, respectively, whereas the brown and green curves represent the peak cost of consumption with and without demand management.The red line shows the maximum allowable demand threshold (about 5.5 kW). When the demand exceeds the peak limit, the DRM service turns some appliances off according to the priority assigned. We can see the DRM load profile (brown curve) peak is lowered and the valleys are filled as expected of a peak shaving algorithm. We sampled appliance consumption at 10 min duration. However, a 5 min timeframe was used for peak simulation, running the algorithm at a 10 s interval then normalizing the resultThe grey and blue curve of Figure 15 denotes the load profile with and without the demand management, respectively, whereas the brown and green curves represent the peak cost of consumption with and without demand management.The red line shows the maximum allowable demand threshold (about 5.5 KW). When the demand exceeds the peak limit, the DRM service turns some appliances off according to the priority assigned. We can see the DRM load profile (brown curve) peak is lowered and the valleys are filled as expected of a peak shaving algorithm.

Discussion
The main highlights from the experimental setup concerning the research objectives: 1. IoTivity-Lite middleware: The IoTivity middleware from OCF was selected to handle interoperability, scalability, and resource management semantic gaps inherent in IoT systems. Experimentation showed that indeed both Wi-Fi and ethernet devices could effectively and uniformly exchange data through the IoTivity-Lite HAN. Though the essential functions of the IoTivity-lite middleware are effective; functionalities such as provisioning, and security are only available in Arduino DUE and ESP32 due to AVR board limited RAM. Latencies in data delivery of ~4 s were observed for Gateway-to-cloud communicating over the Back4App cloud services.

Discussion
The main highlights from the experimental setup concerning the research objectives: 1.
IoTivity-Lite middleware: The IoTivity middleware from OCF was selected to handle interoperability, scalability, and resource management semantic gaps inherent in IoT systems. Experimentation showed that indeed both Wi-Fi and ethernet devices could effectively and uniformly exchange data through the IoTivity-Lite HAN. Though the essential functions of the IoTivity-lite middleware are effective; functionalities such as provisioning, and security are only available in Arduino DUE and ESP32 due to AVR board limited RAM. Latencies in data delivery of~4 s were observed for Gateway-to-cloud communicating over the Back4App cloud services.

2.
Porting IoTivity-Lite Arduino AVR & ARM: The IoTivity middleware is a recent ongoing project with a growing community and interest. However, this framework was not available on low-memory, low-cost hardware such as the Arduino architecture. Therefore, the IoTivity middleware is ported to the Arduino MCU representing one of the novelties of this work. To this end, Contiki OS was used and adapted for Arduino Arch. The experimentation shows that Contiki OS on Arduino is stable and responsive, and its memory footprint is lightweight enough to allow sufficient space on the Arduino RAM for IoTivity stack features such as discovery, CRDUN operations, device, and resource provisioning on AVR arch as well security on DUE devices.
From the above observations, further work and focus should be placed on: 3. Enhancing security using the IoTivity onboarding and provisioning mechanism to authenticate the client that interfaces to the HAN resource server. This feature was not fully implemented because of software inconsistency with the IoT-rest-API-server.

4.
IoTivity Cloud, OCF has updated its IoTivity-Lite framework to add a cloud interface to the IoTivity network. This facility can be used to remove the need for the IoT-rest-API-server easily implementing all security mechanisms available. This also reduces the development load and facilitates maintenance.

5.
Wireless communication, Wi-Fi should be adapted to all HAN devices for easier penetration and adaptation in residential places. We recommend using technology with embedded wireless protocol to optimize the HAN data communication.

6.
Smart grid signals from the energy utility can take advantage of this platform. But the interface needs to be fully defined from the cloud backend, this can be a cloud job provided as SaaS in response to requests from the utility.

Conclusions
This article strives to participate in the growing research concerning the smart grid's potential for modernization of the electricity grid in the effort of energy utilities to effectively handle increasing peak load, especially in the residential sector.
Therefore, "Cloud-based IoTivity platform for Home Energy Management Applications", a cost-effective, efficient, and performing communication platform leveraging IoT enabling technologies, was presented and deployed to provide and demonstrate intelligent energy management applications, mainly in domestic places within the South African context. This article addressed the IoT semantic gaps regarding interoperability, scalability, and the cost and availability of technology issues pertaining to HEM.
Thus, we focused on the architectural design and backend requirements of the platform around open source IoT technologies and developed a completed prototype providing an experimental setup to test the platform's performance for smart-grid-related interventions in households. The experimental DRM load profile shows that the demand promptly falls back below the peak limit after performing the peak shaving algorithm, generating savings of up to 17% on the morning and evening peak loads. The overall response time for GET or POST requests for device-to-device and cloud-to-device resource requests average~4 s for feedback and appliance actuation.

Future Research
The low-cost and miniaturization requirements present noticeable performance issues in terms of hardware memory constraints and response time and limit the deployment of IoTivity middleware security and management tools. Improvement of the platform could focus on: • Security can be increased in the platform using the IoTivity onboarding and provisioning mechanism to authenticate the client that interfaces to the HAN resource server. This capability was not fully implemented because of software inconsistency with the IoT-rest-API-server • A higher-end embedded device for HAN servers able to handle multiple clients while maintaining a fast response time was observed as an issue with AVR motes, and in some capacities with the DUE servers due to its reduced processing speed and constrained memory. A miniaturized, higher memory wireless MCU running at a faster clock would provide a faster response time.
• Smart grid signals from the energy utility can take advantage of this platform. However, the interface needs to be fully defined from the cloud interface. This can be a cloud job that requires monitoring or listening via an API provided by utility-to-smartgrid incentives and propagation of these to home gateways. A more modern approach would be to leverage "Data Lakes" on cloud platforms.