send

xod-dev/esp8266-mcu/send

Send a message through an opened TCP connection Possible errors: — Can't send the data to the socket
send
@/send
Send a message through an opened TCP connection Possible errors: — Can't send the data to the socket
INET@/esp8266-mcu-inet
An internet connection
SOCKxod/net/socket
A socket
MSGstring
The message to send
SENDpulse
Send the message
send
INET
SOCK
MSG
SEND
INET'
DONE
SOCK'
SOCK'xod/net/socket
A socket
DONEpulse
Pulses when the message is successfully sent
INET'@/esp8266-mcu-inet
An internet connection
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_SEND
#pragma XOD error_raise enable

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

        auto socketIdx = getValue<input_SOCK>(ctx);
        auto inet = getValue<input_INET>(ctx);
        auto msg = getValue<input_MSG>(ctx);
        auto client = inet.sockets[socketIdx];
        if (client == nullptr) {
            raiseError(ctx);
            return;
        }

        size_t lastWriteSize;

        for (auto it = msg.iterate(); it; ++it) {
            lastWriteSize = client->write((char)*it);
            if (lastWriteSize == 0) {
                raiseError(ctx);
                return;
            }
        }

        client->flush();

        emitValue<output_DONE>(ctx, 1);
        emitValue<output_SOCKU0027>(ctx, socketIdx);
        emitValue<output_INETU0027>(ctx, inet);
    }
}