Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arduino 1.8.5 #8

Open
SvenDS opened this issue Jul 30, 2018 · 2 comments
Open

Arduino 1.8.5 #8

SvenDS opened this issue Jul 30, 2018 · 2 comments

Comments

@SvenDS
Copy link

SvenDS commented Jul 30, 2018

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
Copy link
Author

SvenDS commented Aug 23, 2018

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
Copy link
Author

SvenDS commented Aug 23, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant