赞
踩
STM32-ESP8266-EMQX-WPF方案实现之ESP8266连接EMQX服务器
通过STM32采集数据,ESP8266连接热点发送数据到云服务器EMQX,EMQX转发给WPF应用程序的方案
此文章是通过串口调试助手使得ESP8266连接到EMQX服务器订阅和接收消息
使用的硬件:ESP8266-01S,杜邦线,usb转ttl
使用的软件:串口调试助手,ESP8266烧录的固件、烧录固件的软件
烧录MQTT固件的软件
串口调试工具
烧录硬件软件都准备齐全后,参照网上教程烧录即可。
需要参考的ESP8266指令集如上所示。
ESP8266连接到具有上网功能的WIFI(如手机热点)
代码如下(示例):
AT
OK
AT+CWMODE=1
OK
AT+CWJAP="Honor30Pro","12345678."
WIFI CONNECTED
AT+RST
OK
代码如下(示例):
AT
OK
AT
OK
AT+CWMODE?
+CWMODE:1
OK
AT+CWSTATE?
+CWSTATE:2,"Honor30Pro"
OK
AT+CIPSTA?
+CIPSTA:ip:"192.168.43.51"
+CIPSTA:gateway:"192.168.43.1"
+CIPSTA:netmask:"255.255.255.0"
AT+MQTTUSERCFG=0,1,"WATERSYSTEMTEST","","",0,0,""
OK
AT+MQTTCONN=0,"IP地址",1883,1
+MQTTCONNECTED:0,1,"IP地址","1883","",1
OK
AT+MQTTSUB=0,"123/",0
OK
AT+MQTTPUB=0,"123/","ADSFG",0,0
OK
+MQTTSUBRECV:0,"123/",5,ADSFG
AT+MQTTUNSUB=0,"123/"
OK
AT
OK
AT+MQTTUSERCFG=0,1,"WATERSYSTEMTEST","","",0,0,""
OK
AT+MQTTCONN=0,"ip地址",1883,1
+MQTTCONNECTED:0,1,"ip地址","1883","",1
OK
AT+MQTTSUB=0,"123/",0
OK
+MQTTSUBRECV:0,"123/",17,{ "msg": "qwer" }
AT+MQTTPUB=0,"123/","ADSFG",0,0
OK
+MQTTSUBRECV:0,"123/",5,ADSFG
在EMQX上新建一个客户端连接服务器(即充当异地PC设备上的WPF应用程序)
经过测试,模拟的客户端可以发送123/主题信息,且ESP8266可以正常收到。
经过测试,ESP8266能够对123/主题发送给信息,且模拟的客户端订阅了此主题后可以正常收到。
此时就完成了ESP8266-EMQX-其他客户端的信息传递。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。