I. Product Overview
This product is a smart wireless sensor gateway device that supports the standardModbus RTU protocolof AndIntelligent wireless sensor gateway deviceand hasmulti node sensor data acquisition, communication parameter configurationSecondlydevice management function. Communication with upper computer (PLC, touch screen, SCADA system, etc.) through RS485 interface, supporting complete register read and write operations, can be widely used inindustrial automation, environmental monitoring, Smart Agriculture, Livestock Farming, Building Securityand other fields. As the core hub of wireless sensor networks, this gateway can manage up to 64 wireless sensor nodes simultaneously, converting the data from each sensor into the standard Modbus RTU protocol format for easy integration with the upper computer system.
As the core hub of wireless sensor networks, this gateway can manage up to64 wireless sensor nodesConvert the data from each sensor into a standard Modbus RTU protocol format for easy integration into the upper computer system.
II. Overview of Core Functional System (Calculated from Protocol)
Based on the register definitions, operation cases, and data structures in this protocol document, the following functional modules of the product can be fully calculated:
| Serial Number | Functional Module | Functional Description | Corresponding register/basis |
|---|---|---|---|
| 1 | Modbus RTU slave communication | Standard Modbus RTU slave mode, RS485 physical interface, supports function codes 03/06/10 | Chapter 2 and Chapter 3 |
| 2 | Multi node sensor management | Supports up to 64 wireless sensor nodes online simultaneously, with each node addressing independently | 0002H Register (Range 0~63), Sensor Data Area Allocation Rules |
| 3 | 7 types of sensors supported | Temperature and humidity, ear tags (livestock), smoke detector, radar, infrared, remote control, universal 1527 equipment | Index Register Low 8-bit Type Encoding Definition |
| 4 | Dual data reporting mode | Active reporting mode (sensor automatic push)+Query reporting mode (host polling read) | 0005H register |
| 5 | Sensor binding and pairing system | Software instruction binding+hardware button binding (long press for 5 seconds), LED indicator status feedback | 0006H Register, Chapter 6 Binding Management Instructions |
| 6 | Full parameter register configuration | The slave address (1-247), baud rate (5 levels), and reporting mode can all be modified through registers | 0003H~0005H registers |
| 7 | Sensor Lifecycle Management | Add nodes, read data, delete individual nodes, and clear all bindings with one click | Write multiple registers (0x10) operation+0007H register |
| 8 | Multi dimensional data acquisition | Temperature/humidity/vibration/smoke concentration/human presence detection/electricity/sub device type and other types of data | Data1/Data2/Battery field definitions |
| 9 | Battery level monitoring | Real time battery capacity monitoring of each wireless sensor node (0%~100%) | Battery register (+5 offset) |
| 10 | Firmware version query | Read the firmware version number of the device for easy version management and maintenance confirmation | 0001H Read Only Register |
| 11 | Broadcast address support | Supports Modbus broadcast address 0xFF (255) and can issue commands to all slave stations | Address Range Description |
| 12 | CRC16 verification mechanism | Using CRC-16/MODBUS polynomial 0xA001 verification to ensure data transmission integrity | Chapter 2 Verification Methods+Appendix C Language Algorithm |
III. Detailed Explanation of Supported Sensor Types
According to the encoding definition of the low 8 bits (sensor type field) of the Index register in the protocol, the gateway supports the following7 sensor types, and can be extended more:
3.1 Sensor Type Encoding Table
| Type Encoding | Sensor Name | Main Data Fields | Data1 Meaning | Data2 Meaning | Typical Application Scenarios |
|---|---|---|---|---|---|
| 00H | Universal 1527 Encoding Device | Sub device Type+Status Data | Idle | Sub device Type Encoding | Universal Wireless Remote Control/Door Magnet/Door and Window Sensor |
| 01H | Temperature and Humidity Sensor | Temperature+Humidity+Electricity | Temperature Value (0.1 ° C) | Humidity Value (0.1%) | Greenhouse, Warehouse, Computer Room, Laboratory |
| 02H | Ear tag sensor (livestock specific) | Temperature+vibration counting+electricity | Temperature value (0.1 ° C) | Vibration frequency (times) | Livestock temperature monitoring, estrus/health warning |
| 03H | Smoke detector/smoke sensor | Smoke concentration+electricity | Idle | Smoke concentration (ppm) | Warehouse fire prevention, kitchen security, factory fire protection |
| 04H | Radar Human Presence Sensor | Presence Status+Battery | Idle | Presence Status (0=unmanned/1=manned) | Intelligent Lighting, Conference Room, Toilet Linkage |
| 05H | Infrared PIR Sensor | Presence Status+Battery | Idle | Presence Status (0=unmanned/1=manned) | Intrusion Alarm, Corridor Sensing, Security Monitoring |
| 06H | Wireless remote control | Button status+sub device type | Idle | Button status data | Remote control, light control, device switch |
| 07H+ | Reserved extension | To be defined (XXXX) | To be defined | To be defined | Expansion bits for future new sensor types |
3.2 Detailed Description of Data Formats for Each Sensor
① Temperature and Humidity Sensor (Type=01H)
| Byte Position | Field Name | Data Type | Unit | Value Range | Example |
|---|---|---|---|---|---|
| +0~+1 (Byte0~1) | Index | UINT16 | - | High 8 bits=Number (0~63), Low 8 bits=Type (0x01) | 0x0001 represents Temperature and Humidity Sensor No.1 |
| +2~+5 (Byte2~5) | Device Address Addr | UINT32 | - | 32-bit Unique Identifier | 0x12345678 |
| +6~+7 (Byte6~7) | Temperature Data1 | INT16 | 0.1 ° C | -3276.8~3276.7 ° C | 0x00FB=25.1 ° C; 0xFEC=-2.0 ° C |
| +8~+9 (Byte8~9) | Humidity Data2 | UINT16 | 0.1% | 0~100% | 0x028B=65.1%; 0x01F4=50.0% |
| +10~+11 (Byte10-11) | Battery | UINT16 | 1% | 0%~100% | 0x0064=100%; 0x0032=50% |
② Ear Tag Sensor - Livestock Breeding Specific (Type=02H)
A wireless ear tag sensor designed specifically for livestock such as cattle, sheep, and pigs, which is a major feature of this product.
| Byte Position | Field Name | Data Type | Unit | Value Range | Business Meaning |
|---|---|---|---|---|---|
| +0~+1 | Index | UINT16 | - | Low 8 Bits=0x02 | Identified as Ear Tag Type |
| +2~+5 | Device Address Addr | UINT32 | - | Unique identifier | Unique ID for each livestock |
| +6~+7 | Temperature Data1 | INT16 | 0.1 ° C | Body temperature range | Livestock body temperature (e.g. 38.5 ° C=normal cow body temperature) |
| +8~+9 | Vibration Data2 | UINT16 | or | 0~65535 | Activity level/vibration frequency, used to determine the activity level or abnormal behavior of livestock |
| +10~+11 | Battery | UINT16 | 1% | 0%~100% | Ear tag battery remaining power |
③ Smoke/Smoke Sensor (Type=03H)
| Byte Position | Field Name | Data Type | Unit | Value Range | Remarks |
|---|---|---|---|---|---|
| +6~+7 | Data1 | — | — | Idle | Reserved Unused |
| +8~+9 | Smoke Concentration Data2 | UINT16 | ppm | 0~5000 ppm | 0x1388=5000 ppm (high concentration alarm threshold) |
| +10~+11 | Battery | UINT16 | 1% | 0% ~ 100% | Sensor battery level |
④ Radar human presence sensor (Type=04H)&infrared PIR sensor (Type=05H)
Both types of sensors are used for human presence detection, but their technical principles are different:
| Comparison item | Radar sensor (Type=04H) | Infrared PIR sensor (Type=05H) |
|---|---|---|
| Detection Principle | Millimeter wave radar Doppler effect | Pyroelectric infrared detection |
| Data2 value | 0x0000=No one present; 0x0001=Someone | 0x0000=No one present; 0x0001=Someone |
| Advantages | Penetrating plastic/glass, not affected by temperature, capable of detecting small movements (such as breathing), suitable for "lighting up when people are around" | Low cost, extremely low power consumption, suitable for mobile detection |
| shortcoming | relatively high cost | Unable to detect stationary human body, affected by environmental temperature |
| Applicable scenarios | Intelligent office/conference room/bathroom (precise presence detection) | Corridor/aisle/entrance (motion detection) |
⑤ Wireless Remote Control (Type=06H)&Universal 1527 Encoding Device (Type=00H)
| field | Wireless Remote Control (06H) | Universal 1527 device (00H) |
|---|---|---|
| Data1 | free | free |
| Data2 | Key status data (specific encoding depends on remote control model) | Sub device type encoding (updated by the host after binding) |
| Remark | Used to receive 433MHz remote control button signals | Compatible with most EV1527 encoded wireless transmission devices on the market (door magnets, water immersion, vibration, etc.) |
4, Communication Parameters and Frame Format Specification
4.1 Basic Communication Parameters
| parameter item | default value | Optional values/ranges | configuration method |
|---|---|---|---|
| communication protocol | Modbus RTU | — | fixed |
| physical interface | RS485 | — | fixed |
| Data Format | 8N1 (8 data bits, no checksum, 1 stop bit) | Configurable | Default 8N1 |
| Slave Address | 1 | 1~247 | Write to 0003H Register |
| Broadcast Address | 255 (0xFF) | Only 255 | Send commands to all slave stations |
| Baud Rate | 9600 bps | 9600/19200/38400/57600/115200 | Write to 0004H register |
| Verification method | CRC16 | Polynomial 0xA001 (MODBUS standard) | Fixed |
| Maximum number of sensors | — | 64 | Hardware limitation |
| Frame interval time | ≥ 3.5 character time | @9600bps ≈ 3.6ms; @115200bps ≈ 0.3ms | RTU protocol requirements |
4.2 Baud Rate Configuration Comparison Table (0004H Register)
| write value | Actual baud rate | Single character time | 3.5 character interval | Applicable scenarios |
|---|---|---|---|---|
| 0 | 9600 bps | ≈ 1.04 ms | ≈ 3.6 ms | Default recommendation, stable and reliable |
| 1 | 19200 bps | ≈ 0.52 ms | ≈ 1.8 ms | Medium speed demand |
| 2 | 38400 bps | ≈ 0.26 ms | ≈ 0.9 ms | Faster speed |
| 3 | 57600 bps | ≈ 0.17 ms | ≈ 0.6 ms | high-speed transmission |
| 4 | 115200 bps | ≈ 0.087 ms | ≈ 0.3 ms | maximum speed, ensuring line quality |
4.3 supported function code
| function code | name | direction | purpose |
|---|---|---|---|
| 0x03 | read and hold register | master station → slave station | Read version number, number of nodes, sensor data, etc |
| 0x06 | Write a single register | Master Station → Slave Station | Set address, baud rate, mode, startup binding, etc |
| 0x10 | Write multiple registers | Master Station → Slave Station | Add sensors, delete nodes, batch write data, etc |
5, Complete Register Mapping Table
5.1 System Control Register Area (0001H~000FH)
| register address | Register Name | Read/Write Permissions | Data Format | Value Range/Description |
|---|---|---|---|---|
| 0001H | Version Number | Read Only | UIT16 | Device Firmware Version Number, such as 0x0102 for V1.2 |
| 0002H | Current Number of Online Nodes | Read Only | UINT16 | The current number of registered and bound sensor nodes (0~63) |
| 0003H | RS485 address | read and write | UINT16 | Modbus slave address, default 1, range 1~247 |
| 0004H | Serial port baud rate | read and write | UINT16 | 0=9600, 1=19200, 2=38400, 3=57600, 4=115200 |
| 0005H | Active reporting mode setting | read and write | UINT16 | 0=Active reporting enabled (default); 1=Enable query reporting |
| 0006H | Activate binding pairing function | Just write | UINT16 | Write 1 to start binding (indicator light flashing, automatic exit after 20 seconds timeout) |
| 0007H | Clear all bound data | Just write | UINT16 | Clear all bound sensor data, rebind required |
| 0008H ~ 000FH | Reserve | — | — | Reserve for future expansion use |
5.2 Sensor Data Register Area (Starting from 0010H)
Each sensor occupies6 consecutive registers (12 bytes)Supports up to 64 sensors:
| Sensor Number | Register address range | +0 Index | +1 Addr_H | +2 Addr_L | +3 Data1 | +4 Data2 | +5 Battery |
|---|---|---|---|---|---|---|---|
| Sensor 1 | 0010H ~ 0015H | Number+Type | Address 16 digits high | Address low 16 digits | Data 1 | Data 2 | battery level |
| Sensor 2 | 0016H ~ 001BH | Ditto. | Ditto. | Ditto. | Ditto. | Ditto. | Ditto. |
| Sensor 3 | 001CH ~ 0021H | Ditto. | Ditto. | Ditto. | Ditto. | Ditto. | Ditto. |
| Sensor 4 | 0022H ~ 0027H | Ditto. | Ditto. | Ditto. | Ditto. | Same as | Same as |
| ... | Increasing by+6 | ... | ... | ... | ... | ... | ... |
| Sensor N | 0010H+(N-1) * 6~0015H+(N-1) * 6 | Same as | Same as | Same as | Same as | Same as | Same as |
| Sensor 64 | 012AH~012FH | Same as | Same as | Same as | Same as | Same as | Same as |
VI. Detailed explanation of working mode
6.1 Dual data reporting mode
The gateway supports two data reporting modes, which can be switched through the 0005H register:
Mode 0: Active reporting mode (default)
- After wireless sensors detect data changes,automatically uploads the data to the gateway
- . The gateway updates the internal register cache immediately after receiving it
- . The upper computer can read the latest data at any time through the 0x03 function code.
- Advantages:Good real-time performance, sensor side actively pushes, data updates in a timely manner
- Applicable scenarios: scenarios that requirereal-time monitoring(such as temperature limit alarm, personnel intrusion detection, etc.)
Mode 1: Query Reporting Mode
- Wireless sensors are only available inWhen receiving a gateway query commandOnly returned data
- The upper computer initiates a read request → the gateway queries the sensor → returns data
- Advantages:power savingThe sensor is mostly in a dormant state for most of the time
- Applicable scenarios:battery poweredSensors, low-power priority scenarios (such as remote monitoring in agriculture)
6.2 Binding and pairing process
Before adding wireless sensors to the gateway, the binding and pairing operation must be completed first. SupportTwo triggering methods:
Method 1: Software instruction binding (written to 0006H via Modbus)
- The upper computer writes values to the 0006H register1Send 01 06 00 06 00 01 A8 0B
- The gateway enters binding mode,The indicator light starts flashing
- Enable wireless sensors for the targetSend data once(or trigger its emission signal)
- The gateway receives and recognizes sensor signals,Automatically allocate a free storage slotRecord the sensor address
- Binding successful: The indicator light stops flashing, and the gateway returns a response of 01 06 00 06 00 01 A8 0B (success code 1)
- If no sensor signal is received within 20 seconds, return timeout response 01 06 00 06 00 02 E8 0A (timeout code 2), exit binding mode
Method 2: Hardware key binding
- Long press the pairing button on the gateway panel for 5 seconds
- Enter binding mode (with exactly the same effect as software instructions)
- The subsequent steps are the same as Method 1
7, Complete operation case (10 instances including byte by byte parsing)
The following provides a complete operation example covering all functions, including hexadecimal request/response frames and field by field parsing.
7.1 System Register Operations (6 Examples)
Case 1: Read Device Firmware Version Number (Read 0001H)
| Project | Content |
|---|---|
| Operation Type | Read and Hold Register (Function Code 0x03) |
| Request Frame (Hexadecimal) | 01 00 01 00 01 D5 CA |
| Request Resolution | [Address=01] [Function code=03] [Starting address=0001H] [Number of registers=1] [CRC=D5CA] |
| Response Frame (Hexadecimal) | 01 03 02 01 02 B8 44 |
| Response analysis | [Address=01] [Function code=03] [Byte count=2] [Data=0102] →Version 1.2[CRC=B844] |
Case 2: Read the current number of online sensor nodes (read 0002H)
| project | Content |
|---|---|
| Request frame | 01 03 00 02 00 01 25 CA |
| Response frame | 01 03 02 00 08 B9 82 |
| Interpretation of results | Currently, there are8sensor nodes online |
Case 3: Modify the RS485 slave address of the device (write 0003H → new address=2)
| Project | Content |
|---|---|
| Operation Type | Write a single register (function code 0x06) |
| Request Frame | 01 06 00 03 00 02 F8 0B |
| Request Resolution | [Address=01] [Function code=06] [Register=0003H] [Data=0002 → Address changed to 2] [CRC=F80A] |
| Response frame | 01 06 00 03 00 02 F8 0B (echo request frame, indicating successful writing) |
| Attention | After modification, the new address (0x02) needs to be used for subsequent communication |
Case 4: Modify the serial port baud rate to 19200 (write 0004H → value=1)
| Project | Content |
|---|---|
| Request frame | 01 06 00 04 00 01 09 CB |
| Request parsing | [Address=01] [Function code=06] [Register=0004H] [Data=0001 → Baud rate option 1] [CRC=09CB] |
| Response frame | 01 06 00 04 00 01 09 CB (successful) |
| Note that | After modification, the baud rate of the upper computer serial port needs to be switched to 19200 to continue communication |
Case 5: Switch to query reporting mode (write 0005H → value=1)
| Project | Content |
|---|---|
| Request frame | 01 06 00 05 00 01 58 0B |
| Request parsing | [Address=01] [Function Code=06] [Register=0005H] [Data=0001 → Query Mode] [CRC=580B] |
| Response frame | 01 06 00 05 00 01 58 0B (successfully switched to query reporting mode) |
Case 6: Start sensor binding pairing (write 0006H → value=1)
| project | Content |
|---|---|
| Request frame | 01 06 00 06 00 01 A8 0B |
| Request parsing | [Address=01] [Function Code=06] [Register=0006H] [Data=0001 → Startup Binding] [CRC=A80B] |
| Response frame (successful) | 01 06 00 06 00 01 A8 0B (Code 1=Command execution successful, waiting for sensor network access) |
| Response frame (timeout) | 01 06 00 06 00 02 E8 0A (Code 2=No sensor connected to the network within 20 seconds, timeout exit) |
7.2 Sensor data register operation (4 examples)
Case 7: Manually adding sensor 1 to the system (write address 0x12345678)
When the 32-bit address of the sensor device is known, it can be directly added to the system through register writing:
| project | Content |
|---|---|
| Operation Type | Write multiple registers (function code 0x10) |
| destination address | The starting address 0010H of sensor 1 data area is continuously written into three registers (Index+Addr_H+Addr_L) |
| Request frame | 01 10 00 10 00 03 06 00 01 12 34 56 78 A1 E1 |
| Byte by byte parsing | [01=Address] [10=Function Code] [00 10=Starting Address 0010H] [00 03=Writing 3 registers] [06=6 bytes of data in total] [00 01=1+temperature and humidity type] [12 34=address high 16 bits] [56 78=address low 16 bits] [A1 E1=CRC] |
| Response frame | 01 10 00 10 00 03 81 CD (confirm to write 3 registers starting from 0010H) |
Case 8: Read all data from sensor 1 (6 registers=12 bytes)
| project | Content |
|---|---|
| Request frame | 01 03 00 10 00 06 C4 0D |
| Request parsing | [01=Address] [03=Function Code] [00 10=Starting Address 0010H] [00 06=Read 6 registers] [CRC=C40D] |
| Response frame | 01 03 0C 00 01 12 34 56 78 00 FA 01 F4 00 64 B5 F2 |
| Byte by byte parsing | [01=Address] [03=Function Code] [0C=12 bytes of data] [00 01 → Sensor 1+Temperature and Humidity Type (01H)] [12 34 56 78 → 32-bit device address 0x12345678] [00 FA → Temperature 25.0 ° C (250 × 0.1)] [01 F4 → Humidity 50.0% (500 × 0.1)] [00 64 → Battery 100%] [B5 F2 = CRC] |
Case 9: Delete Sensor 1 (Clear Address Register)
The method to delete sensors is to reset all corresponding address registers to zero:
| project | Content |
|---|---|
| Request frame | 01 10 00 10 00 03 06 00 00 00 00 00 00 E7 15 |
| Request parsing | [01=Address] [10=Function Code] [00 10=Starting Address] [00 03=3 registers] [06=6 bytes of data] [00 00 00 00 00=all reset] [E7 15=CRC] |
| Response frame | 01 10 00 10 00 03 81 CD (deleted successfully) |
| Effect | The address of sensor 1 has been reset, the system no longer receives data from that sensor, and the storage slot has been released |
Case 10: Directly writing temperature and humidity data from sensor 1
| project | Content |
|---|---|
| Request frame | 01 10 00 13 00 02 01 2C 02 58 72 19 |
| Request parsing | [01=Address] [10=Function Code] [00 13=Starting Address 0013H (Data1)] [00 02=Write 2 registers] [04=4-byte data] [01 2C → Temperature 30.0 ° C (300 × 0.1)] [02 58 → Humidity 60.0% (600 × 0.1)] [72 19=CRC] |
| Response frame | 01 10 00 13 00 02 B0 0D (write successful) |
8. Exception handling When the slave station detects an illegal operation, it returns an abnormal response:
8.1 Modbus Exception Response Format
When an illegal operation is detected by the slave station, an abnormal response is returned:
- The highest bit of the normal function code becomes 1 (such as 0x03 → 0x83, 0x06 → 0x86, 0x10 → 0x90)
- followed by a 1-byte exception code
| Exception Code | Meaning | Common Causes | Solution |
|---|---|---|---|
| 01 | Illegal Function Code | Unsupported Function Code Used | Only 0x03/0x06/0x10 |
| 02 | Illegal Data Address | Register Address Exceeded Valid Range | Check if Address is within the range of 0001H~012FH |
| 03 | Illegal Data Value | The written data value exceeds the allowed range | Check the value range (such as address should be between 1-247) |
8.2 Binding function return code (0006H register)
| Return code | Meaning | indicates that |
|---|---|---|
| 1 | command execution was successful | Binding instruction has been received, gateway enters pairing mode and waits for sensor network access |
| 2 | Binding timeout | No sensor signal received within 20 seconds, automatically exits binding mode |
8.3 Fault diagnosis checklist
| Problem phenomenon | Possible causes | Solution |
|---|---|---|
| Communication timeout, no response | RS485 address mismatch or baud rate inconsistency | Check configuration of 0003H address register and 0004H baud rate register |
| Sensor data read all zero | Sensor node unregistered/bound, or address write error | Check if the address register starting from 0010H is correctly written to non-zero values |
| Unable to write to register | Function code usage error or insufficient permissions | Confirm correct function code: 0x06 for single write, 0x10 for multiple writes; Note that 0001H/0002H is read-only |
| CRC check error | . Error occurred during data transmission | Check the RS485 line connection (whether A+/B - is reversed, whether the terminal resistance is missing), recalculate CRC |
| Binding failure (repeated timeout) | Sensor is not within communication range or battery is exhausted | Shorten the distance between the sensor and the gateway, replace the sensor battery |
| Partial sensor data is not updated | The sensor exceeds the wireless signal coverage range | Adjust the gateway antenna direction, or add a repeater |
9. Precautions and best practices
9.1 Key precautions
- Frame interval timemust be maintained between adjacent frames. BI_659] 3.5 character time3.5 character timeThe silence interval. Shortest frame interval at different baud rates:
- 9600 bps: approximately 3.6 ms
- 115200 bps: approximately 0.3 ms
- Big-endian byte orderWhen using function code 0x10 to write multiple registers, data must be written according toBig End ModeOrganization, high bytes come first and low bytes come last.
- Broadcast operation no response: When sending a command to the broadcast address 0xFF, all slave stations perform the operation butdoes not return a response frame.
- Sensor addition rule: When adding a sensor, the address register (Addr_H+Addr_L) must be writtenNon zero value; Writing all zeros is equivalent to deleting the node.
- Operation Interval: After updating sensor data, wait for at least100msbefore performing the next register operation.
- Risk of clearing binding: Writing to the 0007H register willclear all bound sensor data at once. Before operation, please confirm that there is no need to retain the existing configuration. After clearing, you need to rebind one by one.
9.2 Recommended Operating Procedure
- First Power On: Read 0001H to confirm firmware version, read 0002H to confirm initial state
- Configure communication parameters: Modify 0003H (address), 0004H (baud rate), 0005H (reporting mode) as needed
- Bind sensors: Add sensors one by one by pressing 0006H or physically
- Verify binding: Read 0002H to confirm node number, read corresponding sensor data area to confirm data is normal
- Daily operation and maintenance: Regularly read sensor Battery field to monitor battery level and replace low battery sensor batteries in a timely manner
Implement CRC16 algorithm
This protocol adoptsMODBUS standard CRC16verification algorithm, polynomial0xA001(i.e. bit reversed form of 0x8005). The following is a complete C language reference implementation:
#include <stdint.h>
/**
* MODBUS CRC16 计算
* @param data 待计算的数据缓冲区指针
* @param len 数据长度(字节)
* @return 16 位 CRC 校验值(低字节在前)
*
* 多项式:0xA001(MODBUS 标准)
* 初始值:0xFFFF
*/
uint16_t calc_crc(uint8_t *data, uint16_t len)
{
uint16_t crc = 0xFFFF; // 初始值
for (uint16_t i = 0; i < len; i++)
{
crc ^= data[i]; // 与当前字节异或
for (uint8_t j = 0; j < 8; j++) // 逐位处理
{
if (crc & 0x0001) // 最低位为 1
{
crc >>= 1; // 右移一位
crc ^= 0xA001; // 与多项式异或
}
else
{
crc >>= 1; // 仅右移
}
}
}
return crc;
}
/* 使用示例:
* uint8_t frame[] = {0x01, 0x03, 0x00, 0x01, 0x00, 0x01};
* uint16_t crc = calc_crc(frame, 6);
* 结果:crc = 0xCAD5(低字节 0xD5 在前,高字节 0xCA 在后)
*/
11. Data Download and Technical Support
- This document version:V1.3(Updated on October 3, 2025)
- Protocol follows standards:Modbus Industrial Standard Protocol Specification
- The specific register definition shall be based on the actual firmware of the device
- If you need technical support, please contact the manufacturer for the latest register mapping table and protocol documentation
Version iteration history
| Version number | Release date | Main changes |
|---|---|---|
| V1.1 | 2025-09-01 | Basic version, using standard Modbus RTU protocol as the main node communication protocol |
| V1.2 | 2025-09-21 | Added software instruction start binding function; Added hardware button start binding function |
| V1.3 (current) | 2025-10-03 | Revised the maximum supported number of sensors to 64; Add sensor type data fields; Provide detailed instructions on the format of sensor data segments; Fixed the binding timeout to 20 seconds; Add 0007H register (one click clear all bindings) |
12, Typical application scenarios
Scenario 1: Smart Agriculture - Greenhouse Environment Monitoring System
Deploy inside the greenhouseTemperature and humidity sensor (Type=01H)aggregates data through this gateway and uploads it to the PLC or touch screen control system via Modbus RTU. It can be linked with ventilation fans, sprinkler systems, sunshades and other equipment to achieve automatic temperature and humidity control. Supports up to 64 sensor points64 sensor pointsMeet the multi-point monitoring needs of large connected greenhouses.
Scenario 2: Smart Livestock - Livestock Health Management
Wear for each cow/sheepWireless Ear Tag Sensor (Type=02H)The gateway collects temperature and activity data of livestock in a centralized manner. When the body temperature of a certain livestock exceeds the set threshold, an automatic alarm (disease warning) will be triggered, or when there is an abnormal change in activity, the estrus/health status will be determined.64 node capacityCapable of covering the livestock management needs of small and medium-sized farms.
Scenario 3: Fire Safety - Warehouse/Computer Room Fireworks Monitoring
DeploymentSmoke sensor (Type=03H)Real time monitoring of smoke concentration in key areas such as warehouses and computer rooms. When the concentration exceeds the threshold, the Modbus upper computer triggers the sound and light alarm, exhaust system, or notifies the fire linkage platform. Combined with temperature and humidity sensors, comprehensive environmental safety monitoring can also be achieved.
Scenario 4: Intelligent Building - Human Presence Perception and Lighting Linkage
Install in offices, conference rooms, and bathroomsRadar sensor (Type=04H)orInfrared PIR sensor (Type=05H)To achieve precise personnel presence detection. The radar scheme can detect micro movements (even breathing), achieving true“People are about to light upIntelligent lighting control greatly saves energy. Sensor data is connected to the Building Automation System (BAS) or KNX/Modbus bus through a gateway.
Scenario 5: Security Alarm - Intrusion Detection and Wireless Remote Control
CombineInfrared sensor (Type=05H)Implement perimeter intrusion detection, combined withWireless remote control (Type=06H)Used for arming/disarming operations.Universal 1527 device (Type=00H)Compatible with various wireless detectors such as door magnets, glass breakage, and water immersion, a complete wireless security system is built, and all data is uniformly connected to the alarm host or SCADA platform through Modbus RTU.
Leave a Reply