Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

ESP8266 Class Reference

ESP8266Interface class. More...

#include <ESP8266.h>

Data Structures

struct  fw_at_version
 ESP8266 firmware AT version. More...
struct  fw_sdk_version
 ESP8266 firmware SDK version. More...

Public Types

enum  scan_mode { SCANMODE_ACTIVE = 0, SCANMODE_PASSIVE = 1 }
 

Scan mode.

More...

Public Member Functions

bool at_available (void)
 Check AT command interface of ESP8266.
bool echo_off (void)
 Disable echo - required for OOB processing to work.
struct fw_sdk_version sdk_version (void)
 Check sdk version from which firmware is created.
struct fw_at_version at_version (void)
 Check AT instruction set version from which firmware is created.
bool startup (int mode)
 Startup the ESP8266.
bool reset (void)
 Reset ESP8266.
bool dhcp (bool enabled, int mode)
 Enable/Disable DHCP.
nsapi_error_t connect (const char *ap, const char *passPhrase)
 Connect ESP8266 to AP.
bool disconnect (void)
 Disconnect ESP8266 from AP.
const char * ip_addr (void)
 Get the IP address of ESP8266.
const char * mac_addr (void)
 Get the MAC address of ESP8266.
const char * gateway ()
 Get the local gateway.
const char * netmask ()
 Get the local network mask.
int scan (WiFiAccessPoint *res, unsigned limit, scan_mode mode, unsigned t_max, unsigned t_min)
 Scan for available networks.
bool dns_lookup (const char *name, char *ip)
 Perform a dns query.
nsapi_error_t open_udp (int id, const char *addr, int port, int local_port=0)
 Open a socketed connection.
nsapi_error_t open_tcp (int id, const char *addr, int port, int keepalive=0)
 Open a socketed connection.
nsapi_error_t send (int id, const void *data, uint32_t amount)
 Sends data to an open socket.
int32_t recv_udp (int id, void *data, uint32_t amount, uint32_t timeout=ESP8266_RECV_TIMEOUT)
 Receives datagram from an open UDP socket.
int32_t recv_tcp (int id, void *data, uint32_t amount, uint32_t timeout=ESP8266_RECV_TIMEOUT)
 Receives stream data from an open TCP socket.
bool close (int id)
 Closes a socket.
