我是用的esp32开环环境配置是arduino中文社区提供的2.0.9版本,blinker库使用的是0.3.10版本,以下是在编译时出现的问题
1.找不到esp_camera.h头文件
报错信息如下:
In file included from C:\Users\X_MRX\AppData\Local\Temp\.arduinoIDE-unsaved2023611-25912-1onb5ct.8x6f\Blinker_ESP32_CAM\Blinker_ESP32_CAM.ino:50:0:
C:\Users\X_MRX\AppData\Local\Temp\.arduinoIDE-unsaved2023611-25912-1onb5ct.8x6f\Blinker_ESP32_CAM\ESP32_CAM_SERVER.h:4:10: fatal error: esp_camera.h: No such file or directory
#include "esp_camera.h"
^~~~~~~~~~~~~~
compilation terminated.
exit status 1
Compilation error: esp_camera.h: No such file or directory
解决办法:
选择正确的开发板
2.F宏定义报错
报错信息如下:
C:\Users\X_MRX\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.9\cores\esp32/Arduino.h:176, from d:\arduino\libraries\Blinker\src\modules\mqtt\Adafruit_MQTT.h:25, from d:\arduino\libraries\Blinker\src\modules\mqtt\Adafruit_MQTT.cpp:22: d:\arduino\libraries\Blinker\src\modules\mqtt\Adafruit_MQTT.cpp: In member function 'const char* Adafruit_MQTT::connectErrorString(int8_t)': C:\Users\X_MRX\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.9\cores\esp32/WString.h:38:55: error: cannot convert 'const __FlashStringHelper*' to 'const char*' in return #define F(string_literal) (FPSTR(PSTR(string_literal))) ^ d:\arduino\libraries\Blinker\src\modules\mqtt\Adafruit_MQTT.cpp:279:22: note: in expansion of macro 'F' case 1: return F("The Server does not support the level of the MQTT protocol requested"); ^ C:\Users\X_MRX\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.9\cores\esp32/WString.h:38:55: error: cannot convert 'const __FlashStringHelper*' to 'const char*' in return #define F(string_literal) (FPSTR(PSTR(string_literal))) ^ d:\arduino\libraries\Blinker\src\modules\mqtt\Adafruit_MQTT.cpp:280:22: note: in expansion of macro 'F' case 2: return F("The Client identifier is correct UTF-8 but not allowed by the Server"); ^ C:\Users\X_MRX\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.9\cores\esp32/WString.h:38:55: error: cannot convert 'const __FlashStringHelper*' to 'const char*' in return #define F(string_literal) (FPSTR(PSTR(string_literal))) ^ d:\arduino\libraries\Blinker\src\modules\mqtt\Adafruit_MQTT.cpp:281:22: note: in expansion of macro 'F' case 3: return F("The MQTT service is unavailable"); ^ C:\Users\X_MRX\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.9\cores\esp32/WString.h:38:55: error: cannot convert 'const __FlashStringHelper*' to 'const char*' in return #define F(string_literal) (FPSTR(PSTR(string_literal))) ^ d:\arduino\libraries\Blinker\src\modules\mqtt\Adafruit_MQTT.cpp:282:22: note: in expansion of macro 'F' case 4: return F("The data in the user name or password is malformed"); ^ C:\Users\X_MRX\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.9\cores\esp32/WString.h:38:55: error: cannot convert 'const __FlashStringHelper*' to 'const char*' in return #define F(string_literal) (FPSTR(PSTR(string_literal))) ^ d:\arduino\libraries\Blinker\src\modules\mqtt\Adafruit_MQTT.cpp:283:22: note: in expansion of macro 'F' case 5: return F("Not authorized to connect"); ^ C:\Users\X_MRX\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.9\cores\esp32/WString.h:38:55: error: cannot convert 'const __FlashStringHelper*' to 'const char*' in return #define F(string_literal) (FPSTR(PSTR(string_literal))) ^ d:\arduino\libraries\Blinker\src\modules\mqtt\Adafruit_MQTT.cpp:284:22: note: in expansion of macro 'F' case 6: return F("Exceeded reconnect rate limit. Please try again later."); ^ C:\Users\X_MRX\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.9\cores\esp32/WString.h:38:55: error: cannot convert 'const __FlashStringHelper*' to 'const char*' in return #define F(string_literal) (FPSTR(PSTR(string_literal))) ^ d:\arduino\libraries\Blinker\src\modules\mqtt\Adafruit_MQTT.cpp:285:22: note: in expansion of macro 'F' case 7: return F("You have been banned from connecting. Please contact the MQTT server administrator for more details."); ^ C:\Users\X_MRX\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.9\cores\esp32/WString.h:38:55: error: cannot convert 'const __FlashStringHelper*' to 'const char*' in return #define F(string_literal) (FPSTR(PSTR(string_literal))) ^ d:\arduino\libraries\Blinker\src\modules\mqtt\Adafruit_MQTT.cpp:286:23: note: in expansion of macro 'F' case -1: return F("Connection failed"); ^ C:\Users\X_MRX\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.9\cores\esp32/WString.h:38:55: error: cannot convert 'const __FlashStringHelper*' to 'const char*' in return #define F(string_literal) (FPSTR(PSTR(string_literal))) ^ d:\arduino\libraries\Blinker\src\modules\mqtt\Adafruit_MQTT.cpp:287:23: note: in expansion of macro 'F' case -2: return F("Failed to subscribe"); ^ C:\Users\X_MRX\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.9\cores\esp32/WString.h:38:55: error: cannot convert 'const __FlashStringHelper*' to 'const char*' in return #define F(string_literal) (FPSTR(PSTR(string_literal))) ^ d:\arduino\libraries\Blinker\src\modules\mqtt\Adafruit_MQTT.cpp:288:23: note: in expansion of macro 'F' default: return F("Unknown error"); ^ exit status 1 Compilation error: exit status 1
解决办法:
按照报错信息提示的Adafruit_MQTT.cpp地址并将其使用文本文档形式打开,找到如下两个函数
在你的代码中大概的return 大概是这个样子的return reinterpret_cast<const char*>(F("your_error_string"));
将全部的return修改为return static_cast<const char*>(reinterpret_cast<const __FlashStringHelper*>(F("your_error_string"));
然后再次进行编译就可以了。