链接 mqtt 失败 connecting to MQTT... Connectting failed
本帖最后由 hudcan 于 2022-8-22 09:36 编辑各位大佬请求一个问题,我想用 esp32 控制电脑开机参考的这篇文章(https://post.smzdm.com/p/aoown0g7/),
这个代码我去年也是用的这个,当时是正常运行的,昨天想改一下,发现原来的代码也运行不了了,不知道是不是哪里有什么问题?
但是烧录后报这个错,请问是啥原因?
代码如下:
/**********************************************
* ESP32 + ARDUINO + Blinker + XiaoAi
* Remote boot by WOL
* Creater:Faiz
*/
#define BLINKER_WIFI
#define BLINKER_MIOT_OUTLET
#include <Blinker.h>
#include <WiFiUdp.h>
#include <WiFi.h>
char auth[] = "xxxxxxxxxx"; //密钥
char ssid[] = "Faiz"; //wifi名
char pswd[] = "xxxxxxxx"; //wifi密码
//The udp library class
WiFiUDP udp;
bool oState = false;
BlinkerButton Button1("awaking");
//awaking!
void button1_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
digitalWrite(LED_BUILTIN, HIGH);
delay(50);
digitalWrite(LED_BUILTIN,LOW);
delay(50);
pcawaking();
digitalWrite(LED_BUILTIN, HIGH);
delay(50);
digitalWrite(LED_BUILTIN, LOW);
delay(50);
digitalWrite(LED_BUILTIN, HIGH);
delay(50);
digitalWrite(LED_BUILTIN, LOW);
delay(50);
}
void miotPowerState(const String & state)
{
BLINKER_LOG("need set power state: ", state);
if (state == BLINKER_CMD_ON) {
BlinkerMIOT.powerState("on");
BlinkerMIOT.print();
digitalWrite(LED_BUILTIN, HIGH);
delay(25);
digitalWrite(LED_BUILTIN, LOW);
delay(25);
pcawaking();
digitalWrite(LED_BUILTIN, HIGH);
delay(25);
digitalWrite(LED_BUILTIN, LOW);
delay(25);
digitalWrite(LED_BUILTIN, HIGH);
delay(25);
digitalWrite(LED_BUILTIN, LOW);
oState = false;//force off!!
}
else if (state == BLINKER_CMD_OFF) {
digitalWrite(LED_BUILTIN, LOW);
BlinkerMIOT.powerState("off");
BlinkerMIOT.print();
oState = false;
}
}
void miotQuery(int32_t queryCode)
{
BLINKER_LOG("MIOT Query codes: ", queryCode);
switch (queryCode)
{
case BLINKER_CMD_QUERY_ALL_NUMBER :
BLINKER_LOG("MIOT Query All");
BlinkerMIOT.powerState(oState ? "on" : "off");
BlinkerMIOT.print();
break;
case BLINKER_CMD_QUERY_POWERSTATE_NUMBER :
BLINKER_LOG("MIOT Query Power State");
BlinkerMIOT.powerState(oState ? "on" : "off");
BlinkerMIOT.print();
break;
default :
BlinkerMIOT.powerState(oState ? "on" : "off");
BlinkerMIOT.print();
break;
}
digitalWrite(LED_BUILTIN, HIGH);
delay(25);
digitalWrite(LED_BUILTIN, LOW);
delay(25);
digitalWrite(LED_BUILTIN, HIGH);
delay(25);
digitalWrite(LED_BUILTIN, LOW);
}
void pcawaking()
{
int i=0;
char mac={0xXX,0xXX,0xXX,0xXX,0xXX,0xXX};//mac地址
char pac;
char * Address = "xxx.xxx.xxx.255";//udp adress //群发最后为.255
int Port = 3333;//udp port
//make magicpacket
for(i=0;i<6;i++)
{
pac=0xFF;
}
for(i=6;i<102;i+=6)
{
memcpy(pac+i,mac,6);
}
udp.beginPacket(Address, Port);
udp.write((byte*)pac, 102);//send pac to txbuffer
udp.endPacket();//biubiubiu
}
void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);
Blinker.vibrate();
uint32_t BlinkerTime = millis();
Blinker.print("millis", BlinkerTime);
}
void setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);
BlinkerMIOT.attachPowerState(miotPowerState);
BlinkerMIOT.attachQuery(miotQuery);
Button1.attach(button1_callback);
}
void loop()
{
Blinker.run();
}
请按照文档,安装指定版本的依赖 点灯官方 发表于 2022-8-22 09:51
请按照文档,安装指定版本的依赖
能不能具体一点呢,我只把 GitHub 的 blinker-library 放到了指定的目录,不知道你说的依赖指的是? hudcan 发表于 2022-8-22 09:56
能不能具体一点呢,我只把 GitHub 的 blinker-library 放到了指定的目录,不知道你说的依赖指的是? ...
您好,这是官网文档地址:
https://diandeng.tech/doc/getting-start-esp32-wifi
页:
[1]