Performance Optimization LoRa Network by Artiﬁcial Bee Colony Algorithm to Determination of the Load Proﬁles in Dwellings

: This paper presents a system to improve the performance of the Long Range (LoRa) network using an algorithm derived from the artiﬁcial bee colony (ABC), which obtains a minimum packet lost rate (PLR) in the LoRa network and allows to more accurately determine load proﬁles of dwellings, with smaller a time measurement and less data transmission. The developed algorithm calculates the conﬁguration parameters of the LoRa network, monitoring in real time the data tra ﬃ c, and is implemented in gateway LoRa network monitor (GLNM). Intelligent measurement equipment has been developed to determine the dwelling load proﬁles. This energy measurement device for dwelling (EMDD) measures the variables and consumption of electricity in each home with measurement times that can be conﬁgured. This research also develops the GLNM gateway, which monitors and receives data from the EMDDs installed and uploads them to the cloud using Firebase. This developed system allows to perform demand forecasting studies, analysis of home consumption, optimization of electricity tari ﬀ s, etc., applied to smart grids.


Introduction
Smart meters (SMs) allow households to see their electricity consumption in real time and track energy consumption. This information of the consumption of the houses, allows householders to understand the activities of greater consumption and to be able to modify their patterns of consumption, and implement behaviours to reduce their electricity bill. In addition, smart meters facilitate the use of time-of-use rates, which can help to reduce peak demand and facilitate daily consumption.
SMs installed in dwellings are usually owned by the utility company. In this sense, access to information may be restricted to the company's own communications network, generally through the power line wave introduced in the electrical signal. SMs may not have a communications port (optical, serial, or USB), and it is not possible to extract information from it.
On the other hand, the access times to the data of the SMs are not usually less than 15 s. To obtain real-time load profiles with greater accuracy, it is necessary to perform measurements of electrical variables with lower data acquisition intervals.
The installation of SMs in dwellings has to be done with the minimum interference for the users. That is the reason why the use of wireless technologies for sending and receiving data is very appropriate. Among the existing wireless technologies, low consumption technologies are especially important. In this research, the LoRa Low Power Wide Area Network (LPWAN) network has been chosen, with transmission distances of up to 10 km.

Bibliography
Parameters Measured Features Topics [20] -Study of SMs international regulation Local interface of SMs in households [21] Voltage and current SM Design Demand response capabilities [22] Energy consumption LDR to measure SMs pulses Monitoring electrical energy consumption [23] Electricity consumption Thermal and chemical energy storage Electric vehicles System model Optimization of energy storage units [24] Voltage, current and active power Analysis of measured data to improve electrical energy consumption [28] Energy consumption Commercial SMs Data analysis and clustering [29] Energy consumption ZigBee wireless Data analysis in different scenarios [30] Energy consumption Commercial SMs study and estimation of indicators of load profiles in dwellings [31] Energy consumption Commercial SMs Measure time 15 min Obtaining and analysis of load profiles in houses in Evora (Portugal) [32] Energy consumption Commercial SMs Measure time 15 min Obtaining and analysis of load profiles in 1000 houses in Poland [33] Energy consumption Commercial SMs Measure time 30 min Smart meter dataset Data Analysis and Clustering [34] Energy consumption Commercial SMs Obtaining and analysis of load profiles in 154 houses in Stockholm (Sweden) [35] Energy consumption Commercial SMs Data analysis and Clustering [36] Energy consumption Commercial SMs Obtaining and analysis of load profiles in 1000 houses in Latvia [37] Voltage, current and active power Power Tracker SM Measure time 60 s ZigBee Wireless Monitoring the electricity consumption of domestic appliances in an Australian house [38,39] Electrical variables Schneider Electric EM64XX Application of heuristic techniques for the detection of abnormal energy consumption [40] Electrical variables Schneider Electric EM64XX Classification of load profiles [41] Voltage, current, active power and illumination level Control and measurement system design LoRa wireless Measure time 5 s Smart public Lighting control Energy efficiency In this paper, the authors propose a system to improve the efficiency of LoRa networks using the ABC algorithm to obtain load profiles of dwellings in real time. Therefore, the authors present a number of novel contributions over our previous work and the state-of-the-art: Design of our own system to measurement the electrical variables and to obtain the load profile of dwellings using EMDD and GLNM monitors and a configuration of the LoRa network to reduce PLR. -EMDD and GLNM are low cost and open source, and evaluated successfully. -Implementation of an ABC algorithm that optimizes the LoRa network to minimize PLR.
The limitations of this research are as follows: -The maximum range of the LoRa network is 10 km. This research has been developed in a city, wherein the maximum range is 5 km, due to the high density of buildings. - The maximum number of devices for each GLNM is 300 EMDDs. Therefore, it is necessary to install one GLNM device for every 300 dwellings. -EMDD cannot send data with cadences lower than 0.5 s. - The accuracy of EMDD is 1%. - The maximum power measured is 23 kW. Figure 1 shows the LoRa network diagram with n EMDDs installed in the different dwellings, either in individual dwellings or buildings. These EMDDs send the measured data through a LoRa network to GLMN that concentrates the reception of information, processes the messages with the measurements, and uploads them to Firebase, using a Wi-Fi network. On the other hand, GLNM also executes the ABC algorithm if necessary when receiving a message from some EMDD to obtain the new optimal configuration of the LoRa network. Finally, the measured data are available in computers, smartphones, or tablet for viewing or processing in real time.

Theoretical Background
Energies 2020, 13, 517 4 of 29 In this paper, the authors propose a system to improve the efficiency of LoRa networks using the ABC algorithm to obtain load profiles of dwellings in real time. Therefore, the authors present a number of novel contributions over our previous work and the state-of-the-art: -Design of our own system to measurement the electrical variables and to obtain the load profile of dwellings using EMDD and GLNM monitors and a configuration of the LoRa network to reduce PLR. -EMDD and GLNM are low cost and open source, and evaluated successfully. -Implementation of an ABC algorithm that optimizes the LoRa network to minimize PLR.
The limitations of this research are as follows: -The maximum range of the LoRa network is 10 km. This research has been developed in a city, wherein the maximum range is 5 km, due to the high density of buildings. - The maximum number of devices for each GLNM is 300 EMDDs. Therefore, it is necessary to install one GLNM device for every 300 dwellings. -EMDD cannot send data with cadences lower than 0.5 s. - The accuracy of EMDD is 1%. - The maximum power measured is 23 kW. Figure 1 shows the LoRa network diagram with n EMDDs installed in the different dwellings, either in individual dwellings or buildings. These EMDDs send the measured data through a LoRa network to GLMN that concentrates the reception of information, processes the messages with the measurements, and uploads them to Firebase, using a Wi-Fi network. On the other hand, GLNM also executes the ABC algorithm if necessary when receiving a message from some EMDD to obtain the new optimal configuration of the LoRa network. Finally, the measured data are available in computers, smartphones, or tablet for viewing or processing in real time.

