open-tcp

xod-dev/esp8266/open-tcp

Open a TCP connection to the specified server. Possible errors: — Can't open TCP connection
open-tcp
@/open-tcp
Open a TCP connection to the specified server. Possible errors: — Can't open TCP connection
INET@/esp8266-inet
An internet connection
HOSTstring
Server name or IP address
PORTnumber
A destination server port number
CONNpulse
Open the connection
open-tcp
INET'
SOCK
DONE
INET
HOST
PORT
CONN
DONEpulse
Pulses when the TCP connection is successfully open
SOCKxod/net/socket
The socket connected
INET'@/esp8266-inet
An internet connection
To use the node in your project you should have the xod-dev/esp8266 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_CONN
#pragma XOD error_raise enable

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

        auto host = getValue<input_HOST>(ctx);
        char _host[length(host) + 1] = { 0 };
        dump(host, _host);

        uint32_t port = (uint32_t)getValue<input_PORT>(ctx);

        auto inet = getValue<input_INET>(ctx);
        bool res = inet.wifi->createTCP(_host, port);

        if (res) {
            emitValue<output_SOCK>(ctx, 0);
            emitValue<output_DONE>(ctx, 1);
        } else {
            raiseError(ctx);
        }

        emitValue<output_INETU0027>(ctx, inet);
    }
}