本篇內(nèi)容主要講解“MQTT如何連接阿里云接收和發(fā)送數(shù)據(jù)”,感興趣的朋友不妨來(lái)看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來(lái)帶大家學(xué)習(xí)“MQTT如何連接阿里云接收和發(fā)送數(shù)據(jù)”吧!
我們提供的服務(wù)有:成都網(wǎng)站制作、網(wǎng)站設(shè)計(jì)、微信公眾號(hào)開(kāi)發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、蓮池ssl等。為上1000家企事業(yè)單位解決了網(wǎng)站和推廣的問(wèn)題。提供周到的售前咨詢(xún)和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的蓮池網(wǎng)站制作公司
根據(jù)上一條的學(xué)習(xí),如果沒(méi)看過(guò)可以去看一下上面的2.1中移4G模塊-ML302-OpenCpu開(kāi)發(fā)-(MQTT連接阿里云-訂閱主題)
數(shù)據(jù)是可以接收了,那怎么發(fā)送呢。
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!\"}"; //*** 對(duì)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); //*** 對(duì)topic的拼接*** // 調(diào)用IOT_MQTT_Publish_Simple發(fā)送數(shù)據(jù) 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函數(shù)
topic_name:topic名字
qos:qos
data:數(shù)據(jù)
len:發(fā)送數(shù)據(jù)長(zhǎng)度
int IOT_MQTT_Publish_Simple(void *handle, const char *topic_name, int qos, void *data, int len)
這是一個(gè)比較簡(jiǎn)單的MQTT發(fā)送程序
到此,相信大家對(duì)“MQTT如何連接阿里云接收和發(fā)送數(shù)據(jù)”有了更深的了解,不妨來(lái)實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢(xún),關(guān)注我們,繼續(xù)學(xué)習(xí)!
文章名稱(chēng):MQTT如何連接阿里云接收和發(fā)送數(shù)據(jù)
文章鏈接:http://vcdvsql.cn/article44/gghoee.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營(yíng)銷(xiāo)、網(wǎng)站導(dǎo)航、網(wǎng)站策劃、網(wǎng)站改版、品牌網(wǎng)站制作、App設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)