Electrical Variables Measurement
The device measures the electrical variables (v, i, and p), while both the power factor (PF) and the reactive power q are calculated. Sánchez-Sutil et al. [24] developed the evaluation and calibration of a smart meter to be used in dwellings.
The variable power factor PF can be expressed as the ratio of the average active power p avr to the product of the R.M.S. values of voltage and current, respectively [24]:

Electrical Variables Measurement
The device measures the electrical variables (v, i, and p), while both the power factor (PF) and the reactive power q are calculated. Sánchez-Sutil et al. [24] developed the evaluation and calibration of a smart meter to be used in dwellings.
The variable power factor PF can be expressed as the ratio of the average active power p avr to the product of the R.M.S. values of voltage and current, respectively [24]: Energies 2020, 13, 517

of 29
For sinusoidal voltage and current waveforms, PF reduces to cos(ϕ). Finally, the R.M.S. reactive power q is given by [24]: q r.m.s = v r.m.s ·i r.m.s · sin(arccos(ϕ)) (2) The active and reactive energy is obtained from the RMS values, as shown in the Equations (3) and (4):

LoRa
Several parameters are available for the customization of the LoRa modulation: (i) bandwidth (BW); (ii) spreading factor (SF); (iii) code rate (CR). LoRa uses an unconventional definition of the spreading factor as the logarithm, in base 2, of the number of chirps per symbol. These parameters influence the effective bitrate of the modulation, its resistance to interference noise, and its ease of decoding. Noreen et al. [42] provided in depth analysis of the impact of these three parameters on the data rate and time on air, and Phung et al. [43] provided an in-depth analysis and assessment of LoRaWAN functional components: its capabilities (total traffic load, packet delivery quality) versus its efficiency (collision and frequency usage).
The papers [44][45][46][47] analysed the different configuration parameters: the carrier frequency (CF), SF, BW, and CR in a LoRA network. The combination of these parameters provides different energy values and transmission ranges: CF: is the centre frequency used for the transmission band. For the transceiver, it is in the range of 433 MHz in Asia, 868 MHz in Europe, and 915 MHz in North America.
SF: is the number of chips per symbol. Its value is an integer between 7 and 12. The greater value of SF, the more capability the receiver has to move away the noise from the signal.
BW: represents the range of frequencies in the transmission band. It can only be chosen among three options: 125, 250, or 500 kHz.
CR: The coding rate expression is CR = 4/(4 + n), n is from 1 to 4. This denotes that every four useful bits are encoded by 5, 6, 7, or 8 transmission bits. The smaller the coding rate is, the higher the time on air is to transmit data.
The nominal bit-rate (in bits per second) is obtained taking into account these parameters. Moreover, the expression of the bit-rate is given in Equation (5) [44,45]: where t sym refers to the duration (in seconds) of a symbol and depends on SF and BW. The payload symbol is calculated prior to the time on air (or packet duration). For a given payload noted PL (in bytes), a spreading factor SF, and a coding rate CR, the number of symbols N PHY used to transmit the payload can be calculated in Equation (7). CRC (cyclic redundancy check) indicates the presence (value 1) or not (value 0) of the CRC field in the physical message and DE indicates if the mechanism to prevent issues about the clock drift of the crystal reference oscillator is used (value 1 for SF12 and SF11, 0 for others) [44,45].
Energies 2020, 13, 517 6 of 29 Equations (8) and (9) represent how these two terms have been calculated, where N p is the number of symbols used by the radio transceiver as the physical preamble of the message [44,45].
The actual time on the air for a packet can be defined as the duration of uplink and downlink transmissions, where t pk depends on the parameters of LoRa modulation such as SF, BW, and CR and can be expressed as the sum of the time needed to transmit the preamble and the physical message per Equation (10) [44,45]: t pk = t p +t PHY (10)

Algorithm ABC
In the ABC algorithm, the artificial bee colony includes three groups of bees: employed bees, observers and explorers [1][2][3]. A bee that waits in the dance area to make the decision to choose a food source is named an observer and one that goes to the food source visited by it before is named an employee bee. The other type of bee is the explorer bee, which performs random searches to discover new sources. The position of a food source offers a possible solution to the optimization problem and the nectar amount from a food source corresponds to the quality of the associated solution, determined by Equation (11) [2,3]: An artificial observer bee selects a food source as a function of the probability value associated with that food source, p(i), calculated by the following Expression (5) [2,3]: where n is the number of food sources equal to the number of employed bees, and fitness(i) is the fitness of the solution given in Equation (15) which is inversely proportional to the f(i) given in Equation (12) where f(i) is the optimization function of the problem. In order to produce a candidate food position from the old one in memory, the ABC uses the following Expression (13) [2,3]: v ij = z ij + ∅ ij · z ij −z kj (13) where k ∈ {1, 2, . . . , n} and j ∈ {1, 2, . . . , D} are randomly chosen indexes. Although k is determined randomly, it has to be different from i. φ i,j is a random number between [0, 1]. It controls the production of neighbor food sources around z i,j and represents the comparison of two food positions visible to a bee. Assume that the abandoned source is z i and j ∈ {1, 2, . . . , D}, then the scout discovers a new food source to be replaced with z i . This operation can be defined as in (14) [2,3]: (14) There are three control parameters in the ABC: the number of food sources, which is equal to the number of employed or onlooker bees (n) and the value of limit for the maximum cycle number (N max cycle ). Figure 2 shows the flow chart of the ABC algorithm.

