当前位置:网站首页>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
边栏推荐
- Why can some programmers get good offers with average ability?
- 微信模版消息errcode“:40165,“errmsg“:“invalid weapp pagepath
- Android WiFi hide SSID configuration method
- What can the enterprise exhibition hall design bring to the enterprise?
- To view the data in redis, in addition to the command line and client, you have a third option
- 码农的进阶之路 | 每日趣闻
- Kotlin apply method
- 靠贴牌飞利浦冲击上市,德尔玛的自有品牌又该如何“起跳”?
- Setting access to win10 shared folder without verification
- SQL | return customer name, relevant order number and total price of each order
猜你喜欢

WordPress article directory plug-in luckywp table of contents setup tutorial

【189. 轮转数组】

How to read PMBOK guide in 3 steps (experience + data sharing)

One line of code solves the problem that the time to fetch datetime from MySQL database is less than eight hours

Multilevel mesoporous organometallic framework material zif-8 loaded with lactic acid oxidase (LOD) / ferric oxide (Fe304) / doxorubicin / insulin /cas9 protein / metronidazole / emodin methyl ether

軟件測試英語常見詞匯

RS232/RS485转4G DTU 上传基于Modbus协议的温湿度传感器数据到远程TCP服务器

Byte beating | the first batch of written examination for game R & D post (question solution)

Navicat premium 15 tool is automatically deleted by anti-virus protection software solution

When a logical deletion encounters a unique index, what are the problems and solutions?
随机推荐
軟件測試英語常見詞匯
What can the enterprise exhibition hall design bring to the enterprise?
Limiting visibility of symbols when linking shared libraries
Unity HTC and Pico are the same
AOSP ~ WIFI默认开启 + GPS默认关闭 + 蓝牙默认关闭 + 旋转屏幕关闭
CPT 102_LEC 17
动态给对象添加属性
那些笑着离开“北上广”的人,为何最后都哭了?
Xampp is used under M1 chip, and the installation extension error
ADVANCE. AI CEO Shoudong will share the compliance of cross-border e-commerce using AI technology at the 2022 emerging market brands online Summit
码农的进阶之路 | 每日趣闻
MySQL backup and recovery
Win10 安装Office 2016出现错误代码30204-44怎么处理?
Looking at the ups and downs of the mobile phone accessories market from the green Union's sprint for IPO
Stc8a8k64d4 EEPROM read / write failure
SQL | return customer name, relevant order number and total price of each order
AOSP ~ logcat chatty line expired
STC8A8K64D4 EEPROM读写失败
MySQL备份与恢复
How can Delma's own brand "take off" when Philips is listed on the market?