Project background
As the number of students and staff at universities grows, dormitory conditions have become more complex. Associated issues have increased, including rising power consumption, use of high-power appliances causing fires, smoking-related fires, and energy waste when power is left on after occupants leave.
To address these issues, a dormitory management system based on the Internet of Things was designed. The system is a power-monitoring solution for rooms, using an IM1281B electrical parameter acquisition module to collect voltage, current, power factor, and other electrical parameters. A Renesas microcontroller forwards the collected data via a Wi-Fi module to the China Mobile OneNet IoT cloud platform, enabling remote monitoring of each dormitory's power usage.
System architecture

Hardware interfaces
- Wi-Fi module serial port 0: TXD P101, RXD P100
- IM1281B electrical parameter acquisition module serial port 2: TXD P302, RXD P301
- OLED display module: SCL P502, SDA P501
Components used
The implementation uses RT-Thread provided component packages: AT component package, I2C component package, and UART component package.
An attempt was made to use the provided OneNet component package to connect to the OneNet platform, but the package version was too old and caused many unresolved issues. The project therefore uses a simple HTTP method to connect to the OneNet platform.
HTTP data format
When sending HTTP data to the OneNet platform, a fixed format is required.
For example, to send a variable named TEMP with a value of 50:
POST /devices/572818307/datapoints HTTP/1.1
api-key:DqYM=rNTLXuoh2i9cDu34iHhi60=
Host:api.heclouds.com
Content-Length:59
{"datastreams":[{"id":"TEMP","datapoints":[{"value":50}]}]}
In the above format, the identifiers for device ID and Master-APIkey are parameters created when registering the product on the platform. The initial lines form the protocol header, and the last line is the data payload. The number 59 indicates the length of the final data payload line.
Data packet example
An example payload that reports multiple datastreams:
{"datastreams":[{"id":"VoL_d","datapoints":[{"value":50}]},{"id":"Cur_d","datapoints":[{"value":50}]},{"id":"Pow_d","datapoints":[{"value":50}]},{"id":"Enr_d","datapoints":[{"value":50}]},{"id":"PF_d","datapoints":[{"value":50}]}]}
Packet assembly is essentially a string concatenation process.
ALLPCB
