Smarter Grid in the 5G Era: Integrating the Internet of Things With a Cyber-Physical System

The Smart Grid, a fusion of digital technologies and advanced communication methods, enables the transformation of power distribution, transmission, and generation by responding to fluctuations in electricity consumption. Conventional electrical grids often leave consumers unaware of their energy usage patterns, resulting in both energy wastage and financial loss. To enhance energy efficiency, the consumption patterns of consumers need regulation. Smart Grids efficiently employs Demand-Side Management (DSM) strategies, including peak clipping, load shifting, and consumer awareness campaigns, to optimize energy consumption and achieve energy savings. DSM’s synergy with smart meters and smart energy management systems (SEMS) emerges as a powerful trio in comprehensive energy conservation and optimization. The integration of SEMS with the Internet of Things (IoT), augmented by the advancements in 5G technology, emerges as a transformative paradigm. SEMS, operating within the IoT ecosystem bolstered by 5G connectivity, facilitates the instantaneous and efficient integration of IoT in SEMS, enabling real-time data collection, in-depth analysis, and data-driven decisions for optimal energy management. This empowers users with the ability to make data-driven decisions, yielding tangible outcomes in the form of efficacy, cost reductions, and fortified sustainability initiatives. We present a SEMS that amalgamates three microcontroller units to create a smart meter that is further integrated with a cloud-based middleware module and consumer API. Furthermore, it collects vital power metrics such as voltage, current, kWh, kW, and PF. Consumers can conveniently access this data in real-time via an API. Energy service companies can leverage this data for incentive programs and to motivate customers to optimize their energy consumption. These datasets serve as a foundational element for the development of diverse DSM strategies. This research work presents the deployment, and performance evaluation of an IoT-based SEMS that is implemented in diverse settings, including industrial, commercial, building, and warehouse setups. Moreover, as a test case, our evaluation extends to the specific conservation of energy within air-conditioning systems. The SEMS achieves significant energy conservation, with calculated savings ranging from 5% to 53%, showcasing its effectiveness in targeted energy management. The real-time data and case studies further demonstrate the efficiency of the presented work.


