is-open

xod-dev/esp8266-mcu/is-open

Checks if a TCP connection is open
is-open
@/is-open
Checks if a TCP connection is open
SOCKxod/net/socket
A socket
INET@/esp8266-mcu-inet
An internet connection
CHKpulse
Perform the check
is-open
SOCK
INET
CHK
Y
N
Npulse
Pulses if the connection is closed
Ypulse
Pulses if the connection is open
To use the node in your project you should have the xod-dev/esp8266-mcu library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.

C++ implementation

#pragma XOD evaluate_on_pin disable
#pragma XOD evaluate_on_pin enable input_CHK

node {
    void evaluate(Context ctx) {
        if (!isInputDirty<input_CHK>(ctx))
            return;

        auto socketIdx = getValue<input_SOCK>(ctx);
        auto inet = getValue<input_INET>(ctx);
        auto client = inet.sockets[socketIdx];

        if (client->connected()) {
            emitValue<output_Y>(ctx, 1);
        } else {
            emitValue<output_N>(ctx, 1);
        }
    }
}