# IoT Data Collection – Interfacing with Commercial Building Monitoring Solutions, Part II

> During the course of the ÄLLITÄ project, the team has deployed various building monitoring solutions around the campus.

## Overview
In our previous article, “IoT Data Collection – Interfacing with Commercial Building Monitoring Solutions, Part I”, we explored connecting a district heating energy monitoring device to the Savonia data backend using a Raspberry Pi-based Modbus TCP client. This article discusses integrating third-party LoRaWAN air quality sensors using a Milesight UG65 LoRaWAN gateway deployed at the campus.

## Sensor Hardware
The project utilized **Small Data Garden Ltd.** Iotsu L3 sensors:
*   **AQ05 variant:** Measures indoor temperature, humidity, and CO2 concentration.
*   **AQ01 variant:** Measures indoor temperature, humidity, CO2 concentration, and total concentration of volatile organic compounds (tVOC).

These battery-operated devices feature a default transmission interval of 2 hours, with a minimum possible interval of 10 minutes.

## Integration Strategy
The integration process followed these steps:
1.  Configure devices and data forwarding on the gateway.
2.  Build and deploy an application server for payload decoding and data handling.
3.  Install devices in selected locations.
4.  Monitor the data flow.

We chose to perform payload decoding in the backend rather than on the gateway to ensure better maintainability, avoid vendor dependencies, and centralize logging and error handling.

## Gateway Configuration
The Milesight UG65 gateway handles device OTAA joins, sessions, and data forwarding via HTTP. Configuration steps included:
*   Logging into the gateway web UI.
*   Creating a new application under "Network Server".
*   Setting up an HTTP "Data Transmission" option pointing to our backend application server.
*   Adding devices using their EUI numbers and app keys.

## Payload Decoding
Since no public decoders were available for the Iotsu L3, we developed a custom decoder based on the sensor data sheet. The process involved:
*   **Binary Interpretation:** Converting base64-encoded payloads into raw binary.
*   **Bit Manipulation:** Using bitmasks and shifts to extract values (e.g., battery voltage, configuration flags, and environmental measurements).
*   **Timestamping:** Since sensors lack internal clocks, timestamps were generated on the gateway side. We calculated timestamps by cumulatively subtracting the measurement interval (30 minutes) from the arrival time for each of the four measurement sets per transmission.

## Backend Application
The backend is a NodeJS program using:
*   **Express:** An HTTP server to receive messages from the gateway.
*   **Decoder:** Logic to extract data based on the sensor model (AQ01 vs AQ05).
*   **Message Formatter:** Constructs JSON messages for the data backend.
*   **Thingsboard PE:** The final destination for data, where it is visualized via dashboards.

## Conclusion
This work forms the "data generation layer" for the ÄLLITÄ project, providing the foundational data necessary for AI tools, prediction models, and advanced building automation.

## Project Team
*   **Mika Leskinen**, RDI Specialist, DigiCenter, Savonia University of Applied Sciences
*   **Aki Happonen**, Digital Development Manager, DigiCenter, Savonia University of Applied Sciences
*   **Laura Leppänen**, RDI Specialist, Savonia University of Applied Sciences
*   **Shahbaz Baig**, RDI Specialist, DigiCenter, Savonia University of Applied Sciences

## References
*   Small Data Garden Ltd., 2017. *Manual – IOTSU AQ Combo for LoRaWAN*.
*   Xiamen Milesight IoT Co., Ltd., 2026. *Data Sheet – Semi-Industrial LoRaWAN Gateway UG65*.