In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to design and implement the MQTTv5-based smart park message bus system". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to design and implement the MQTTv5-based smart park message bus system".
MQTT v5 server implementation
For this reason, we design and implement the Haizhou Wisdom Park message bus system SailMQ.
Haizhou Wisdom Park message bus system is a MQTT server implementation, based on the comprehensive MQTT v3.1.1 and MQTT v5 support provided by gmqtt, to provide users with future-oriented smart park infrastructure.
The message bus system of Haizhou Wisdom Park includes the following subsystems:
Haizhou Wisdom Park Management system SailUI
Message bus system SailMQ of Haizhou Wisdom Park
The two subsystems complement each other and are indispensable.
Design models and terminology equipment (Device) and device administrator (Device Manager)
All kinds of intelligent terminal devices of the Internet of things and industrial computers used to interact with old systems are uniformly called devices, which are the basic units of user management. Devices belong to a specific device administrator, and a device administrator can take charge of multiple devices.
App and App Manager (App Manager)
The application system used to display, control and obtain the status of devices is called App,App belonging to a specific App administrator. App administrators are authorized to access multiple devices, and the App they manage has the right to interact with these devices.
Client
The device and App are called clients uniformly.
Theme
Topics are divided into three levels, such as dm-1/dev-1/DATA, where the Client ID,dm-1 of the dev-1 is the corresponding client and the User Name,DATA of the administrator to which it belongs is the channel name (Channel Name).
The names of all channels are as follows:
OFFLINE
DATA
CONTROL
CREPLY
QUERY
QREPLY
Rule engine
The rules engine is a system module for verifying message formats, which will be described in more detail in the following chapters.
Access control connection
In MQTT protocol, the first message sent by the client to the server is the CONNECT message. The system verifies the customer identifier (Client Identifier), user name (User Name), password (Password), testamentary subject (Will Topic) and testamentary message (Will Payload) in this message. In the client of MQTT v5 protocol, if there is an authentication method (Authentication Method), it should be set to jwt. And set the authentication data (Authentication Data) to be the same as the password.
The configuration rules for the above fields are described in detail below:
Client identifier
It should be configured as dev-XXX (device) or app-YYY (App) depending on its type.
User name
Configure according to the client type, when the client type is a device, it should be set to its device administrator's User Name; when the client type is App, and here it should be set to its App administrator's User Name.
Password
If you need to obtain the password, please install SailPasswordGenerator and enter the corresponding parameters according to the prompts on the interface to get the password.
Testamentary subject
The setting of the testamentary theme varies depending on the client type, and should be set to dm-XXX/dev-YYY/OFFLINE; if the type is device and empty if the type is App.
Testamentary message
The setting of testamentary theme varies according to the type of client. If the type is App, it should be left empty. If the type is device, the testamentary message needs to be verified by the rule engine. For more information about the rule engine, please refer to the following section.
Subscription
Subscriptions support shared and unshared subscriptions, which vary according to different client types:
When the client type is a device, it can subscribe to topics dm-XXX/dev-YYY/CONTROL and dm-XXX/dev-YYY/QUERY.
When the client type is App, she can subscribe to the device to which the App administrator is authorized, and the channels to which she can subscribe are DATA, CREPLY, and QREPLY;. At this time, she can also subscribe to the corresponding shared subscription topic. For example, the App named app-1, whose App administrator is am-1,am-1, and the authorized device to which the administrator of dev-1 belongs is dev-1, and the administrator of dev-1 is dm-1. In this case, app-1 can subscribe to dm-1/dev-1/DATA, dm-1/dev-1/CREPLY and dm-1/dev-1/QREPLY; and the corresponding shared subscription topics, such as $share/ {ShareName} / dm-1/dev-1/DATA.
Publish
The release supports QOS0, 1, 2.
Publishing varies depending on the type of client:
When the client type is a device, the topics that can be published are dm-XXX/dev-YYY/DATA, dm-XXX/dev-YYY/CREPLY, and dm-XXX/dev-YYY/QREPLY.
When the client type is App, she can post messages to the device to which the App administrator is authorized, and the channels are CONTROL and QUERY. For example, the App named app-1, whose App administrator is am-1,am-1, and the authorized devices to which dev-1 belongs are dev-1, and the administrator of dev-1 is dm-1, then app-1 can publish topics such as dm-1/dev-1/CONTROL and dm-1/dev-1/QUERY.
If the access control verification of the above release passes, then the verification of the rule engine will be carried out. For more information about the rule engine, please refer to the following sections.
Rule engine
When a message enters the system, the rules engine validates it.
First, the rule engine looks for rules in Redis according to the topic of the message. For example, when the topic is dm-1/dev-1/CONTROL, the rule engine looks for rules in the following priority order:
Dm-1/dev-1/CONTROL
Dm-1/*/CONTROL
* / * / CONTROL
* / / *
When the rule engine finds the appropriate rule, it does not continue to query down.
The rule is a specially customized json. Here is an example:
{"age": "number", "books": "list", "isStudent": "bool", "name": "string", "other": "object", "score": {"math": "number", "music": "number", "sport": "number"}, "tag": "value"}
If a message wants to pass the verification of the above rules, it must meet its definition:
Age should be set to type number
Books should be set to a list
IsStudent should be set to true or false
Name should be set to a string
Other should be set to an object, and the key-value pair of the object is not required.
Score should be set as an object, and it should recursively meet the requirements of key-value pairs in the rule, and there is no limit to the level of recursion.
Tag should be set to a value of type number, bool, or string
The message must not contain fields that are not defined in the rule
Appendix known libraries that support MQTTv5
Paho java
Paho python
Paho c
Paho C++
MQTT.js
Python sample code import paho.mqtt.client as mqttimport jsonPASSWORD = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjbGllbnRJZCI6ImFwcC0xIiwidXNlcm5hbWUiOiJhbS0xIn0.fkotiit0lMJhO1FO2P9cvAF8g7KKL9xHF7XgMyq1H-5" def on_connect (client, userdata, flags, reason, properties): print (flags, reason, properties) client.subscribe ("dm-1/dev-1/CREPLY") msg = {"light": "on"} client.publish ("dm-1/dev-1/CONTROL", json.dumps (msg), 2, True) def on_message (client, userdata) Msg): print (msg.topic + "" + str (msg.payload)) client = mqtt.Client (client_id= "app-1", protocol=mqtt.MQTTv5) client.username_pw_set ("am-1", PASSWORD) client.on_connect = on_connectclient.on_message = on_messageclient.connect ("localhost", 1883, 60) client.loop_forever () Thank you for reading The above is the content of "how to realize the design of MQTTv5-based smart park message bus system". After the study of this article, I believe you have a deeper understanding of how to realize the design of MQTTv5-based smart park message bus system, and the specific use needs to be verified by practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.