test public

Dependencies:   HttpServer_snapshot_mbed-os

Embed: (wiki syntax)

« Back to documentation index

ESP32 Class Reference

ESP32Interface class. More...

#include <ESP32.h>

Public Member Functions

bool get_version_info (char *ver_info, int buf_size)
 Checks Version Information.
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.
bool ble_set_role (int role)
 Sets BLE Role.
bool ble_get_role (int *role)
 Gets BLE Role.
bool ble_set_device_name (const char *name)
 Sets BLE Device's Name.
bool ble_get_device_name (char *name)
 Gets BLE Device's Name.
bool ble_start_services ()
 GATTS Creates and Starts Services.
bool ble_set_scan_response (const uint8_t *data, int len)
 Sets BLE Scan Response.
bool ble_start_advertising ()
 Starts Advertising.
bool ble_stop_advertising ()
 Stops Advertising.
bool ble_set_addr (int addr_type, const uint8_t *random_addr=NULL)
 Sets BLE Device's Address.
bool ble_get_addr (uint8_t *public_addr)
 Gets BLE Device's Address.
bool ble_set_advertising_param (const advertising_param_t *param)
 Sets Parameters of Advertising.
bool ble_set_advertising_data (const uint8_t *data, int len)
 Sets Advertising Data.
bool ble_set_service (const gatt_service_t *service_list, int num)
 GATT Sets Service.
bool ble_set_characteristic (int srv_index, int char_index, const uint8_t *data, int len)
 GATTS Sets Characteristic.
bool ble_notifies_characteristic (int srv_index, int char_index, const uint8_t *data, int len)
 GATTS Notifies of Characteristics.
bool ble_set_scan_param (int scan_type, int own_addr_type, int filter_policy, int scan_interval, int scan_window)
 Sets Parameters of BLE Scanning.
bool ble_start_scan (int interval=0)
 Enables BLE Scanning.
bool ble_stop_scan ()
 Disables BLE scan.
bool ble_connect (int conn_index, const uint8_t *remote_addr)
 Establishes BLE connection.
bool ble_disconnect (int conn_index)
 Ends BLE connection.
bool ble_discovery_service (int conn_index, ble_primary_service_t *service, int *num)
 GATTC Discovers Primary Services.
bool ble_discovery_characteristics (int conn_index, int srv_index, ble_discovers_char_t *discovers_char, int *char_num, ble_discovers_desc_t *discovers_desc, int *desc_num)
 GATTC Discovers Characteristics.
int32_t ble_read_characteristic (int conn_index, int srv_index, int char_index, uint8_t *data, int amount)
 GATTC Reads a Characteristic.
int32_t ble_read_descriptor (int conn_index, int srv_index, int char_index, int desc_index, uint8_t *data, int amount)
 GATTC Reads a Descriptor.
bool ble_write_characteristic (int conn_index, int srv_index, int char_index, const uint8_t *data, int amount)
 GATTC Writes Characteristic.
bool ble_write_descriptor (int conn_index, int srv_index, int char_index, int desc_index, const uint8_t *data, int amount)
 GATTC Writes Descriptor.
void ble_process_oob (uint32_t timeout, bool all)
 For executing OOB processing on background.
void ble_attach_sigio (mbed::Callback< void()> cb_func)
 Register a callback on state change.
void ble_attach_conn (mbed::Callback< void(int, uint8_t *)> cb_func)
 Attach a function to call whenever the BLE connection establishes.
void ble_attach_disconn (mbed::Callback< void(int)> cb_func)
 Attach a function to call whenever the BLE connection ends.
void ble_attach_write (mbed::Callback< void(ble_packet_t *)> cb_func)
 Attach a function to call whenever characteristic data is written.
void ble_attach_scan (mbed::Callback< void(ble_scan_t *)> cb_func)
 Attach a function to call whenever scan data is received.

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 53 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 1102 of file ESP32.cpp.

void ble_attach_conn ( mbed::Callback< void(int, uint8_t *)>  cb_func )

Attach a function to call whenever the BLE connection establishes.

