Before starting the text, I need to thank the netizen "Xiaolong" and the netizens in the emqtt.io group for their help, I have just started to use MQTT There are many things I don't understand, when I asked about the solution in the emqtt.io group, "Xiaolong" gave me a detailed explanation of some MQTT knowledge points and provided solutions, thank you very much. I think some of the things mentioned in it are still very useful for beginners, so here is a summary of my chat history with "Xiaolong" for your reference.
Question 1: If the MCU has limited cache and limited processing power, it is impossible to send messages at once, how to publish messages through MQTT in this case? First, assemble the header of the publish protocol, write the length of the payload in it, send it out through TCP, and then send the payload little by little. If you can't get the total payload length, this is difficult. Because you send a publish protocol report, after the server reads the length of the payload in the head, it will continue to read until it reaches the required length, and then the publish is counted. Therefore, your need is to first confirm the length of the content you publish, then group the publish packet header, fill in the payload length, tcp:send(head), and then send the payload one by one, such as 1k at a time, or send the data according to the normal tcp, and send it all the way, even if the publish is over. The next send belongs to the TCP layer, and you don't need to intervene. If in the TCP layer, send fails, there must be a problem with the socket, the connection is broken, you have to reconnect to the MQTT server, if it is not finished, then the server session will also end, that is, the server has not received the data. Reconnect, you have to resend the message, as long as it is disconnected, you have to reconnect, whether you want to resend the data, depends on whether you have saved the previous data. Also, if the message is important, you can use qos=1 or 2 to ensure that the server receives the message, qos=1 requires one round trip, qos=2 needs four round trips, qos=0 is very simple, as long as you send it out, it doesn't matter.
Question 2: Are there many open source resources for MQTT?
The hyperlink login is visible.There are a lot of them
Question 3: Why does MQTT generally not provide persistence functions?
The MQTT protocol is designed according to the device's online design, and the data is stored in memory
Question 4: Is MQTT memory consuming?
MQTT is more memory-consuming, and the measured data of emqtt is: 38W, memory accounts for 14G, CPU 15%
Question 5: What is the relationship between session and client?
For example, if you have a board, as a client, initiate an MQTT connection request to connect to the MQTT server, for example, it is an EMQTT service, after the EMQTT server receives the connection request of this board, it will establish a TCP connection with the board on the TCP layer, and within EMQTT, a process will be generated to communicate with this board, and a process will also be generated, called session. This sessoin is a theme that specializes in managing the subscription of this board, and other boards will also send it to the session corresponding to this board if they publish the topic of interest to this board, if this session receives the subscribed topic, and finds that the client is still alive, it will send the data through this client through TCP to this board, if it is found that the client is no longer there, that is, the board and the server are broken. Then the session will save the received subscription topic in the session first, and the next time the board is connected, and cleansession=false, then the session will not be cleared, and when connecting this time, the previously received subscription message will be sent to the board, which is probably what it means.
Question 6: How does emqtt know that the connected client is the same?
When connecting, you need to set a client ID, this ID can be left unset, if not set, a unique ID will be automatically generated on the emqtt server side, if you want to use session, you must have a unique ID, you can use IMEI. If you must receive offline messages, you must use a definite ID.
Question 7: Can the session time of emqtt be modified?
You can change the session time, now it's 48 hours, you can change it to a week, if you want it to be permanent, I'm afraid emqtt is not suitable.
Question 8: Is the access permission of emqtt written in the configuration file?
etc/acl.config
Question 9: What is the distribution of emqtt?
Distributed simply means connecting several of your servers together, any one or more of them, as long as they are not all broken, emqtt can run normally. EMQTT data is shared by several nodes, and if there is a problem with a node, the data will not be lost, but the session data on the node will be lost.
|