The driver for the ESP32 WiFi module

Embed: (wiki syntax)

« Back to documentation index

ESP32Stack Class Reference

ESP32Stack Class Reference

ESP32Stack class Implementation of the NetworkStack for the ESP32. More...

#include <ESP32Stack.h>

Inherited by ESP32Interface, and ESP32InterfaceAP.

Protected Member Functions

 ESP32Stack (PinName en, PinName io0, PinName tx, PinName rx, bool debug, PinName rts, PinName cts, int baudrate)
 ESP32Stack lifetime.
virtual int socket_open (void **handle, nsapi_protocol_t proto)
 Open a socket.
virtual int socket_close (void *handle)
 Close the socket.
virtual int socket_bind (void *handle, const SocketAddress &address)
 Bind a server socket to a specific port.
virtual int socket_listen (void *handle, int backlog)
 Start listening for incoming connections.
virtual int socket_connect (void *handle, const SocketAddress &address)
 Connects this TCP socket to the server.
virtual int socket_accept (void *handle, void **socket, SocketAddress *address)
 Accept a new connection.
virtual int socket_send (void *handle, const void *data, unsigned size)
 Send data to the remote host.
virtual int socket_recv (void *handle, void *data, unsigned size)
 Receive data from the remote host.
virtual int socket_sendto (void *handle, const SocketAddress &address, const void *data, unsigned size)
 Send a packet to a remote endpoint.
virtual int socket_recvfrom (void *handle, SocketAddress *address, void *buffer, unsigned size)
 Receive a packet from a remote endpoint.
virtual void socket_attach (void *handle, void(*callback)(void *), void *data)
 Register a callback on state change of the socket.
virtual nsapi_error_t setsockopt (nsapi_socket_t handle, int level, int optname, const void *optval, unsigned optlen)
 Set stack-specific socket options The setsockopt allow an application to pass stack-specific hints to the underlying stack.
virtual nsapi_error_t getsockopt (nsapi_socket_t handle, int level, int optname, void *optval, unsigned *optlen)
 Get stack-specific socket options The getstackopt allow an application to retrieve stack-specific hints from the underlying stack.

Detailed Description

ESP32Stack class Implementation of the NetworkStack for the ESP32.

Definition at line 27 of file ESP32Stack.h.


Constructor & Destructor Documentation

ESP32Stack ( PinName  en,
PinName  io0,
PinName  tx,
PinName  rx,
bool  debug,
PinName  rts,
PinName  cts,
int  baudrate 
) [protected]

ESP32Stack lifetime.

Parameters:
enEN pin
io0IO0 pin
txTX pin
rxRX pin
debugEnable debugging
rtsRTS pin
ctsCTS pin
baudrateThe baudrate of the serial port.

Definition at line 22 of file ESP32Stack.cpp.


Member Function Documentation

nsapi_error_t getsockopt ( nsapi_socket_t  handle,
int  level,
int  optname,
void *  optval,
unsigned *  optlen 
) [protected, virtual]

Get stack-specific socket options The getstackopt allow an application to retrieve stack-specific hints from the underlying stack.

For unsupported options, NSAPI_ERROR_UNSUPPORTED is returned and optval is unmodified.

Parameters:
handleSocket handle
levelStack-specific protocol level
optnameStack-specific option identifier
optvalDestination for option value
optlenLength of the option value
Returns:
0 on success, negative error code on failure

Definition at line 302 of file ESP32Stack.cpp.

nsapi_error_t setsockopt ( nsapi_socket_t  handle,
int  level,
int  optname,
const void *  optval,
unsigned  optlen 
) [protected, virtual]

Set stack-specific socket options The setsockopt allow an application to pass stack-specific hints to the underlying stack.

For unsupported options, NSAPI_ERROR_UNSUPPORTED is returned and the socket is unmodified.

Parameters:
handleSocket handle
levelStack-specific protocol level
optnameStack-specific option identifier
optvalOption value
optlenLength of the option value
Returns:
0 on success, negative error code on failure

Definition at line 269 of file ESP32Stack.cpp.

int socket_accept ( void *  handle,
void **  socket,
SocketAddress *  address 
) [protected, virtual]

Accept a new connection.