Parameters:
cb_funcPointer to the function to be calledt cb_func argument 0: disconnect, 1: connect

Definition at line 1787 of file ESP32.cpp.

void ble_attach_disconn ( mbed::Callback< void(int)>  cb_func )

Attach a function to call whenever the BLE connection ends.

Parameters:
cb_funcPointer to the function to be calledt cb_func argument 0: disconnect, 1: connect

Definition at line 1794 of file ESP32.cpp.

void ble_attach_scan ( mbed::Callback< void(ble_scan_t *)>  cb_func )

Attach a function to call whenever scan data is received.

Parameters:
cb_funcPointer to the function to be called

Definition at line 1808 of file ESP32.cpp.

void ble_attach_sigio ( mbed::Callback< void()>  cb_func )

Register a callback on state change.

The specified callback will be called on state changes.

The callback may be called in an interrupt context and should not perform expensive operations.

Note! This is not intended as an attach-like asynchronous api, but rather as a building block for constructing such functionality.

The exact timing of when the registered function is called is not guaranteed and susceptible to change. It should be used as a cue to make ble_process_oobl calls to find the current state.

Parameters:
cb_funcfunction to call on state change

Definition at line 1779 of file ESP32.cpp.

void ble_attach_write ( mbed::Callback< void(ble_packet_t *)>  cb_func )

Attach a function to call whenever characteristic data is written.

Parameters:
cb_funcPointer to the function to be called

Definition at line 1801 of file ESP32.cpp.

bool ble_connect ( int  conn_index,
const uint8_t *  remote_addr 
)

Establishes BLE connection.

Parameters:
conn_indexIndex of BLE connection; only 0 is supported for the single connection right now, but multiple BLE connections will be supported in the future.
remote_addrRemote BLE address
Returns:
true: success, false: failure

Definition at line 1534 of file ESP32.cpp.

bool ble_disconnect ( int  conn_index )

Ends BLE connection.

Parameters:
conn_indexIndex of BLE connection; only 0 is supported for the single connection right now, but multiple BLE connections will be supported in the future.
Returns:
true: success, false: failure

Definition at line 1554 of file ESP32.cpp.

bool ble_discovery_characteristics ( int  conn_index,
int  srv_index,
ble_discovers_char_t *  discovers_char,
int *  char_num,
ble_discovers_desc_t *  discovers_desc,
int *  desc_num 
)

GATTC Discovers Characteristics.

Parameters:
conn_indexIndex of BLE connection; only 0 is supported for the single connection right now, but multiple BLE connections will be supported in the future.
srv_indexService's index. It can be fetched with "ble_discovery_service()"
discovers_charCharacteristic info
char_numNumber of characteristic info
discovers_descDescriptor info
desc_numNumber of descriptor info
Returns:
true: success, false: failure

Definition at line 1607 of file ESP32.cpp.

bool ble_discovery_service ( int  conn_index,
ble_primary_service_t *  service,
int *  num 
)

GATTC Discovers Primary Services.

Parameters:
conn_indexIndex of BLE connection; only 0 is supported for the single connection right now, but multiple BLE connections will be supported in the future.
serviceService info
numNumber of service info
Returns:
true: success, false: failure

Definition at line 1572 of file ESP32.cpp.

bool ble_get_addr ( uint8_t *  public_addr )

Gets BLE Device's Address.

Parameters:
public_addrBLE public address
Returns:
true: success, false: failure

Definition at line 1279 of file ESP32.cpp.

bool ble_get_device_name ( char *  name )

Gets BLE Device's Name.

Parameters:
nameThe BLE device name
Returns:
true: success, false: failure

Definition at line 1150 of file ESP32.cpp.

bool ble_get_role ( int *  role )

Gets BLE Role.

Parameters:
roleINIT_CLIENT_ROLE: client role, INIT_SERVER_ROLE: server role
Returns:
true: success, false: failure

Definition at line 1127 of file ESP32.cpp.

bool ble_notifies_characteristic ( int  srv_index,
int  char_index,
const uint8_t *  data,
int  len 
)

