## 4 JFML-IoT-Based Energy Management System
### Layered System Architecture  
The proposed energy management system follows a modular, multi-layered architecture that promotes scalability, interoperability, and adaptability to a wide range of smart building scenarios. The system leverages the capabilities of the JFML-IoT library to implement fuzzy inference in embedded devices, integrating heterogeneous sensor data and control logic efficiently.  
* **Perception Layer**: This layer comprises environmental sensing and actuation components. It includes Arduino-compatible sensors for temperature, humidity, luminance, CO\({}_{2}\), and occupancy detection (e.g., DHT22, BH1750, MH-Z19, PIR modules), as well as actuators for HVAC and lighting control. These components capture real-time physical data and implement local actions as dictated by the FIS.
* **Communication Layer**: Responsible for transmitting sensed data and control commands using the MQTT protocol, which ensures lightweight and reliable communication between devices. Each sensor node acts as an MQTT publisher, while actuator nodes and the processing unit act as subscribers, enabling real-time data flow. To ensure accurate and robust communication, this layer employs MQTT with Quality of Service (QoS) levels 1 or 2 depending on the criticality of the data. Additionally, data packets are protected using cyclic redundancy checks (CRCs) or checksums at the device level, and each message is timestamped and logged for traceability and fault detection.
* **Processing Layer**: This layer hosts the JFML-IoT inference engine, capable of executing fuzzy logic rules in compliance with the IEEE Std 1855-2016. It processes incoming sensor data, evaluates the fuzzy rule base, and determines the appropriate control actions. The processing unit can be deployed on embedded microcontrollers with WiFi support (e.g., ESP32) or on a Raspberry Pi running a lightweight Java Virtual Machine.
* **Application Layer**: Provides interfaces for system configuration, data visualization, and interaction with building management systems (BMSs). This layer may include dashboards, alert systems, or integration with external analytics tools to monitor energy consumption and comfort metrics in real-time.  
To facilitate a clearer understanding of the system's modular structure, Figure 1 provides a visual overview of the layered architecture proposed in this work. Each layer is decoupled in terms of functionality and responsibility, ensuring scalability and reusability across different deployment scenarios. The perception layer encompasses all sensing and actuation hardware, while the communication layer ensures reliable data exchange via MQTT using a publish/subscribe model. The processing layer hosts the fuzzy inference engine, and the application layer interfaces with users and external systems through REST APIs or WebSockets.  
This architecture promotes a clear separation of concerns--between sensing, communication, processing, and user interaction--which is fundamental to the flexibility and extensibility of the JFML-IoT framework. Recent studies have emphasized the importance of modular communication layers and standardized protocols in smart building infrastructures, particularly within Digital Twin and integrated control paradigms [48; 49]. These insights reinforce our architectural design and highlight the role of lightweight communication mechanisms in building scalable, interoperable, and energy-aware systems. While the current implementation relies exclusively on Wi-Fi for communication, the architecture is protocol-agnostic and can be extended to other wireless or wired technologies--such as ZigBee, LoRa, or Ethernet--depending on deployment constraints and energy efficiency requirements. Furthermore, although advanced security features are not yet included, the communication layer supports secure protocols such as MQTT over TLS, providing a solid foundation for future improvements in encryption, authentication, and GDPR-compliant data protection.