【问题标题】:Having trouble programming wifi on esp8266在 esp8266 上编程 wifi 时遇到问题
【发布时间】: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/…
  • 我只是复制代码示例以开始使用。显然它们已经过时了,但我会留下这篇文章,以防有人遇到同样的问题。

标签: arduino ide wifi esp8266


【解决方案1】:

您需要注意 Arduino 不是 C,它基于 C++。因此,像下面这样添加您的包含以使用基于 C SDK 的函数。

extern "C" {
  #include "user_interface.h"
}

【讨论】:

    【解决方案2】:

    Arduino IDE 菜单上有代码示例

    File > Examples
    

    还有一个名为 WiFiWebClient 的示例,您只需更改您的 wifi ssid 和密码。

    将它保存到一个新文件夹中,您可以通过修改示例中的地址向 Internet 上的任何站点发出 http 请求。

    从制造商的示例开始,因此您无需依赖过时/部分教程。

    【讨论】:

    • 此外,Arduino StackExchange 网站上可能会提供更好的帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-22
    • 2014-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多