GATTS Notifies of Characteristics.

Parameters:
srv_indexService's index starting from 1
char_indexCharacteristic's index starting from 1
dataData buffer address
lenData len
Returns:
true: success, false: failure

Definition at line 1464 of file ESP32.cpp.

void ble_process_oob ( uint32_t  timeout,
bool  all 
)

For executing OOB processing on background.

Parameters:
timeoutAT parser receive timeout
allif TRUE, process all OOBs instead of only one

Definition at line 1767 of file ESP32.cpp.

int32_t ble_read_characteristic ( int  conn_index,
int  srv_index,
int  char_index,
uint8_t *  data,
int  amount 
)

GATTC Reads a Characteristic.

Parameters:
conn_indexIndex of BLE connection; only 0 is supported for the single connection right now, but multiple BLE connections will be supported in the future.
srv_indexService's index. It can be fetched with "ble_discovery_service()"
char_indexCharacteristic's index. It can be fetched with "ble_discovery_characteristics()"
dataRead data buffer
amountAmount of bytes to be received
Returns:
Data size of received

Definition at line 1661 of file ESP32.cpp.

int32_t ble_read_descriptor ( int  conn_index,
int  srv_index,
int  char_index,
int  desc_index,
uint8_t *  data,
int  amount 
)

GATTC Reads a Descriptor.

Parameters:
conn_indexIndex of BLE connection; only 0 is supported for the single connection right now, but multiple BLE connections will be supported in the future.
srv_indexService's index. It can be fetched with "ble_discovery_service()"
char_indexCharacteristic's index. It can be fetched with "ble_discovery_characteristics()"
desc_indexDescriptor's index. It can be fetched with "ble_discovery_characteristics()"
dataRead data buffer
amountAmount of bytes to be received
Returns:
true: success, false: failure

Definition at line 1694 of file ESP32.cpp.

bool ble_set_addr ( int  addr_type,
const uint8_t *  random_addr = NULL 
)

Sets BLE Device's Address.

Parameters:
addr_type0: public address, 1: random address
addrRandom address data. Valid only when addr_type is 1.
Returns:
true: success, false: failure

Definition at line 1256 of file ESP32.cpp.

bool ble_set_advertising_data ( const uint8_t *  data,
int  len 
)

Sets Advertising Data.

Parameters:
dataAdvertising data
lenData len
Returns:
true: success, false: failure

Definition at line 1323 of file ESP32.cpp.

bool ble_set_advertising_param ( const advertising_param_t *  param )

Sets Parameters of Advertising.

Parameters:
paramParameters. See advertising_param_t.
Returns:
true: success, false: failure

Definition at line 1301 of file ESP32.cpp.

bool ble_set_characteristic ( int  srv_index,
int  char_index,
const uint8_t *  data,
int  len 
)

GATTS Sets Characteristic.

Parameters:
srv_indexService's index starting from 1
char_indexCharacteristic's index starting from 1
dataData buffer address
lenData len
Returns:
true: success, false: failure

Definition at line 1444 of file ESP32.cpp.

bool ble_set_device_name ( const char *  name )

Sets BLE Device's Name.

Parameters:
nameThe BLE device name
Returns:
true: success, false: failure

Definition at line 1133 of file ESP32.cpp.

bool ble_set_role ( int  role )

Sets BLE Role.

Parameters:
roleINIT_CLIENT_ROLE: client role, INIT_SERVER_ROLE: server role
Returns:
true: success, false: failure

Definition at line 1113 of file ESP32.cpp.

bool ble_set_scan_param ( int  scan_type,
int  own_addr_type,
int  filter_policy,
int  scan_interval,
int  scan_window 
)

Sets Parameters of BLE Scanning.