Parameters:
handleHandle in which to store new socket
serverSocket handle to server to accept from
Returns:
0 on success, negative on failure
Note:
This call is not-blocking, if this call would block, must immediately return NSAPI_ERROR_WOULD_WAIT

Definition at line 157 of file ESP32Stack.cpp.

void socket_attach ( void *  handle,
void(*)(void *)  callback,
void *  data 
) [protected, virtual]

Register a callback on state change of the socket.

Parameters:
handleSocket handle
callbackFunction to call on state change
dataArgument to pass to callback
Note:
Callback may be called in an interrupt context.

Definition at line 258 of file ESP32Stack.cpp.

int socket_bind ( void *  handle,
const SocketAddress &  address 
) [protected, virtual]

Bind a server socket to a specific port.

Parameters:
handleSocket handle
addressLocal address to listen for incoming connections on
Returns:
0 on success, negative on failure.

Definition at line 85 of file ESP32Stack.cpp.

int socket_close ( void *  handle ) [protected, virtual]

Close the socket.

Parameters:
handleSocket handle
Returns:
0 on success, negative on failure
Note:
On failure, any memory associated with the socket must still be cleaned up

Definition at line 63 of file ESP32Stack.cpp.

int socket_connect ( void *  handle,
const SocketAddress &  address 
) [protected, virtual]

Connects this TCP socket to the server.

Parameters:
handleSocket handle
addressSocketAddress to connect to
Returns:
0 on success, negative on failure

Definition at line 135 of file ESP32Stack.cpp.

int socket_listen ( void *  handle,
int  backlog 
) [protected, virtual]

Start listening for incoming connections.

Parameters:
handleSocket handle
backlogNumber of pending connections that can be queued up at any one time [Default: 1]
Returns:
0 on success, negative on failure

Definition at line 113 of file ESP32Stack.cpp.

int socket_open ( void **  handle,
nsapi_protocol_t  proto 
) [protected, virtual]

Open a socket.

Parameters:
handleHandle in which to store new socket
protoType of socket to open, NSAPI_TCP or NSAPI_UDP
Returns:
0 on success, negative on failure

Definition at line 39 of file ESP32Stack.cpp.

int socket_recv ( void *  handle,
void *  data,
unsigned  size 
) [protected, virtual]

Receive data from the remote host.

Parameters:
handleSocket handle
dataThe buffer in which to store the data received from the host
sizeThe maximum length of the buffer
Returns:
Number of received bytes on success, negative on failure
Note:
This call is not-blocking, if this call would block, must immediately return NSAPI_ERROR_WOULD_WAIT

Definition at line 196 of file ESP32Stack.cpp.

int socket_recvfrom ( void *  handle,
SocketAddress *  address,
void *  buffer,
unsigned  size 
) [protected, virtual]

Receive a packet from a remote endpoint.

Parameters:
handleSocket handle
addressDestination for the remote SocketAddress or null
bufferThe buffer for storing the incoming packet data If a packet is too long to fit in the supplied buffer, excess bytes are discarded
sizeThe length of the buffer
Returns:
The number of received bytes on success, negative on failure
Note:
This call is not-blocking, if this call would block, must immediately return NSAPI_ERROR_WOULD_WAIT

Definition at line 242 of file ESP32Stack.cpp.

int socket_send ( void *  handle,
const void *  data,
unsigned  size 
) [protected, virtual]

Send data to the remote host.

Parameters:
handleSocket handle
dataThe buffer to send to the host
sizeThe length of the buffer to send
Returns:
Number of written bytes on success, negative on failure
Note:
This call is not-blocking, if this call would block, must immediately return NSAPI_ERROR_WOULD_WAIT

Definition at line 181 of file ESP32Stack.cpp.

int socket_sendto ( void *  handle,
const SocketAddress &  address,
const void *  data,
unsigned  size 
) [protected, virtual]

Send a packet to a remote endpoint.

Parameters:
handleSocket handle
addressThe remote SocketAddress
dataThe packet to be sent
sizeThe length of the packet to be sent
Returns:
The number of written bytes on success, negative on failure
Note:
This call is not-blocking, if this call would block, must immediately return NSAPI_ERROR_WOULD_WAIT

Definition at line 216 of file ESP32Stack.cpp.