2
votes

So I think I'm doing fairly well so far, have the arduino IDE installed, add the ESP8266 module, manage to get an LED blinking on and off. Time to connect to the WIFI and do some stuff.

Unfortunately, it all falls apart then. I get errors about undefined references to wifi_set_opmode, wifi_station_set_config and wifi_station_connect. Now, this isn't my first rodeo with C so I started looking for documentation on these functions and how they are included but can find nothing except people apparently quite happily using them. I've tried adding all sorts of #includes but nothing helps so far. So time to ask for a little help.

Here is the code I am trying to run (pretty uneventful)

#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);
}

My board selection is "Generic ESP8266 module"

Here are the errors.

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()'
2
Having done a search of all the files in the arduino directory for these commands, I am unable to locate them. Best assumption is this information is out-of-date and these are hidden API commands that have "gone away". - Richard Thomas
The function prototypes can be found at Arduino15\packages\esp8266\hardware\esp8266\2.3.0\tools\sdk\include\user_interface.h. The Arduino15 folder location is found in the line following File > Preferences > More preferences can be edited directly in the file. As for the definitions and the cause for the error, I don't know. - per1234
When you are programming them with the Arduino IDE, why not use the ESP8266WiFi.h classes? No need to call underlying Espressif SDK functions directly. arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/… - Maximilian Gerhardt
I was just copying code examples to get started. Evidently they are out of date but I'll leave this post in case anyone runs across the same issue. - Richard Thomas

2 Answers

2
votes

You need to notice that Arduino is not C, it's based on C++. So add your inclusion like below to use C SDK based functions.

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

Arduino IDE has code examples on menu

File > Examples

There is also example called WiFiWebClient where you need to change only your wifi ssid and password.

Save it to a new folder and you can make http requests to any site on Internet by modifying the address on the example.

Start from the examples of the manufacturer so you don't need to rely on outdated / partial tutorials.