Websockets help
Posted: Fri Sep 04, 2015 11:19 am
I've gotten the example working for Websockets in the latest build. It is successfully displaying a timestamp, but I can't seem to figure out how to send text commands via websockets.
This is probably a datatype question, the million different datatypes in C go over my head most of the time. I'm missing something in my understanding of the "payload". I would have thought I could do something like this:
It certainly doesn't like that since payload is not a string. I get that it's not a string, I get that I have to cast it. But everything I've tried to correctly cast it keeps failing.
Can someone point me in the right direction?
This is probably a datatype question, the million different datatypes in C go over my head most of the time. I'm missing something in my understanding of the "payload". I would have thought I could do something like this:
Code: Select all
void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) {
switch(type) {
case WStype_TEXT:
Serial.printf("[%u] get Text: %s\n", num, payload);
if (payload=="hello"){
// echo data back to browser
webSocket.sendTXT(num, "yes", 3);
} else{
// echo data back to browser
webSocket.sendTXT(num, "no", 2);
}
break;
}
}
It certainly doesn't like that since payload is not a string. I get that it's not a string, I get that I have to cast it. But everything I've tried to correctly cast it keeps failing.
Can someone point me in the right direction?