Problem Formulation
The objective of the problem is the optimization of the LoRa network, so that the PLR is minimized. The LoRa network has three configuration parameters (BW, SF, and CR), which have a decisive influence on the PLR reduction. In addition, these parameters represent the constraints of the problem. The optimization function used to obtain the minimization of PRL in real time is given by Among the possible solutions, the algorithm selects the highest possible BW, to ensure a higher transmission speed. As can be seen in Equation (11): where BWmax is the maximum possible BW value. After BW is selected, if there is more than a minimum, the algorithm must find the highest SF in order to obtain a signal with less noise. As shown in Equation (12): where SFmax is the maximum possible SF value. Selected both BW and SF, if there is more than a minimum, the algorithm must search for the highest CR to have a higher transmission speed.
where CRmax is the maximum possible value CR.
To define the population (pop), where n is the number of variables, three in this problem, and p the number of possible variations, which in our problem is 72. Each state shows the combination of BW, SF, and CR.

Problem Formulation
The objective of the problem is the optimization of the LoRa network, so that the PLR is minimized. The LoRa network has three configuration parameters (BW, SF, and CR), which have a decisive influence on the PLR reduction. In addition, these parameters represent the constraints of the problem. The optimization function used to obtain the minimization of PRL in real time is given by Among the possible solutions, the algorithm selects the highest possible BW, to ensure a higher transmission speed. As can be seen in Equation (11): (16) where BW max is the maximum possible BW value. After BW is selected, if there is more than a minimum, the algorithm must find the highest SF in order to obtain a signal with less noise. As shown in Equation (12): (17) where SF max is the maximum possible SF value. Selected both BW and SF, if there is more than a minimum, the algorithm must search for the highest CR to have a higher transmission speed. (18) where CR max is the maximum possible value CR. To define the population (pop), where n is the number of variables, three in this problem, and p the number of possible variations, which in our problem is 72. Each state shows the combination of BW, SF, and CR.

EMDD Design
This research has performed the development of EMDD from the initial design phase to the construction of a final prototype. The objective is to obtain a prototype to provide load profiles in dwellings, by measuring electrical variables with sensors. The communication is done through the LoRa LPWAN network.
Moreover, the core of EMDD is the AMR3 (Arduino Mega Rev 3) development board [48], together with DLGS (Dragino LoRa GPS Shield) [49] for LoRa network access and GPS positioning. The EMDD design is modular, which allows for the quick and easy replacement of components of the system that are damaged, without the rest of the device being affected or out of service, making the system scalable. Figure 3 shows the EMDD block diagram, where the device components and the relationship between them and the main AMR3 component can be seen. This research has performed the development of EMDD from the initial design phase to the construction of a final prototype. The objective is to obtain a prototype to provide load profiles in dwellings, by measuring electrical variables with sensors. The communication is done through the LoRa LPWAN network.
Moreover, the core of EMDD is the AMR3 (Arduino Mega Rev 3) development board [48], together with DLGS (Dragino LoRa GPS Shield) [49] for LoRa network access and GPS positioning. The EMDD design is modular, which allows for the quick and easy replacement of components of the system that are damaged, without the rest of the device being affected or out of service, making the system scalable. Figure 3 shows the EMDD block diagram, where the device components and the relationship between them and the main AMR3 component can be seen. To measure electrical variables (v, i, and p), EMDD works together with the PZEM meter (PZEM-004t) [50]. PZEM communication with AMR3 is through Serial1 port. AMR3 is supplied through a source that converts the 230 V AC mains voltage into 7-12 V DC accepted by AMR3. The other components used in the system (DLS and PZEM) are supplied through AMR3. Figure 4 shows the wiring diagram for EMDD.  To measure electrical variables (v, i, and p), EMDD works together with the PZEM meter (PZEM-004t) [50]. PZEM communication with AMR3 is through Serial1 port. AMR3 is supplied through a source that converts the 230 V AC mains voltage into 7-12 V DC accepted by AMR3. The other components used in the system (DLS and PZEM) are supplied through AMR3. Figure 4 shows the wiring diagram for EMDD.   Table 2 shows the budget of the components used to build EMDD. Due to its low cost, it is ideal for use in dwellings monitoring.

. GLNM Design
This research has also developed a device that works as a gateway, to which is added the feature of monitoring the LoRa network in order to optimize data traffic on the network and minimize PLR. Inside this device is installed the proposed ABC algorithm, responsible for network optimization.
The microcontroller chosen for GLNM is AMR3 [48], which has four serial ports. Two serial ports are needed: one to communicate with the GPS receiver in DLGS [49] and another to send data to place WMP [51] and upload the information to the cloud using the Firebase [52] service.
The design of GLNM is modular, which allows for the quick and easy replacement of system components that are damaged, without the rest of the device being affected or out of service, making the system scalable. Figure 5 shows the GLNM block diagram.  Table 2 shows the budget of the components used to build EMDD. Due to its low cost, it is ideal for use in dwellings monitoring.

GLNM Design
This research has also developed a device that works as a gateway, to which is added the feature of monitoring the LoRa network in order to optimize data traffic on the network and minimize PLR. Inside this device is installed the proposed ABC algorithm, responsible for network optimization.
The microcontroller chosen for GLNM is AMR3 [48], which has four serial ports. Two serial ports are needed: one to communicate with the GPS receiver in DLGS [49] and another to send data to place WMP [51] and upload the information to the cloud using the Firebase [52] service.
The design of GLNM is modular, which allows for the quick and easy replacement of system components that are damaged, without the rest of the device being affected or out of service, making the system scalable. Figure 5 shows the GLNM block diagram. Energies 2020, 13, 517 10 of 29 AMR3 and WMP are supplied from a source that converts the mains voltage of 230 V AC to 7-12 V DC. DLGS is powered through AUR3. Figure 6 shows the wiring diagram for GLNM.  Table 3 shows the budget of the components used in GLNM.  AMR3 and WMP are supplied from a source that converts the mains voltage of 230 V AC to 7-12 V DC. DLGS is powered through AUR3. Figure 6 shows the wiring diagram for GLNM. AMR3 and WMP are supplied from a source that converts the mains voltage of 230 V AC to 7-12 V DC. DLGS is powered through AUR3. Figure 6 shows the wiring diagram for GLNM.  Table 3 shows the budget of the components used in GLNM.   Table 3 shows the budget of the components used in GLNM.

