arduino-websocketclient icon indicating copy to clipboard operation
arduino-websocketclient copied to clipboard

Arduino 1.8.5

Open SvenDS opened this issue 7 years ago • 2 comments

Seems not to be compatible with arduino 1.8.5? If I install 1.6.9 evrything is working but with the 1.8.5 handshake is ok also server is receiving data from client. But client (arduino) is not receiving data from server. I have no idea why.

SvenDS avatar Jul 30 '18 12:07 SvenDS

Something is not working in this code... It gets the data but I can not read it

char* WSClient::getData() {
    uint8_t msgtype;
    uint8_t bite;
    unsigned int length;
    uint8_t mask[4];
    uint8_t index;
    unsigned int i;
    bool hasMask = false;

    // char array to hold bytes sent by server to client
    // message could not exceed 256 chars. Array initialized with NULL
    char socketStr[256] = {NULL};

    if (socket_client->connected() && socket_client->available()) {
        msgtype = timedRead();
        if (!socket_client->connected()) {
            return (char*)socketStr;
        }

        length = timedRead();


        if (length > 127) {
            hasMask = true;
            length = length & 127;
        }


        if (!socket_client->connected()) {
            return (char*)socketStr;
        }

        index = 6;



        if (length == 126) {
            length = timedRead() << 8;
            if (!socket_client->connected()) {
                return (char*)socketStr;
            }
            
            length |= timedRead();
            if (!socket_client->connected()) {
                return (char*)socketStr;
            }   

        } else if (length == 127) {

            while(1) {
                // halt, can't handle this case
            }
        }


        if (hasMask) {
            // get the mask
            mask[0] = timedRead();
            if (!socket_client->connected()) {
                return (char*)socketStr;
            }

            mask[1] = timedRead();
            if (!socket_client->connected()) {
                return (char*)socketStr;
            }

            mask[2] = timedRead();
            if (!socket_client->connected()) {
                return (char*)socketStr;
            }

            mask[3] = timedRead();
            if (!socket_client->connected()) {
                return (char*)socketStr;
            }
        }


        if (hasMask) {
            for (i=0; i<length; ++i) {
                socketStr[i] = (char) (timedRead() ^ mask[i % 4]);
                if (!socket_client->connected()) {
                    return (char*)socketStr;
                }
            }
        } else {
            for (i=0; i<length; ++i) {
                socketStr[i] = (char) timedRead();
                if (!socket_client->connected()) {
                    return (char*)socketStr;
                }
            }            
        }
    }
    return (char*)socketStr;
}

SvenDS avatar Aug 23 '18 04:08 SvenDS

Found a library that works perfect! https://github.com/larkin/ESP32-Websocket

SvenDS avatar Aug 23 '18 19:08 SvenDS