The IoT-ModBus IoT communication protocol is based on the Netty framework

The IoT-ModBus IoT communication protocol is based on the Netty framework

2022-09-05 0 887
Resource Number 38216 Last Updated 2025-02-24
¥ 0USD Upgrade VIP
Download Now Matters needing attention
Can't download? Please contact customer service to submit a link error!
Value-added Service: Installation Guide Environment Configuration Secondary Development Template Modification Source Code Installation
The iot-modbus IoT communication protocol recommended in this issue is based on the netty framework, supports COM (serial port) and TCP protocols, supports two modes of server and client, realizes Java control of smart devices, and supports high-concurrency communication between multiple devices in a device group.

introduce

The Internet of Things communication protocol, based on the netty framework, supports COM (serial port) and TCP protocols, supports two modes of server and client, realizes Java control of smart devices, and supports high-concurrency communication of multiple devices in a device group. Using the factory design mode, the code is highly encapsulated by inheriting and rewriting, and can be used as an SDK to provide an encapsulated interface, so that specific business developers can use the interface directly without caring about the underlying implementation of the communication protocol. Command control such as heartbeat, backlight, code scanning, card swiping, finger vein, temperature and humidity, and door lock (support multi-lock) are realized. The code is rich in comments, including examples of uploading and issuing commands, which is very easy to get started.

Software architecture

Software Architecture The infrastructure uses Spring Boot2.x + Netty4.X + Maven3.6.x, and logbacks are used for logs.

Installation tutorial
System: Windows 7 or above;
Install Jdk1.8 or later;
Install Maven 3.6 or later;
Import the code into Eclipse or Idea as a Maven project.
Directions for use
Description of the engineering structure:
iot-modbus //IoT communication parent project
├── doc // Document management
├── iot-modbus-client //netty communication client
├── iot-modbus-netty //netty communication sub-project
├── iot-modbus-serialport // serial communication sub-project
├── iot-modbus-server //netty communication server
├── iot-modbus-test // Use sample project
└── tools //Communication command debugging tool
For configuration files, see the application.yml files in the resources directory of the iot-modbus-test subproject
Start the file, see the App.java file of the iot-modbus-test subproject
After the service is started, the default server port is 8080, and the netty communication port is 4000
For the communication command debugging tool, see the NetAssist.exe in the tools directory
Communication instructions are Hex encoded (hexadecimal)
Instruction format
The heartbeat command (7E 04 00 BE 01 00 00 74 77 7F) is used as an example to illustrate the subscript, which starts at 0
The 0th bit is the starting character, the length is fixed to occupy 1 byte, and the fixed format is 7E
The first and second bits are the data length, which is calculated from the command letter to the data bit (i.e., from 3 bits to the instruction length – 3 bits), and the length is fixed at 2 bytes, for example: 04 00, which means that the length is 4
The third bit is a commandor, and the length is fixed at one byte, for example, BE, which indicates a heartbeat instruction
The fourth digit is the device number, which is fixed in length and occupies one byte, for example, 01, indicating that the device number is 1
The fifth bit is the layer address, and the length is fixed at 1 byte, for example, 00, which indicates that all layers of the device are not executed
The sixth bit is the slot address, and the length is fixed at one byte, for example, 00, which indicates that all slots of the device are not executed
The instruction length -3 to -2 bits is the check digit, and the CRC16_MODBUS (length, command, address, data) is used, for example: 74 77, see the :ModbusCrc16Utils.java tool class for details
The last bit is the ending character, the length is fixed to occupy 1 byte, and the fixed format: 7F
Debugging instructions

1. Find the iot-modbus-test subproject App.java file to start the server, as shown in the following figure:

The IoT-ModBus IoT communication protocol is based on the Netty framework插图

Note: After the project is successfully started, the port of the server for the output of console logs is 8080. The project service name is: iot-modbus-test; The socket communication port on the server is 4000.

2. Copy NetAssist, the communication command debugging tool in the project tools directory, to the Windows desktop, double-click to open it, and configure the parameters, as shown in the following figure:

 

The IoT-ModBus IoT communication protocol is based on the Netty framework插图1

