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

Ping events propagated to main code socketIO events #18

Closed
iKK001 opened this issue Feb 14, 2022 · 4 comments
Closed

Ping events propagated to main code socketIO events #18

iKK001 opened this issue Feb 14, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@iKK001
Copy link

iKK001 commented Feb 14, 2022

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.

@khoih-prog
Copy link
Owner

Hi @iKK001

Thanks for the good enhancement.

I've already implemented / tested OK the changes, with the addition of sIOtype_PING as well as sIOtype_PONG, so that you can use as necessary.

Will inform when the new release already published.

Thanks and Regards,

khoih-prog added a commit that referenced this issue Feb 15, 2022
### Release v2.13.0

1. Add support to ESP32_S3.
2. Add sIOtype_PING and sIOtype_PING SocketIO events. Check [Ping events propagated to main code socketIO events #18](#18)
3. Add [ESP32_WebSocketClientSocketIO](examples/ESP32_WebSocketClientSocketIO) example
4. Update `Packages' Patches`
khoih-prog added a commit that referenced this issue Feb 15, 2022
### Release v2.13.0

1. Add support to ESP32_S3.
2. Add sIOtype_PING and sIOtype_PING SocketIO events. Check [Ping events propagated to main code socketIO events #18](#18)
3. Add [ESP32_WebSocketClientSocketIO](examples/ESP32_WebSocketClientSocketIO) example
4. Update `Packages' Patches`
khoih-prog added a commit that referenced this issue Feb 15, 2022
### Release v2.13.0

1. Add support to ESP32_S3.
2. Add sIOtype_PING and sIOtype_PING SocketIO events. Check [Ping events propagated to main code socketIO events #18](#18)
3. Add [ESP32_WebSocketClientSocketIO](examples/ESP32_WebSocketClientSocketIO) example
4. Update `Packages' Patches`
khoih-prog added a commit that referenced this issue Feb 15, 2022
### Release v2.13.0

1. Add support to `ESP32_S3`.
2. Add `sIOtype_PING` and `sIOtype_PING` SocketIO events. Check [Ping events propagated to main code socketIO events #18](#18)
3. Add [ESP32_WebSocketClientSocketIO](examples/ESP32_WebSocketClientSocketIO) example
4. Update `Packages' Patches`
@khoih-prog
Copy link
Owner

Hi @iKK001

The new WebSockets_Generic releases v2.13.0 has just been published. Your contribution is noted in Contributions and Thanks

Best Regards,


Release v2.13.0

  1. Add support to ESP32_S3.
  2. Add sIOtype_PING and sIOtype_PING SocketIO events. Check Ping events propagated to main code socketIO events #18
  3. Add ESP32_WebSocketClientSocketIO example
  4. Update Packages' Patches

@khoih-prog khoih-prog added the enhancement New feature or request label Feb 15, 2022
@khoih-prog
Copy link
Owner

Also have a look at the additions in many SIO_related examples, such as:

case sIOtype_PING:
Serial.println("[IOc] Get PING");
break;
case sIOtype_PONG:
Serial.println("[IOc] Get PONG");
break;

@iKK001
Copy link
Author

iKK001 commented Feb 15, 2022

Thank you very much for this quick change and new version.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants