Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By Focak
#41237 Hello to all,

I need help with testing esp websocket .
I tried AdySan websocket: https://github.com/AdySan/WittyCloudTes ... yCloudTest ,
i working fast and stabile when sending one variable value in websocket response:



case WStype_TEXT:

switch(payload[0]){

case 'l': case 'L': // Request LDR
LDRvalue = analogRead(LDR);
delay(5);
webSocket.sendTXT(0,LDRvalue);
break;

I would like to send multiple variable values in websocket response . How it is possible ?
For example in case receiving "l" reply is :

webSocket.sendTXT(0,LDRvalue); sending only one variable value .
How I can send multiple values in response ?
User avatar
By danbicks
#41671 Hi,

You may consider building a string first with data then send the whole string. I hope this example gives you some guidance.

case 'l': case 'L': // Request LDR
LDRvalue = analogRead(LDR);
delay(5);

String MyPayload;
MyPayload = "Transmitted Data: "; // Here we build payload string!
MyPayload += "LDR Value: ";
MyPayload += (LDRvalue);

webSocket.sendTXT(0,MyPayload);
break;

Regards

Dans