远程开机,编译时出错,求大神看看-Arduino中文社区 - Powered by Discuz! Archiver

youdongkiang 发表于 2021-6-5 15:09

远程开机,编译时出错,求大神看看

本帖最后由 youdongkiang 于 2021-6-5 15:11 编辑








Arduino:1.8.9 (Windows 10), 开发板:"Generic ESP8266 Module, 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), dtr (aka nodemcu), 26 MHz, 40MHz, DOUT (compatible), 1MB (FS:64KB OTA:~470KB), 2, nonos-sdk 2.2.1+100 (190703), v2 Lower Memory, Disabled, None, Only Sketch, 115200"

D:\程序\_______\_______.ino: In function 'void miotPowerState(const String&)':

_______:21:12: error: 'D2' was not declared in this scope

D:\程序\_______\_______.ino:30:18: note: in expansion of macro 'PW'

_______:35:5: error: 'BlinkerAliGenie' was not declared in this scope

_______:21:12: error: 'D2' was not declared in this scope

D:\程序\_______\_______.ino:41:18: note: in expansion of macro 'PW'

_______:46:5: error: 'BlinkerAliGenie' was not declared in this scope

D:\程序\_______\_______.ino: In function 'void miotQuery(int32_t)':

_______:22:12: error: 'D5' was not declared in this scope

D:\程序\_______\_______.ino:58:19: note: in expansion of macro 'PM'

_______:59:5: error: 'BlinkerAliGenie' was not declared in this scope

_______:63:5: error: 'BlinkerAliGenie' was not declared in this scope

_______:66:3: error: 'BlinkerAliGenie' was not declared in this scope

D:\程序\_______\_______.ino: In function 'void button1_callback(const String&)':

_______:21:12: error: 'D2' was not declared in this scope

D:\程序\_______\_______.ino:85:16: note: in expansion of macro 'PW'

D:\程序\_______\_______.ino: In function 'void heartbeat()':

_______:22:12: error: 'D5' was not declared in this scope

D:\程序\_______\_______.ino:91:19: note: in expansion of macro 'PM'

D:\程序\_______\_______.ino: In function 'void setup()':

_______:22:12: error: 'D5' was not declared in this scope

D:\程序\_______\_______.ino:104:11: note: in expansion of macro 'PM'

_______:21:12: error: 'D2' was not declared in this scope

D:\程序\_______\_______.ino:110:11: note: in expansion of macro 'PW'

D:\程序\_______\_______.ino: In function 'void loop()':

_______:22:12: error: 'D5' was not declared in this scope

D:\程序\_______\_______.ino:126:23: note: in expansion of macro 'PM'

exit status 1
'D2' was not declared in this scope

在文件 -> 首选项开启
“编译过程中显示详细输出”选项
这份报告会包含更多信息。


大神们怎么解决啊,在线等
#define BLINKER_PRINT Serial
#define BLINKER_WIFI
#define BLINKER_MIOT_OUTLET   //小爱同学


#include <Blinker.h>


char auth[] = "ea47b142001c";
char ssid[] = "TP-LINK_776E";
char pswd[] = "123456789";
BlinkerButton Button1("btn-abc");   //定义按钮数据键值
BlinkerText Text1("TextKey");      //文件显示键值


bool oState = false;


bool power;
bool lastpower;


int counter = 0;
String pState;//存储检测到的电源状态


#define PW D2    //继电器控制管脚
#define PM D5    //电源检测管脚




void miotPowerState(const String & state)
{
BLINKER_LOG("need set power state: ", state);


if (state == BLINKER_CMD_ON) {
    digitalWrite(PW, HIGH);
    delay(200);
    digitalWrite(PW, LOW);
    Serial.println("开了");


    BlinkerAliGenie.powerState("on");
    BlinkerAliGenie.print();


    oState = true;
}
else if (state == BLINKER_CMD_OFF) {
    digitalWrite(PW, HIGH);
    delay(200);
    digitalWrite(PW, LOW);
    Serial.println("关了");


    BlinkerAliGenie.powerState("off");
    BlinkerAliGenie.print();


    oState = false;
}
}




void miotQuery(int32_t queryCode)
{
BLINKER_LOG("AliGenie Query codes: ", queryCode);


if (digitalRead(PM) == true) {
    BlinkerAliGenie.powerState("on");
    BlinkerAliGenie.powerState("on");
}
else {
    BlinkerAliGenie.powerState("off");
    BlinkerAliGenie.powerState("off");
}
BlinkerAliGenie.print();


}


void dataRead(const String & data)      // 如果未绑定的组件被触发,则会执行其中内容
{
BLINKER_LOG("Blinker readString: ", data);


Blinker.vibrate();


uint32_t BlinkerTime = millis();


Blinker.print("millis", BlinkerTime);


}


void button1_callback(const String & state)   //点灯app内控制按键触发
{
BLINKER_LOG("get button state: ", state);
digitalWrite(PW, HIGH);
delay(200);
digitalWrite(PW, LOW);
}


void heartbeat() {
if (digitalRead(PM) == true) {
    pState = "开机";
}
else {
    pState = "关机";
}


Text1.print(pState, "电源状态反馈");
Serial.println("心跳反馈");
}


void setup()
{
pinMode(PM, INPUT);
Serial.begin(115200);
#if defined(BLINKER_PRINT)
BLINKER_DEBUG.stream(BLINKER_PRINT);
#endif


pinMode(PW, OUTPUT);            //定义io口为输出
digitalWrite(PW, LOW);         //定义io默认为高电平


Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);


BlinkerMIOT.attachPowerState(miotPowerState);
BlinkerMIOT.attachQuery(miotQuery);
Button1.attach(button1_callback);
Blinker.attachHeartbeat(heartbeat);


}


void loop()
{
Blinker.run();
power = digitalRead(PM);
if (power != lastpower) {
    if (digitalRead(PM) == true) {
      pState = "开机";
    }
    else {
      pState = "关机";
    }
    Text1.print(pState, "电源状态反馈");
    Serial.println("反馈");
}
lastpower = power;



}


youdongkiang 发表于 2021-6-5 15:12

:'(:'(:'(:'(

ahua7336 发表于 2021-6-5 18:09

检查一下ESP8266 引脚编号显示 D2 D3 有问题

王尼玛1 发表于 2021-6-5 21:14

开发版选择 NodeMCU1.0ESP12E

coloz 发表于 2021-6-6 00:28

IDE中选择您实际使用的开发板,或者将D2改成实际使用的GPIO编号

topdog 发表于 2021-6-6 00:34

#define PW 2    //继电器控制管脚
#define PM 5    //电源检测管脚

x970274 发表于 2021-6-8 11:47

感觉像是说D2定义有问题吧。该成数字引脚编号或者   char xxx = 'D2';   应该可以解决

topdog 发表于 2021-6-24 23:59

https://www.arduino.cn/thread-104403-1-1.html
页: [1]
查看完整版本: 远程开机,编译时出错,求大神看看