-1

I'm building a small project using NodeMCU (ESP8266). I want to scan all available WiFi networks collect them in array. Here is my function:

String getWifiArray(void){
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  delay(500);
  byte n = WiFi.scanNetworks();
  String nets[] = {};
  for (byte i=0; i<n; i++){
    nets[i]= WiFi.SSID(i);
  }

  return nets[];
}

I get expected primary-expression before ']' token error. How could I fix this code?

neptunereach
  • 105
  • 2
  • 7
  • Dynamically allocate the memory and return the address of the pointer. For a string array, it is reference of the reference. Use native c instead of arduino specific classes. – cagdas Sep 29 '18 at 06:50

1 Answers1

0

A function can't return a whole array. A function can have only one return value. Instead pass in an array from the caller and let this function populate that.

Also you created your array to have zero elements. So when you put in the first string you overwrite the bounds of the array and corrupt memory.

Delta_G
  • 2,927
  • 2
  • 9
  • 15