timum-viw / socket.io-client

A socket.io-client implementation for ESP8266 and Arduino
228 stars 90 forks source link

[SOLVED] How to include variables in socket.emit()? #80

Closed GowthamGottimukkala closed 4 years ago

GowthamGottimukkala commented 4 years ago

I am having trouble including variables in socket.emit(). My variable is timeClient.getFormattedTime() which returns a string

If I use socket.emit("timestamp", timeClient.getFormattedTime().c_str()); then my output is [SIoC] add packet 42["timestamp",01:19:25] but I can't receive this in my server.

I am receiving it only if the output is like below [SIoC] add packet 42["timestamp","01:19:25"]

How should I do this?

GowthamGottimukkala commented 4 years ago

I solved this by keeping my variable in quotes (like a string). Don't know if this is the right way.

String message = "";
message += "\"";
message += myvariable;
message += "\"";
socket.emit ("timestamp", message.c_str());