Microcontroller
A microcontroller is a small computer implemented in an integrated circuit, containing at least one processor, memory, and inputs/outputs that can be programmed using various applications with Energies 2020, 13, 517 11 of 29 connected peripherals. This component, in addition to peripherals, is widely used in control and process applications in industrial and residential environments.
In recent years, there has been a significant advance in electronics, which has led to the development of very powerful hardware at low cost, which can be used in devices such as those developed in this paper.
EMDD has been used to build the development board AMR3 [48] based on ATmega2560. To program EMDD, the Arduino open-source platform is used.
EMDD uses the Serial1 port of AMR3 to communicate with PZEM, because the Serial port is used for programming and debugging the program code. AMR3 has four serial ports available.
To implement GLNM AMR3 based on ATmega328P is used as the system kernel. GLNM uses the Serial port for programming and monitoring the operation of the equipment, Serial1 for communication with GPS and Serial2 to send data to WMP.
2. LoRa wireless communication There are several components of different brands in the market that allow the development of wireless systems based on LoRa, among which it is worth mentioning: (i) Arduino MKR WAN 1300 [53]; (ii) Monteino [54]; (iii) Lopy4 [55]; (iv) Libelium [56]; (v) Dragino [57]. Each of these components is based on different chips that implement LoRa technology. The components used are: As can be seen, the various platforms have similar features. The selection of the platform to be integrated in EMDD depends on characteristics and added values that improve the performance of the final system.
In this sense, EMDD uses Dragino, since it can be integrated with AMR3 by a shield. The integration with the Arduino family brings great advantages due to the versatility offered by this platform, with a multitude of components that complement the LoRa LPWAN network. The LoRa family of components from the manufacturer Dragino offer a complete solution.
DLGS can be configured with different transmission frequencies (BW), CR, and SF, to adapt to data transmission with LoRa protocol over long distances. This feature makes the system highly flexible and usable. In addition to the functionalities of access to the LoRa network, DLGS uses a global positioning system that allows the device to be located where it is installed. The characteristics of DLGS are exposed in [49].
DLGS uses the LoRa SX1276/SX1278 chip as the core of the LoRa transmission system. This microchip is designed for professional environments to integrate sensor networks, such as irrigation systems, smart cities and smart homes, smart meters, smart phone detection, building and industrial automation, etc., with minimum energy consumption.
3. Electrical power meter EMDD reads the electrical variables (v, i, and p). To measure these variables, sensors with different measurement techniques are available on the market.
As for current sensors, the most commonly used techniques are measurement with Hall effect sensors and current transformers. Another fundamental aspect is whether the sensor is invasive or non-invasive, the former need to modify the installation where the measurement is made, and the latter do not need to modify the installation. ACS712 [64] and ACS714 are two examples of invasive sensors, in contrast, the STC-013 [65] sensor is an example of a non-invasive sensor.
The sensors described above measure instantaneous values, and additional calculations are required to obtain the RMS values. To obtain RMS values without additional calculations, the PZEM-004t [50] sensor can be used to obtain the electrical variables v, i, and p in a single sensor, so it has been used as a measurement sensor for electrical variables in this investigation.

EMDD Program
The chosen microcontroller will be responsible for executing the program for the measurement of electrical variables and interaction with the LoRa LPWAN network.
In the first place, EMDD must (i) start Serial1 for communication with PZEM; (ii) start PZEM sensor; (ii) start DLGS for access to LoRa network. The tasks described above are only performed when the device is connected or reset.
Once the device has been started, the following tasks are performed cyclically while the device is connected: (i) read electrical variables from the PZEM sensor; (ii) send the measurements made to the LoRa network; (iii) read data from the LoRa network while waiting for the confirmation of arrival of the data sent.
Once the data have been sent to the network, EMDD waits for confirmation. If no response is received in a maximum time defined as a parameter of the LoRa network, EMDD must send a data loss message to GLNM. In this situation, GLNM must run the ABC algorithm to determine an optimal new network configuration that matches the system to the best possible performance. Figure 7 shows the flowchart for EMDD.
Energies 2020, 13, 517 12 of 29 latter do not need to modify the installation. ACS712 [64] and ACS714 are two examples of invasive sensors, in contrast, the STC-013 [65] sensor is an example of a non-invasive sensor. The sensors described above measure instantaneous values, and additional calculations are required to obtain the RMS values. To obtain RMS values without additional calculations, the PZEM-004t [50] sensor can be used to obtain the electrical variables v, i, and p in a single sensor, so it has been used as a measurement sensor for electrical variables in this investigation.

EMDD Program
The chosen microcontroller will be responsible for executing the program for the measurement of electrical variables and interaction with the LoRa LPWAN network.
In the first place, EMDD must (i) start Serial1 for communication with PZEM; (ii) start PZEM sensor; (ii) start DLGS for access to LoRa network. The tasks described above are only performed when the device is connected or reset.
Once the device has been started, the following tasks are performed cyclically while the device is connected: (i) read electrical variables from the PZEM sensor; (ii) send the measurements made to the LoRa network; (iii) read data from the LoRa network while waiting for the confirmation of arrival of the data sent.
Once the data have been sent to the network, EMDD waits for confirmation. If no response is received in a maximum time defined as a parameter of the LoRa network, EMDD must send a data loss message to GLNM. In this situation, GLNM must run the ABC algorithm to determine an optimal new network configuration that matches the system to the best possible performance. Figure 7 shows the flowchart for EMDD.

GLNM Program
First, GLNM performs the initialization of DLGS for access to the LoRa network, and the GPS positioning system will only perform the initiation when the device is connected, or a reset is performed.
Once the initialization tasks have been completed, GLNM must perform a series of processes to ensure the correct functioning of the system. The process starts with the reading of data from the LoRa network. If the message received contains electrical measurement data, these data are sent directly to Firebase [52]. On the other hand, if the received message is a packet loss message, the proposed ABC algorithm is executed in order to find an optimal network configuration and send the new configuration parameters to all connected EMDDs. Figure 8 shows the flowchart for GLNM.

GLNM Program
First, GLNM performs the initialization of DLGS for access to the LoRa network, and the GPS positioning system will only perform the initiation when the device is connected, or a reset is performed.
Once the initialization tasks have been completed, GLNM must perform a series of processes to ensure the correct functioning of the system. The process starts with the reading of data from the LoRa network. If the message received contains electrical measurement data, these data are sent directly to Firebase [52]. On the other hand, if the received message is a packet loss message, the proposed ABC algorithm is executed in order to find an optimal network configuration and send the new configuration parameters to all connected EMDDs. Figure 8 shows the flowchart for GLNM.

