当前位置:网站首页>Rs232/rs485 to 4G DTU uploading temperature and humidity sensor data based on Modbus protocol to remote TCP server
Rs232/rs485 to 4G DTU uploading temperature and humidity sensor data based on Modbus protocol to remote TCP server
2022-06-11 02:47:00 【Seeking to fly】
RS232/RS485 turn 4G DTU Upload based on Modbus Protocol temperature and humidity sensor data
1 Hardware preparation
- 4G DTU a
- USB turn 232 An adapter line
- 485 A temperature and humidity sensor
- 12V Power Supply 2 individual
- LTE-Cat1 A IOT network card
2 Topology

DTU RS485 <-----> Sensors 485 Line (A Pick up A,B Pick up B)
DTU RS232 <-----> USB turn RS232 Adapter
DTU Power Supply ( Headphone hole power supply )<-----> DC 12V External power supply
Sensor power cord <-----> DC 12V External power supply
3 Prepare knowledge
3.1 What is? DTU
3.1.1 Concept
DTU(Data Transfer Unit): Data transmission unit , It is specially used to convert serial port data to IP Data or will IP Data conversion to serial port data , A terminal device that transmits through a wireless communication network . Save development time , Quickly upload device data to the server .
3.1.2 DTU type
There are two kinds of classification , One is the following according to the communication mode 7 class ;
- GPRS
- 4G
- NB-IoT
- LORA
- ZigBee
- WiFi
- satellite
The second is to classify according to the interface type .
- RS232
- RS485
- TTL
3.2 RS232
RS Express Recommend Standard( Recommended standards ), One of the serial port standards , The more commonly used . Industrial controlled RS-232 Mouth generally only uses RXD、TXD、GND Three lines . The interface form is DB9.
3.3 RS485
RS The above meaning .RS232 Interface , It can realize point-to-point communication , But it can not realize the networking function , Later RS485 That solved the problem .RS485 The master-slave communication mode is generally adopted in the communication network .RS485/MODBUS It is a popular way of network distribution , Easy to implement , Support RS485 There are many instruments .1
3.4 Modbus RTU agreement
3.4.1 Concept
Modbus RTU It's a compact , Binary representation of data . Subsequent orders / The data has a checksum with cyclic redundancy check (CRC16).
Modbus The agreement is a Master/Slave Architecture protocol . and TCP It's kind of similar .
A node is master node , Other uses Modbus The nodes of the protocol participating in the communication are slave node . every last slave Every device has a The only address .
3.4.2 An example of an order
request :01 03 00 00 00 02 C4 0B
| byte | function | meaning |
|---|---|---|
| 01 | Device address | The device address is 1 |
| 03 | Function code | At present, it is 03 Read request |
| 00 00 | Device address | Register start address , from 00 00 Register starts reading |
| 00 02 | Read register length | Read 2 Length , Corresponding reply 4 Bytes |
| C4 0B | Effectiveness and effectiveness | CRC16 Effectiveness and effectiveness |
reply :01 03 04 00 0C 00 02 BB F1
| byte | function | meaning |
|---|---|---|
| 01 | Device address | The device address is 1 |
| 03 | Function code | At present, it is 03 Read reply |
| 04 | Data length | At present, it is 03 Read reply |
| 00 0C | Device address | register 1 The number |
| 00 02 | Read register length | Read 2 Length , Corresponding reply 4 Bytes |
| BB F1 | Effectiveness and effectiveness | CRC16 Effectiveness and effectiveness |
4 Looking forward to the goal
- Pass the data of the sensor device through 4G The network reports to the ECS ( Completed )
- Send commands to sensors through the network
5 Debugging process
5.1 build TCP The server
Install... On the server Socket Program , start-up TCP monitor .
5.2 To configure 4G DTU Set up TCP Server connection
- Set up DTU The way it works is Data transparent transmission ;
- Set the... Of the above servers IP And port values ;
- Format message , Including heartbeat packets and registration data ;
- Click Save parameter , Click restart device .( After configuring the device every time , Must be restarted to take effect )
- Check whether the data is received on the server .
If you receive data , Indicates that the network communication service is OK Of .
5.3 Equipped with temperature and humidity sensors
Use USB turn 485 The adapter is connected to the temperature sensor ,DC 12V The power supply supplies power to the sensor .
To avoid conflicts with other sensor addresses , Set the address value of the temperature sensor to 3, Then write to the sensor , Then read the data .
You can see that the data collection is successful .
5.4 Set up Modbus Active polling parameters

The function of this configuration is ,DTU A read command can be sent to the sensor 03 03 00 00 00 02 C5 E9, Corresponds to the address of the temperature sensor set in the previous step .DTU After receiving the reply data , The byte array data will be uploaded according to the set upload type 【json belt IMEI】 adopt 4G Network upload to step 5.1 Set up TCP Server . The format of the entire packet is as follows .
{
"IMEI":863488052947903,"time":"2022-06-10 16:03:43","wenshidu":[1,15,3,42]}
5.5 Integration testing
Connect the above devices , Conduct integration test . There are a few lines , You can use a combiner .
6 result
Read temperature and humidity data ,4 Bytes , front 2 One represents the temperature , after 2 One represents humidity , take [1,27,3,6] give an example .
[1,27] = 0x011B = 0d283 , except 10 be equal to 28.3℃
[3,6] = 0x0306 = 0d777, except 10 be equal to 77.7 RH
边栏推荐
- Unity camera camera about layer mask cullingmask settings
- AOSP ~ 默认开启开发者模式
- 深度学习基础篇【4】从0开始搭建EasyOCR并进行简单文字识别
- 新来的同事问我 where 1=1 是什么意思???
- CPT 102_LEC 16
- ShaderGraphs
- Jetpack Compose Box控件
- [AI weekly] AI and freeze electron microscopy reveal the structure of "atomic level" NPC; Tsinghua and Shangtang proposed the "SIM" method, which takes into account semantic alignment and spatial reso
- How to use phpMyAdmin to optimize MySQL database
- CPT 102_LEC 13-14
猜你喜欢
随机推荐
Cyclodextrin metal organic framework( β- Cd-mof) loaded with dimercaptosuccinic acid / emodin / quercetin / sucralose / diflunisal / omeprazole (OME)
error exepected identifier before ‘(‘ token, grpc 枚举类编译错误
Whether the software test needs to master the programming ability
How to add two factor authentication for WordPress websites
Baidu submits sitemap to prompt the solution of "index type is not handled"
AOSP ~ modify default volume
Forest v1.5.22 发布!支持Kotlin
OpenJudge NOI 1.13 18:Tomorrow never knows?
蓝桥杯_小蓝吃糖果_鸽巢原理 / 抽屉原理
AOSP ~ 修改默认音量
Problems with JDBC tool classes
[MySQL 45 -10] Lesson 10 how MySQL selects indexes
PHP starts OpenSSL and reports OpenSSL support=> disabled (install ext/openssl)
OpenJudge NOI 1.13 17:文字排版
Limiting visibility of symbols when linking shared libraries
HUST软件工程(实验2)--TDD测试驱动开发实验。
HOSATAPD_ CLI debug using WiFi whitelist
Introduction to the functions of today's headline search webmaster platform (portal)
Net core Tianma XingKong series - Interface Implementation for dependency injection and mutual conversion of database tables and C entity classes
[189. rotation array]








