Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By Stevenelson
#27819 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:

Code: Select allvoid 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?
User avatar
By Stevenelson
#27824 Here's the error that gives me:

Error: initializing argument 1 of 'int strcmp(const char*, const char*)' [-fpermissive]
int _EXFUN(strcmp,(const char *, const char *));
^
invalid conversion from 'uint8_t* {aka unsigned char*}' to 'const char*' [-fpermissive]