## 5 Case Study: Experimental Validation in a Representative Smart Building Scenario
### Implementation of the JFML-IoT-Based Energy Management System
#### 5.4.1 Sensor and Actuator Object Instantiation  
In the current version of JFML-IoT, all sensors and actuators are implemented as sub-classes of the abstract classes Sensor and Actuator, respectively. These classes are available in the official GitHub repository ([[https://github.com/JfMRes/JFML_IoT](https://github.com/JfMRes/JFML_IoT)]([https://github.com/JfMRes/JFML_IoT](https://github.com/JfMRes/JFML_IoT)), accessed on 16 July 2025) and allow flexible instantiation for various IoT platforms using MQTT as the communication protocol. Each sensor or actuator is instantiated with its identifier, MQTT topic, and relevant configuration parameters. For example, see (Listing 3):
``` TemperatureSensortemperature1=newTemperatureSensor( \"Temperature1\", \"mqtt/zone1/temp\"); TemperatureSensortemperature2=newTemperatureSensor( \"Temperature2\", \"mqtt/zone2/temp\"); HumiditySensorhumidity1=new HumiditySensor( \"Humidity1\", \"mqtt/zone1/humidity\"); HumiditySensorhumidity2=new HumiditySensor( \"Humidity2\", \"mqtt/zone2/humidity\"); IlluminanceSensorilluminance1=newIlluminanceSensor( \"Illuminance1\", \"mqtt/zone1/lux\"); IlluminanceSensorilluminance2=newIlluminanceSensor( \"Illuminance2\", \"mqtt/zone2/lux\"); OccupancySensoroccupancy1=newOccupancySensor( \"Occupancy1\", \"mqtt/zone1/occupancy\"); OccupancySensoroccupancy2=newOccupancySensor(\"Occupancy2\", \"mqtt/zone2/occupancy\"); CO2 Sensor co2 = new CO2 Sensor(\"CO2 Level\", \"mqtt/co2\"); HVAControlActuator hvac = new HVAControlActuator( \"HVAControl\", \"mqtt/hvac/control\"); VentilationControlActuator ventilation=new VentilationControlActuator( \"VentilationControl\", \"mqtt/ventilation/control\"); LightingControlActuator light1 = new LightingControlActuator( \"LightingControl1\", \"mqtt/zone1/light/set\"); LightingControlActuator light2 = new LightingControlActuator( \"LightingControl2\", \"mqtt/zone2/light/set\");

#### 5.4.2 Association of Devices to Embedded Systems

Each embedded system (e.g., ESP32, Raspberry Pi) is defined as an instance of the class EmbeddedSystem, grouping the sensors and actuators deployed in a specific room or zone (Listing 4):

EmbeddedSystem zone1 = new EmbeddedSystemESP32(\"Zone_1\"); zone1.addSensor(temperature1); zone1.addSensor(humidity1); zone1.addSensor(illuminancel1); zone1.addSensor(occupancy1); zone1.addActuator(light1); EmbeddedSystem zone2 = new EmbeddedSystemESP32(\"Zone_2\"); zone2.addSensor(temperature2); zone2.addSensor(humidity2); zone2.addSensor(illuminance2); zone2.addSensor(occupancy2); zone2.addActuator(light2); EmbeddedSystem zoneCentral = new EmbeddedSystemESP32(\"Zone_Central\"); zoneCentral.addSensor(co2); EmbeddedSystem zoneAir = new EmbeddedSystemESP32(\"Zone_Air\"); zoneAir.addActuator(ventilation); zoneAir.addActuator(hvac);

#### 5.4.3 Definition of Communication Node with MQTT

The embedded systems communicate via MQTT with a central coordinator, which subscribes to sensor topics and publishes commands to actuators. A communication node is defined as follows (Listing 5):

EmbeddedSystem nodeMQTT = new EmbeddedSystemRPi(\"node_MQTT\"); nodeMQTT.addEmbeddedSystem(zone1); nodeMQTT.addEmbeddedSystem(zone2); nodeMQTT.addEmbeddedSystem(zoneCentral); nodeMQTT.addEmbeddedSystem(zoneAir);nodeMQTT. addMQTT(mqtt) ;

#### 5.4.4 Loading the FML File and Executing Inference

The fuzzy controller, previously defined in FML, is parsed and linked to the inference engine hosted in a central node.