Skip to content

Reconnection problems #95

Open
Open
@gdhgdhgdh

Description

@gdhgdhgdh

ESP8266 with Arduino 1.8.13, ArduinoWebsockets 0.5.0

I was reading #75 because I'm having the same probem. I have put my websocket setup calls into its own function:


void onEventsCallback(WebsocketsEvent event, String data) {
    if(event == WebsocketsEvent::ConnectionOpened) {
        Serial.println("Connnection Opened");
    } else if(event == WebsocketsEvent::ConnectionClosed) {
        Serial.println("Connnection Closed");
        setupWebsocket();
    }
}

void setupWebsocket() {
    client = {}; // as advised in issue #75 
    client.onMessage(onMessageCallback);
    client.onEvent(onEventsCallback);
    client.setInsecure(); // yes, lame
    client.connect(websockets_connection_string);
}

void setup() {
// [..  Serial + wifi setup not shown..]

    setupWebsocket();
}

This works fine until the remote websocket is closed - my code does not successfully reconnect :( I DO see the Connection Closed and then shortly after Connection Opened on the Serial output, but I don't get any new incoming WS messages after that.

What am I doing wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood for newcomershelp wantedExtra attention is neededpossible-bugSomething isn't working, and I think it is a bug

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions