WiFi.SSID() usage example

The documentation does not have an example of how to use this WiFi function and states that it returns a char*. On the Photon I am getting a build error stating:

error: invalid conversion from 'const char*' to 'char*' [-fpermissive] 

where the declaration is:

char *connectedSSID;

And the call of WiFi.SSID()

connectedSSID = WiFi.SSID();

You are getting back a pointer to an internal buffer created by the function, so it’s always good practice to copy the contents rather than just relying on the pointer to stay valid.

So you could go either of these ways

  String mySSID = String(WiFi.SSID());
  // or my favourite because I don't like String ;-)
  char myCharSSID[64];
  strcpy(myCharSSID, WiFi.SSID());

Thanks again for explaining this and providing options.

1 Like