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