4 #include <twr_scheduler.h>
14 #define TWR_ESP8266_TX_MAX_PACKET_SIZE 1024
16 #define TWR_ESP8266_TX_FIFO_BUFFER_SIZE TWR_ESP8266_TX_MAX_PACKET_SIZE
17 #define TWR_ESP8266_RX_FIFO_BUFFER_SIZE 2048
31 TWR_ESP8266_EVENT_WIFI_CONNECT_SUCCESS = 2,
32 TWR_ESP8266_EVENT_WIFI_CONNECT_ERROR = 3,
33 TWR_ESP8266_EVENT_SOCKET_CONNECT_SUCCESS = 4,
34 TWR_ESP8266_EVENT_SOCKET_CONNECT_ERROR = 5,
35 TWR_ESP8266_EVENT_SOCKET_SEND_SUCCESS = 6,
36 TWR_ESP8266_EVENT_SOCKET_SEND_ERROR = 7,
37 TWR_ESP8266_EVENT_DATA_RECEIVED = 8,
38 TWR_ESP8266_EVENT_AP_AVAILABILITY_RESULT = 9,
39 TWR_ESP8266_EVENT_DISCONNECTED = 10
49 TWR_ESP8266_STATE_READY = 0,
50 TWR_ESP8266_STATE_ERROR = 1,
51 TWR_ESP8266_STATE_INITIALIZE = 2,
52 TWR_ESP8266_STATE_IDLE = 3,
53 TWR_ESP8266_STATE_RECEIVE = 4,
54 TWR_ESP8266_STATE_INITIALIZE_COMMAND_SEND = 5,
55 TWR_ESP8266_STATE_INITIALIZE_COMMAND_RESPONSE = 6,
56 TWR_ESP8266_STATE_WIFI_CONNECT_COMMAND = 7,
57 TWR_ESP8266_STATE_SOCKET_CONNECT_COMMAND = 8,
58 TWR_ESP8266_STATE_SOCKET_SEND_COMMAND = 9,
59 TWR_ESP8266_STATE_SOCKET_SEND_DATA = 10,
60 TWR_ESP8266_STATE_WIFI_CONNECT_RESPONSE = 11,
61 TWR_ESP8266_STATE_SOCKET_CONNECT_RESPONSE = 12,
62 TWR_ESP8266_STATE_SOCKET_SEND_RESPONSE = 13,
63 TWR_ESP8266_STATE_WIFI_CONNECT_ERROR = 14,
64 TWR_ESP8266_STATE_SOCKET_CONNECT_ERROR = 15,
65 TWR_ESP8266_STATE_SOCKET_SEND_ERROR = 16,
66 TWR_ESP8266_STATE_SOCKET_RECEIVE = 17,
67 TWR_ESP8266_STATE_DISCONNECTED = 18,
68 TWR_ESP8266_STATE_SNTP_CONFIG_COMMAND = 19,
69 TWR_ESP8266_STATE_SNTP_CONFIG_RESPONSE = 20,
70 TWR_ESP8266_STATE_SNTP_TIME_COMMAND = 21,
71 TWR_ESP8266_STATE_SNTP_TIME_RESPONSE = 22,
72 TWR_ESP8266_STATE_AP_AVAILABILITY_OPT_COMMAND = 23,
73 TWR_ESP8266_STATE_AP_AVAILABILITY_OPT_RESPONSE = 24,
74 TWR_ESP8266_STATE_AP_AVAILABILITY_COMMAND = 25,
75 TWR_ESP8266_STATE_AP_AVAILABILITY_RESPONSE = 26
77 } twr_esp8266_state_t;
81 TWR_ESP8266_CONFIG_MODE_STATION = 0,
82 TWR_ESP8266_CONFIG_MODE_AP = 1
83 } twr_esp8266_config_mode_t;
87 twr_esp8266_config_mode_t mode;
92 char sntp_server1[128];
93 char sntp_server2[128];
94 char sntp_server3[128];
101 twr_esp8266_state_t _state;
102 twr_esp8266_state_t _state_after_init;
105 uint8_t _tx_fifo_buffer[TWR_ESP8266_TX_FIFO_BUFFER_SIZE];
106 uint8_t _rx_fifo_buffer[TWR_ESP8266_RX_FIFO_BUFFER_SIZE];
109 char _command[TWR_ESP8266_TX_FIFO_BUFFER_SIZE];
110 char _response[TWR_ESP8266_RX_FIFO_BUFFER_SIZE];
111 uint8_t _message_buffer[TWR_ESP8266_TX_MAX_PACKET_SIZE];
112 size_t _message_length;
113 size_t _message_part_length;
114 uint8_t _init_command_index;
115 uint8_t _timeout_cnt;
bool twr_esp8266_connect(twr_esp8266_t *self)
Enable ESP8266 and connect to WiFi.
void twr_esp8266_get_ap_availability(twr_esp8266_t *self, bool *available, int *rssi)
Get AP availability result.
uint32_t twr_esp8266_get_received_message_data(twr_esp8266_t *self, uint8_t *buffer, uint32_t buffer_size)
Get received message data.
uint32_t twr_esp8266_get_received_message_length(twr_esp8266_t *self)
Get length of the received message.
bool twr_esp8266_ssl_connect(twr_esp8266_t *self, const char *host, uint16_t port)
Establish SSL Connection.
void twr_esp8266_get_ssid(twr_esp8266_t *self, char *ssid)
Get SSID.
bool twr_esp8266_udp_connect(twr_esp8266_t *self, const char *host, uint16_t port)
Establish UDP Connection.
void twr_esp8266_set_station_mode(twr_esp8266_t *self, char *ssid, char *password)
Set station mode.
bool twr_esp8266_send_data(twr_esp8266_t *self, const void *buffer, size_t length)
Send data.
bool twr_esp8266_is_ready(twr_esp8266_t *self)
Check if modem is ready for commands.
bool twr_esp8266_disconnect(twr_esp8266_t *self)
Disable ESP8266 and disconnect.
bool twr_esp8266_tcp_connect(twr_esp8266_t *self, const char *host, uint16_t port)
Establish TCP Connection.
void twr_esp8266_init(twr_esp8266_t *self, twr_uart_channel_t uart_channel)
Initialize ESP8266.
void twr_esp8266_set_password(twr_esp8266_t *self, char *password)
Set password.
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.
bool twr_esp8266_check_ap_availability(twr_esp8266_t *self)
Check AP availability.
void twr_esp8266_set_sntp(twr_esp8266_t *self, int timezone)
Enable SNTP and set time zone.
void twr_esp8266_get_password(twr_esp8266_t *self, char *password)
Get password.
twr_esp8266_event_t
Callback events.
void twr_esp8266_set_ssid(twr_esp8266_t *self, char *ssid)
Set SSID.
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.
@ TWR_ESP8266_EVENT_READY
Ready event.
@ TWR_ESP8266_EVENT_ERROR
Error event.
size_t twr_scheduler_task_id_t
Task ID assigned by scheduler.
twr_uart_channel_t
UART channels.
Structure of FIFO instance.