Cloud Store
LoRa devices, including DLGS, can access IoT and cloud computing using gateways. The gateways can be configured with different communication protocols. On the other hand, there are a wide variety of services for processing data in the cloud.
Among the many options available, Firebase [52] has been chosen in this research as a platform for integrating data from the different EMDDs, and allows the integration of data with a multitude of programming and integration possibilities, making it possible to achieve any configuration required for the application to be performed, so that the data is available on a multitude of devices (computers, smartphones, etc.). Firebase has paid and free versions that mean the user can adapt to the profile that best suits the needs of service.

Results
The authors have studied the performance of three dwellings to test the functioning of the system proposed in this paper. GLNM is located on the terrace of the Higher Polytechnic School of Jaen de Jaen. The dwellings are located in Jaen (Spain), with different distances to GLNM. The different locations make it possible to evaluate the performance of the network, in order to perform PLR measurement tests with the different possible combinations of BW, SF and CR.

Dwellings Location
The dwellings were chosen to have different typologies that allow different load profiles to be studied. This way, you have a flat and a single-family dwelling. Table 4 shows a summary of the characteristics of dwellings. Single-family home 320 0.923 Table 5 contains geolocation data referring to zone 30 of the different dwellings and GLNM. For a better visualization, Figure 9 shows the position of each of the elements that participate in the test.

Cloud Store
LoRa devices, including DLGS, can access IoT and cloud computing using gateways. The gateways can be configured with different communication protocols. On the other hand, there are a wide variety of services for processing data in the cloud.
Among the many options available, Firebase [52] has been chosen in this research as a platform for integrating data from the different EMDDs, and allows the integration of data with a multitude of programming and integration possibilities, making it possible to achieve any configuration required for the application to be performed, so that the data is available on a multitude of devices (computers, smartphones, etc.). Firebase has paid and free versions that mean the user can adapt to the profile that best suits the needs of service.

Results
The authors have studied the performance of three dwellings to test the functioning of the system proposed in this paper. GLNM is located on the terrace of the Higher Polytechnic School of Jaen de Jaen. The dwellings are located in Jaen (Spain), with different distances to GLNM. The different locations make it possible to evaluate the performance of the network, in order to perform PLR measurement tests with the different possible combinations of BW, SF and CR.

Dwellings Location
The dwellings were chosen to have different typologies that allow different load profiles to be studied. This way, you have a flat and a single-family dwelling. Table 4 shows a summary of the characteristics of dwellings.  Table 5 contains geolocation data referring to zone 30 of the different dwellings and GLNM. For a better visualization, Figure 9 shows the position of each of the elements that participate in the test.

LoRa
In order to perform the Received Signal Strength Indicator (RSSI) and PLR measurement test, measurements have been made for each dwelling with the 72 possible combinations of parameters.
In each of the combinations, 4320 packages have been sent, which corresponds to 6 h of duration with one package every 5 s. The size of the payload used is 31 bytes, which have the following content: (i) 4 bytes for the EMDD number; (ii) 4 bytes for the voltage; (iii) 4 bytes for the current; (iv) 4 bytes for the active energy; (v) 4 bytes for the reactive energy; (vi) 11 bytes for the GPS position. Under the conditions defined above, an exhaustive test has been carried out in each of the dwellings studied, as described in Section 5.1, in order to make comparisons.
The data represented for the three dwellings are reflected in Figures 10-12. These data have been represented as a function of parameter BW modifying CR and SF, obtaining the graphs of PLR (ratio to be minimized) and RSSI.
The analysis in Figure 10a indicates that, for SF less than 10, a very small PLR is obtained with any combination of CR. It is also possible to observe that, for SF 11 and 12, the PLR increases until

