# Smart Internet of Things Power Meter for Industrial and Domestic Applications
## 3 Proposed Solution
### Software Architecture
#### 3.2.3 Measurement Data Acquisition Architecture  
It was necessary to acquire and store the measured data from our device and the industrial power meters for the calibration process and for further analysis. To accomplish this task, we implemented a data aggregation system capable of converting the various communication protocols utilized by the measurement devices: the Siemens SENTRON PAC4200 power meter supports the Modbus TCP protocol, and the Janitza UMG-96 RM and Phoenix Contact EEM-MA400 integrate the Modbus RTU protocol, and our device supports the Modbus TCP, RTU, and MQTT protocols. While for other devices, we utilized the Modbus protocol, and we opted to retrieve data from our device via the MQTT protocol. This choice was made due to MQTT's widespread adoption in IoT applications and to test if it negatively affects the measurement process by introducing delays in data transmission.  
To easily present, correlate, and analyze the measurement data gathered from all the devices, we decided to use Grafana, an open-source observability platform. A Raspberry Pi 5 single-board computer (8 GB RAM) was selected to serve as host for Grafana and for the InfluxDB database that will hold the measurement data gathered from the power meters. We installed the latest available 64-bit version of Raspberry Pi OS based on Debian 12 Linux, connected the system to the local Wi-Fi network, and then installed Grafana v10.4.0 and InfluxDB v1.8.10. Finally, we created a dashboard with trends for the measured values of interest (voltage, current, power, frequency, power factor, and THD).  
To populate the database, we needed a method to convert the measured data acquired from the meters through the Modbus TCP/RTU and MQTT protocols. For this purpose, we used Node-RED, a flow-based programming tool. This programming environment was selected due to the availability of multiple libraries that offer support for InfluxDB database connectivity and various communication protocols, including Modbus and MQTT. We installed Node-RED v3.1.7 locally on a Raspberry Pi 3B+ single-board computer running the latest available 64-bit version of Raspberry Pi OS. This computer was also connected to the local Wi-Fi network using its Ethernet port to the Siemens PAC4200 power meter. The Janitza and Phoenix Contact power meters serial interfaces were connected to a two-port RS485-USB interface. Each serial port can be accessed independently by the operating system and the Node-RED program.  
Each power meter, including our device, has a separate Node-RED flow responsible for periodically reading the measured data from the device using the Modbus RTU/TCP protocol (industrial meters) or MQTT (our device), converting the data and then inserting them into the database. For the MQTT protocol, a way to route the client's messages was needed; therefore, we installed Mosquitto, an open-source MQTT message broker, on the Raspberry Pi 3B+ computer. Both our measuring device's MQTT client and the client from the Node-RED data conversion flow connect to the broker and subscribe to the same topic. The communication between the single board computers and our meter is facilitated through the local network's router, as it can be seen in Figure 4, and the diagram of the protocol conversion and message flow can be observed in Figure 5.