I. INTRODUCTION
An electric grid (EG) commonly referred to as a power grid (PG) is an interconnected network of the generation, transmission, and distribution system for supplying electricity to the consumers.The technology and operation of the conventional electric grid (CEG) is more than 100 years old without any significant developments in its basic infrastructure, regardless of the fact, that the energy demand and its usage have risen drastically during the last few decades, which further necessitates the efficient control and effective management of electricity besides the production of electricity on larger scale.
In 2021, worldwide electricity demand rose by 6% -the highest percentage rise since 2010, as a result, the CO2 emissions have reached new heights [1].Further, the demand for electricity is expected to rise by 3.3% in 2024 as well [2].The energy usage and its increasing need drastically create the inevitable challenges for EG such as load management, recurrent power failures, and environmental vulnerabilities.
The aforementioned challenges are worse in underdeveloped nations, where there is a huge gap between demand and supply of electricity and an increase in energy loss due to mismanagement [3].For example, Pakistan's total electricity demand has increased substantially in the last few years and is likely to rise in a similar manner.A recent study predicts that Pakistan's need for electricity is expected to reach 346 TWh by 2030 whereas it could reach 601 TWh in 2035, and a much larger 2297.7 TWh by 2050 [4].This means that every year, on average, the demand will grow by about 12.15%.However, the generation capacity has failed to align with the escalating demand, resulting in chronic energy shortages.Despite the prevailing energy crisis and the load shedding of almost 10 hours a day [5], Pakistan's generation from renewable sources remains notably low, accounting for only 4% of the total [6].Thermal resources, on the other hand, constitute the largest share at 68% of the overall energy generation Furthermore, a significant portion of electricity consumption, approximately 75%, is attributed to residential and industrial consumers in the country [6].Figure 1 displays Pakistan's electricity generation and consumption from diverse sources and sectors.
These issues can be effectively addressed by bringing substantial improvements in the CEG.The smart grid (SG) represents a technological evolution of CEG that offers a promising solution to future energy demands.The SG employs cutting-edge digital technologies and bi-directional communication protocols to monitor and control in Real Time (RT).It also tracks energy consumption patterns and responds to changes in electricity usage, optimizing the operation of generation, transmission, and distribution components of CEG.The foundational SG model stems from the advanced-metering-infrastructure (AMI) concept, integrating demand-side-management (DSM) as a pivotal technology for enhancing energy efficiency (EE) [7].DSM monitors and regulates energy consumption from the consumer's perspective.Figure 2 illustrates the SG, featuring multiple power sources, transmission lines, Energy Management Systems (EMSs) installed in diverse buildings, and a central control center.The DSM employs RT command and control techniques to regulate electricity consumption patterns, thereby enhancing the overall EE of a system.Figure 3 shows various DSM approaches.It is worth mentioning that the paper primarily focuses on the implementation of the Energy Conservation/Efficiency Strategy within the framework of smart energy management systems (SEMS).This strategy involves achieving energy efficiency through the utilization of energy-saving algorithms and directives, leveraging data from the Cloud Analytics (CA) layer.Details are provided in section III of the paper.Successful implementation of DSM techniques stabilizes electricity consumption and positively impacts the overall energy demand of electric supply companies (ESCOs).Effective DSM schemes modify customer load profiles (LPs) and can also alter ESCOs' maximum demand (MD), leading to reduced energy rates [8].DSM offers a cost-effective strategy for achieving EE that is crucial in developing countries where transitioning from CEG to SG might be economically challenging due to extensive infrastructural changes [8].Furthermore, according to the United Nations Sustainable Development Goals, EE stands as the most cost-effective approach to satisfy escalating energy demand [9].As Pakistan's energy costs continue to rise, the FIGURE 2. The representation of the SG, featuring multiple power sources, transmission lines, energy management systems (EMSs) installed in diverse buildings, and a central control center [7], [10] .need for more sustainable and efficient energy consumption becomes imperative.The EE, alongside improved monitoring and control systems, plays a crucial role in mitigating the impact of these rising tariffs.By embracing energyefficient practices, consumers and industries can not only cut costs but also alleviate the strain on the national power grid [10].Furthermore, better monitoring and control systems enable RT tracking of energy usage patterns, allowing for proactive adjustments to optimize consumption during peak hours and reduce wastage.DSM contributes to this goal by facilitating load control and monitoring, thereby enhancing EE [11].
With the recent developments in digital technologies, the DSM techniques supported by automated smart monitoring and effective control methodologies are emerging as the bedrock for SEMS [8].The ESCOs deploy SEMS for the monitoring, control, and optimization of electricity transmission, distribution, and generation.SEMS is a technological framework deployed at the consumers' end that empowers both consumers and ESCOs to monitor electricity consumption patterns and adapt/alter energy usage within residences, buildings, industries, and other facilities.Consequently, the efficiency of DSM correlates with an efficient energy management system (EMS) that monitors and controls energy consumption patterns as well as responds to energy-saving algorithms and directives [7].A pivotal element in transitioning from EMS to SEMS is the successful deployment of smart meters (SMs) [12].The SMs are essential for bi-directional communication in the smart environment (SE).SMs transfer all data to the data centers periodically which can be further utilized for monitoring, data analysis, load profiling, and DSM.The SMs associative with the Internet of Things (IoT) technologies can revolutionize the SEMS, making it more successful and efficient in the SG [13].
IoT technology plays a crucial role in managing power and resources in SE.It enables efficient networking, monitoring, and responsive control of various electrical devices [14].This technology also allows seamless two-way communication among sensors, devices, and the electrical network that further reducing the need for human intervention in command and control and consequently optimizing resources [15], [16].This also empowers customers and ESCOs to regulate energy consumption patterns and promote EE [8].
To implement successful DSM in SG, an efficient, costeffective, autonomous, reliable, and RT EMS is essential.According to authors in [17], Heating, Ventilation, and Air Conditioning (HVAC) systems make-up 60% of electricity usage in the Gulf States and 44% in Pakistan [18].In developing nations, residential buildings contribute over 45% of the electricity demand on the grid [19].Rashid and Sahir suggest that residential loads, which include shift-able loads, can assist in shifting peak demand and managing energy [20].In a report, NEPRA highlighted that residential consumers consume around 50% of the total electricity generated in the country, while industrial usage stands at 26% [6].This underscores the potential impact of targeting EE improvements in both residential and industrial sectors to achieve substantial energy savings.As homes and buildings constitute a major part of the grid load so regulating their consumption is crucial for better network performance.This study focuses on RT DSM control within SG using IoT-based SEMS in 4 buildings.This approach integrates the SMs and an IoT middleware (cloud) module to manage and analyze data effectively.
The key contributions of this research are outlined as follows: • Offers a framework with SMs and IoT middleware for efficient data management.
• Presents a multilayered EMS architecture for effective appliance control.
• Includes deployment, and RT evaluation of the solution, including separate SM for Air Conditioning (AC) control.
• Evaluate EMS performance in different locations, confirming applicability and scalability.
• Aim for RT energy savings by reducing energy without compromising comfort.The remainder of this paper is organized as follows: Section II presents the literature review.The system architecture is detailed in Section III.Section IV encompasses the demonstration, deployment, and RT performance evaluation using RT data.Section V outlines the challenges and potential benefits of the presented solution.Finally, in conclusion, Section VI provides a summary of the findings and offers insights for potential future research directions.

II. LITERATURE REVIEW
Efficient energy management is crucial to meet growing power demand and enhance quality of life.The shift to a SG integrates renewable energy sources (RES), communication, and automation for optimized energy usage and reduced reliance on the grid through load control, temperature regulation, and integration of RES consequently decreasing utility grid demand and lowering electricity costs [21].The imminent threat of climate change due to rising CO2 emissions from increased energy demand in buildings necessitates effective solutions.The SGs offer a solution through, DSM and demand response (DR) strategies, contributing to reducing energy demand and CO2 emissions in buildings and promoting energy sustainability.This study [22] comprehensively explores diverse DR strategies and technologies for SG-adopted buildings, discussing insights, challenges, and potential enhancements to drive sustainable energy practices.Efficient electrical energy management within a SG is crucial for energy savings, and IoT-based systems are emerging as effective tools for monitoring appliance consumption.The work [23] presents a novel IoT device, integrating cloud and edge analytics, for DSM in a SE.The prototype's autolabeling capability for RT load identification demonstrates the feasibility and effectiveness of this approach.
In SE, appliances interconnect with a data center to monitor and measure energy consumption, benefiting both ESCOs and consumers.This enables users to track usage and automate appliances for efficient energy use.SEMS have emerged from these setups, offering automated DSM for ESCOs to reduce waste and consumers to minimize bills.The DSM encompasses measures to enhance consumption efficiency, spanning from material improvements to RT monitoring and control.Authors in [24] offers a DSM overview, and presents challenges as well as further directions, providing an overview of this field.
The work in [25] addresses the importance of DSM in SG, focusing on efficient communication infrastructure and energy storage planning approach.The approach considers user preferences and cost balance in energy management that improves peak-to-average ratio (PAR), cost, and energy consumption in SG networks.The paper [26] investigates blockchain-based DSM, focusing on PAR reduction and minimizing power consumption.
The Home Energy Management System (HEMS) concept emerges from smart home developments, aiming for automated, adaptive, and efficient appliance interactions.When integrated with SG technology, HEMS aids in improving power systems quality through DSM resulting in reduced power losses and improved voltage profiles [27].The rise of smart homes, powered by advancements in wireless protocols and cloud services, has ushered in a new era.The article [28] introduces ZiWi, a fog computing Home Automation System (HAS) that facilitates seamless communication between ZigBee and WiFi devices.The DSM using DR is effective for consumer-side energy management.HEMS utilizes energy management controllers/schedulers to optimize appliance and energy resource usage.This study [29] presents a model and proposes a Particle Swarm Optimization (PSO) based scheduler for HEMS, demonstrating its application in a smart home with real-time pricing (RTP) and time of use (ToU) considerations.Another research work [30] introduces an advanced HEMS utilizing nonintrusive load monitoring (NILM) and an automated multi-objective power scheduling approach.The proposed system effectively schedules household appliances in response to DR schemes and demonstrates its feasibility in a RT environment.This paper [17] introduces a SEMS for smart homes, utilizing Big Data technologies and IoT to monitor and save energy.It employs IoTenabled devices and a mesh wireless network, gathering data of energy consumption and communicating it to a centralized server for analysis.The proposed EMS uses Business Intelligence and Big Data analytics software to manage energy consumption.
The research work [31] offers an architecture that integrates, local fog nodes, home gateways, and cloud servers to ensure interoperability and secure connectivity between PG and the Internet.Another work [32] proposes an IoT-based Commercial-Building-Energy Management-System (CBEMS) utilizing Smart-Compact-Energy-Meters (SCEMs) and DSM for monitoring and controlling energy usage and power quality.The article [33] addresses the increasing electricity consumption driven by household appliances and the need for better monitoring.It proposes an IoT-enabled SM to track the electricity consumption of various household devices that further promotes awareness and assists customers in managing energy usage.The growing use of smart appliances and the resulting demand-supply gap drive the need for DSM.The proposed SEMS [34] integrates ZigBee communication, optimization algorithms, and IoT for data storage and analytics.The paper [7] emphasizes the role of EMS in monitoring and managing electricity consumption patterns using digital communication technologies.The proposed EMS, implemented on a PCB, tracks electricity usage, transmits data to Google Firebase cloud, and produces LPs that are accessible via a web application for efficient DSM implementation.Some recent articles [35], [36] explore the integration of RES, energy storage technologies, microgrid management systems, digital twin-based methods, artificial intelligence (AI), and machine learning (ML) strategies with cloud computing to enhance energy management.They emphasize that efficient monitoring and control are the foundation for achieving EE and reaching net-zero energy buildings (nZEB).The paper in [37] introduces a data-driven architecture for exchanging, managing, and processing energy-related data from European buildings.It combines AI and ML algorithms for EE services and effective building operations.This study presents [38] EMS for smart homes that integrate to reduce electricity bills.Authors in [39] introduce a cost-effective open-source IoT solution for RT monitoring of solar power stations, leveraging IoT technologies to enhance energy production efficiency and environmental conditions.The laboratory prototype is designed for scalability to monitor large-scale photovoltaic stations, sending alerts to remote users for any deviations in solar power generation quality from predefined standards.Another work [40] presents an Intelligent Monitoring System (IMS) for Photovoltaic (PV) systems, utilizing affordable hardware and lightweight software for easy implementation in diverse PV power plant settings.The proposed system uses IoT for data handling and communication, along with a personal cloud server and web monitoring.
The paper [41] introduces IntelliHome that employs big data analytics and machine learning to actively engage users in RT energy-saving, validated by a successful case study, affirming its effectiveness in reducing electrical energy consumption.Electricity usage in Pakistani buildings has surged by 26.46% since 2006, maintaining an annual growth rate of +2.9% [18].Notably, residential buildings contribute significantly, accounting for 45% of the nation's total energy consumption.In the next two decades, building energy usage is expected to rise by over 40% [19].As electricity remains the primary energy source for buildings and its demand continues to increase therefore effective energy management strategies are crucial, especially for developing countries.
The following is the summary of research gaps: In the context of energy monitoring and energy management features, various research works reveal the following key points: Energy Monitoring Features: Most works lack RT power factor (PF) evaluation and bidirectional power measurement.This work provides comprehensive energy monitoring features (kW, kWh, kVarh) with RT PF evaluation.
Energy Management Features: This work addresses the energy management gap by providing complete load control and middleware integration.
Real-Time Performance Evaluation: While most works focus on RT performance evaluation, some do not offer multiple location evaluations.
Real-Time Energy Saving: This work aims for RT energy savings through efficient load control while maintaining comfort levels.
It also highlights that while various research works have contributed to energy monitoring and management, there is a need for a comprehensive solution that covers RT monitoring, load control, middleware (cloud) integration, and energy savings.This study effectively bridges the gaps by providing a single integrated approach that encompasses all the mentioned features, leading to a robust and efficient energy management system.Table 1 provides the comparison of various SEMS with the presented work.

