Skip to content
Warren Gay edited this page Nov 20, 2015 · 4 revisions

write_func_t

typedef void (*write_func_t)(char b);

This callback is invoked to write one byte to the UART connected to the ESP device.

read_func_t

typedef char (*read_func_t)();

This callback is used to read one byte from the UART connected to the ESP device.

poll_func_t

typedef bool (*poll_func_t)();

This callback is used to determine if there is data to be read from the UART, which is connected to the ESP device. The callback should return true if there is data to be read and otherwise false.

idle_func_t

typedef void (*idle_func_t)();

This function is called when the receiving method(s) no longer have data to be read from the UART, but are still waiting for a data event.

If you are running an RTOS and need some voluntary thread changes, you could perform a yeild() call within the idle callback.

recv_func_t

typedef void (*recv_func_t)(int sock,int ch);

This callback is invoked by the ESP8266 class when there is socket data to be read. The socket is provided in the call along with the data byte ch.

TCP

The value of ch will be int(-1) when the remote end of a TCP socket has closed the connection. The socket remains logically open by the ESP8266 class, and must be closed to release the socket resource.

UDP

The value of ch will be int(-1) for a UDP socket when the last byte has been read from the UDP datagram. The socket remains open for further I/O.

accept_t

typedef void (*accept_t)(int sock);

This accept callback signals the fact that there has been an accept request made to the ESP server. Within this callback, the code should then invoke the method ESP8266::accept(socket,recv_cb) to link this new socket to the data receiving callback (recv_cb). An example accept callback is shown below (esp is an instance of the ESP8266 class):

// This is the data receiver callback:
void
server_recv(int sock,int byte) {
    
    if ( byte == -1 ) {
        close(sock);
    } else  {
        // Do something with data byte
    }
}

// The accept callback:
void
accept_cb(int sock) {

    if ( sock >= 0 ) {
        // Accept connect and associate data receiver
        // callback with the new socket "sock"
        esp.accept(sock,server_recv);
    } else  {    
        // The server has closed this socket
    }
}

The purpose of the esp.accept() call (not the callback), is to associate the accepted socket "sock" with the data receiving callback (named "server_recv" in the example).

Clone this wiki locally