@GoForSmoke Haha, yeah that is true as well. It's just that i don't understand why Arduino's String implementation is so much more RAM intensive, why don't they just use the char* functions but wrap them in a human-readable format - like string.compareTo instead of strcmpstrtoantrhstr() (to exacerbate what i'm trying to say here). I'm no C++ programmer, so i don't have these methods 'baked' into my mind, but i have used PHP which inherits a lot of the same function names and also there i found they weren't really human-readable. But this creates a whole different discussion which is not my point here).
Question regarding sscanf
I'm now using the sscanf function (which is awesome and saves a lot of roll-your-own-parser-time) this way:
void dataReceivedAction(WebSocket &socket, char* dataString, byte frameLength) {
// below debug print is a leftover from the example webSocketServer library.
#ifdef DEBUG
Serial.print("Got data: ");
Serial.write((unsigned char*)dataString, frameLength);
//Serial.println("\n");
#endif
// first, extract command and params if there are any
String command;
String param1;
String param2;
int numExtracted = sscanf(dataString, "%s %s %s", &command, ¶m1, ¶m2);
switch(numExtracted) {
case 0:
Serial.println("ERROR, ERROR, ERROR! NO VALID REQUEST FOUND.");
break;
case 1:
Serial.println("extraction yielded only a function call.");
Serial.println("command: ");
Serial.println(command);
Serial.println("\n\n");
break;
case 2:
Serial.println("extraction yielded a function call + 1 parameter.");
Serial.println("command: ");
Serial.println(command);
Serial.println("\n");
Serial.println("param1: ");
Serial.println(param1);
Serial.println("\n\n");
break;
case 3:
Serial.println("extraction yielded a function call + 2 parameters.");
Serial.println("command: ");
Serial.println(command);
Serial.println("\n");
Serial.println("param1: ");
Serial.println(param1);
Serial.println("\n");
Serial.println("param2: ");
Serial.println(param2);
Serial.println("\n\n");
break;
}
}
But, when i run this, i get a lot of gibberish AFTER the debug line (see screenshot)
Something is not right with the way i use sscanf, can anyone point out what?
Also, i know my switch-case debug could probably written in a tenth the amount of lines so proposals are greatly welcomed!
[EDIT: i've now removed all the command and param serial.println's.]
no weird gibberish and also allmost real-time communication with my app, instead of a 3 second delay.
i've changed my switch statement to the following:
Serial.println("Extraction yielded a function call + " + String(numExtracted-1) + " parameter(s).");
which just only lets me know what the signature is of what is called, enough for now but i'd like to
show the name of the function and the parameters as well..
IP adress:
192.168.1.200
Got data: SET_Mode bla test
extraction yielded a function call + 2 parameters.
function GET_Speed called...