timum-viw / socket.io-client

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

Node JS server receiving Undefined payload from ESP8266/Arduino socket #59

Closed TonySchmelzer closed 4 years ago

TonySchmelzer commented 4 years ago

My arduino socket client is working - both sending and receiving. The server side is NodeJS server on Raspberry Pi. I am missing some key point it appears.

Key Arduino lines: String msgString = "\"ESP_0001, 72, 29.30, 43\""; webSocket.emit("ESP", msgString.c_str());

Code compiles and executes as expected on ESP8266: [SIoC] packet "42["ESP","ESP_0001, 72, 29.30, 43"]" emitted

However, in Node JS the payload is undefined. I can see the data in console.log but I cannot access the data since it is undefined.

Key Node lines: socket.on('ESP', function(error, data) { //data from ESP module if (error) console.log(error); newString = (data + ":End").toString(); console.log(newString); });

Console.log output: ESP_0001, 72, 29.30, 43 undefined:End

I was expecting the payload to be a single string. I am not experienced programmer and need a nudge to get node and the socket client working together. I can see the string in the console followed by CR and "undefined". I cannot access the string.

Thanks.