In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-15 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 Ali Cloud to receive and send data". Interested friends may wish to take 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 Aliyun to receive and send data.
Shift 4G module-ML302-OpenCpu development-(MQTT connect Aliyun-receive and send data)
According to the previous study, if you haven't seen it, you can take a look at the above 2.1C 4G module-ML302-OpenCpu Development-(MQTT connection Aliyun-subscription topic)
The data can be received, so how to send it?
Int example_publish (void * handle) {int res = 0; const char * fmt = "/% s/%s/user/get"; char * topic = NULL; int topic_len = 0; char * payload = "{\" message\ ":\" hello!\ "}" / / * splicing of topic * 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); / / * stitching of topic * * / call IOT_MQTT_Publish_Simple to send data 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;}
IOT_MQTT_Publish_Simple function
Topic_name:topic name
Qos:qos
Data: data
Len: length of data sent
Int IOT_MQTT_Publish_Simple (void * handle, const char * topic_name, int qos, void * data, int len)
This is a relatively simple MQTT sending program
At this point, I believe you have a deeper understanding of "how to connect MQTT to Ali Cloud to receive and send data". 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.