Parameters:
scan_type0: passive scan 1: active scan
own_addr_type0: public address 1: random address 2: RPA public address 3: RPA random address
filter_policy0: BLE_SCAN_FILTER_ALLOW_ALL 1: BLE_SCAN_FILTER_ALLOW_ONLY_WLST 2: BLE_SCAN_FILTER_ALLOW_UND_RPA_DIR 3: BLE_SCAN_FILTER_ALLOW_WLIST_PRA_DIR
scan_intervalscan interval
scan_windowscan window
Returns:
rue: success, false: failure

Definition at line 1484 of file ESP32.cpp.

bool ble_set_scan_response ( const uint8_t *  data,
int  len 
)

Sets BLE Scan Response.

Parameters:
dataScan response data
lenData len
Returns:
true: success, false: failure

Definition at line 1188 of file ESP32.cpp.

bool ble_set_service ( const gatt_service_t *  service_list,
int  num 
)

GATT Sets Service.

Parameters:
service_listGATT service list. see gatt_service_t.
numNumber of GATT service list
Returns:
true: success, false: failure

Definition at line 1355 of file ESP32.cpp.

bool ble_start_advertising (  )

Starts Advertising.

Returns:
true: success, false: failure

Definition at line 1220 of file ESP32.cpp.

bool ble_start_scan ( int  interval = 0 )

Enables BLE Scanning.

Parameters:
interval0: scanning is continuous !0: scanning should last for <interval> seconds and then stop automatically
Returns:
true: success, false: failure

Definition at line 1501 of file ESP32.cpp.

bool ble_start_services (  )

GATTS Creates and Starts Services.

Returns:
true: success, false: failure

Definition at line 1168 of file ESP32.cpp.

bool ble_stop_advertising (  )

Stops Advertising.

Returns:
true: success, false: failure

Definition at line 1238 of file ESP32.cpp.

bool ble_stop_scan (  )

Disables BLE scan.

Returns:
true: success, false: failure

Definition at line 1516 of file ESP32.cpp.

bool ble_write_characteristic ( int  conn_index,
int  srv_index,
int  char_index,
const uint8_t *  data,
int  amount 
)

GATTC Writes Characteristic.

Parameters:
conn_indexIndex of BLE connection; only 0 is supported for the single connection right now, but multiple BLE connections will be supported in the future.
srv_indexService's index. It can be fetched with "ble_discovery_service()"
char_indexCharacteristic's index. It can be fetched with "ble_discovery_characteristics()"
dataWrite data buffer
amountAmount of data to be written
Returns:
true: success, false: failure

Definition at line 1727 of file ESP32.cpp.

bool ble_write_descriptor ( int  conn_index,
int  srv_index,
int  char_index,
int  desc_index,
const uint8_t *  data,
int  amount 
)

GATTC Writes Descriptor.

Parameters:
conn_indexIndex of BLE connection; only 0 is supported for the single connection right now, but multiple BLE connections will be supported in the future.
srv_indexService's index. It can be fetched with "ble_discovery_service()"
char_indexCharacteristic's index. It can be fetched with "ble_discovery_characteristics()"
desc_indexDescriptor's index. It can be fetched with "ble_discovery_characteristics()"
dataWrite data buffer
amountAmount of data to be written
Returns:
true: success, false: failure

Definition at line 1747 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 878 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 432 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 416 of file ESP32.cpp.

bool disconnect ( void   )

Disconnect ESP32 from AP.

Returns:
true only if ESP32 is disconnected successfully

Definition at line 474 of file ESP32.cpp.

bool get_version_info ( char *  ver_info,
int  buf_size 
)

Checks Version Information.

Parameters:
ver_infobuffer address for storing version information
buf_sizebuffer size
Returns:
String of Version Information

Definition at line 127 of file ESP32.cpp.

int8_t get_wifi_status (  ) const

Get the connection status.

Returns:
The connection status according to ConnectionStatusType

Definition at line 1107 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 30 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 551 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 485 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 517 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 585 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 686 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 691 of file ESP32.cpp.

bool readable (  )

Checks if data is available.

Definition at line 930 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 803 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 648 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 717 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 263 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 924 of file ESP32.cpp.

bool writeable (  )

Checks if data can be written.

Definition at line 935 of file ESP32.cpp.