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 1,297
Resource Number 38216 Last Updated 2025-02-24
¥ 0HKD 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/the-iot-modbus-iot-communication-protocol-is-based-on-the-netty-framework/

Share free open-source source code

Q&A
  • 1. Automatic: After making an online payment, click the (Download) link to download the source code; 2. Manual: Contact the seller or the official to check if the template is consistent. Then, place an order and make payment online. The seller ships the goods, and both parties inspect and confirm that there are no issues. ICTcoder will then settle the payment for the seller. Note: Please ensure to place your order and make payment through ICTcoder. If you do not place your order and make payment through ICTcoder, and the seller sends fake source code or encounters any issues, ICTcoder will not assist in resolving them, nor can we guarantee your funds!
View details
  • 1. Default transaction cycle for source code: The seller manually ships the goods within 1-3 days. The amount paid by the user will be held in escrow by ICTcoder until 7 days after the transaction is completed and both parties confirm that there are no issues. ICTcoder will then settle with the seller. In case of any disputes, ICTcoder will have staff to assist in handling until the dispute is resolved or a refund is made! If the buyer places an order and makes payment not through ICTcoder, any issues and disputes have nothing to do with ICTcoder, and ICTcoder will not be responsible for any liabilities!
View details
  • 1. ICTcoder will permanently archive the transaction process between both parties and snapshots of the traded goods to ensure the authenticity, validity, and security of the transaction! 2. ICTcoder cannot guarantee services such as "permanent package updates" and "permanent technical support" after the merchant's commitment. Buyers are advised to identify these services on their own. If necessary, they can contact ICTcoder for assistance; 3. When both website demonstration and image demonstration exist in the source code, and the text descriptions of the website and images are inconsistent, the text description of the image shall prevail as the basis for dispute resolution (excluding special statements or agreements); 4. If there is no statement such as "no legal basis for refund" or similar content, any indication on the product that "once sold, no refunds will be supported" or other similar declarations shall be deemed invalid; 5. Before the buyer places an order and makes payment, the transaction details agreed upon by both parties via WhatsApp or email can also serve as the basis for dispute resolution (in case of any inconsistency between the agreement and the description of the conflict, the agreement shall prevail); 6. Since chat records and email records can serve as the basis for dispute resolution, both parties should only communicate with each other through the contact information left on the system when contacting each other, in order to prevent the other party from denying their own commitments. 7. Although the probability of disputes is low, it is essential to retain important information such as chat records, text messages, and email records, in case a dispute arises, so that ICTcoder can intervene quickly.
View details
  • 1. As a third-party intermediary platform, ICTcoder solely protects transaction security and the rights and interests of both buyers and sellers based on the transaction contract (product description, agreed content before the transaction); 2. For online trading projects not on the ICTcoder platform, any consequences are unrelated to this platform; regardless of the reason why the seller requests an offline transaction, please contact the administrator to report.
View details

Related Source code

ICTcoder Customer Service

24-hour online professional services