III. SYSTEM MODEL
This work offers monitoring of various electrical devices/facilities and controlling their power use in RT.It also tracks and assesses numerous power metrics (PM) like voltage, current, apparent power, reactive power, active power, and PF.It also works for the monitoring and control of numerous appliances like ACs.The SEMS includes hardware components that integrate 3 microcontroller-units (MCUs) [42], [43], [44] to make SM and software components that include a cloud server (middleware module) [45], and an application programming interface (API) [46] that

B. OVERVIEW OF SMART ENERGY MANAGEMENT SYSTEM
The SEMS includes hardware components that integrate 3 microcontroller-units (MCUs) to make SM and software components that include a cloud server (middleware module), and an application programming interface (API) that communicates wirelessly and can analyze data efficiently.They are explained in subsections.2.
The mathematical computation of PMs is detailed as follows [47].
RMS values of current and voltage are calculated by Equation (1) and Equation ( 2) respectively where, • i Phase (n) = Instantaneous current sample at time n • i Phase Offset = Offset employed to eliminate the influence of Additive White Gaussian Noise (AWGN) from the current-converter.In essence, it helps in reducing noise interference in the current conversion process.
• v Phase (n) = Instantaneous voltage sample at time n v Phase Offset = Offset employed to eliminate the influence of AWGN from the voltage-converter • Sample Count = Sample count within a designated time interval • K iPhase = Current Scaling − Factor (SF) • K vPhase = Voltage SF Active Power (kW) and Reactive Power (kVarh) are calculated using Equations ( 3) and (4). (3) where, • K ACTph = SF for kW  Apparent power of each phase is calculated by Equation (5).
After calculating per phase kW, kVarh and apparent power, the cumulative sum of these parameters is determined by the following equations.
The PF is determined using the below equation.