LoRa
In order to perform the Received Signal Strength Indicator (RSSI) and PLR measurement test, measurements have been made for each dwelling with the 72 possible combinations of parameters.
In each of the combinations, 4320 packages have been sent, which corresponds to 6 h of duration with one package every 5 s. The size of the payload used is 31 bytes, which have the following content: (i) 4 bytes for the EMDD number; (ii) 4 bytes for the voltage; (iii) 4 bytes for the current; (iv) 4 bytes for the active energy; (v) 4 bytes for the reactive energy; (vi) 11 bytes for the GPS position. Under the conditions defined above, an exhaustive test has been carried out in each of the dwellings studied, as described in Section 5.1, in order to make comparisons.
The data represented for the three dwellings are reflected in Figures 10-12. These data have been represented as a function of parameter BW modifying CR and SF, obtaining the graphs of PLR (ratio to be minimized) and RSSI.
The analysis in Figure 10a indicates that, for SF less than 10, a very small PLR is obtained with any combination of CR. It is also possible to observe that, for SF 11 and 12, the PLR increases until reaching values of 100% PLR, which indicates that it is not recommended for this frequency. Of the Energies 2020, 13, 517 15 of 29 combinations that are produced with BW 125 kHz, the one that produces the minimum is that of SF 9 and CR of 4/8, and a PLR of 0.0238%.
The frequency of 250 kHz offers similar results, with the exception that good results are obtained from PLR up to SF of 11, reaching 100% with SF 12 that do not make it recommendable to use in conjunction with this frequency. The minimum is 0% for SF of 8 and CR of 4/8.
Finally, the 500 kHz frequency offers a good distribution of PLR in all the analysed combinations, with maximum values below 4.5% e PLR and a minimum of 0.1389% with SF of 11 and a CR 4/5. reaching values of 100% PLR, which indicates that it is not recommended for this frequency. Of the combinations that are produced with BW 125 kHz, the one that produces the minimum is that of SF 9 and CR of 4/8, and a PLR of 0.0238%. The frequency of 250 kHz offers similar results, with the exception that good results are obtained from PLR up to SF of 11, reaching 100% with SF 12 that do not make it recommendable to use in conjunction with this frequency. The minimum is 0% for SF of 8 and CR of 4/8.
Finally, the 500 kHz frequency offers a good distribution of PLR in all the analysed combinations, with maximum values below 4.5% e PLR and a minimum of 0.1389% with SF of 11 and a CR 4/5. In support of the analysis done, the statistical values (mean µ and standard deviation σ) were obtained for the entire test range performed in dwelling #1. Table 6 shows the results obtained. It can be observed that the values obtained for PLR confirm that the best frequency for this dwelling is 500 kHz. The average signal strength is similar for the three transmission frequencies around −93 dBm. Table 7 shows the sensitivity of RSSI by changing the parameters BW, SF, and CR for dwelling #1.  In support of the analysis done, the statistical values (mean µ and standard deviation σ) were obtained for the entire test range performed in dwelling #1. Table 6 shows the results obtained. It can be observed that the values obtained for PLR confirm that the best frequency for this dwelling is 500 kHz. The average signal strength is similar for the three transmission frequencies around −93 dBm. Table 7 shows the sensitivity of RSSI by changing the parameters BW, SF, and CR for dwelling #1.  The minimum PLR for dwelling #2 with the frequency of 125 kHz 0.0464%, which is obtained with SF of 8 and CR of 4/8. The distribution of PLR is maintained with good ratios until SF of 10, above this value the PLR increases notably reaching values of 100%. Therefore, combinations of SF above 11 are not recommended in this case.
As for the 250 kHz frequency, a minimum PLR of 0% is obtained with SF of 11 and CR of 4/8. For this frequency, only the SF of 12 produces significant losses, while the remaining combinations can be considered as acceptable to work with this frequency.
The 500 kHz frequency has a very stable distribution and only presents a small distortion that reaches PLR of 35% for SF of 8 and CR of 5. A minimum of 0.0694% is obtained for SF 11 and CR of 4/8.  The minimum PLR for dwelling #2 with the frequency of 125 kHz 0.0464%, which is obtained with SF of 8 and CR of 4/8. The distribution of PLR is maintained with good ratios until SF of 10, above this value the PLR increases notably reaching values of 100%. Therefore, combinations of SF above 11 are not recommended in this case.
As for the 250 kHz frequency, a minimum PLR of 0% is obtained with SF of 11 and CR of 4/8. For this frequency, only the SF of 12 produces significant losses, while the remaining combinations can be considered as acceptable to work with this frequency.
The 500 kHz frequency has a very stable distribution and only presents a small distortion that reaches PLR of 35% for SF of 8 and CR of 5. A minimum of 0.0694% is obtained for SF 11 and CR of 4/8. The analysis of the statistical data for dwelling #2 confirms that the best frequency for this dwelling is 500 kHz. The signal strength remains more or less constant with values below −92 dBm. The analysis of the statistical data for dwelling #2 confirms that the best frequency for this dwelling is 500 kHz. The signal strength remains more or less constant with values below −92 dBm. Tables 8  and 9 shows the statistical results and the sensitivity of RSSI by changing the parameters BW, SF, and CR for dwelling #2 respectively. The analysis of the data for dwelling #3 with the frequency of 125 kHz remains stable around 0% for SF less than or equal to 10 with all CR, for major SF there are notable increases in PLR reaching losses of 100%. The minimum on this occasion is 0.3704%, with SF 10 and CR 4/8.
If we pass to the frequency of 250 kHz, it is possible to observe that the minimum is achieved with SF of 8 and CR of 4/6 in 0%. As can be seen, the PLR increases in this frequency, reaching a maximum of 100% with SF of 12 and the whole range of CR.  Tables 8 and 9 shows the statistical results and the sensitivity of RSSI by changing the parameters BW, SF, and CR for dwelling #2 respectively. The analysis of the data for dwelling #3 with the frequency of 125 kHz remains stable around 0% for SF less than or equal to 10 with all CR, for major SF there are notable increases in PLR reaching losses of 100%. The minimum on this occasion is 0.3704%, with SF 10 and CR 4/8.
If we pass to the frequency of 250 kHz, it is possible to observe that the minimum is achieved with SF of 8 and CR of 4/6 in 0%. As can be seen, the PLR increases in this frequency, reaching a maximum of 100% with SF of 12 and the whole range of CR.
Finally, there is the analysis of dwelling #3 remains stable for almost all possibilities of SF and CR, with values between 0 and 5% for all high values of SF and CR. The minimum on this occasion is 0.5767% with SF of 8 and CR of 4/7. Finally, there is the analysis of dwelling #3 remains stable for almost all possibilities of SF and CR, with values between 0 and 5% for all high values of SF and CR. The minimum on this occasion is 0.5767% with SF of 8 and CR of 4/7.
The statistical calculations realized for dwelling #3 are shown in Table 10, with a minimum value of 11.3068% for 500 kHz. Table 11 reflects the data obtained for the sensitivity of the LoRa receiver. As a final summary, for BW 125 kHz, PLRs up to SF 10 with any CR value are acceptable. With the transmission frequency of 250 kHz, PLR are produced with acceptable values with SF equal to or less than 11 and any CR. As for the 500 kHz frequency, low PLR rates occur, and the only problems detected refer to 12 SF and 4/8 CR.
On the other hand, the greater the transmission distance, the better the results with the lower frequency, increasing this frequency as it approaches the transmission point, in order to obtain higher speeds in the reception and sending of information. It is possible to observe that, for dwelling #3, the closest to the 125 kHz gateway and BW, SF above 9 leads to a total loss of packets, which confirms that for shorter distances the 125 kHz frequency is less adequate. In this sense, and also for dwelling #3 and 500 kHz frequency, stable and small values are obtained, which corroborates that this frequency is adequate for shorter distances.

ABC Algorithm Test
It is necessary to check the functioning of the ABC algorithm, with the three dwellings working at the same time. It should be remembered that the optimization is performed on the entire system, so the algorithm optimization result will be applied to the parameters of the LoRa network and all connected devices.
The test has been performed during 6 h sending information of measures realized every 5 s. Figure 13 shows the optimization result with three parameter changes in the 6 h of operation, which adjusts the network parameters. The statistical calculations realized for dwelling #3 are shown in Table 10, with a minimum value of 11.3068% for 500 kHz. Table 11 reflects the data obtained for the sensitivity of the LoRa receiver. As a final summary, for BW 125 kHz, PLRs up to SF 10 with any CR value are acceptable. With the transmission frequency of 250 kHz, PLR are produced with acceptable values with SF equal to or less than 11 and any CR. As for the 500 kHz frequency, low PLR rates occur, and the only problems detected refer to 12 SF and 4/8 CR.
On the other hand, the greater the transmission distance, the better the results with the lower frequency, increasing this frequency as it approaches the transmission point, in order to obtain higher speeds in the reception and sending of information. It is possible to observe that, for dwelling #3, the closest to the 125 kHz gateway and BW, SF above 9 leads to a total loss of packets, which confirms that for shorter distances the 125 kHz frequency is less adequate. In this sense, and also for dwelling #3 and 500 kHz frequency, stable and small values are obtained, which corroborates that this frequency is adequate for shorter distances.

