In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 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 connect MQTT to RRPC communication". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to connect MQTT to RRPC communication.
China shift 4G module-ML302-OpenCpu development-(MQTT connects Aliyun-RRPC communication)
What is RRPC communication
MQTT protocol is an asynchronous communication mode based on PUB/SUB, which is not suitable for the scenario where the server synchronously controls the device side to return the result. The Internet of things platform establishes a set of synchronization mechanism of request and response based on MQTT protocol, which can realize synchronous communication without changing MQTT protocol. The Internet of things platform provides API to the server, the device only needs to reply to the PUB message in a fixed format, and the server uses API to synchronously obtain the response results of the device.
Noun interpretation
RRPC:Revert-RPC . RPC (Remote Procedure Call) adopts client / server mode, and users can request services remotely without knowing the underlying technical protocols. On the other hand, RRPC can realize the function that the server requests the device and enables the device to respond.
RRPC request message: a message sent to the device side in the cloud.
RRPC response message: a message that the device responds to the cloud.
RRPC message ID: the unique message ID generated by the cloud for each RRPC call.
RRPC subscription Topic: the Topic passed by the device side when subscribing to RRPC messages, including wildcards.
RRPC principle
The specific process is as follows:
The Internet of things platform receives a RRPC call from the user server and sends a RRPC request message to the device. The message body is the data passed in by the user, and Topic is the Topic defined by the Internet of things platform, which contains a unique RRPC message ID.
After receiving the downstream message, the device replies to a RRPC response message in the specified RRPC format (including the only RRPC message ID previously sent from the cloud) to the cloud. The cloud extracts the message ID in the Topic, matches the previous RRPC request message, and then returns it to the user server.
If the device is not online during the call, the cloud will return the device offline error to the user server; if the device does not reply to the RRPC response message within the timeout period (within 8 seconds), the cloud will return a timeout error to the user server.
RRPC Communication related Topic
The Topic formats related to RRPC communications are as follows:
RRPC request message Topic:/sys/$ {YourProductKey} / ${YourDeviceName} / rrpc/request/$ {messageId}
RRPC response message Topic:/sys/$ {YourProductKey} / ${YourDeviceName} / rrpc/response/$ {messageId}
RRPC subscribe to Topic:/sys/$ {YourProductKey} / ${YourDeviceName} / rrpc/request/+
The above content is from https://help.aliyun.com/document_detail/90567.html
From the above, you can see that you need to get the messageId in topic and then send it back.
If your ML302 module is not connected to Aliyun, you can take a look at this. Move the 4G module-ML302-OpenCpu Development-(MQTT connects Aliyun)
Https://blog.csdn.net/qq_33259323/article/details/108638945
Https://www.bilibili.com/read/cv7876527
1. Subscribe to RRPC example_subscribe_rrpc function int example_subscribe_rrpc (void * handle) {int res = 0; const char * fmt = "/ sys/%s/%s/rrpc/request/+"; char * topic = NULL; int topic_len = 0; topic_len = strlen (fmt) + strlen (DEMO_PRODUCT_KEY) + strlen (DEMO_DEVICE_NAME) + 1; topic = HAL_Malloc (topic_len) If (topic = = NULL) {cm_printf ("[ALIYUN]: memory not enough\ n"); return-1;} memset (topic, 0, topic_len); HAL_Snprintf (topic, topic_len, fmt, DEMO_PRODUCT_KEY, DEMO_DEVICE_NAME); cm_printf ("topic:%s\ r\ n", topic) Res = IOT_MQTT_Subscribe (handle, topic, IOTX_MQTT_QOS0, example_message_arrive_rrpc, NULL); if (res
< 0) { cm_printf("[ALIYUN]: subscribe failed\n"); HAL_Free(topic); return -1; } HAL_Free(topic); return 0;}2.接收数据 example_message_arrive_rrpc函数char DEMO_RRPC_SessionId[19];void example_message_arrive_rrpc(void *pcontext, void *pclient, iotx_mqtt_event_msg_pt msg){ iotx_mqtt_topic_info_t *topic_info = (iotx_mqtt_topic_info_pt) msg->Msg; char * sendMessage = NULL; const char * sendMessage_fmt = "% d"; int sendMessage_len = 20; int cm_test_read_gpio = 0; cm_printf ("example_message_arrive_rrpc\ n"); switch (msg- > event_type) {case IOTX_MQTT_EVENT_PUBLISH_RECEIVED: / * print topic name and topic message * / cm_printf ("[ALIYUN]: Message Arrived:") Cm_printf ("Topic:%. * s", topic_info- > topic_len, topic_info- > ptopic); cm_printf ("Payload:%. * s", topic_info- > payload_len, topic_info- > payload); cm_printf ("\ n"); / / extract sessionId strncpy (DEMO_RRPC_SessionId,topic_info- > ptopic+46,19) Cm_printf ("[ALIYUN]: sessionId:% s", DEMO_RRPC_SessionId); / / received data: topic_info- > payload / / Why / / send example_publish_rrpc (sendMessage); break; default: break;}} 3. Send data example_publish_rrpc function int example_publish_rrpc (unsigned char * payload) {int res = 0; const char * fmt = "/ sys/%s/%s/rrpc/response/%s"; char * topic = NULL; int topic_len = 0; / / char * payload = "{\" message\ ":\" hello!\ "}" ] cm_printf ("MQTT send message:% s", payload); topic_len = strlen (fmt) + strlen (DEMO_PRODUCT_KEY) + strlen (DEMO_DEVICE_NAME) + 1 + strlen (DEMO_RRPC_SessionId); topic = HAL_Malloc (topic_len); if (topic = = NULL) {cm_printf ("[ALIYUN]: memory not enough\ n"); return-1;} memset (topic, 0, topic_len) HAL_Snprintf (topic, topic_len, fmt, DEMO_PRODUCT_KEY, DEMO_DEVICE_NAME,DEMO_RRPC_SessionId); cm_printf ("[ALIYUN]: example_publish_rrpc:% s", topic); res = IOT_MQTT_Publish_Simple (0, topic, IOTX_MQTT_QOS0, payload, strlen (payload)); if (res < 0) {cm_printf ("[ALIYUN]: publish failed, res =% d\ n", res) HAL_Free (topic); return-1;} HAL_Free (topic); return 0;} at this point, I believe you have a deeper understanding of "how MQTT connects RRPC communications". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.