Power factor = P ACTIVE P Apparent (9)
2) SOFTWARE COMPONENTS Cloud middleware module [45] and API [46] are key hardware components of cloud-based SEMS for data communication and integration.An API is the front-end mobile user interfaces were crafted using a cross-platform Integrated Development Environment (IDE) [46].It serves as a set of rules and tools for building software and facilitating communication between different software applications.IoT enabled APIs play a pivotal role in enabling RT data exchange, seamless integration and interaction among diverse devices, sensors, and platforms within an IoT ecosystem.
A cloud middleware module is a software layer that acts as an intermediary between SMs and API.It facilitates communication, data exchange, and interoperability among different devices, services, and applications.It also includes features like data storage, data processing, and scalability.It utilizes lightweight Message Queuing Telemetry Transport (MQTT) protocol for data communication between SM and cloud middleware module.An API capacitates consumers to get the RT data using Hypertext Transfer Protocol (HTTP) protocol.Cloud middleware serves as an MQTT broker for MQTT integration, and it interacts with hosted APIs on web servers for HTTP integration.

C. OPERATIONS OF SEMS
The SEMS operation involves following steps: • MSP430F67641 analyzes PM, sends data to TM4C129x via UART.
• TM4C129x stores data in EEPROM every 30 seconds.
• TM4C129x converts data to JSON, transfers via UART to nodeMCU for MQTT protocol publication to IoT middleware, repeated every 30 seconds.
• IoT middleware integrates devices, enabling data storage, RT access, and processing.
• API connects middleware to users via nodeMCU for remote access.
• Analytical engine generates reports for electricity PM assessment, usage statistics, and analysis.
The flow chart of the presented SEMS is provided in Figure 6.