Note: Select TCP Client as the protocol type (the debugging tool is used as the client terminal for simulated hardware communication). Remote host address: Enter the IP address of the local computer; Enter the remote host port into the server port 4000; Receive and transmit encoding selection HEX; Finally, click the Connect button to connect, and the server console log output is shown in the following figure after the connection is successful:

The IoT-ModBus IoT communication protocol is based on the Netty framework插图2

3. The client uploads the heartbeat command to the server, as shown in the following figure:

The IoT-ModBus IoT communication protocol is based on the Netty framework插图3

Note: Copy the heartbeat command to the data sending window of NetAssist, and then click the send button. At this time, the server will receive the heartbeat command, as shown in the following figure:

The IoT-ModBus IoT communication protocol is based on the Netty framework插图4

Note: The communication connection between the client and the server needs to be maintained by the client sending heartbeat instructions to the server at regular intervals, and the sending frequency can generally be set to once every 5 seconds in the production environment. Note: During debugging, if the communication connection between NetAssist and the server is disconnected, you need to manually click the connection button of NetAssist to send a heartbeat command to the server again.

4. Use Postman to request the server to send a control single lock command to the client, as shown in the following figure:

 

The IoT-ModBus IoT communication protocol is based on the Netty framework插图5

  • Note: Enter the Postman server to send a control single-lock command interface, fill in the request address and parameters: http://127.0.0.1:8080/iot-modbus-test/test/openlock/1/1, and the server console logs are output as shown in the following figure:
The IoT-ModBus IoT communication protocol is based on the Netty framework插图6
资源下载此资源为免费资源立即下载
Telegram:@John_Software

Disclaimer: This article is published by a third party and represents the views of the author only and has nothing to do with this website. This site does not make any guarantee or commitment to the authenticity, completeness and timeliness of this article and all or part of its content, please readers for reference only, and please verify the relevant content. The publication or republication of articles by this website for the purpose of conveying more information does not mean that it endorses its views or confirms its description, nor does it mean that this website is responsible for its authenticity.

Ictcoder Free source code The IoT-ModBus IoT communication protocol is based on the Netty framework https://ictcoder.com/kyym/the-iot-modbus-iot-communication-protocol-is-based-on-the-netty-framework.html

Share free open-source source code

Q&A
  • 1, automatic: after taking the photo, click the (download) link to download; 2. Manual: After taking the photo, contact the seller to issue it or contact the official to find the developer to ship.
View details
  • 1, the default transaction cycle of the source code: manual delivery of goods for 1-3 days, and the user payment amount will enter the platform guarantee until the completion of the transaction or 3-7 days can be issued, in case of disputes indefinitely extend the collection amount until the dispute is resolved or refunded!
View details
  • 1. Heptalon will permanently archive the process of trading between the two parties and the snapshots of the traded goods to ensure that the transaction is true, effective and safe! 2, Seven PAWS can not guarantee such as "permanent package update", "permanent technical support" and other similar transactions after the merchant commitment, please identify the buyer; 3, in the source code at the same time there is a website demonstration and picture demonstration, and the site is inconsistent with the diagram, the default according to the diagram as the dispute evaluation basis (except for special statements or agreement); 4, in the absence of "no legitimate basis for refund", the commodity written "once sold, no support for refund" and other similar statements, shall be deemed invalid; 5, before the shooting, the transaction content agreed by the two parties on QQ can also be the basis for dispute judgment (agreement and description of the conflict, the agreement shall prevail); 6, because the chat record can be used as the basis for dispute judgment, so when the two sides contact, only communicate with the other party on the QQ and mobile phone number left on the systemhere, in case the other party does not recognize self-commitment. 7, although the probability of disputes is very small, but be sure to retain such important information as chat records, mobile phone messages, etc., in case of disputes, it is convenient for seven PAWS to intervene in rapid processing.
View details
  • 1. As a third-party intermediary platform, Qichou protects the security of the transaction and the rights and interests of both buyers and sellers according to the transaction contract (commodity description, content agreed before the transaction); 2, non-platform online trading projects, any consequences have nothing to do with mutual site; No matter the seller for any reason to require offline transactions, please contact the management report.
View details

Related Article

make a comment
No comments available at the moment
Official customer service team

To solve your worries - 24 hours online professional service