# Remote Monitoring and Diagnosis for Building Maintenance Units Based on Internet of Things System
## 2 System Design and Application  
### Overall System Architecture Design  
This article proposes a remote real-time status monitoring and fault diagnosis system for BMUs based on the IoT. The system architecture and data transmission process are illustrated in Figure 1a,b. As shown in Figure 1a, the system consists of 4 layers. Perception Layer (\(L_{p}\)): This layer collects raw data through sensors and actuators on the BMU, which is processed by a gateway device (\(G\)) using Modbus RTU or similar protocols. Raw data \(D_{p}(t)\) are converted to a network-compatible format \(D_{p}^{\prime}(t)\), as shown in Formula (1):  
\[L_{p}:D_{p}(t)\xrightarrow{\Pi_{\text{ModbusRTU}}}D_{p}^{\prime}(t) \tag{1}\]  
Network Layer (\(L_{n}\)): This layer ensures reliable data transmission from the perception layer to the data processing layer using communication technologies such as 5G or Wi-Fi, following the TCP/IP protocol stack. The data \(D_{p}^{\prime}(t)\) are transmitted as \(D_{dp}(t)\), as shown in Formula (2):  
\[L_{n}:D_{p}^{\prime}(t)\xrightarrow{\Pi_{\text{TCP/IP},\Pi_{\text{SC/WIFI}}} }D_{dp}(t) \tag{2}\]  
Figure 1: (**a**) The structure of the system based on IoT. (**b**) Data transmission process. Data Processing Layer (\(L_{dp}\)): At this core layer, data from the network layer is analyzed using real-time fault diagnosis models (\(M_{d}\)), generating diagnostic results \(R(t)\). This process is represented using Formula (3):  
\[L_{dp}:D_{dp}(t)\xrightarrow{M_{fd}}R(t) \tag{3}\]  
The results \(R(t)\) are published using MQTT and API for application access, as shown in Formula (4):  
\[Pub:R(t)\xrightarrow{\Pi_{MQTT},API}R^{\prime}(t) \tag{4}\]  
Application Layer (\(L_{d}\)): users interact with the system through a client interface, retrieving the diagnostic results \(R^{\prime}(t)\) and visualizing device status and fault information, as shown in Formula (5):  
\[L_{a}:R^{\prime}(t)\to U(t) \tag{5}\]  
The system's modular design, incorporating edge computing, cloud computing, and standard communication protocols, ensures seamless data flow across layers, achieving real-time monitoring and fault diagnosis for BMUs. As shown in Figure 1b, the cloud server hosts both a TCP/IP server and an MQTT server. When remote devices come online, they establish connections with designated server ports. The TCP server then initiates Modbus requests for data acquisition using the format specified in Equation (6). The gateway returns data in the format shown in Equation (7). The received command formats are parsed into actual datasets, which are subsequently packaged into JSON format via the MQTT protocol and published under the topic '$BMUMS/DevTx/id'. The application layer can access all device data by subscribing to this topic. \[Req=[Slave\_Addr]+[FC]+[Start\_Addr]+[Quantity]+[CRC] \tag{6}\]  
\[Resp=[Slave\_Addr]+[FC]+[Byte\_Count]+[Data\_Byes]+[CRC] \tag{7}\]  
This entire process is implemented in the server as detailed in Algorithm 1:  
``` Input: client_socket Output: continuously monitor and process client requests
1. import socket
2. import MQTT
3. socket.socket() // Create a server-side socket object
4. bind((\"ip\",\"port)) // Bind the host's IP address and port number
5. Listen()
6. while True:
7. accept() // Wait for the client's connection request
8. recv() // Receive gateway MAC ID
9. send() // Send MODBUS command to the client
10. recv0 // Receive gateway return message
11. analy() // Data parsing function
12. mqt_client.publish() // MQTT server publishes messages
12. if the device goes offline
13. close() // Close the connection
14. break

### Establishment of the Real-Time Fault Diagnosis Model Based on Multi-Correlation Data

Diagnosing faults in BMUs effectively necessitates integrating diverse, multi-source data, including both real-time operational parameters and prior knowledge derived from equipment documentation and expert systems. To address this challenge, this paper proposes a collaborative fault inference chain model.