Cloud Computing 12 min read

LoRa‑Based Environmental Monitoring and Control for Data Center Using TencentOS Tiny

The article describes a complete LoRa‑based environmental monitoring and control system for data centers, built on TencentOS Tiny and featuring a LoRa gateway, sensor‑rich node, LCD display, relay and LED modules, cloud integration via Tencent Cloud IoT Explorer, and a WeChat mini‑program for remote management.

Tencent Cloud Developer
Tencent Cloud Developer
Tencent Cloud Developer
LoRa‑Based Environmental Monitoring and Control for Data Center Using TencentOS Tiny

This article presents a complete LoRa‑based solution for monitoring and controlling the environment of a data center (or smart building). It introduces the advantages of LoRa (long‑range, low‑power, low‑cost) and describes the overall system architecture, which consists of LoRa end devices, a LoRa gateway, a server, and a cloud platform.

1. Overview LoRa, created by Semtech, can achieve 3‑5 times longer transmission distance than traditional RF under the same power consumption. A LoRaWAN network typically includes terminals (with LoRa modules), gateways (or base stations), a network server, and a cloud service.

2. Scheme Design The project uses the P‑NUCLEO‑LRWAN3 kit (gateway and node) and the ST Nucleo‑F746ZG board with an SX1301‑based LRWAN_GS module. The node integrates multiple I2C sensors (HTS221 temperature/humidity, LPS22HB pressure, LIS3MDL magnetometer, LSM6DS3 6‑axis IMU). Data collected by the node are sent to the cloud via LoRa, where they can be visualized and used for control.

3. Hardware Implementation The hardware includes:

LoRa kit (gateway + node)

LCD (ST7735R) for real‑time data display

Relay module (optocoupler isolated) for 220 V load control

E53 SC1 expansion module (LED street lamp, BH1750 light sensor, 24Cxx EEPROM) for light‑level based control

All modules are assembled into a compact LoRa node, with local buttons for manual control of the LED lamp, relay, and LCD backlight.

4. Software Design

(1) LoRa source code

The firmware is built on TencentOS Tiny. The following key variables are defined for reporting:

uint16_t report_period = 1;
bool    report_power_switch = 0;
bool    report_motor_fan = 0;
float   report_pressure = 0;
float   report_height = 0;
float   first_pressure = 0;
float   first_height = 0;
extern float pressure_hPa;
extern float temperature_degC;
extern float height;

typedef struct device_data_st {
    uint8_t  temperature;
    uint8_t  humidity;
    uint16_t period;
    unsigned int quantity;
    bool     power_switch;
    bool     motor_fan;
    float    pressure;
    float    height;
} __PACKED__ dev_data_t;

The key task scans three buttons to toggle LCD backlight, LED power, and motor fan, updating the LCD and sending status to the cloud.

void key_task(void *arg) {
    int lcd_back_flag = 1;
    while (1) {
        tos_task_delay(10);
        if (HAL_GPIO_ReadPin(KEY1_GPIO_Port, KEY1_Pin) == GPIO_PIN_RESET) {
            tos_task_delay(100);
            if (HAL_GPIO_ReadPin(KEY1_GPIO_Port, KEY1_Pin) == GPIO_PIN_RESET) {
                lcd_back_flag = ~lcd_back_flag;
                if (lcd_back_flag == 1) {
                    LCD_LED_CLR; // turn off backlight
                } else {
                    LCD_LED_SET; // turn on backlight
                }
            }
        }
        // similar handling for KEY2 (LED) and KEY3 (relay)
    }
}

The main application entry initializes peripherals, reads sensor data, formats it, displays it on the LCD, and periodically sends it to the LoRa gateway.

void application_entry(void *arg) {
    printf("APP RUNNING...\r\n");
    // initialization code omitted for brevity
    while (1) {
        // read sensors, update LCD, print debug info
        tos_task_delay(500);
        #ifdef LORA_REPORT
        if (sum1 >= report_period) {
            // pack dev_data_t and send via LoRa
            tos_lora_module_send(dev_data_wrapper.u.serialize, sizeof(dev_data_t));
        }
        #endif
    }
}

(2) Cloud Platform Implementation The data are uploaded to Tencent Cloud IoT Explorer, where a LoRa project is created, product properties are defined, and real‑time data are visualized.

(3) Mini‑Program Implementation A WeChat mini‑program, based on the official demo, integrates both LoRa and NB‑IoT devices, allowing users to switch pages to view and control different terminals.

5. Conclusion LoRa’s strong penetration and long range make it ideal for monitoring data‑center environments and building smart buildings. Compared with NB‑IoT (which may require SIM cards) and Wi‑Fi (limited penetration), LoRa offers lower deployment cost and higher reliability. Future work includes adding breaker status detection, PLC integration, and expanding control capabilities.

LoRAIoTembeddedCloud PlatformTencentOS TinyData Center Monitoring
Tencent Cloud Developer
Written by

Tencent Cloud Developer

Official Tencent Cloud community account that brings together developers, shares practical tech insights, and fosters an influential tech exchange community.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.