IV. DEPLOYMENT AND PERFORMANCE EVALUATION
In this section, we showcase and assess the presented solution through RT implementation results.We particularly highlight the effects of employing a dedicated SM for the automated control of the AC system considering various Time Slots (TS) based on 24 hours and dynamics of corporate building.
For performance analysis and validation of the presented solution, SMs with 100A current transformers (CTs) were deployed at the primary distribution-boards (DB) of 4 distinct facilities/locations of Stylo Pvt Ltd, a renowned private company in Lahore, Pakistan.Every SM captures the PM of its respective location/facility and transmits the data to the central middleware IoT based cloud server for further investigation.The deployment of SMs and CTs is depicted in Figure 7, while data collection, RT monitoring, and various reports from the central cloud server are facilitated through the API, as shown in Figure 8.
Data from SMs was collected through the CA layer using an API to facilitate energy assessment.The collected data underwent thorough analysis employing various techniques, as illustrated in detail in Figures 4 and 6.These figures provide a comprehensive overview of the SEMS's layered architecture, operations, and data flow, enhancing the understanding of the energy assessment process.Figure 9 (a) displays the daily average kWh consumption from 2023-03-06 to 2023-04-25 of all facilities i.e., Stylo Factory (SF) Stylo Head Quarter (SHQ), Stylo Shop (SS) and Stylo Warehouse (SW).It is observed from the figure that energy consumption shows variations based on influence of operational hours and working days.Consumption is generally higher on weekdays compared to weekends.Notably, energy consumption is lower on Sundays (off days) compared to other days of the week.A significant increase in consumption is observed of SHQ from 1500 kWh to almost 2200 kWh on 2023-03-28 to 2023-3-29.This spike is attributed to the turning on of central HVAC units, resulting in increased energy demand.Additionally, energy consumption is consistent on weekends (Sundays) when both units are off, contributing to lower energy usage.For SS and SW, the energy consumption pattern follows a relatively consistent trend throughout the period.It may also be noted that during the National/Public Holidays [48] i.e., on 2023-03-23 on Pakistan's Resolution Day, and from 2023-04-21 to 2023-04-25 on Eid-ul-Fitr holidays energy consumption is observed to be low, similar to weekends (off days).This is due to no business activities and operational hours during these holiday periods.Figure 9  daily average kVarh consumption from 2023-03-06 to 2023-04-25 of all facilities which also shows the same trend as of kWh figure.PF is a crucial parameter in electrical systems that measures the efficiency of power usage and indicates the balance between real power (kW) and apparent power (kVA) in a circuit.A high PF indicates efficient energy utilization, while a low PF signifies wastage of energy due to reactive power.Maintaining a high PF is essential for optimal energy consumption and reduced electricity costs.Figure 9(c) displays the daily average PF from 2023-03-06 to 2023-04-25 of all facilities, by analyzing the PF data, it can be observed that SF consistently exhibits a relatively lower PF.This low PF might be attributed to inductive loads in the factory's operations.Inductive loads, common in industrial setups, cause a phase shift between current and voltage, resulting in a lower PF, which leads to the penalties [49].This suggests a scope for PF correction measures to enhance EE and reduce power wastage in the SF.Recording these data across all locations is of paramount importance for Stylo Pvt. Ltd.This practice not only helps in optimizing energy usage and cost reduction but also aids in meeting sustainability goals, ensuring regulatory compliance, and making informed infrastructure decisions.Additionally, it enables predictive maintenance, load balancing, and empowers data-driven decisions, ultimately contributing to enhanced operational efficiency and a culture of energy conservation.
Monitoring MD is very important as it offers insights for load shifting, DR strategies, and cost reduction.Understanding peak demand patterns can guide decisions related to equipment operation schedules and energy -conservation measures.Further, it aids in load forecasting and capacity planning to prevent overloads and power interruptions.The data includes the half-hourly MD for two different dates, 2023-03-08 and 2023-04-18, showing the electricity demand patterns of all locations as shown in Figure 10, it displays the variation throughout the day, with higher values during certain hours.There is also a notable drop in MD during the break hours and during night hours.
For SHQ, on 2023-03-08, the MD ranges from 8.4048 kW during non-peak hours to a peak of 124.6 kW.On 2023-04-18, the MD followed a similar pattern, ranging from 9.064 kW during non-peak hours to a peak of 176.17 kW.However, the overall energy demand is notably higher compared to 2023-03-08.This increase in demand is attributed to the HVAC system being tuned on to maintain a comfortable working environment.The SS follows the same trend as of SHQ, that displays the increase in MD on 2023-04-18 due to the turning on of the HVAC load to make the comfortable shopping environment.It may also be noted that MD is lower in non-operating hours.
For SF, on 2023-03-08, the MD ranges from 0.618 kW during non-peak hours to a peak of 30.591 kW during the evening hours (20:00 to 20:30), whereas on 2023-04-18, the MD ranges from 0.103 kW during non-peak hours to peak of 57.371 kW during the evening (20:30 to 21:00).For SW, MD occurs typically during the late morning and early afternoon hours, between 10:00 AM and 03:00 PM, with values ranging from approximately 19 kW to 27 kW.The lowest demand occurs during the early morning hours, around 5:00 AM, with values as low as 8 kW.The data for 2023-03-08 shows a higher MD compared to 2023-04-18.This variation in MD between the two dates reflects the dynamic nature of the warehouse's operations which is attributed to specific operational requirements, increased dispatch orders, or other factors leading to a greater need for electrical power during that particular day.The operational Schedule of Stylo facilities is provided in Table 3.
Based on the daily gross unit's consumption and MD data for SHQ and SS, it becomes evident that HVAC systems, particularly AC, significantly contribute to electricity consumption.Therefore, effectively managing their usage can have a substantial impact on enhancing EE and sustainability.To illustrate this and as a proof of concept, a dedicated SM was installed to monitor, regulate, and optimize the electricity consumption of the data center's AC at SHQ.This choice was deliberate as the data center's AC operates continuously, underscoring its significance in energy management, conservation and peak clipping.To achieve this, SM with a nodeMCU, a relay module and time relay is connected to the magnetic contactor, as shown in Figure 11, which further operates the load based on the received signal from CA layer.The operations of a magnetic contactor in load management involves a synchronized process driven by signals received from the CA layer, efficiently executed with the assistance of nodeMCU, a relay module, and a time relay.To achieve EE, we developed an algorithm based on the temperature difference and the operation dynamics of data center's AC.The details of each TS and the related algorithm are provided in Figure 12, it intelligently assesses and responds to different TS.The algorithm was executed within the CA layer and further processed at the ECON layer.When the CA layer identifies specific TS, it sends a signal to the nodeMCU.The nodeMCU acts as a bridge, receiving and interpreting this signal.Upon receiving the CA's instructions, the nodeMCU triggers the relay module.This relay module, in turn, controls the magnetic contactor.The magnetic contactor, being a powerful electrical switch, either opens or closes based on the relay's command.The timer relay ensures that the magnetic contactor operates at the right moment, aligning with the CA's load management strategy and the related algorithm.Figure 13 illustrates the comparison of power consumption before and after the implementation of an energy-optimization algorithm during specific TS.It demonstrates notable improvements in energy conservation, contributing to enhanced EE and sustainability.The highest savings of 6.7 kWh (53%) were observed during ''Night Energy Optimization,'' followed by ''Thermal Comfort Dynamic Lock,'' ''Evening Energy Optimization,'' and the lowest savings of 0.5 kWh (5%) in ''Midday Surge Handling.''

