【发布时间】:2017-12-28 20:11:06
【问题描述】:
所以我认为到目前为止我做得很好,安装了 arduino IDE,添加了 ESP8266 模块,设法让 LED 闪烁。是时候连接 WIFI 并做一些事情了。
不幸的是,这一切都崩溃了。我收到有关对 wifi_set_opmode、wifi_station_set_config 和 wifi_station_connect 的未定义引用的错误。现在,这不是我第一次使用 C 进行牛仔竞技表演,所以我开始寻找关于这些函数以及它们是如何包含在内的文档,但除了人们显然很高兴地使用它们之外,什么也找不到。我尝试添加各种#includes,但到目前为止没有任何帮助。所以是时候寻求一点帮助了。
这是我正在尝试运行的代码(非常顺利)
#include <user_interface.h>
#define LED_1 13
void setup() {
// put your setup code here, to run once:
pinMode(LED_1, OUTPUT);
const char ssid[32] = "qqqq";
const char password[32] = "wwww";
struct station_config stationConf;
wifi_set_opmode( STATION_MODE );
os_memcpy(&stationConf.ssid, ssid, 32);
os_memcpy(&stationConf.password, password, 32);
wifi_station_set_config(&stationConf);
wifi_station_connect();
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(LED_1, HIGH);
delay(500);
digitalWrite(LED_1, LOW);
delay(500);
}
我的板子选择是“通用 ESP8266 模块”
这是错误。
sketch\blinktest.ino.cpp.o:(.text.setup+0x8): undefined reference to `wifi_set_opmode(unsigned char)'
sketch\blinktest.ino.cpp.o:(.text.setup+0x10): undefined reference to `wifi_station_set_config(station_config*)'
sketch\blinktest.ino.cpp.o:(.text.setup+0x14): undefined reference to `wifi_station_connect()'
【问题讨论】:
-
在 arduino 目录中搜索了这些命令的所有文件后,我无法找到它们。最好的假设是此信息已过时,并且这些是“消失”的隐藏 API 命令。
-
函数原型可以在 Arduino15\packages\esp8266\hardware\esp8266\2.3.0\tools\sdk\include\user_interface.h 中找到。 Arduino15 文件夹位置位于文件>首选项>更多首选项可以直接在文件中编辑之后的行中。至于错误的定义和原因,我不知道。
-
当您使用 Arduino IDE 对它们进行编程时,为什么不使用
ESP8266WiFi.h类?无需直接调用底层的乐鑫 SDK 函数。 arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/… -
我只是复制代码示例以开始使用。显然它们已经过时了,但我会留下这篇文章,以防有人遇到同样的问题。