-->
Page 1 of 1

how to compare a string tyo uint8_t?

PostPosted: Wed Nov 30, 2016 2:18 am
by canedje
Hello.
I using websockets for de NodeMCU in the next format:
Code: Select allvoid webSocketEvent(WStype_t type, uint8_t * payload, size_t lenght)

There is a mesage coming in with case:
Code: Select allcase WStype_TEXT: {
           USE_SERIAL.printf("[WSc] get text: %s\n", payload);
  }

Now I want to test payload with a string by :
if ( payload == string)
This gives errors because I try to compare a string to uint8_t pointer.
How to convert the string to uint8_t or visa versa to be able to compare?

Thanks in advance

Re: how to compare a string tyo uint8_t?

PostPosted: Wed Nov 30, 2016 3:13 am
by FreddyVictor
try using the strcmp() function eg:
if (strcmp( (char *) payload, "TestString") == 0) // returns 0 if the same

above code may work ! 8-)

Re: how to compare a string tyo uint8_t?

PostPosted: Wed Nov 30, 2016 6:53 am
by canedje
Thanks, I will try!