V. DISCUSSION
This section outlines the deployment challenges and potential benefits of the presented SEMS.
Deploying a SEMS in various real-world settings, including industrial, commercial, building, and warehouse setups, involves addressing a spectrum of challenges.The primary challenges are succinctly outlined below.
Data Transmission and Interoperability: Challenge: Achieving smooth data transmission and interoperability between SM, API, and middleware module/cloud server.
Solution: Standardized communication protocols such as MQTT and HTTP were implemented for the data transmission between the SM, API, and middleware module.These protocols capacitate devices and systems to communicate effectively with each other.The AP layer facilitates communication with the cloud server for monitoring parameters like device info and energy use.It is accessible remotely via IP/TCP modules.The COM layer serves as the bridge connecting the cloud server and the SEMS deployed at the user's end using IoT protocols for bidirectional data exchange.
Real-Time Data Management: Challenge: Managing RT data collection, storage, and analysis.
Solution: The CA layer utilizes cloud services for storage, analytics, and energy-saving directives/algorithms.A cloud middleware module facilitates communication, data exchange, and interoperability among different devices, services, and applications.It utilizes MQTT protocol for data communication between SM and cloud middleware module.An API capacitates consumers to get the RT data using HTTP protocol.The middleware module and efficient communication protocols addressed challenges associated with RT data management.
Technical literacy and Training: Challenge: Ensuring that facility/location managers are adequately and adopt/monitor the system effectively.
Solution: Training programs for facility/location managers were conducted to address this challenge.This also addresses varying levels of technical literacy among end-users.
Additional challenges, such as limited access to advanced technologies and socio-economic factors, for instance, the willingness to adopt new technology, may arise, particularly in developing countries.Mitigating these challenges can be achieved through comprehensive training initiatives and the implementation of incentives programs which will be carried out in the future amplification of this research.
Implementing a comprehensive energy monitoring and control solution that tracks voltage, current, kWh, kVArh, kW, PF, and manages various loads like HVAC and AC offers numerous benefits, particularly in developing countries.The integration of 5G technology is pivotal for enhancing the performance of both the SG and SEMS.5G ensures highspeed communication, enabling rapid data exchange for RT monitoring and control within the SEMS, that facilitate quick decision-making thereby enhancing overall responsiveness.Additionally, 5G provides robust connectivity, ensuring continuous communication between SEMS components even in dynamic environments [50].Whereas IoT integration in SEMS brings advantages, including RT monitoring for instant data collection and analysis, optimizing energy management strategies.The synergy of SEMS with IoT empowers users with data-driven decision-making capabilities, promoting efficient and sustainable energy practices through continuous data collection on various parameters.This helps identify inefficiencies and implement costeffective measures, improving overall efficiency and reducing operational costs.IoT integration also allows ESCOs to provide EE recommendations, leading to a substantial reduction in energy wastage and contributing to the system's reliability [10].The potential benefits of the presented system summarized below.
Energy Cost Reduction: By monitoring and optimizing energy consumption, businesses, facilities, and households can reduce their electricity bills significantly.Further, ESCOs can pinpoint inefficiencies in the distribution network, reduce losses, and lower operational costs.This, in turn, can lead to reduced electricity bills for consumers and improved financial sustainability for ESCOs.
Improved Energy Efficiency: The RT monitoring of power consumption at various facilities, such as SS and SHQ, helps identify energy-intensive equipment and areas.Utility companies can offer EE recommendations to businesses, facilities, and households, leading to reduced energy wastage.
Enhanced Reliability: Monitoring helps identify and address power quality issues, reducing downtime and equipment damage due to voltage spikes or drops thereby extending the lifespan of electrical equipment and reducing maintenance costs.ESCOs can leverage RT data to predict and prevent grid failures.This is crucial in regions with vulnerable grid infrastructure, where outages can have serious economic and social consequences.
Environmental Impact: Developing countries rely on fossil fuels for power generation Reduced energy consumption translates to a smaller carbon footprint, improving air quality and, contributing to environmental sustainability.It aligns with global efforts to combat climate change.
Peak Load Management: By implementing load-shedding strategies during peak demand hours, utility companies can alleviate stress on the grid and avoid expensive infrastructure upgrades, benefiting both the company's bottom line and consumers' pocketbooks.
Data-Driven Decision Making: Access to comprehensive energy data enables informed decision-making regarding energy-related investments and future planning.Smart Grid Integration: In developing countries, where grid infrastructure is less robust, this solution can lay the foundation for smarter and more efficient energy grids.
Figure 14 displays the benefits of the presented SEMS.