ABC Algorithm Test
It is necessary to check the functioning of the ABC algorithm, with the three dwellings working at the same time. It should be remembered that the optimization is performed on the entire system, so the algorithm optimization result will be applied to the parameters of the LoRa network and all connected devices.
The test has been performed during 6 h sending information of measures realized every 5 s. Figure 13 shows the optimization result with three parameter changes in the 6 h of operation, which adjusts the network parameters.  It can be observed that the dwelling with the lowest PLR is #1, and the one with the highest PLR is #3, which in no case exceeds 10%, which is quite a small value and acceptable for a LoRa network.

Measurement of Electrical Variables
In order to construct the load profiles of dwellings, it is first necessary to measure the electrical variables necessary to obtain the active and reactive energies. The measurements are made with the PZEM meter, which obtains the RMS values v, i, and p. Subsequently, calculations are made to obtain the values of q, PF, as well as active and reactive energy.
The measurements are made every 5 s, this time can be changed to adapt to the monitoring needing in each installation. Therefore, the system adapts to the configuration required by each user. Figure 14a,c,e show the voltage and current for dwellings #1, #2, and #3. Figure 14b,c,e illustrate the active and reactive powers for dwellings #1, #2 and #3. The data correspond to 14 days of data collection, sent through the LoRa LPWAN network using the proposed ABC algorithm. It can be observed that the dwelling with the lowest PLR is #1, and the one with the highest PLR is #3, which in no case exceeds 10%, which is quite a small value and acceptable for a LoRa network.

Measurement of Electrical Variables
In order to construct the load profiles of dwellings, it is first necessary to measure the electrical variables necessary to obtain the active and reactive energies. The measurements are made with the PZEM meter, which obtains the RMS values v, i, and p. Subsequently, calculations are made to obtain the values of q, PF, as well as active and reactive energy.
The measurements are made every 5 s, this time can be changed to adapt to the monitoring needing in each installation. Therefore, the system adapts to the configuration required by each user. Figure 14a,c,e show the voltage and current for dwellings #1, #2, and #3. Figure 14b,c,e illustrate the active and reactive powers for dwellings #1, #2 and #3. The data correspond to 14 days of data collection, sent through the LoRa LPWAN network using the proposed ABC algorithm.

Daily Load Profiles
The objective of EMDD is to obtain daily load profiles. Therefore, this section includes the results obtained for daily load profiles with hourly distribution for the three dwellings under study. Figure 15 shows the hourly load profiles of active and reactive energy of each dwelling in the four seasons of the year. Data collection over extended periods of at least one year allows for a fairly accurate characterization of user load profiles.

