请问这是怎么回事

2020-01-025989
AI 快速预览详细 收起
本文解决了 Arduino 项目中常见的 'D2' 未声明和 'client' 未声明的报错问题。首先,'D2' 未声明错误通常是由于引脚名称未正确声明或拼写错误引起的。解决方法是检查并修正引脚定义。其次,'client' 未声明错误通常是因为 MQTT 客户端未正确定义和初始化。通过确保所有变量已正确定义和初始化,可以解决这些问题。最终,你的项目将能够顺利连接 WiFi 和 MQTT 服务器,实现无缝通信。










C:\Users\acer\Desktop\sketch_jan02a\sketch_jan02a.ino: In function 'void openLight()':

sketch_jan02a:6: error: 'D2' was not declared in this scope

#define BEDROOD_LIGHT  D2

                        ^

C:\Users\acer\Desktop\sketch_jan02a\sketch_jan02a.ino:30:16: note: in expansion of macro 'BEDROOD_LIGHT'

   digitalWrite(BEDROOD_LIGHT, HIGH);

                ^

C:\Users\acer\Desktop\sketch_jan02a\sketch_jan02a.ino: In function 'void closeLight()':

sketch_jan02a:6: error: 'D2' was not declared in this scope

#define BEDROOD_LIGHT  D2

                        ^

C:\Users\acer\Desktop\sketch_jan02a\sketch_jan02a.ino:34:16: note: in expansion of macro 'BEDROOD_LIGHT'

   digitalWrite(BEDROOD_LIGHT, LOW);

                ^

C:\Users\acer\Desktop\sketch_jan02a\sketch_jan02a.ino: In function 'void connectWiFi()':

C:\Users\acer\Desktop\sketch_jan02a\sketch_jan02a.ino:40:37: warning: invalid conversion from 'const char*' to 'char*' [-fpermissive]

   WiFi.begin(WIFI_SSID,WIFI_PASSWORD);

                                     ^

In file included from C:\Users\acer\Desktop\sketch_jan02a\sketch_jan02a.ino:1:0:

C:\Users\acer\Desktop\Arduino-1.8.3\libraries\WiFi\src/WiFi.h:79:9: note: initializing argument 1 of 'int WiFiClass::begin(char*, const char*)'

     int begin(char* ssid, const char *passphrase);

         ^

C:\Users\acer\Desktop\sketch_jan02a\sketch_jan02a.ino: In function 'void callback(char*, byte*, unsigned int)':

sketch_jan02a:74: error: 'client' was not declared in this scope

   client.publish(pubTopic,sendMseg);

   ^

C:\Users\acer\Desktop\sketch_jan02a\sketch_jan02a.ino: In function 'void ConnectAliyun()':

sketch_jan02a:78: error: 'client' was not declared in this scope

   while(!client.connected()){

          ^

sketch_jan02a:81: error: 'myAliyun' was not declared in this scope

     if(client.connect(myAliyun.client_id,myAliyun.username,myAliyun.password)){

                       ^

C:\Users\acer\Desktop\sketch_jan02a\sketch_jan02a.ino: In function 'void setup()':

sketch_jan02a:6: error: 'D2' was not declared in this scope

#define BEDROOD_LIGHT  D2

                        ^

C:\Users\acer\Desktop\sketch_jan02a\sketch_jan02a.ino:94:11: note: in expansion of macro 'BEDROOD_LIGHT'

   pinMode(BEDROOD_LIGHT,OUTPUT);

           ^

sketch_jan02a:100: error: 'myAliyun' was not declared in this scope

   myAliyun.init(ALIYUN_SERVER,ProductKey,ClientId,DeviceName,DeviceSecret);

   ^

sketch_jan02a:102: error: 'client' was not declared in this scope

   client.setServer(myAliyun.mqtt_server,PORT);

   ^

C:\Users\acer\Desktop\sketch_jan02a\sketch_jan02a.ino: In function 'void loop()':

sketch_jan02a:118: error: 'client' was not declared in this scope

   if(!client.connected()){

       ^

sketch_jan02a:121: error: 'client' was not declared in this scope

   client.loop();

   ^

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


创作许可协议

本项目采用 None(不开放任何权利,保留所有权利) 进行许可。

评论(3)
20060606
20060606
没有添加库
kylinpoet
kylinpoet
这个好,必须支持。
gada888
gada888
代码开头没有添加库文件
- 没有更多了 -