21 #if DEVICE_SERIAL && DEVICE_INTERRUPTIN && defined(MBED_CONF_EVENTS_PRESENT) && defined(MBED_CONF_NSAPI_PRESENT) && defined(MBED_CONF_RTOS_API_PRESENT) 25 #include "drivers/BufferedSerial.h" 26 #include "netsocket/nsapi_types.h" 27 #include "netsocket/WiFiAccessPoint.h" 29 #include "platform/ATCmdParser.h" 30 #include "platform/Callback.h" 31 #include "platform/mbed_chrono.h" 32 #include "platform/mbed_error.h" 33 #include "rtos/Mutex.h" 34 #include "rtos/ThisThread.h" 40 #ifndef ESP8266_CONNECT_TIMEOUT 41 #define ESP8266_CONNECT_TIMEOUT 15s 43 #ifndef ESP8266_SEND_TIMEOUT 44 #define ESP8266_SEND_TIMEOUT 2s 46 #ifndef ESP8266_RECV_TIMEOUT 47 #define ESP8266_RECV_TIMEOUT std::chrono::seconds(2) 49 #ifndef ESP8266_MISC_TIMEOUT 50 #define ESP8266_MISC_TIMEOUT std::chrono::seconds(2) 52 #ifndef ESP8266_DNS_TIMEOUT 53 #define ESP8266_DNS_TIMEOUT 15s 56 #define ESP8266_SCAN_TIME_MIN 0ms 57 #define ESP8266_SCAN_TIME_MAX 1500ms 58 #define ESP8266_SCAN_TIME_MIN_DEFAULT 120ms 59 #define ESP8266_SCAN_TIME_MAX_DEFAULT 360ms 62 #define ESP8266_SDK_VERSION 2000000 63 #define ESP8266_SDK_VERSION_MAJOR ESP8266_SDK_VERSION/1000000 65 #define ESP8266_AT_VERSION 1000000 66 #define ESP8266_AT_VERSION_MAJOR ESP8266_AT_VERSION/1000000 67 #define ESP8266_AT_VERSION_TCP_PASSIVE_MODE 1070000 68 #define ESP8266_AT_VERSION_WIFI_SCAN_CHANGE 1060000 70 #define FW_AT_LEAST_VERSION(MAJOR,MINOR,PATCH,NUSED,REF) \ 71 (((MAJOR)*1000000+(MINOR)*10000+(PATCH)*100) >= REF ? true : false) 73 struct esp8266_socket {
75 nsapi_protocol_t proto;
87 ESP8266(PinName tx, PinName rx,
bool debug =
false, PinName rts = NC, PinName cts = NC);
96 struct fw_sdk_version {
100 fw_sdk_version(
int major,
int minor,
int patch) : major(major), minor(minor), patch(patch) {}
110 struct fw_at_version {
114 fw_at_version(
int major,
int minor,
int patch) : major(major), minor(minor), patch(patch) {}
122 bool at_available(
void);
136 struct fw_sdk_version sdk_version(void);
143 struct fw_at_version at_version(void);
151 bool startup(
int mode);
167 bool dhcp(
bool enabled,
int mode);
176 nsapi_error_t connect(
const char *ap,
const char *passPhrase);
183 bool disconnect(
void);
191 bool ip_info_print(
int enable);
198 const char *ip_addr(
void);
209 bool set_ip_addr(
const char *ip,
const char *gateway,
const char *netmask);
216 const char *mac_addr(
void);
223 const char *gateway();
230 const char *netmask();
255 std::chrono::duration<unsigned, std::milli> t_max,
256 std::chrono::duration<unsigned, std::milli> t_min);
264 bool dns_lookup(
const char *name,
char *ip);
278 nsapi_error_t open_udp(
int id,
const char *addr,
int port,
int local_port = 0,
int udp_mode = 0);
291 nsapi_error_t open_tcp(
int id,
const char *addr,
int port,
int keepalive = 0);
311 int32_t recv_udp(
struct esp8266_socket *socket,
void *data, uint32_t amount, mbed::chrono::milliseconds_u32 timeout = ESP8266_RECV_TIMEOUT);
321 int32_t recv_tcp(
int id,
void *data, uint32_t amount, mbed::chrono::milliseconds_u32 timeout = ESP8266_RECV_TIMEOUT);
336 void set_timeout(mbed::chrono::milliseconds_u32 timeout = ESP8266_MISC_TIMEOUT);
361 template <
typename T,
typename M>
362 void sigio(T *obj, M method)
385 bool set_sntp_config(
bool enable,
int timezone = 0,
const char *server0 =
nullptr,
386 const char *server1 =
nullptr,
const char *server2 =
nullptr);
399 bool get_sntp_config(
bool *enable,
int *timezone,
char *server0,
400 char *server1,
char *server2);
413 bool get_sntp_time(std::tm *t);
415 template <
typename T,
typename M>
416 void attach(T *obj, M method)
426 int8_t default_wifi_mode();
431 bool set_default_wifi_mode(
const int8_t mode);
440 bool set_country_code_policy(
bool track_ap,
const char *country_code,
int channel_start,
int channels);
446 nsapi_connection_status_t connection_status()
const;
453 bool start_uart_hw_flow_ctrl();
461 bool stop_uart_hw_flow_ctrl(
bool board_only =
false);
466 bool cond_enable_tcp_passive_mode();
474 void bg_process_oob(std::chrono::duration<uint32_t, std::milli> timeout,
bool all);
485 static const int8_t WIFIMODE_STATION = 1;
486 static const int8_t WIFIMODE_SOFTAP = 2;
487 static const int8_t WIFIMODE_STATION_SOFTAP = 3;
488 static const int8_t SOCKET_COUNT = 5;
496 int uart_enable_input(
bool lock);
500 struct fw_sdk_version _sdk_v;
501 struct fw_at_version _at_v;
505 int32_t _recv_tcp_passive(
int id,
void *data, uint32_t amount, std::chrono::duration<uint32_t, std::milli> timeout);
529 } *_packets, * *_packets_end;
530 void _clear_socket_packets(
int id);
531 void _clear_socket_sending(
int id);
538 void _process_oob(std::chrono::duration<uint32_t, std::milli> timeout,
bool all);
541 void _oob_packet_hdlr();
542 void _oob_connect_err();
543 void _oob_conn_already();
545 void _oob_socket0_closed();
546 void _oob_socket1_closed();
547 void _oob_socket2_closed();
548 void _oob_socket3_closed();
549 void _oob_socket4_closed();
550 void _oob_connection_status();
551 void _oob_socket_close_err();
552 void _oob_watchdog_reset();
554 void _oob_tcp_data_hdlr();
556 void _oob_scan_results();
557 void _oob_send_ok_received();
558 void _oob_send_fail_received();
569 int _sock_sending_id;
573 char _gateway_buffer[16];
574 char _netmask_buffer[16];
575 char _mac_buffer[18];
580 nsapi_protocol_t proto;
582 int32_t tcp_data_avbl;
583 int32_t tcp_data_rcvd;
586 struct _sock_info _sock_i[SOCKET_COUNT];
589 struct _scan_results {
594 struct _scan_results _scan_r;
597 nsapi_connection_status_t _conn_status;
signed int nsapi_error_t
Type used to represent error codes.
signed int nsapi_size_or_error_t
Type used to represent either a size or error passed through sockets.
The Mutex class is used to synchronize the execution of threads.
Class providing buffered UART communication functionality using separate circular buffer for send and...
Parser class for parsing AT commands.
Callback class based on template specialization.