1、视频教程

https://www.bilibili.com/video/BV1mJ411r7M9/?spm_id_from=333.788.videocard.9

资料下载:

https://download.csdn.net/download/weixin_42269817/15406748

自己服务器打开把mqttd这个文件复制进来

一开始运行可能会报我这个错误

解决办法:https://www.microsoft.com/zh-cn/download/confirmation.aspx?id=40784

下载自己对应的位的直接在服务器里面默认安装

2、查询服务器的ipv4然后(这里替换自己的ipv4)http://172.21.87.83:18083/#/

默认的用户名和密码:

admin

public

ESP8266代码:

/*Basic ESP8266 MQTT exampleThis sketch demonstrates the capabilities of the pubsub library in combinationwith the ESP8266 board/library.It connects to an MQTT server then:- publishes "hello world" to the topic "outTopic" every two seconds- subscribes to the topic "inTopic", printing out any messagesit receives. NB - it assumes the received payloads are strings not binary- If the first character of the topic "inTopic" is an 1, switch ON the ESP Led,else switch it offIt will reconnect to the server if the connection is lost using a blockingreconnect function. See the 'mqtt_reconnect_nonblocking' example for how toachieve the same result without blocking the main loop.To install the ESP8266 board, (using Arduino 1.6.4+):- Add the following 3rd party board manager under "File -> Preferences -> Additional Boards Manager URLs":http://arduino.esp8266.com/stable/package_esp8266com_index.json- Open the "Tools -> Board -> Board Manager" and click install for the ESP8266"- Select your ESP8266 in "Tools -> Board"*/#include <ESP8266WiFi.h>
#include <PubSubClient.h>// Update these with values suitable for your network.const char* ssid = "123321";
const char* password = "12345678";
const char* mqtt_server = "47.113.118.21";WiFiClient espClient;
PubSubClient client(espClient);
long lastMsg = 0;
char msg[50];
int value = 0;void setup_wifi() {delay(10);// We start by connecting to a WiFi networkSerial.println();Serial.print("Connecting to ");Serial.println(ssid);WiFi.begin(ssid, password);while (WiFi.status() != WL_CONNECTED) {delay(500);Serial.print(".");}randomSeed(micros());Serial.println("");Serial.println("WiFi connected");Serial.println("IP address: ");Serial.println(WiFi.localIP());
}void callback(char* topic, byte* payload, unsigned int length) {Serial.print("Message arrived [");Serial.print(topic);Serial.print("] ");for (int i = 0; i < length; i++) {Serial.print((char)payload[i]);}Serial.println();// Switch on the LED if an 1 was received as first characterif ((char)payload[0] == '1') {digitalWrite(BUILTIN_LED, LOW);   }if ((char)payload[0] == '0'){digitalWrite(BUILTIN_LED, HIGH);  }}void reconnect() {// Loop until we're reconnectedwhile (!client.connected()) {Serial.print("Attempting MQTT connection...");// Create a random client IDString clientId = "ESP8266Client-";clientId += String(random(0xffff), HEX);// Attempt to connectif (client.connect(clientId.c_str())) {Serial.println("connected");// Once connected, publish an announcement...client.publish("outTopic", "hello world");// ... and resubscribeclient.subscribe("inTopic");} else {Serial.print("failed, rc=");Serial.print(client.state());Serial.println(" try again in 5 seconds");// Wait 5 seconds before retryingdelay(5000);}}
}void setup() {pinMode(BUILTIN_LED, OUTPUT);     // Initialize the BUILTIN_LED pin as an outputSerial.begin(115200);setup_wifi();client.setServer(mqtt_server, 1883);client.setCallback(callback);reconnect();while(!client.subscribe("led",0)){Serial.println("订阅失败;尝试重新订阅!");client.subscribe("led",0);delay(300);}Serial.println("订阅成功~~~");
}void loop() {if (!client.connected()) {reconnect();}client.loop();long now = millis();if (now - lastMsg > 2000) {lastMsg = now;++value;snprintf (msg, 50, "This is message :%ld", value);Serial.print("Publish message: ");Serial.println(msg);client.publish("text", msg);}
}

此外遇到问题:

会话里面什么都没有

解决:阿里云服务器控制台:

我直接端口全开

最后成功

