WiFi.SSID(); not displaying on web app properly [SOLVED]

I’m trying to display SSID on my webapp using WiFi.SSID(); but am getting strange characters: A tall hexigon with a question mark inside and a capital “Z”. I suspect this is a datatype issue. I am able to pass a string to my webapp and display it properly. I am also able print the SSID successfully to a terminal over serial. But when I try to pass the SSID value to my web app I get the strange characters. I found in the reference material that WiFi.SSID(); returns a char* datatype and have been trying to convert that to a string before passing it to my webapp but nothing has worked. I found a post on this forum very specific to converting char* to string but couldn’t make it work. Here are snippets of my code that pertain without the datatype conversion attempts.

String SSID = “None”;

void setup() {
Spark.variable(“SSID”, SSID, STRING);

void loop() {
SSID = WiFi.SSID(); // WiFi SSID of connected network

If i print SSID over serial I see the correct value but I figure maybe the print function doesn’t care about the datatype where as maybe the Spark.variable function does.

Anyone see anything obvious I am doing wrong.

The thing is, that Spark.variable() stores a pointer to the variable at the moment when you set it up, but with the String class you have no real control over the actual location of the stored string.
So when you change the value, the location of your string will possibly change and hence your Spark.variable will not reflect the current value anymore.

So your best bet is to use a char SSID[64] with strcpy() instead.

BTW: Even if a class implements a method or an operator that would give you what you want, the important thing is to look at the caller if it actually will make use of that operator/method.

1 Like

Thanks ScruffR, that worked!

1 Like