-->
Page 1 of 1

Best way to send & receive an array over websockets

PostPosted: Mon Sep 17, 2018 9:51 pm
by Espradio01
Best way to send & receive an array over websockets

On the client side I'm using javascript that sends the data.

I'm sending to a microcontroller (ESP8266) that is programmed in c++ using the https://github.com/Links2004/arduino WebSockets library with the arduino IDE.

At the moment I'm sending the variable which I build up on the client side. It is then sent to the microcontroller and received by the payload buffer.

I am sending this from the client

Code: Select all#,tank,pond,1537272000,1537272000,Normal,4789,12

I received here in the code:

Code: Select allcase WStype_TEXT: Serial.printf("[%u] get Text: %s\n", num, payload);

this is the result of what I receive
Code: Select all[0] here it is: #,tank,pond,1537272000,1537272000,Normal,4789,12

I am using a hash(#) to mark the start of the data. I have been googling and searching forums for days but can't fathom which is the best way to do this.
Some examples show strtok ans strtok_r, some pop each character into a buffer ..many wayt to skin a cat I guess.
But the code already has a uint8 received buffer namely PAYLOAD.
So....
What is the fastest most elegant code to split this up into different variables so that they can be compared?