void set_timeout (uint32_t timeout_ms=ESP8266_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 sigio (mbed::Callback< void()> func)
 Attach a function to call whenever sigio happens in the serial.
template<typename T , typename M >
void sigio (T *obj, M method)
 Attach a function to call whenever sigio happens in the serial.
void attach (mbed::Callback< void()> status_cb)
 Attach a function to call whenever network state has changed.
int8_t default_wifi_mode ()
 Read default Wifi mode from flash.
bool set_default_wifi_mode (const int8_t mode)
 Default Wifi mode written to flash only if changes.
bool set_country_code_policy (bool track_ap, const char *country_code, int channel_start, int channels)
nsapi_connection_status_t connection_status () const
 Get the connection status.
bool start_uart_hw_flow_ctrl ()
 Start board's and ESP8266's UART flow control.
bool stop_uart_hw_flow_ctrl ()
 Stop board's and ESP8266's UART flow control.
void bg_process_oob (uint32_t timeout, bool all)
 For executing OOB processing on background.
void flush ()
 Flush the serial port input buffers.
int uart_enable_input (bool lock)
 Enables or disables uart input and deep sleep.

Detailed Description

ESP8266Interface class.

This is an interface to a ESP8266 radio.

Definition at line 67 of file ESP8266.h.


Member Enumeration Documentation

enum scan_mode

Scan mode.

Enumerator:
SCANMODE_ACTIVE 

active mode

SCANMODE_PASSIVE 

passive mode

Definition at line 203 of file ESP8266.h.


Member Function Documentation

bool at_available ( void   )

Check AT command interface of ESP8266.

Returns:
true if ready to respond on AT commands

Definition at line 106 of file ESP8266.cpp.

struct ESP8266::fw_at_version at_version ( void   ) [read]

Check AT instruction set version from which firmware is created.

Returns:
fw_at_version which tells major, minor and patch version

Definition at line 155 of file ESP8266.cpp.

void attach ( mbed::Callback< void()>  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
void bg_process_oob ( uint32_t  timeout,
bool  all 
)

For executing OOB processing on background.

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

Definition at line 756 of file ESP8266.cpp.

bool close ( int  id )

Closes a socket.

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

Definition at line 956 of file ESP8266.cpp.

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

Connect ESP8266 to AP.

Parameters:
apthe name of the AP
passPhrasethe password of AP
Returns:
NSAPI_ERROR_OK in success, negative error code in failure

Definition at line 329 of file ESP8266.cpp.

nsapi_connection_status_t connection_status (  ) const

Get the connection status.

Returns:
The connection status according to ConnectionStatusType

Definition at line 1261 of file ESP8266.cpp.

int8_t default_wifi_mode (  )

Read default Wifi mode from flash.

return Station, SoftAP or SoftAP+Station - 0 on failure

Definition at line 1228 of file ESP8266.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 ESP8266 enables/disables DHCP successfully

Definition at line 297 of file ESP8266.cpp.

bool disconnect ( void   )

Disconnect ESP8266 from AP.

Returns:
true only if ESP8266 is disconnected successfully

Definition at line 359 of file ESP8266.cpp.

bool dns_lookup ( const char *  name,
char *  ip 
)

Perform a dns query.

Parameters:
nameHostname to resolve
ipBuffer to store IP address
Returns:
0 true on success, false on failure

Definition at line 606 of file ESP8266.cpp.

bool echo_off ( void   )

Disable echo - required for OOB processing to work.

Returns:
true if echo was successfully disabled

Definition at line 125 of file ESP8266.cpp.

void flush (  )

Flush the serial port input buffers.

If you do HW reset for ESP module, you should flush the input buffers from existing responses from the device.

Definition at line 1244 of file ESP8266.cpp.

const char * gateway (  )

Get the local gateway.

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

Definition at line 399 of file ESP8266.cpp.

const char * ip_addr ( void   )

Get the IP address of ESP8266.

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

Definition at line 369 of file ESP8266.cpp.

const char * mac_addr ( void   )

Get the MAC address of ESP8266.

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

Definition at line 385 of file ESP8266.cpp.

const char * netmask (  )

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 413 of file ESP8266.cpp.

nsapi_error_t open_tcp ( int  id,
const char *  addr,
int  port,
int  keepalive = 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
portthe port on the destination
tcp_keepaliveTCP connection's keep alive time, zero means disabled
Returns:
NSAPI_ERROR_OK in success, negative error code in failure

Definition at line 555 of file ESP8266.cpp.

nsapi_error_t open_udp ( int  id,
const char *  addr,
int  port,
int  local_port = 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
portthe port on the destination
local_portUDP socket's local port, zero means any
Returns:
NSAPI_ERROR_OK in success, negative error code in failure

Definition at line 504 of file ESP8266.cpp.

bool readable (  )

Checks if data is available.

Definition at line 989 of file ESP8266.cpp.

int32_t recv_tcp ( int  id,
void *  data,
uint32_t  amount,
uint32_t  timeout = ESP8266_RECV_TIMEOUT 
)

Receives stream data from an open TCP 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 826 of file ESP8266.cpp.

int32_t recv_udp ( int  id,
void *  data,
uint32_t  amount,
uint32_t  timeout = ESP8266_RECV_TIMEOUT 
)

Receives datagram from an open UDP 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 884 of file ESP8266.cpp.

bool reset ( void   )

Reset ESP8266.

Returns:
true only if ESP8266 resets successfully

Definition at line 258 of file ESP8266.cpp.

int scan ( WiFiAccessPoint res,
unsigned  limit,
scan_mode  mode,
unsigned  t_max,
unsigned  t_min 
)

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
t_maxMaximum scan time per channel
t_minMinimum scan time per channel in active mode, can be omitted in passive mode
Returns:
Number of entries in res, or if count was 0 number of available networks, negative on error see nsapi_error

Definition at line 467 of file ESP8266.cpp.

struct ESP8266::fw_sdk_version sdk_version ( void   ) [read]

Check sdk version from which firmware is created.

Returns:
fw_sdk_version which tells major, minor and patch version

Definition at line 135 of file ESP8266.cpp.

nsapi_error_t 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:
NSAPI_ERROR_OK in success, negative error code in failure

Definition at line 615 of file ESP8266.cpp.

bool set_country_code_policy ( bool  track_ap,
const char *  country_code,
int  channel_start,
int  channels 
)
Parameters:
track_apif TRUE, sets the county code to be the same as the AP's that ESP is connected to, if FALSE the code will not change
country_codeISO 3166-1 Alpha-2 coded country code
channel_startthe channel number to start at
channelsnumber of channels

Definition at line 1266 of file ESP8266.cpp.

bool set_default_wifi_mode ( const int8_t  mode )

Default Wifi mode written to flash only if changes.

Definition at line 1251 of file ESP8266.cpp.

void set_timeout ( uint32_t  timeout_ms = ESP8266_MISC_TIMEOUT )

Allows timeout to be changed between commands.

Parameters:
timeout_mstimeout of the connection

Definition at line 984 of file ESP8266.cpp.

void sigio ( T *  obj,
method 
)

Attach a function to call whenever sigio happens in the serial.

Parameters:
objpointer to the object to call the member function on
methodpointer to the member function to call

Definition at line 322 of file ESP8266.h.

void sigio ( mbed::Callback< void()>  func )

Attach a function to call whenever sigio happens in the serial.

Parameters:
funcA pointer to a void function, or 0 to set as none
bool start_uart_hw_flow_ctrl ( void   )

Start board's and ESP8266's UART flow control.

Returns:
true if started

Definition at line 194 of file ESP8266.cpp.

bool startup ( int  mode )

Startup the ESP8266.

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

Definition at line 239 of file ESP8266.cpp.

bool stop_uart_hw_flow_ctrl ( void   )

Stop board's and ESP8266's UART flow control.

Returns:
true if started

Definition at line 176 of file ESP8266.cpp.

int uart_enable_input ( bool  lock )

Enables or disables uart input and deep sleep.

Parameters:
lockif TRUE, uart input is enabled and deep sleep is locked if FALSE, uart input is disabled and deep sleep is unlocked

Definition at line 1294 of file ESP8266.cpp.

bool writeable (  )

Checks if data can be written.

Definition at line 994 of file ESP8266.cpp.