The driver for the ESP32 WiFi module

Embed: (wiki syntax)

« Back to documentation index

ESP32 Class Reference

ESP32Interface class. More...

#include <ESP32.h>

Public Member Functions

int get_firmware_version (void)
 Check firmware version of ESP8266.
bool set_mode (int mode)
 Sets the Wi-Fi Mode.
bool dhcp (bool enabled, int mode)
 Enable/Disable DHCP.
bool connect (const char *ap, const char *passPhrase)
 Connect ESP32 to AP.
bool disconnect (void)
 Disconnect ESP32 from AP.
const char * getIPAddress (void)
 Get the IP address of ESP32.
const char * getMACAddress (void)
 Get the MAC address of ESP32.
const char * getGateway ()
 Get the local gateway.
const char * getNetmask ()
 Get the local network mask.
bool isConnected (void)
 Check if ESP32 is conenected.
int scan (WiFiAccessPoint *res, unsigned limit)
 Scan for available networks.
bool open (const char *type, int id, const char *addr, int port, int opt=0)
 Open a socketed connection.
bool send (int id, const void *data, uint32_t amount)
 Sends data to an open socket.
int32_t recv (int id, void *data, uint32_t amount, uint32_t timeout=ESP32_RECV_TIMEOUT)
 Receives data from an open socket.
bool close (int id, bool wait_close=false)
 Closes a socket.
void setTimeout (uint32_t timeout_ms=ESP32_MISC_TIMEOUT)
 Allows timeout to be changed between commands.
bool readable ()
 Checks if data is available.
bool writeable ()
 Checks if data can be written.
void attach_wifi_status (mbed::Callback< void(int8_t)> status_cb)
 Attach a function to call whenever network state has changed.
int8_t get_wifi_status () const
 Get the connection status.

Static Public Member Functions

static ESP32getESP32Inst (PinName en, PinName io0, PinName tx, PinName rx, bool debug, PinName rts, PinName cts, int baudrate)
 Static method to create or retrieve the single ESP32 instance.

Detailed Description

ESP32Interface class.

This is an interface to a ESP32 radio.

Definition at line 37 of file ESP32.h.


Member Function Documentation

void attach_wifi_status ( mbed::Callback< void(int8_t)>  status_cb )

Attach a function to call whenever network state has changed.

Parameters:
funcA pointer to a void function, or 0 to set as none

Definition at line 972 of file ESP32.cpp.

bool close ( int  id,
bool  wait_close = false 
)

Closes a socket.

Parameters:
idid of socket to close, valid only 0-4
wait_close
Returns:
true only if socket is closed successfully

Definition at line 789 of file ESP32.cpp.

bool connect ( const char *  ap,
const char *  passPhrase 
)

Connect ESP32 to AP.

Parameters:
apthe name of the AP
passPhrasethe password of AP
Returns:
true only if ESP32 is connected successfully

Definition at line 334 of file ESP32.cpp.

bool dhcp ( bool  enabled,
int  mode 
)

Enable/Disable DHCP.

Parameters:
enabledDHCP enabled when true
modemode of DHCP 0-softAP, 1-station, 2-both
Returns:
true only if ESP32 enables/disables DHCP successfully

Definition at line 318 of file ESP32.cpp.

bool disconnect ( void   )

Disconnect ESP32 from AP.

Returns:
true only if ESP32 is disconnected successfully

Definition at line 376 of file ESP32.cpp.

int get_firmware_version ( void   )

Check firmware version of ESP8266.

Returns:
integer firmware version or -1 if firmware query command gives outdated response

Definition at line 98 of file ESP32.cpp.

int8_t get_wifi_status (  ) const

Get the connection status.

Returns:
The connection status according to ConnectionStatusType

Definition at line 977 of file ESP32.cpp.

ESP32 * getESP32Inst ( PinName  en,
PinName  io0,
PinName  tx,
PinName  rx,
bool  debug,
PinName  rts,
PinName  cts,
int  baudrate 
) [static]

Static method to create or retrieve the single ESP32 instance.

Definition at line 25 of file ESP32.cpp.

const char * getGateway (  )

Get the local gateway.

Returns:
Null-terminated representation of the local gateway or null if no network mask has been recieved

Definition at line 453 of file ESP32.cpp.

const char * getIPAddress ( void   )

Get the IP address of ESP32.

Returns:
null-teriminated IP address or null if no IP address is assigned

Definition at line 387 of file ESP32.cpp.

const char * getMACAddress ( void   )

Get the MAC address of ESP32.

Returns:
null-terminated MAC address or null if no MAC address is assigned

Definition at line 419 of file ESP32.cpp.

const char * getNetmask (  )

Get the local network mask.

Returns:
Null-terminated representation of the local network mask or null if no network mask has been recieved

Definition at line 487 of file ESP32.cpp.

bool isConnected ( void   )

Check if ESP32 is conenected.

Returns:
true only if the chip has an IP address

Definition at line 588 of file ESP32.cpp.

bool open ( const char *  type,
int  id,
const char *  addr,
int  port,
int  opt = 0 
)

Open a socketed connection.

Parameters:
typethe type of socket to open "UDP" or "TCP"
idid to give the new socket, valid 0-4
portport to open connection with
addrthe IP address of the destination
addrthe IP address of the destination
opttype=" UDP" : UDP socket's local port, zero means any type=" TCP" : TCP connection's keep alive time, zero means disabled
Returns:
true only if socket opened successfully

Definition at line 593 of file ESP32.cpp.

bool readable (  )

Checks if data is available.

Definition at line 845 of file ESP32.cpp.

int32_t recv ( int  id,
void *  data,
uint32_t  amount,
uint32_t  timeout = ESP32_RECV_TIMEOUT 
)

Receives data from an open socket.

Parameters:
idid to receive from
dataplaceholder for returned information
amountnumber of bytes to be received
Returns:
the number of bytes received

Definition at line 700 of file ESP32.cpp.

int scan ( WiFiAccessPoint *  res,
unsigned  limit 
)

Scan for available networks.

Parameters:
apPointer to allocated array to store discovered AP
limitSize of allocated res array, or 0 to only count available AP
Returns:
Number of entries in res, or if count was 0 number of available networks, negative on error see nsapi_error

Definition at line 550 of file ESP32.cpp.

bool send ( int  id,
const void *  data,
uint32_t  amount 
)

Sends data to an open socket.

Parameters:
idid of socket to send to
datadata to be sent
amountamount of data to be sent - max 1024
Returns:
true only if data sent successfully

Definition at line 619 of file ESP32.cpp.

bool set_mode ( int  mode )

Sets the Wi-Fi Mode.

Parameters:
modemode of WIFI 1-client, 2-host, 3-both
Returns:
true only if ESP32 was setup correctly

Definition at line 171 of file ESP32.cpp.

void setTimeout ( uint32_t  timeout_ms = ESP32_MISC_TIMEOUT )

Allows timeout to be changed between commands.

Parameters:
timeout_mstimeout of the connection

Definition at line 839 of file ESP32.cpp.

bool writeable (  )

Checks if data can be written.

Definition at line 850 of file ESP32.cpp.