Daily Load Profiles
The objective of EMDD is to obtain daily load profiles. Therefore, this section includes the results obtained for daily load profiles with hourly distribution for the three dwellings under study. Figure 15 shows the hourly load profiles of active and reactive energy of each dwelling in the four seasons of the year. Data collection over extended periods of at least one year allows for a fairly accurate characterization of user load profiles. With the information from the load profiles, it is possible to perform studies of energy efficiency, both in homes and in the electrical network, demand forecasting, smart grids, distributed generation, use of renewable energies, etc.
Working with new smart meters, as is the case with EMDD, helps in a very efficient and interesting way to obtain load profiles in real time. With the information gathered, a large window of work is opened that will allow electrical engineering to make significant advances through the analysis of results, studies, simulations, or any other type of use of the data. The uploading of data in real time to the cloud contributes significantly to these advances and to making the current electricity grids more intelligent and with new capacities that allow for a significant improvement.
Energies 2020, 13, 517 20 of 29 With the information from the load profiles, it is possible to perform studies of energy efficiency, both in homes and in the electrical network, demand forecasting, smart grids, distributed generation, use of renewable energies, etc.
Working with new smart meters, as is the case with EMDD, helps in a very efficient and interesting way to obtain load profiles in real time. With the information gathered, a large window of work is opened that will allow electrical engineering to make significant advances through the analysis of results, studies, simulations, or any other type of use of the data. The uploading of data in real time to the cloud contributes significantly to these advances and to making the current electricity grids more intelligent and with new capacities that allow for a significant improvement. In order to be able to make a time comparison within the same graph for each dwelling and season of the year, Figure 16 is constructed, which shows the performance of each dwelling at each time of the year. It is possible to observe that in dwelling #1 the maximum consumptions take place In order to be able to make a time comparison within the same graph for each dwelling and season of the year, Figure 16 is constructed, which shows the performance of each dwelling at each time of the year. It is possible to observe that in dwelling #1 the maximum consumptions take place in summer. Dwelling #2 has the highest consumptions in winter, however dwelling #3 has similar consumptions at all times of the year. In addition to the hourly load profiles, it is especially interesting to perform any study in real time to obtain the energy curves. This possibility can also be obtained with the use of EMDD working in a LoRa network optimized with ABC. In this sense, Figure 17 shows the data obtained for one day of each season of the year, the data shown correspond to the active and reactive energy. In addition to the hourly load profiles, it is especially interesting to perform any study in real time to obtain the energy curves. This possibility can also be obtained with the use of EMDD working in a LoRa network optimized with ABC. In this sense, Figure 17 shows the data obtained for one day of each season of the year, the data shown correspond to the active and reactive energy. In addition to the hourly load profiles, it is especially interesting to perform any study in real time to obtain the energy curves. This possibility can also be obtained with the use of EMDD working in a LoRa network optimized with ABC. In this sense, Figure 17 shows the data obtained for one day of each season of the year, the data shown correspond to the active and reactive energy. Another added feature of EMDD is the realization of daily curves of accumulated energy consumption. These curves also make it possible to study the consumption produced in each home and the hours of maximum demand. The study of these curves offers great possibilities of analysis: one of them is to try to distribute the daily consumption so that the demand of the dwelling is stabilized in the hours where the energy has a lower price. Figure 18 shows the daily measured energy. Another added feature of EMDD is the realization of daily curves of accumulated energy consumption. These curves also make it possible to study the consumption produced in each home and the hours of maximum demand. The study of these curves offers great possibilities of analysis: one of them is to try to distribute the daily consumption so that the demand of the dwelling is stabilized in the hours where the energy has a lower price. Figure 18 shows the daily measured energy.  Another added feature of EMDD is the realization of daily curves of accumulated energy consumption. These curves also make it possible to study the consumption produced in each home and the hours of maximum demand. The study of these curves offers great possibilities of analysis: one of them is to try to distribute the daily consumption so that the demand of the dwelling is stabilized in the hours where the energy has a lower price. Figure 18 shows the daily measured energy. To finish with the results section, a comparison is made of the active power in relation to the active consumption at the same instant, both punctually and accumulated over time. This comparison makes it possible to evaluate the reactive power demand and try to reduce the consumption of reactive energy as much as possible, so that the electrical installation is much more efficient, and therefore more profitable for the user and helps to protect the environment by reducing CO2 emissions. Figure 19 shows excessive reactive power consumption for dwelling #2 in winter. This consumption should be corrected by means of a study of the connected equipment and the energy efficiency that they possess. This would allow to have a more efficient and friendly installation with respect to the environment. To finish with the results section, a comparison is made of the active power in relation to the active consumption at the same instant, both punctually and accumulated over time. This comparison makes it possible to evaluate the reactive power demand and try to reduce the consumption of reactive energy as much as possible, so that the electrical installation is much more efficient, and therefore more profitable for the user and helps to protect the environment by reducing CO 2 emissions. Figure 19 shows excessive reactive power consumption for dwelling #2 in winter. This consumption should be corrected by means of a study of the connected equipment and the energy efficiency that they possess. This would allow to have a more efficient and friendly installation with respect to the environment.  To finish with the results section, a comparison is made of the active power in relation to the active consumption at the same instant, both punctually and accumulated over time. This comparison makes it possible to evaluate the reactive power demand and try to reduce the consumption of reactive energy as much as possible, so that the electrical installation is much more efficient, and therefore more profitable for the user and helps to protect the environment by reducing CO2 emissions. Figure 19 shows excessive reactive power consumption for dwelling #2 in winter. This consumption should be corrected by means of a study of the connected equipment and the energy efficiency that they possess. This would allow to have a more efficient and friendly installation with respect to the environment. In the rest of situations and seasons of the year, reactive consumption is around 30%. An energy study could be performed with the data provided by EMDD. This study would allow to reduce the consumption of reactive energy to the owner of the housing that would result in a better operation of its installation, reduction of reactive energy that would imply a smaller generation, and a greater efficiency in the electrical network, as well as a reduction of CO2 emitted to the atmosphere.
The analysis performed in this section is just one example of the possibilities offered by the use of the smart meter EMDD. By making an appropriate and planned use of the characteristics of the equipment, numerous advantages can be obtained. Among the advantages obtained with EMDD, it is important to highlight: • Analysis and forecast of the demand. • Adjustment of the electricity bill.
• Power factor improvement. • Energy efficiency and reduction of electricity consumption.

Conclusions
This research develops a system for the determination of load profiles in dwellings using a LoRa LPWAN network to perform data transmission. It also implements an algorithm based on ABC, which optimizes the configuration parameters of the LoRa network to obtain a PLR that improves the efficiency of the network. In the rest of situations and seasons of the year, reactive consumption is around 30%. An energy study could be performed with the data provided by EMDD. This study would allow to reduce the consumption of reactive energy to the owner of the housing that would result in a better operation of its installation, reduction of reactive energy that would imply a smaller generation, and a greater efficiency in the electrical network, as well as a reduction of CO 2 emitted to the atmosphere.
The analysis performed in this section is just one example of the possibilities offered by the use of the smart meter EMDD. By making an appropriate and planned use of the characteristics of the equipment, numerous advantages can be obtained. Among the advantages obtained with EMDD, it is important to highlight: • Analysis and forecast of the demand. • Adjustment of the electricity bill. • Power factor improvement.

•
Energy efficiency and reduction of electricity consumption.

Conclusions
This research develops a system for the determination of load profiles in dwellings using a LoRa LPWAN network to perform data transmission. It also implements an algorithm based on ABC, which optimizes the configuration parameters of the LoRa network to obtain a PLR that improves the efficiency of the network. The algorithm has been implemented in GLNM, a device that monitors the network and executes the ABC algorithm to adapt the network configuration when the PLR is increased in real time. GLNM is responsible for receiving data from installed EMDDs and uploading it to the cloud using Firebase.
EMDD is a smart meter developed to obtain load profiles in homes with configurable measurement times. The possibilities of EMDD measurement include hourly load profiles, measurements of electrical variables, curves of active and reactive energy in real time, as well as curves of active and reactive energy accumulated daily. The features of EMDD facilitate studies on demand forecasting, energy optimization of the dwelling, improvement of electricity billing, etc.
The results obtained by applying the ABC algorithm to each house individually have a PLR of 11.1% for dwelling #1, 3.23% for dwelling #2, and 11.03% for dwelling #3. Subsequently, a study has been realized for the dwellings working together, obtaining PLR values lower than 10%. PRL are very reduced, which guarantees the reliability of the system made with EMDD and GLNM devices. Meanwhile, with the application of the ABC algorithm, the optimal configuration is obtained in real time. EMDD is designed to measure up to 23 kW with an accuracy of less than 1%.
With a PLR less than 10%, using the ABC algorithm, hourly load profiles have been determined in different seasons of the year for a measurement interval of 5 s. Also, the study performed in the three dwellings over 14 days allows to verify the reliability of EMDD. Graphs (electrical variables, active energy, and instantaneous reactive and daily accumulated energy) obtained with the additional characteristics of EMDD have been included.
The consumption of reactive power versus active power has been obtained, indicating the relationship between these powers and allows a study to reduce reactive consumption and achieve more efficient dwellings.