Discuss here different C compiler set ups, and compiling executables for the ESP8266

User avatar
By Mingy
#47944 I am using Windows EclipseArduino IDE V3

I have been beating my head against the wall for a few days with this problem. I have code which includes
Serial.print(WiFi.SSID(i));
Serial.print(WiFi.RSSI(i));

When I compile under Arduino IDE there are no errors. When I compile the exact same code under EclipseArduino IDE V3 the (i) is flagged as an error. The exact same code
Serial.print(WiFi.SSID());
Serial.print(WiFi.RSSI());

Is fine, except, of course I can't scan for more than 1 network. I did complete "clean" reinstalls of Arduino and EclipseArduino but it didn't help.

I suspect the problem is in the file "ESP8266WiFiMulti.cpp" where the compile can't figure out what
strdup() is 2 lines newAP.ssid = strdup(ssid);

I get the error - Function 'strdup' could not be resolved

It turns out that strdup is not a standard c function.

I've tried setting compiler flags but nothing seems to work. I can get rid of the problem by inserting my own version of strdup() but that might cause other issues when the library is updated.

Does anybody have any suggestions?

Thanks
User avatar
By martinayotte
#47947 There 2 different issues here.

The first one about RSSI(i) vs RSSI(), where the first is defined in ESP8266WiFiScanClass while the other is defined in ESP8266WiFiSTAClass. Also, since the first one is related to scanNetwork(), it has nothing to do with the ESP8266WiFiMulti which only store a list APs added by addAP() and this list is private without relation with scanned APs.

The second issue with strdup() reveal that there something wrong with your environment, because it is part of following file of the core :
.arduino15/packages/esp8266/hardware/esp8266/2.2.0/cores/esp8266/libc_replacements.c

When you've said that you've reinstalled everything, did you took care of cleaning everything before re-installing ?
(Maybe you have a mix of old version of some files and newer version of some other files which would explain both errors)

Otherwise, maybe you can provide us some piece of code that will show us the problem.
User avatar
By Mingy
#47955 Thanks for the reply and the help.

After I posted my initial comment I realized my strdup "workaround" didn't actually fix the WiFi.SSID(i) and WiFi.RSSI(i) problems and that somehow the issue is associated with scanNetwork() though I don't know c++ to figure out what the issue is. I am mostly an old c programmer.

The strdup() issue was probably a red herring, but something I am going to have to solve. I did go through as many files as I could to clean up arduino and EclipseArduino before reinstalls, but maybe I need to try again.

In order to ensure my original code wasn't wrong I pulled this directly off https://github.com/esp8266/Arduino/blob ... FiScan.ino

Here it is, just in case:

#include "Arduino.h"

/*
* This sketch demonstrates how to scan WiFi networks.
* The API is almost the same as with the WiFi Shield library,
* the most obvious difference being the different file you need to include:
*/
#include "ESP8266WiFi.h"

void setup() {
Serial.begin(115200);

// Set WiFi to station mode and disconnect from an AP if it was previously connected
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);

Serial.println("Setup done");
}

void loop() {
Serial.println("scan start");

// WiFi.scanNetworks will return the number of networks found
int n = WiFi.scanNetworks();
Serial.println("scan done");
if (n == 0)
Serial.println("no networks found");
else
{
Serial.print(n);
Serial.println(" networks found");
for (int i = 0; i < n; ++i)
{
// Print SSID and RSSI for each network found
Serial.print(i + 1);
Serial.print(": ");
Serial.print(WiFi.SSID(i)); //******Error
Serial.print(" (");


Serial.print(WiFi.RSSI((uint8_t) i)); //******Error
Serial.print(")");
Serial.println((WiFi.encryptionType(i) == ENC_TYPE_NONE)?" ":"*");
delay(10);
}
}
Serial.println("");

// Wait a bit before scanning again
delay(5000);
}