VI. CONCLUSION
This research work underscores the vital role of SEMS and IoT in modern energy management.The RT monitoring and DSM capabilities, coupled with data-driven decision-making, hold the key to achieving EE, cost savings, and sustainability.It provides valuable insights into the transformative potential of energy monitoring and optimization through DSM with IoT-Based SEMS.The integration of SEMS with the IoT, augmented by the advancements in 5G technology, emerges as a transformative paradigm.SEMS, operating within the IoT ecosystem bolstered by 5G connectivity, facilitates the instantaneous and efficient integration of IoT in SEMS, enabling RT data collection, in-depth analysis, and data-driven decisions for optimal energy management.The RT data collection, monitoring and analysis capacitate both consumers and ESCOs for precise energy management and optimization.The synergy between DSM strategies, SEMS, and IoT enables consumer awareness, leading to tangible cost reductions in energy consumption.Consumers can make data-driven decisions to reduce their energy bills.
The presented system plays a pivotal role in sustainability initiatives.This research also represents a significant step towards enhancing EE and sustainability in developing countries.By leveraging advanced energy monitoring and control solutions, such as extensive monitoring and the algorithm devised and deployed in the Stylo company's facilities, tangible benefits can be realized.The analysis of daily kWh usage and MD patterns reveals the critical role of data collection in informed energy management.The algorithm's effectiveness in optimizing energy consumption during specific TS, combined with its focus on the data center's conditioning system, showcases the potential for substantial energy savings.The calculated percentage savings range from 5% 53%, as shown in figure 12, highlighting the system's effectiveness in targeted energy management.The research work showcases the adaptability and efficiency of SEMS in various settings, including industrial, commercial, building, and warehouse setups.Specific energy management within critical systems, like air-conditioning, highlights its versatility.ESCOs can leverage the collected data for incentive programs and to motivate customers to optimize their energy consumption.Further, this data forms the foundation for the development of diverse DSM strategies.
Moreover, this research aligns with the broader global shift towards modernizing energy infrastructure.The integration of CEG with SG, facilitated by technologies like SMs, enables precise energy monitoring and DSM.The utilization of the IoT for data collection and control further enhances these efforts.These solutions can reduce energy costs, enhance EE, balance loads, and contribute to environmental sustainability.Moreover, they offer a pathway to improving grid reliability, a crucial factor for economic growth and societal well-being in emerging economies.As the global community grapples with the challenges of sustainable energy, this research underscores the practicality and real-world impact of deploying advanced energy management systems in developing regions.It serves as a beacon of hope for addressing energy-related issues while advancing economic and environmental goals in these vital areas.
1) HARDWARE COMPONENTS It includes SM which incorporates the integration of three MCUs.The first one is the Texas Instruments (TI) MSP430F67641 MCU is employed for computing PM [42].It integrates input circuits for current and voltage monitoring, accommodating up to 50 mA inner currents and a maximum 270 V neutral-to-phase voltage range.Surge suppressor TVS diodes and varistors handle transients.The voltage and current monitoring input circuits are depicted in figures 5(a) and 5(b), respectively.The second MCU, TIVA C Family TI TM4C129x [43], utilizes ARM Cortex-M4F architecture for data storage and remote load control.It interfaces with nodeMCU [44] for bidirectional connectivity.Data is collected via a UART link between the nodeMCU and the SM.The nodeMCU supports various IoT standards and connects wirelessly to the IoT middleware module.Specifications of MCUs are provided in Table
(b) displays the

FIGURE 7 .
FIGURE 7. (a) Smart meter in the distribution box.(b) Current transformer in the distribution.

FIGURE 8 .
FIGURE 8. Application programming interface: Instantaneous state of the SMs.

FIGURE 10 .
FIGURE 10.(a) Comparison of MD of March 08, 2023 and April 18, 2023 for Stylo factory (b) Comparison of MD of March 08, 2023 and April 18, 2023 for Stylo Head Quarter (c) Comparison of MD of March 08, 2023 and April 18, 2023 for Stylo Shop (d) Comparison of MD of March 08, 2023 and April 18, 2023 for Stylo warehouse.

FIGURE 11 .
FIGURE 11.(a) Integration of SM with relay module, time relay and magnetic contactor (b) Experimental-setup to optimize load of air conditioner installed in data center.

FIGURE 12 .
FIGURE 12. (a) Detail of each time-slots (b) Energy optimization algorithm based on operational dynamics.

TABLE 1 .
Comparison between the presented work with various IoT-based SEMS.

TABLE 3 .
Operation schedule of stylo facilities.