My post reply time was limited, I didn't have so long to dive into incomplete code and figured it'd get straightened out.
I've done the address thing so many times before but to tell the truth I have not used any form of scanf() since I first crossed it in the 80's because I had my own input routines that handled errors more completely already working in Basic that I moved into C.
GoForSmoke:
Because it's not const char * but only char *.
And I did assume that payload is a byte array made from text read as bytes.
Why don't you spell out what you see wrong, crypto?
Assumption like that is recipe for disaster. OP did mention his code crashed, so your assumption is mostly incorrect.
As I pointed out, what's wrong is "payload" is NOT a cstring and should not be interpreted as such.
Where did the payload array get shown? I missed that.
Reply #3 does not show what payload contents are, just the array name. The snippets we have force assumptions like the length parameter applying to payload.
A typical command string looks like [1p=123.456].
I pointed out how to do one thing, not fix the sketch we do not have.
void webSocketEvent() as posted is incomplete as well as broken. Note the local char buffer that is not used and lack of check code.
GoForSmoke:
Reply #3 does not show what payload contents are, just the array name. The snippets we have force assumptions like the length parameter applying to payload.
I pointed out how to do one thing, not fix the sketch we do not have.
void webSocketEvent() as posted is incomplete as well as broken. Note the local char buffer that is not used and lack of check code.
Consider this my last reply on this, since thing is getting awkward. But the OP's snippet code was enough to demonstrate the problem I pointed out.
Here's the final working code (minimal snippet) which doesn't reset ESP8266:
void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) {
switch(type) {
case WStype_TEXT:
processCmd((char *)payload);
break;
}
}
void processCmd(char *rx) {
float pos;
sscanf(&rx[2],"p=%f",&pos);
printf("pos=%f\n",pos);
//Do something real with pos here
}
Thanks to all for your help!
That code needs bounds and error checking. It is not fault tolerant at all, data error will either crash it or worse give garbage output with no warnings.
Until I learned to vet data, half the bugs I got were "data errors".
A truth about serial transmission: it has no guarantee.