Skip to content
This repository was archived by the owner on Jan 29, 2023. It is now read-only.
This repository was archived by the owner on Jan 29, 2023. It is now read-only.

Ping events propagated to main code socketIO events #18

@iKK001

Description

@iKK001

Is your feature request related to a problem? Please describe.

Using SocketIO with your library, I could really use the "ping"/"pong" events in the main code to detect when I am off internet.

One application of this feature-request is to trigger my watchdog timer in my Arduino board. If, for some reason, the internet is off then the Arduino board would get restarted.

Describe the solution you'd like

In order to make the above feature work, all we have to add is the following:
(of course not knowing if you have an even better solution to this - if you do, please let me know....)

Inside SocketIOclient_Generic.h file, you can add an event enum (see last line case 7):

typedef enum
{
  sIOtype_CONNECT      = '0',
  sIOtype_DISCONNECT   = '1',
  sIOtype_EVENT        = '2',
  sIOtype_ACK          = '3',
  sIOtype_ERROR        = '4',
  sIOtype_BINARY_EVENT = '5',
  sIOtype_BINARY_ACK   = '6',
  sIOtype_PING         = '7',
} socketIOmessageType_t;

And inside SocketIOclient_Generic-Impl.h file, you can add one line of code to "deviate" the ping to the events-listener in the main code (please not the extra line with runIOCbEvent(sIOtype_PING, payload, length);)

case eIOtype_PING:
  payload[0] = eIOtype_PONG;
  
  WSK_LOGWARN1("[wsIOc] get ping send pong:", (char *) payload);
  
  WebSocketsClient::sendTXT(payload, length, false);            
  runIOCbEvent(sIOtype_PING, payload, length);
  
  break;

This allows in the main code:

void socketIOEvent(socketIOmessageType_t type, uint8_t* payload, size_t length) {
  
    // switch socketIO events
    switch (type) {

        case sIOtype_PING:
            /* PING */
            watchdog.kick();

            break;
    // ...
    }
}

Additional context
I tried to make a pull-request with this but the appropriate permissions are not available.

Feel free to implement the above solution if you find it helpful for others. Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions