Firmware SDK
twr_esp8266

Driver for ESP8266 WiFi module. More...

Data Structures

struct  twr_esp8266_config
 
struct  twr_esp8266_t
 

Typedefs

typedef struct twr_esp8266_t twr_esp8266_t
 ESP8266 instance.
 

Enumerations

enum  twr_esp8266_event_t {
  TWR_ESP8266_EVENT_READY = 0 ,
  TWR_ESP8266_EVENT_ERROR = 1 ,
  TWR_ESP8266_EVENT_WIFI_CONNECT_SUCCESS = 2 ,
  TWR_ESP8266_EVENT_WIFI_CONNECT_ERROR = 3 ,
  TWR_ESP8266_EVENT_SOCKET_CONNECT_SUCCESS = 4 ,
  TWR_ESP8266_EVENT_SOCKET_CONNECT_ERROR = 5 ,
  TWR_ESP8266_EVENT_SOCKET_SEND_SUCCESS = 6 ,
  TWR_ESP8266_EVENT_SOCKET_SEND_ERROR = 7 ,
  TWR_ESP8266_EVENT_DATA_RECEIVED = 8 ,
  TWR_ESP8266_EVENT_AP_AVAILABILITY_RESULT = 9 ,
  TWR_ESP8266_EVENT_DISCONNECTED = 10
}
 Callback events. More...
 
enum  twr_esp8266_state_t {
  TWR_ESP8266_STATE_READY = 0 ,
  TWR_ESP8266_STATE_ERROR = 1 ,
  TWR_ESP8266_STATE_INITIALIZE = 2 ,
  TWR_ESP8266_STATE_IDLE = 3 ,
  TWR_ESP8266_STATE_RECEIVE = 4 ,
  TWR_ESP8266_STATE_INITIALIZE_COMMAND_SEND = 5 ,
  TWR_ESP8266_STATE_INITIALIZE_COMMAND_RESPONSE = 6 ,
  TWR_ESP8266_STATE_WIFI_CONNECT_COMMAND = 7 ,
  TWR_ESP8266_STATE_SOCKET_CONNECT_COMMAND = 8 ,
  TWR_ESP8266_STATE_SOCKET_SEND_COMMAND = 9 ,
  TWR_ESP8266_STATE_SOCKET_SEND_DATA = 10 ,
  TWR_ESP8266_STATE_WIFI_CONNECT_RESPONSE = 11 ,
  TWR_ESP8266_STATE_SOCKET_CONNECT_RESPONSE = 12 ,
  TWR_ESP8266_STATE_SOCKET_SEND_RESPONSE = 13 ,
  TWR_ESP8266_STATE_WIFI_CONNECT_ERROR = 14 ,
  TWR_ESP8266_STATE_SOCKET_CONNECT_ERROR = 15 ,
  TWR_ESP8266_STATE_SOCKET_SEND_ERROR = 16 ,
  TWR_ESP8266_STATE_SOCKET_RECEIVE = 17 ,
  TWR_ESP8266_STATE_DISCONNECTED = 18 ,
  TWR_ESP8266_STATE_SNTP_CONFIG_COMMAND = 19 ,
  TWR_ESP8266_STATE_SNTP_CONFIG_RESPONSE = 20 ,
  TWR_ESP8266_STATE_SNTP_TIME_COMMAND = 21 ,
  TWR_ESP8266_STATE_SNTP_TIME_RESPONSE = 22 ,
  TWR_ESP8266_STATE_AP_AVAILABILITY_OPT_COMMAND = 23 ,
  TWR_ESP8266_STATE_AP_AVAILABILITY_OPT_RESPONSE = 24 ,
  TWR_ESP8266_STATE_AP_AVAILABILITY_COMMAND = 25 ,
  TWR_ESP8266_STATE_AP_AVAILABILITY_RESPONSE = 26
}
 
enum  twr_esp8266_config_mode_t {
  TWR_ESP8266_CONFIG_MODE_STATION = 0 ,
  TWR_ESP8266_CONFIG_MODE_AP = 1
}
 

Functions

void twr_esp8266_init (twr_esp8266_t *self, twr_uart_channel_t uart_channel)
 Initialize ESP8266. More...
 
void twr_esp8266_set_event_handler (twr_esp8266_t *self, void(*event_handler)(twr_esp8266_t *, twr_esp8266_event_t, void *), void *event_param)
 Set callback function. More...
 
void twr_esp8266_set_station_mode (twr_esp8266_t *self, char *ssid, char *password)
 Set station mode. More...
 
void twr_esp8266_set_sntp (twr_esp8266_t *self, int timezone)
 Enable SNTP and set time zone. More...
 
void twr_esp8266_set_sntp_with_servers (twr_esp8266_t *self, int timezone, char *sntp_server1, char *sntp_server2, char *sntp_server3)
 Enable SNTP and set configuration. More...
 
bool twr_esp8266_is_ready (twr_esp8266_t *self)
 Check if modem is ready for commands. More...
 
bool twr_esp8266_connect (twr_esp8266_t *self)
 Enable ESP8266 and connect to WiFi. More...
 
bool twr_esp8266_disconnect (twr_esp8266_t *self)
 Disable ESP8266 and disconnect. More...
 
bool twr_esp8266_tcp_connect (twr_esp8266_t *self, const char *host, uint16_t port)
 Establish TCP Connection. More...
 
bool twr_esp8266_udp_connect (twr_esp8266_t *self, const char *host, uint16_t port)
 Establish UDP Connection. More...
 
bool twr_esp8266_ssl_connect (twr_esp8266_t *self, const char *host, uint16_t port)
 Establish SSL Connection. More...
 
bool twr_esp8266_send_data (twr_esp8266_t *self, const void *buffer, size_t length)
 Send data. More...
 
uint32_t twr_esp8266_get_received_message_length (twr_esp8266_t *self)
 Get length of the received message. More...
 
uint32_t twr_esp8266_get_received_message_data (twr_esp8266_t *self, uint8_t *buffer, uint32_t buffer_size)
 Get received message data. More...
 
bool twr_esp8266_check_ap_availability (twr_esp8266_t *self)
 Check AP availability. More...
 
void twr_esp8266_get_ap_availability (twr_esp8266_t *self, bool *available, int *rssi)
 Get AP availability result. More...
 
void twr_esp8266_get_ssid (twr_esp8266_t *self, char *ssid)
 Get SSID. More...
 
void twr_esp8266_set_ssid (twr_esp8266_t *self, char *ssid)
 Set SSID. More...
 
void twr_esp8266_get_password (twr_esp8266_t *self, char *password)
 Get password. More...
 
void twr_esp8266_set_password (twr_esp8266_t *self, char *password)
 Set password. More...
 

Detailed Description

Driver for ESP8266 WiFi module.

Enumeration Type Documentation

◆ twr_esp8266_event_t

Callback events.

Enumerator
TWR_ESP8266_EVENT_READY 

Ready event.

TWR_ESP8266_EVENT_ERROR 

Error event.

Definition at line 23 of file twr_esp8266.h.

Function Documentation

◆ twr_esp8266_check_ap_availability()

bool twr_esp8266_check_ap_availability ( twr_esp8266_t self)

Check AP availability.

Parameters
[in]selfInstance
Returns
true If command was accepted for processing
false If command was denied for processing

Definition at line 979 of file twr_esp8266.c.

◆ twr_esp8266_connect()

bool twr_esp8266_connect ( twr_esp8266_t self)

Enable ESP8266 and connect to WiFi.

Parameters
[in]selfInstance
Returns
true If command was accepted for processing
false If command was denied for processing

Definition at line 156 of file twr_esp8266.c.

◆ twr_esp8266_disconnect()

bool twr_esp8266_disconnect ( twr_esp8266_t self)

Disable ESP8266 and disconnect.

Parameters
[in]selfInstance
Returns
true If command was accepted for processing
false If command was denied for processing

Definition at line 174 of file twr_esp8266.c.

◆ twr_esp8266_get_ap_availability()

void twr_esp8266_get_ap_availability ( twr_esp8266_t self,
bool *  available,
int *  rssi 
)

Get AP availability result.

Parameters
[in]selfInstance
[in]availableIf AP is available
[in]rssiRSSI

Definition at line 996 of file twr_esp8266.c.

◆ twr_esp8266_get_password()

void twr_esp8266_get_password ( twr_esp8266_t self,
char *  password 
)

Get password.

Parameters
[in]selfInstance
[in]passwordPointer to at least 64 character string

Definition at line 1012 of file twr_esp8266.c.

◆ twr_esp8266_get_received_message_data()

uint32_t twr_esp8266_get_received_message_data ( twr_esp8266_t self,
uint8_t *  buffer,
uint32_t  buffer_size 
)

Get received message data.

Parameters
[in]selfInstance
[in]bufferDestination buffer for received data
[in]buffer_sizeSize of the destination buffer
Returns
Length of the received message. Zero if the destination buffer is not big enough.

Definition at line 795 of file twr_esp8266.c.

◆ twr_esp8266_get_received_message_length()

uint32_t twr_esp8266_get_received_message_length ( twr_esp8266_t self)

Get length of the received message.

Parameters
[in]selfInstance
Returns
length

Definition at line 790 of file twr_esp8266.c.

◆ twr_esp8266_get_ssid()

void twr_esp8266_get_ssid ( twr_esp8266_t self,
char *  ssid 
)

Get SSID.

Parameters
[in]selfInstance
[in]ssidPointer to at least 64 character string

Definition at line 1002 of file twr_esp8266.c.

◆ twr_esp8266_init()

void twr_esp8266_init ( twr_esp8266_t self,
twr_uart_channel_t  uart_channel 
)

Initialize ESP8266.

Parameters
[in]selfInstance
[in]uart_channelUART channel where TX and RX signals are connected

Definition at line 37 of file twr_esp8266.c.

◆ twr_esp8266_is_ready()

bool twr_esp8266_is_ready ( twr_esp8266_t self)

Check if modem is ready for commands.

Parameters
[in]selfInstance
Returns
true If ready
false If not ready

Definition at line 146 of file twr_esp8266.c.

Referenced by twr_esp8266_send_data().

Here is the caller graph for this function:

◆ twr_esp8266_send_data()

bool twr_esp8266_send_data ( twr_esp8266_t self,
const void *  buffer,
size_t  length 
)

Send data.

Parameters
[in]selfInstance
[in]bufferPointer to data to be transmitted
[in]lengthLength of data to be transmitted in bytes
Returns
true If command was accepted for processing
false If command was denied for processing

Definition at line 225 of file twr_esp8266.c.

Here is the call graph for this function:

◆ twr_esp8266_set_event_handler()

void twr_esp8266_set_event_handler ( twr_esp8266_t self,
void(*)(twr_esp8266_t *, twr_esp8266_event_t, void *)  event_handler,
void *  event_param 
)

Set callback function.

Parameters
[in]selfInstance
[in]event_handlerFunction address
[in]event_paramOptional event parameter (can be NULL)

Definition at line 98 of file twr_esp8266.c.

◆ twr_esp8266_set_password()

void twr_esp8266_set_password ( twr_esp8266_t self,
char *  password 
)

Set password.

Parameters
[in]selfInstance
[in]passwordPointer to 64 character string

Definition at line 1017 of file twr_esp8266.c.

◆ twr_esp8266_set_sntp()

void twr_esp8266_set_sntp ( twr_esp8266_t self,
int  timezone 
)

Enable SNTP and set time zone.

Parameters
[in]selfInstance
[in]timezoneTime zone, from -11 to 13

Definition at line 111 of file twr_esp8266.c.

Here is the call graph for this function:

◆ twr_esp8266_set_sntp_with_servers()

void twr_esp8266_set_sntp_with_servers ( twr_esp8266_t self,
int  timezone,
char *  sntp_server1,
char *  sntp_server2,
char *  sntp_server3 
)

Enable SNTP and set configuration.

Parameters
[in]selfInstance
[in]timezoneTime zone, from -11 to 13
[in]sntp_server1First SNTP server
[in]sntp_server2Second SNTP server
[in]sntp_server3Third SNTP server

Definition at line 116 of file twr_esp8266.c.

Referenced by twr_esp8266_set_sntp().

Here is the caller graph for this function:

◆ twr_esp8266_set_ssid()

void twr_esp8266_set_ssid ( twr_esp8266_t self,
char *  ssid 
)

Set SSID.

Parameters
[in]selfInstance
[in]ssidPointer to 64 character string

Definition at line 1007 of file twr_esp8266.c.

◆ twr_esp8266_set_station_mode()

void twr_esp8266_set_station_mode ( twr_esp8266_t self,
char *  ssid,
char *  password 
)

Set station mode.

Parameters
[in]selfInstance
[in]ssidSSID
[in]passwordPassword

Definition at line 104 of file twr_esp8266.c.

◆ twr_esp8266_ssl_connect()

bool twr_esp8266_ssl_connect ( twr_esp8266_t self,
const char *  host,
uint16_t  port 
)

Establish SSL Connection.

Parameters
[in]selfInstance
[in]hostRemote host
[in]portRemote port
Returns
true If command was accepted for processing
false If command was denied for processing

Definition at line 220 of file twr_esp8266.c.

◆ twr_esp8266_tcp_connect()

bool twr_esp8266_tcp_connect ( twr_esp8266_t self,
const char *  host,
uint16_t  port 
)

Establish TCP Connection.

Parameters
[in]selfInstance
[in]hostRemote host
[in]portRemote port
Returns
true If command was accepted for processing
false If command was denied for processing

Definition at line 210 of file twr_esp8266.c.

◆ twr_esp8266_udp_connect()

bool twr_esp8266_udp_connect ( twr_esp8266_t self,
const char *  host,
uint16_t  port 
)

Establish UDP Connection.

Parameters
[in]selfInstance
[in]hostRemote host
[in]portRemote port
Returns
true If command was accepted for processing
false If command was denied for processing

Definition at line 215 of file twr_esp8266.c.