Richard Thomas
Richard Thomas

Reputation: 360

Having trouble programming wifi on esp8266

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()'

Upvotes: 2

Views: 920

Answers (2)

mico
mico

Reputation: 12758

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.

Upvotes: 2

cagdas
cagdas

Reputation: 1644

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"
}

Upvotes: 2

Related Questions