基于MQTT阿里云物联网手机远程控制ESP8266相关推荐

  1. 从零讲起:ESP32+Micropython+MQTT阿里云物联网

    ESP32+Micropython+MQTT阿里云物联网 前言 一.ESP32是什么? 二.Micropthon开发环境搭建 1.ESP32串口驱动下载与安装 三.IDE工具下载及使用说明 1.IDE ...

  2. 移远EC20 4G模块LTE开发板三网通模块 MQTT阿里云物联网

    摘自:移远EC20 4G模块LTE开发板三网通模块 MQTT阿里云物联网STM32代码-电脑看 地址:https://www.bilibili.com/video/BV1EJ411P7CR?from= ...

  3. 手把手教你用Arduino接入阿里云物联网平台,ESP8266连接阿里云物联网平台必看教程...

    使用Ardui no 的方式快速连接阿里云物联网平台. 文中提到的 AliyunIoTSDK 这个 Arduino 库,可以在 Arduino 库商店里搜索到(搜索 AliyunIoTSDK) Ali ...

  4. 安信可Ai-WB1系列AT指令连接MQTT阿里云物联网平台

    文章目录 前言 1 准备材料 2 创建云端设备 3 硬件连接 4 配置终端设备 5 MQTT实现发布&订阅消息 联系我们 前言 本文将介绍安信可AI-WB1系列通过AT指令接入阿里云物联网平台 ...

  5. 移远EC20 4G模块LTE开发板三网通模块 MQTT阿里云物联网STM32代码

    usb转tdl ath 挂断 22点评,要接转送帽 AT+QGPSLOC? gps定位 AT+QGPS=1通过命令启动 启动好之后 505还没有启动 516 还没有定位好, 新版本数据模块,带电瓶转换 ...

  6. 基于阿里云物联网平台MQTT协议实现云端和mqttfx通讯

    本项目的目的,借助阿里云物联网平台实现ESP8266(IDE:Arduino)与小程序(作为客户端)的互相通信,并通过小程序控制以及获取esp8266上的灯状态. 准备材料以及要使用的IDE 阿里云账 ...

  7. 学习日记——阿里云物联网平台

    文章目录 前言 一.阿里云物联网平台 产品架构 产品规格 计费标准 MQTT 二.阿里云创建产品和设备 1.开通物联网平台 2.创建产品 3.添加设备 4.接入阿里云物联网平台 5. 规则引擎 6.M ...

  8. Esp8266 进阶之路29【高级篇】百万条消息免费之乐鑫esp8266使用TCP直连模式MQTT协议接入阿里云物联网平台,支持私家服务器对接,支持阿里云规则引擎。(附带Demo)

    本系列博客学习由非官方人员 半颗心脏 潜心所力所写,不做开发板.仅仅做个人技术交流分享,不做任何商业用途.如有不对之处,请留言,本人及时更改. 序号 SDK版本 内容 链接 1 nonos2.0 搭建 ...

  9. 微信小程序使用MQTT远程控制单片机——阿里云物联网平台

    微信小程序使用MQTT远程控制单片机--阿里云物联网平台① 阿里云物联网平台的使用 第一,注册阿里云 第二,找到找到物联网平台并创建设备 MQTT协议格式的讲解 MQTT中文文档 固定报头 Fixed ...

最新文章

  1. php怎么实现自动售货,PHP自动化售货发卡网源码+教程
  2. 中医治疗慢性病很有效
  3. boost::container实现多态的flat_set
  4. android 查看gpio状态_GPIO子系统重要概念
  5. Auto login to your computer
  6. VMware中NAT网络模式设定
  7. rabbitmq python 发送失败_python rabbitmq no_ack=false
  8. 设计模式系列——单例模式
  9. 单反相机坏点和噪点测试软件,单反相机测试坏点和噪点的软件
  10. sqlplus连接mysql_sqlplus 命令连接数据库
  11. c# spire.xls 设置文字为微软雅黑_微软自带de白板应用,超好用
  12. 正商职业学校预付费云平台系统 的设计与应用
  13. 公司计算机程序员英语怎么说,程序员英语怎么说
  14. 2021年湖南省长沙市房地产行业发展现状分析(附开发投资额、施工面积、商品房销售、待售面积等)[图]
  15. 【软件工程】决策表和决策树
  16. 小学生日常行为规范PPT模板
  17. 【HTML实现弹幕滚动效果和文字动态发光特效代码】
  18. 第二十八课:focusin与focusout,submit,oninput事件的修复
  19. USACO--Broken Necklace(C语言)beads
  20. 计算机突破图灵测试,人工智能巨大突破 计算机首次通过图灵测试

热门文章

  1. speedoffice表格中如何自动求和
  2. Transformers 多语言模型 | 十一
  3. 记录java.util.Collections.unmodifiableList()使用
  4. idea package自动生成_Java idea使用generator自动生成mapper | Rickytsang洛水寒
  5. 浅聊DAO图景和未来
  6. 小米手机保护套自动锁屏功能
  7. 将SQL Server表导出为txt文件
  8. 第1章 SQL Server基本操作
  9. Unity 电脑CPU 显卡查询 存储空间查询
  10. 电子学会python三级笔记