21#if DEVICE_SERIAL && defined(MBED_CONF_EVENTS_PRESENT) && defined(MBED_CONF_NSAPI_PRESENT) && defined(MBED_CONF_RTOS_PRESENT)
23#include "drivers/DigitalOut.h"
24#include "netsocket/nsapi_types.h"
25#include "netsocket/WiFiAccessPoint.h"
26#include "platform/ATCmdParser.h"
27#include "rtos/ThisThread.h"
28#include "drivers/BufferedSerial.h"
30#ifndef ESP32_CONNECT_TIMEOUT
31#define ESP32_CONNECT_TIMEOUT 15000
33#ifndef ESP32_SEND_TIMEOUT
34#define ESP32_SEND_TIMEOUT 2000
36#ifndef ESP32_RECV_TIMEOUT
37#define ESP32_RECV_TIMEOUT 2000
39#ifndef ESP32_MISC_TIMEOUT
40#define ESP32_MISC_TIMEOUT 2000
51 static ESP32 *getESP32Inst(PinName en, PinName io0, PinName tx, PinName rx,
bool debug,
52 PinName rts, PinName cts,
int baudrate);
53 static ESP32 *getESP32Inst(
bool debug =
false);
55 ESP32(PinName en, PinName io0, PinName tx, PinName rx,
bool debug,
56 PinName rts, PinName cts,
int baudrate);
65 bool get_version_info(
char *ver_info,
int buf_size);
73 bool set_mode(
int mode);
82 bool dhcp(
bool enabled,
int mode);
91 bool connect(
const char *ap,
const char *passPhrase);
98 bool disconnect(
void);
105 const char *getIPAddress(
void);
106 const char *getIPAddress_ap(
void);
113 const char *getMACAddress(
void);
114 const char *getMACAddress_ap(
void);
121 const char *getGateway();
122 const char *getGateway_ap();
129 const char *getNetmask();
130 const char *getNetmask_ap();
143 bool isConnected(
void);
166 bool open(
const char *type,
int id,
const char *addr,
int port,
int opt = 0);
176 bool send(
int id,
const void *data, uint32_t amount);
186 int32_t recv(
int id,
void *data, uint32_t amount, uint32_t timeout = ESP32_RECV_TIMEOUT);
195 bool close(
int id,
bool wait_close =
false);
202 void setTimeout(uint32_t timeout_ms = ESP32_MISC_TIMEOUT);
214 void socket_attach(
int id,
void (*callback)(
void *),
void *data);
217 bool config_soft_ap(
const char *ap,
const char *passPhrase, uint8_t chl, uint8_t ecn);
220 bool get_ssid(
char *ap);
221 bool cre_server(
int port);
223 bool accept(
int *p_id);
225 bool set_network(
const char *ip_address,
const char *netmask,
const char *gateway);
226 bool set_network_ap(
const char *ip_address,
const char *netmask,
const char *gateway);
239 int8_t get_wifi_status()
const;
250 static const int8_t WIFIMODE_STATION = 1;
251 static const int8_t WIFIMODE_SOFTAP = 2;
252 static const int8_t WIFIMODE_STATION_SOFTAP = 3;
253 static const int8_t SOCKET_COUNT = 5;
255 static const int8_t STATUS_DISCONNECTED = 0;
256 static const int8_t STATUS_CONNECTED = 1;
257 static const int8_t STATUS_GOT_IP = 2;
262 bool _init_end_common;
272 } *_packets, * *_packets_end;
278 uint32_t last_timeout_ms;
280 std::vector<int> _accept_id;
284 static ESP32 *instESP32;
287 uint32_t _at_version;
289 bool _ids[SOCKET_COUNT];
291 void (*callback)(
void *);
294 } _cbs[SOCKET_COUNT];
296 void _startup_common();
297 bool _startup_wifi();
299 void debugOn(
bool debug);
300 void socket_handler(
bool connect,
int id);
301 void _connect_handler_0();
302 void _connect_handler_1();
303 void _connect_handler_2();
304 void _connect_handler_3();
305 void _connect_handler_4();
306 void _closed_handler_0();
307 void _closed_handler_1();
308 void _closed_handler_2();
309 void _closed_handler_3();
310 void _closed_handler_4();
311 void _connection_status_handler();
312 void _packet_handler();
313 void _clear_socket_packets(
int id);
318 char _gateway_buffer[16];
319 char _netmask_buffer[16];
320 char _mac_buffer[18];
322 char _ip_buffer_ap[16];
323 char _gateway_buffer_ap[16];
324 char _netmask_buffer_ap[16];
325 char _mac_buffer_ap[18];
327#if defined(TARGET_ESP32AT_BLE)
346 uint16_t val_max_len;
354 uint16_t adv_int_min;
355 uint16_t adv_int_max;
357 uint8_t own_addr_type;
359 uint8_t adv_filter_policy;
360 uint8_t peer_addr_type;
361 uint8_t peer_addr[6];
362 } advertising_param_t;
367 uint8_t adv_data[31];
368 uint8_t adv_data_len;
369 uint8_t scan_rsp_data[31];
370 uint8_t scan_rsp_data_len;
378 } ble_primary_service_t;
384 } ble_characteristics_t;
390 } ble_discovers_char_t;
396 } ble_discovers_desc_t;
399#define ADV_TYPE_IND 0
400#define ADV_TYPE_SCAN_IND 2
401#define ADV_TYPE_NONCONN_IND 3
404#define BLE_ADDR_TYPE_PUBLIC 0
405#define BLE_ADDR_TYPE_RANDOM 1
408#define ADV_CHNL_37 0x01
409#define ADV_CHNL_38 0x02
410#define ADV_CHNL_39 0x04
411#define ADV_CHNL_ALL 0x07
414#define ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY 0
415#define ADV_FILTER_ALLOW_SCAN_WLST_CON_ANY 1
416#define ADV_FILTER_ALLOW_SCAN_ANY_CON_WLST 2
417#define ADV_FILTER_ALLOW_SCAN_WLST_CON_WLST 3
420#define INIT_CLIENT_ROLE 1
421#define INIT_SERVER_ROLE 2
428 bool ble_set_role(
int role);
435 bool ble_get_role(
int *role);
442 bool ble_set_device_name(
const char *name);
449 bool ble_get_device_name(
char *name);
455 bool ble_start_services();
463 bool ble_set_scan_response(
const uint8_t *data,
int len);
469 bool ble_start_advertising();
475 bool ble_stop_advertising();
483 bool ble_set_addr(
int addr_type,
const uint8_t *random_addr = NULL);
490 bool ble_get_addr(uint8_t *public_addr);
497 bool ble_set_advertising_param(
const advertising_param_t *param);
505 bool ble_set_advertising_data(
const uint8_t *data,
int len);
513 bool ble_set_service(
const gatt_service_t *service_list,
int num);
523 bool ble_set_characteristic(
int srv_index,
int char_index,
const uint8_t *data,
int len);
533 bool ble_notifies_characteristic(
int srv_index,
int char_index,
const uint8_t *data,
int len);
547 bool ble_set_scan_param(
int scan_type,
int own_addr_type,
int filter_policy,
int scan_interval,
int scan_window);
555 bool ble_start_scan(
int interval = 0);
561 bool ble_stop_scan();
570 bool ble_connect(
int conn_index,
const uint8_t *remote_addr);
578 bool ble_disconnect(
int conn_index);
588 bool ble_discovery_service(
int conn_index, ble_primary_service_t *service,
int *num);
601 bool ble_discovery_characteristics(
602 int conn_index,
int srv_index,
603 ble_discovers_char_t *discovers_char,
int *char_num,
604 ble_discovers_desc_t *discovers_desc,
int *desc_num
617 int32_t ble_read_characteristic(
int conn_index,
int srv_index,
int char_index, uint8_t *data,
int amount);
630 int32_t ble_read_descriptor(
int conn_index,
int srv_index,
int char_index,
int desc_index, uint8_t *data,
int amount);
642 bool ble_write_characteristic(
int conn_index,
int srv_index,
int char_index,
const uint8_t *data,
int amount);
655 bool ble_write_descriptor(
int conn_index,
int srv_index,
int char_index,
int desc_index,
const uint8_t *data,
int amount);
662 void ble_process_oob(uint32_t timeout,
bool all);
688 void ble_attach_conn(
mbed::Callback<
void(
int, uint8_t *)> cb_func);
703 void ble_attach_write(
mbed::Callback<
void(ble_packet_t *)> cb_func);
713#define PRIMARY_SERVICE_BUF_NUM 16
714#define DISCOVERS_CHAR_BUF_NUM 16
715#define DISCOVERS_DESC_BUF_NUM 16
728 int _primary_service_idx;
729 int _discovers_char_idx;
730 int _discovers_desc_idx;
731 ble_primary_service_t _primary_service[PRIMARY_SERVICE_BUF_NUM];
732 ble_discovers_char_t _discovers_char[DISCOVERS_CHAR_BUF_NUM];
733 ble_discovers_desc_t _discovers_desc[DISCOVERS_DESC_BUF_NUM];
741 void _ble_discovers_char();
742 char _int2char(
int data);
743 int _char2int(
char c);
744 int _set_char(
char *buf1,
const uint8_t *buf2,
int size);
Parser class for parsing AT commands.
Class providing buffered UART communication functionality using separate circular buffer for send and...
Callback class based on template specialization.
A digital output, used for setting the state of a pin.
The Mutex class is used to synchronize the execution of threads.