当前位置:网站首页>ESP8266-----MQTT云下设备上云
ESP8266-----MQTT云下设备上云
2022-07-27 21:15:00 【Paradise_Violet】
当esp8266通过MQTT参数成功的连接到MQTT服务端之后,会订阅SW_LED这个主题,并向这个主题发送ESP8266_Online(esp8266上线了消息),MQTT服务端会将这个消息分发给订阅了这个主题的其他客户端
// MQTT已成功连接:ESP8266发送【CONNECT】,并接收到【CONNACK】
//============================================================================
void mqttConnectedCb(uint32_t *args)
{
MQTT_Client* client = (MQTT_Client*)args; // 获取mqttClient指针
INFO("MQTT: Connected\r\n");
// 【参数2:主题过滤器 / 参数3:订阅Qos】
//-----------------------------------------------------------------
MQTT_Subscribe(client, "SW_LED", 0); // 订阅主题"SW_LED",QoS=0
// MQTT_Subscribe(client, "SW_LED", 1);
// MQTT_Subscribe(client, "SW_LED", 2);
// 【参数2:主题名 / 参数3:发布消息的有效载荷 / 参数4:有效载荷长度 / 参数5:发布Qos / 参数6:Retain】
//-----------------------------------------------------------------------------------------------------------------------------------------
MQTT_Publish(client, "SW_LED", "ESP8266_Online", strlen("ESP8266_Online"), 0, 0); // 向主题"SW_LED"发布"ESP8266_Online",Qos=0、retain=0
// MQTT_Publish(client, "SW_LED", "ESP8266_Online", strlen("ESP8266_Online"), 1, 0);
// MQTT_Publish(client, "SW_LED", "ESP8266_Online", strlen("ESP8266_Online"), 2, 0);
}如果esp8266接收到SW_LED这个主题分发的消息的话,就会判断这个消息是否是LED_ON,led开,LED_OFF,led关。
// 根据接收到的主题名/有效载荷,控制LED的亮/灭
//-----------------------------------------------------------------------------------
if( os_strcmp(topicBuf,"SW_LED") == 0 ) // 主题 == "SW_LED"
{
if( os_strcmp(dataBuf,"LED_ON") == 0 ) // 有效载荷 == "LED_ON"
{
GPIO_OUTPUT_SET(GPIO_ID_PIN(4),0); // LED亮
}
else if( os_strcmp(dataBuf,"LED_OFF") == 0 ) // 有效载荷 == "LED_OFF"
{
GPIO_OUTPUT_SET(GPIO_ID_PIN(4),1); // LED灭
}
}当获取到MQTT连接参数后,如何将8266和MQTT 客户端软件连接到百度云天工物接入平台,以及通过向MQTT服务端发布消息,MQTT服务端分发消息来实现8266与MQTT客户端软件的通信
边栏推荐
- 【飞控开发基础教程6】疯壳·开源编队无人机-SPI(六轴传感器数据获取)
- Latex常用总结(2):输入矩阵(输入矩阵、对角阵、方程组等)
- Flutter pull_ to_ refresh-1.6.0/lib/src/internals/slivers. dart:164:13: Error: Method not found: ‘descr
- BUUCTF-bbbbbbrsa
- Zcmu--1720: death is like the wind, I want to pretend to force
- [GWCTF 2019]枯燥的抽奖
- urllib.error. URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: un
- 传奇外网架设教程带图文解说——Gom引擎
- Shuffle, partition and read of tfrecord
- Redis distributed lock
猜你喜欢

BUUCTF-RSA4

【zer0pts CTF 2022】 Anti-Fermat

Use of date

Construction and application of super large scale knowledge map of ants

Starfish OS X metabell strategic cooperation, metauniverse business ecosystem further

Notes on Shangpin project in shangsilicon Valley (I)
![[JS reverse hundred examples] a public resource trading network, reverse analysis of announcement URL parameters](/img/05/7029eb1fe36d7ddab2640f07247c81.png)
[JS reverse hundred examples] a public resource trading network, reverse analysis of announcement URL parameters

2022 summer vacation daily question (5)

【飞控开发基础教程6】疯壳·开源编队无人机-SPI(六轴传感器数据获取)
![[C language] address book (dynamic version)](/img/29/3df19c187bee31ee4671e12d7cc7ff.jpg)
[C language] address book (dynamic version)
随机推荐
Shuffle, partition and read of tfrecord
[NPUCTF2020]EzRSA
2022年土木,建筑与环境工程国际会议(ICCAEE 2022)
XSS Payload 学习浏览器解码
BUUCTF-RSA4
CaEGCN: Cross-Attention Fusion based Enhanced Graph Convolutional Network for Clustering 2021
Character stream learning 14.3
Technical certification | Tupo software and Huawei cloud create a new situation of win-win cooperation
liux常用命令(查看及其开放防火墙端口号+查看及其杀死进程)
BUUCTF-[BJDCTF2020]RSA1
[JS reverse hundred examples] a public resource trading network, reverse analysis of announcement URL parameters
BUUCTF-RSA roll
Error:svn: E155010: ‘/Users/.../Desktop/wrokspace/xxx‘ is scheduled for addition, but is missing
Reduce error demonstration
NDK 系列(6):说一下注册 JNI 函数的方式和时机
BUUCTF-Dangerous RSA
JUC toolkit learning
[NPUCTF2020]EzRSA
J9 Digital Science Popularization: how does the double consensus of Sui network work?
js数组复制速度测试220320