takashi kadono / Mbed OS Nucleo_446

Dependencies:   ssd1331

Embed: (wiki syntax)

« Back to documentation index

ESP8266 Class Reference

ESP8266 Class Reference

ESP8266Interface class. More...

#include <ESP8266.h>

Public Member Functions

int get_firmware_version (void)
 Check firmware version of ESP8266.
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 * getIPAddress (void)
 Get the IP address of ESP8266.
const char * getMACAddress (void)
 Get the MAC address of ESP8266.
const char * getGateway ()
 Get the local gateway.
const char * getNetmask ()
 Get the local network mask.
int scan (WiFiAccessPoint *res, unsigned limit)
 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.
bool 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 setTimeout (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 (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(nsapi_event_t, intptr_t)> status_cb)
 Attach a function to call whenever network state has changed.
int8_t get_default_wifi_mode ()
 Read default Wifi mode from flash.
bool set_default_wifi_mode (const int8_t mode)
 Write default Wifi mode to flash.
nsapi_connection_status_t get_connection_status () const
 Get the connection status.

Detailed Description

ESP8266Interface class.

This is an interface to a ESP8266 radio.

Definition at line 41 of file ESP8266.h.


Member Function Documentation

void attach ( mbed::Callback< void(nsapi_event_t, intptr_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 558 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 510 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 only if ESP8266 is connected successfully

Definition at line 127 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 112 of file ESP8266.cpp.

bool disconnect ( void   )

Disconnect ESP8266 from AP.

Returns:
true only if ESP8266 is disconnected successfully

Definition at line 160 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 346 of file ESP8266.cpp.

nsapi_connection_status_t get_connection_status (  ) const

Get the connection status.

Returns:
The connection status according to ConnectionStatusType

Definition at line 667 of file ESP8266.cpp.

int8_t get_default_wifi_mode (  )

Read default Wifi mode from flash.

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

Definition at line 641 of file ESP8266.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 55 of file ESP8266.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 199 of file ESP8266.cpp.

const char * getIPAddress ( void   )

Get the IP address of ESP8266.

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

Definition at line 169 of file ESP8266.cpp.

const char * getMACAddress ( void   )

Get the MAC address of ESP8266.

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

Definition at line 185 of file ESP8266.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 213 of file ESP8266.cpp.

bool 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:
true only if socket opened successfully

Definition at line 317 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:
true only if socket opened successfully

Definition at line 286 of file ESP8266.cpp.

bool readable (  )

Checks if data is available.

Definition at line 543 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 406 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 454 of file ESP8266.cpp.

bool reset ( void   )

Reset ESP8266.

Returns:
true only if ESP8266 resets successfully

Definition at line 92 of file ESP8266.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 257 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 355 of file ESP8266.cpp.

bool set_default_wifi_mode ( const int8_t  mode )

Write default Wifi mode to flash.

Definition at line 657 of file ESP8266.cpp.

void setTimeout ( uint32_t  timeout_ms = ESP8266_MISC_TIMEOUT )

Allows timeout to be changed between commands.

Parameters:
timeout_mstimeout of the connection

Definition at line 538 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 239 of file ESP8266.h.

void sigio ( 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

Definition at line 553 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 73 of file ESP8266.cpp.

bool writeable (  )

Checks if data can be written.

Definition at line 548 of file ESP8266.cpp.