# Towards the Real-World Deployment of a Smart Home EMS: A DP Implementation on the Raspberry Pi
## 4 Embedded Implementation of the Chosen EMS
### Dynamic Programming Algorithm
### Computational Complexity Analysis

The computational complexity of the optimization stage depends on two variables. The first is the number of time steps in a day (\(N\)); and the second is the coarseness of the SOC variable discretization,

Figure 3: Graph of SOC values representing the actions and the resulting states that the system can choose to schedule its operations. i.e., the number of possible discrete SOC values (\(M\)), which allows computing the SOC discretization step as \(\Delta SOC=M^{-1}\cdot 100\%\). The worst-case complexity of the _Planning_ algorithm is \(O(N^{2}M^{3})\). On the other hand, the worst-case complexity of the _Online Replanning_ algorithm is \(O(NM^{2}+NMlogNM)\). As such, it is lower than the complexity of the _Planning_ algorithm. ### NARX ANNs

The NARX ANNs that forecast the 24-h ahead profiles of load demand and environmental variables were implemented using Matlab/Simulink R2014b with Neural Network Toolbox. Then, C/C++ code was generated taking advantage of Matlab Coder. Finally, the obtained code was further optimized and compiled with Linaro GNU cross-toolchain armv8l-linux-grueabihf version 7.2. ## 5 Experimental Verification and Results

A dedicated test bench was set up to validate the embedded implementation of the chosen EMS under the hypothesis of controlling four smart homes of the type described in Section 3. Such a test bench is described in detail in the following subsection. The input data came from publicly available datasets. Outdoor temperature, solar irradiance, and wind speed data came from the U.S. National Solar Radiation Database [47], whereas load demand data came from [48]. Prices for sold and purchased energy were retrieved from [49]. The data considered for the study referred to the city of Amarillo TX, USA. Given each dataset, a first part of the data was used to train and validate the related ANN. The remaining part was considered as the set of instantaneous measurements to be compared with the forecast profile. The electrical behavior of the appliances of each smart home was emulated by the related wireless sensors, as explained in the following subsection. This approach was followed because the main aim of the work was to assess whether the EMS can run on the embedded platform, perform its computation within the required time frame, and exchange data with the wireless sensors. ### Test Bench Description

Four EMSs of the proposed type were implemented on four Raspberry Pi 3 model B boards running the Linux operating system. This embedded platform was based on a quad-core Broadcom BCM2837 64-bit CPU clocked at 1.2 GHz and has 1 GB of RAM. Furthermore, it provides an onboard WiFi connection, a gigabit Ethernet port, and a Micro SD port to boot the Linux operating system [37]. As an alternative, the proposed EMS could be easily executed on other Linux-based embedded platforms such as the Zedboard [50] by just recompiling the same source code. The wireless sensors used in the test bench have been previously devised in [38] and are based on Wemos D1 mini pro boards. These boards encompass an ESP8266 system-on-chip by Espressif Systems, which includes a low-cost IEEE 802.11b/g/n Wi-Fi chip with full TCP/IP support and a 32-bit RISC L106 microcontroller. For their use in the field, such devices are appropriately interfaced with physical sensors to acquire the variables of interest (e.g., voltage and current of each appliance, solar irradiance, wind speed, and outdoor temperature). At the same time, they send the appropriate power reference to each power electronic converter, and they read the instantaneous battery SOC. For the present work, instead, such wireless sensors were modified to bypass the physical sensors and to emulate the electrical equipment to which they were connected. In particular, the power profiles of renewable generators and electrical loads were computed on the basis of the considered public datasets.