Escolar Documentos
Profissional Documentos
Cultura Documentos
Status
Released
Current version
V0.9.5
Author
Fei Yu
Completion Date
2015.01.22
Reviewer
JG Wu
Completion Date
2015.01.22
[ ] CONFIDENTIAL
1 / 91
] INTERNAL
] PUBLIC
Espressif Systems
February 9, 2015
ESP8266EX
2013.12.25
0.1
2013.12.25
0.1.1
2014.1.15
0.2
2014.1.29
0.3
2014.3.20
0.4
2014.4.17
0.5
JG Wu / Han
Liu
2014.5.14
0.6
API
2014.6.18
0.7
JG Wu
JG Wu
2014.7.10
0.8
Fei Yu
1. upgrade
2.
3. station
4. SSL Server
client
2014.8.13
0.9
Fei Yu
1. espconn
2. sniffer
3. chip
4. mac&ip
2014.9.23
0.9.1
Fei Yu
1
2 flash
3 AP
4 UDP
2014.11.07
0.9.3
Fei Yu
1 DHCP
2 / 91
JG Wu
Han Liu
JG Wu
Han Liu
JG Wu / Han
Liu
Espressif Systems
json API
client/server
1. uart
2. i2c master
3. client/server
4.
5. upgrade
1. espconn
2. gpio api
3.
1. dns
2.
3.
4. softap
5.
heap
6.
February 9, 2015
ESP8266EX
2 RTC
3 ADC
4 stationsoftAP
2014.12.19
0.9.4
Fei Yu
1
2 igmp
2015.01.22
0.9.5
Fei Yu
1Upgrade
2DHCP
3 ap
4smart config
5TCP
6AT
URL
Wi-Fi Wi-Fi
2014
3 / 91
Espressif Systems
February 9, 2015
ESP8266EX
........................................................................................................................ 2
................................................................................................................................ 4
1.
.................................................................................................... 9
2.
.......................................................................................... 10
3.
SDK API .................................................................... 11
3.1.
...................................................................................... 11
3.1.1.
os_timer_arm .................................................................................. 11
3.1.2.
os_timer_disarm .............................................................................. 11
3.1.3.
os_timer_setfn ................................................................................. 12
3.2.
.................................................................................. 12
3.2.1.
system_restore................................................................................. 12
3.2.2.
system_restart ................................................................................. 12
3.2.3.
system_timer_reinit ......................................................................... 13
3.2.4.
system_init_done_cb ....................................................................... 13
3.2.5.
system_get_chip_id ......................................................................... 14
3.2.6.
system_deep_sleep ......................................................................... 14
3.2.7.
system_deep_sleep_set_option ...................................................... 15
3.2.8.
system_set_os_print ........................................................................ 15
3.2.9.
system_print_meminfo .................................................................... 16
3.2.10.
system_get_free_heap_size ............................................................ 16
3.2.11.
system_os_task ................................................................................ 16
3.2.12.
system_os_post ............................................................................... 18
3.2.13.
system_get_time.............................................................................. 18
3.2.14.
system_get_rtc_time ....................................................................... 19
3.2.15.
system_rtc_clock_cali_proc ............................................................. 19
3.2.16.
system_rtc_mem_write ................................................................... 19
3.2.17.
system_rtc_mem_read .................................................................... 20
3.2.18.
system_uart_swap ........................................................................... 21
3.2.19.
system_adc_read ............................................................................. 21
3.3.
SPI Flash ......................................................................... 22
3.3.1.
spi_flash_get_id ............................................................................... 22
3.3.2.
spi_flash_erase_sector .................................................................... 22
3.3.3.
spi_flash_write ................................................................................. 22
3.3.4.
spi_flash_read .................................................................................. 23
3.4.
WIFI ................................................................................. 24
3.4.1.
wifi_get_opmode ............................................................................. 24
3.4.2.
wifi_set_opmode ............................................................................. 24
3.4.3.
wifi_station_get_config ................................................................... 25
3.4.4.
wifi_station_set_config.................................................................... 25
3.4.5.
wifi_station_connect ....................................................................... 25
4 / 91
Espressif Systems
February 9, 2015
ESP8266EX
3.4.6.
wifi_station_disconnect ................................................................... 26
3.4.7.
wifi_station_get_connect_status..................................................... 26
3.4.8.
wifi_station_scan ............................................................................. 27
3.4.9.
scan_done_cb_t ............................................................................... 28
3.4.10.
wifi_station_ap_number_set ........................................................... 28
3.4.11.
wifi_station_get_ap_info ................................................................. 29
3.4.12.
wifi_station_ap_change ................................................................... 29
3.4.13.
wifi_station_get_current_ap_id ...................................................... 29
3.4.14.
wifi_station_get_auto_connect ....................................................... 30
3.4.15.
wifi_station_set_auto_connect ....................................................... 30
3.4.16.
wifi_station_dhcpc_start ................................................................. 31
3.4.17.
wifi_station_dhcpc_stop .................................................................. 31
3.4.18.
wifi_station_dhcpc_status ............................................................... 31
3.4.19.
wifi_softap_get_config .................................................................... 32
3.4.20.
wifi_softap_set_config..................................................................... 32
3.4.21.
wifi_softap_get_station_info ........................................................... 32
3.4.22.
wifi_softap_free_station_info ......................................................... 33
3.4.23.
wifi_softap_dhcps_start .................................................................. 34
3.4.24.
wifi_softap_dhcps_stop ................................................................... 34
3.4.25.
wifi_softap_set_dhcps_lease........................................................... 34
3.4.26.
wifi_softap_dhcps_status ................................................................ 35
3.4.27.
wifi_set_phy_mode ......................................................................... 35
3.4.28.
wifi_get_phy_mode ......................................................................... 36
3.4.29.
wifi_get_ip_info ............................................................................... 36
3.4.30.
wifi_set_ip_info ............................................................................... 37
3.4.31.
wifi_set_macaddr ............................................................................ 38
3.4.32.
wifi_get_macaddr ............................................................................ 38
3.4.33.
wifi_set_sleep_type ......................................................................... 39
3.4.34.
wifi_get_sleep_type......................................................................... 39
3.4.35.
wifi_status_led_install ..................................................................... 40
3.4.36.
wifi_status_led_uninstall ................................................................. 40
3.5.
.................................................................................. 41
3.5.1.
system_upgrade_userbin_check ..................................................... 41
3.5.2.
system_upgrade_flag_set ................................................................ 41
3.5.3.
system_upgrade_flag_check............................................................ 42
3.5.4.
system_upgrade_start ..................................................................... 42
3.5.5.
system_upgrade_reboot .................................................................. 42
3.6.
sniffer ............................................................................. 43
3.6.1.
wifi_promiscuous_enable ................................................................ 43
3.6.2.
wifi_set_promiscuous_rx_cb ........................................................... 43
3.6.3.
wifi_get_channel.............................................................................. 43
3.6.4.
wifi_set_channel .............................................................................. 44
3.7.
smart config ............................................................................ 44
5 / 91
Espressif Systems
February 9, 2015
ESP8266EX
3.7.1.
smartconfig_start ............................................................................. 44
3.7.2.
smartconfig_stop ............................................................................. 45
3.7.3.
get_smartconfig_status ................................................................... 46
3.8.
.......................................................................... 46
3.8.1.
......................................................................................... 46
3.8.1.1. espconn_delete ...................................................................... 46
3.8.1.2. espconn_gethostbyname ...................................................... 47
3.8.1.3. espconn_port .......................................................................... 48
3.8.1.4. espconn_regist_sentcb ......................................................... 48
3.8.1.5. espconn_regist_recvcb ......................................................... 49
3.8.1.6. espconn_sent_callback ......................................................... 49
3.8.1.7. espconn_recv_callback ......................................................... 50
3.8.1.8. espconn_sent.......................................................................... 50
3.8.2.
TCP ................................................................................. 51
3.8.2.1. espconn_accept ..................................................................... 51
3.8.2.2. espconn_secure_accept ....................................................... 51
3.8.2.3. espconn_regist_time.............................................................. 51
3.8.2.4. espconn_get_connection_info ............................................. 52
3.8.2.5. espconn_connect ................................................................... 53
3.8.2.6. espconn_connect_callback .................................................. 53
3.8.2.7. espconn_set_opt .................................................................... 53
3.8.2.8. espconn_disconnect .............................................................. 54
3.8.2.9. espconn_regist_connectcb ................................................... 54
3.8.2.10. espconn_regist_reconcb ....................................................... 55
3.8.2.11. espconn_regist_disconcb ..................................................... 55
3.8.2.12. espconn_secure_connect ..................................................... 56
3.8.2.13. espconn_secure_sent ........................................................... 56
3.8.2.14. espconn_secure_disconnect ................................................ 57
3.8.2.15. espconn_tcp_get_max_con.................................................. 57
3.8.2.16. espconn_tcp_set_max_con .................................................. 57
3.8.2.17. espconn_tcp_get_max_con_allow ...................................... 58
3.8.2.18. espconn_tcp_set_max_con_allow ...................................... 58
3.8.2.19. espconn_recv_hold ................................................................ 59
3.8.2.20. espconn_recv_unhold ........................................................... 59
3.8.3.
UDP ........................................................................................ 60
3.8.3.1. espconn_create ...................................................................... 60
3.8.3.2. espconn_igmp_join ................................................................ 60
3.8.3.3. espconn_igmp_leave ............................................................. 60
3.9.
AT ............................................................................................. 62
3.9.1.
at_response_ok................................................................................ 62
3.9.2.
at_response_error ........................................................................... 62
3.9.3.
at_cmd_array_regist ........................................................................ 62
3.9.4.
at_get_next_int_dec ........................................................................ 63
6 / 91
Espressif Systems
February 9, 2015
ESP8266EX
3.9.5.
at_data_str_copy ............................................................................. 63
3.9.6.
at_init ............................................................................................... 64
3.9.7.
at_port_print ................................................................................... 64
3.10.
json API ................................................................................... 65
3.10.1.
jsonparse_setup ............................................................................... 65
3.10.2.
jsonparse_next ................................................................................. 65
3.10.3.
jsonparse_copy_value ..................................................................... 65
3.10.4.
jsonparse_get_value_as_int ............................................................ 66
3.10.5.
jsonparse_get_value_as_long.......................................................... 66
3.10.6.
jsonparse_get_len............................................................................ 66
3.10.7.
jsonparse_get_value_as_type ......................................................... 67
3.10.8.
jsonparse_strcmp_value .................................................................. 67
3.10.9.
jsontree_set_up ............................................................................... 67
3.10.10.
jsontree_reset .................................................................................. 68
3.10.11.
jsontree_path_name ....................................................................... 68
3.10.12.
jsontree_write_int ........................................................................... 69
3.10.13.
jsontree_write_int_array ................................................................. 69
3.10.14.
jsontree_write_string ...................................................................... 69
3.10.15.
jsontree_print_next ......................................................................... 70
3.10.16.
jsontree_find_next ........................................................................... 70
4.
.................................................................................. 71
4.1.
...................................................................................... 71
4.2.
wifi ........................................................................................... 71
4.2.1.
station ............................................................................. 71
4.2.2.
softap .............................................................................. 72
4.2.3.
scan ......................................................................................... 72
4.3.
smart config ....................................................................... 73
4.4.
json .................................................................................. 74
4.3.1.
json .......................................................................................... 74
4.3.2.
json ...................................................................................... 75
4.5.
espconn ................................................................................... 76
4.4.1
function ................................................................................... 76
4.4.2
espconn ............................................................................................ 76
5.
.......................................................................................... 79
5.1.
GPIO API .................................................................................. 79
5.1.1.
PIN ........................................................................... 79
5.1.2.
gpio_output_set .............................................................................. 79
5.1.3.
GPIO .................................................................... 80
5.1.4.
GPIO .................................................................... 80
5.1.5.
gpio_pin_intr_state_set ................................................................... 81
5.1.6.
GPIO ........................................................................ 81
5.2.
UART API ............................................................................ 81
5.2.1.
uart_init ........................................................................................... 82
7 / 91
Espressif Systems
February 9, 2015
ESP8266EX
5.2.2.
uart0_tx_buffer ................................................................................ 82
5.2.3.
uart0_rx_intr_handler ..................................................................... 83
5.3.
i2c master ................................................................................ 83
5.3.1.
i2c_master_gpio_init ....................................................................... 83
5.3.2.
i2c_master_init ................................................................................ 84
5.3.3.
i2c_master_start .............................................................................. 84
5.3.4.
i2c_master_stop .............................................................................. 84
5.3.5.
i2c_master_send_ack ...................................................................... 85
5.3.6.
i2c_master_send_nack .................................................................... 85
5.3.7.
i2c_master_checkAck ...................................................................... 85
5.3.8.
i2c_master_readByte ....................................................................... 86
5.3.9.
i2c_master_writeByte ...................................................................... 86
5.4.
pwm ................................................................................................. 87
5.4.1.
pwm_init .......................................................................................... 87
5.4.2.
pwm_start ........................................................................................ 87
5.4.3.
pwm_set_duty ................................................................................. 87
5.4.4.
pwm_set_freq .................................................................................. 88
5.4.5.
pwm_get_duty ................................................................................. 88
5.4.6.
pwm_get_freq.................................................................................. 88
6.
.................................................................................................. 89
A.
ESPCONN ................................................................................. 89
A.1.
TCP client ................................................................................. 89
A.1.1.
................................................................................................. 89
A.1.2.
................................................................................................. 89
A.2.
TCP server ............................................................................... 89
A.2.1.
................................................................................................. 89
A.2.2.
................................................................................................. 90
B.
RTC ......................................................................... 90
8 / 91
Espressif Systems
February 9, 2015
ESP8266EX
1.
ESP8266 SDK
SDK API
ESP8266
9 / 91
Espressif Systems
February 9, 2015
ESP8266EX
2.
WIFITCP/IP
SDK
ESP8266
user_main.c
void usre_init(void)
10 / 91
Espressif Systems
February 9, 2015
ESP8266EX
3. SDK API
3.1.
\include\osapi.h
3.1.1. os_timer_arm
Void
os_timer_arm(ETSTimer
*ptimer,uint32_t
milliseconds,
bool
repeat_flag)
ETSTimer*ptimer 4.1
uint32_t milliseconds
bool repeat_flag
3.1.2. os_timer_disarm
11 / 91
Espressif Systems
February 9, 2015
ESP8266EX
3.1.3. os_timer_setfn
3.2.
3.2.1. system_restore
void system_restore(void)
3.2.2. system_restart
void system_restart(void)
12 / 91
Espressif Systems
February 9, 2015
ESP8266EX
3.2.3. system_timer_reinit
us timer timer
1 USE_US_TIMER
2system_timer_reinit user_init
3.2.4. system_init_done_cb
user_init
wifi_station_scan station
init_done_cb_t cb -
void to_scan(void)
{
wifi_station_scan(NULL,scan_done);
13 / 91
Espressif Systems
February 9, 2015
ESP8266EX
}
void user_init(void)
{
wifi_set_opmode(STATION_MODE);
system_init_done_cb(to_scan);
}
3.2.5. system_get_chip_id
id
uint32 system_get_chip_id(void)
id
3.2.6. system_deep_sleep
deep sleep us
user_init
uint32 time_in_us us
Espressif Systems
February 9, 2015
ESP8266EX
3.2.7. system_deep_sleep_set_option
deep sleep deep sleep
init esp_init_data_default.bin
uint8 option
TrueFalse
3.2.8. system_set_os_print
log
Uint8 onoff /
15 / 91
Espressif Systems
February 9, 2015
ESP8266EX
0x00
0x01
3.2.9. system_print_meminfo
data/rodata/bss/heap
3.2.10.
system_get_free_heap_size
heap
Uint32 system_get_free_heap_size(void)
Uint32 heap
3.2.11.
system_os_task
Espressif Systems
February 9, 2015
ESP8266EX
Os_task_t task
Uint8 prio 3 0/1/20
Os_event_t *queue
Uint8 qlen
TrueFalse
#define SIG_RX
#define TEST_QUEUE_LEN
os_event_t *testQueue;
void test_task (os_event_t *e)
{
switch (e->sig) {
case SIG_RX:
os_printf(sig_rx %c\n, (char)e->par);
break;
default:
break;
}
}
void task_init(void)
{
testQueue=(os_event_t*)os_malloc(sizeof(os_event_t)*TEST_QUEUE_LEN);
system_os_task(test_task,USER_TASK_PRIO_0,testQueue,TEST_QUEUE_
LEN);
}
17 / 91
Espressif Systems
February 9, 2015
ESP8266EX
3.2.12.
system_os_post
Uint8 prio
Os_signal_t sig
Os_param_t par
TrueFalse
void task_post(void)
{
system_os_post(USER_TASK_PRIO_0, SIG_RX, a);
}
sig_rx a
3.2.13.
system_get_time
us
uint32 system_get_time(void)
Null
18 / 91
Espressif Systems
February 9, 2015
ESP8266EX
3.2.14.
system_get_rtc_time
RTC RTC
system_get_rtc_time() 10 10 RTC
system_rtc_clock_cali_proc 5 RTC 5 us
10 x 5 = 50 us
deep sleep system_restart RTC
uint32 system_get_rtc_time(void)
Null
RTC
3.2.15.
system_rtc_clock_cali_proc
RTC
uint32 system_rtc_clock_cali_proc(void)
Null
3.2.16.
system_rtc_mem_write
Espressif Systems
February 9, 2015
ESP8266EX
|_ _ _ _ _system data _ _ _ _ _|_ _ _ _ _ _ _ _ _ user data _ _ _ _ _ _ _ _ _|
|
256 bytes
512 bytes
True False
3.2.17.
system_rtc_mem_read
256 bytes
512 bytes
Espressif Systems
February 9, 2015
ESP8266EX
uint32 save_size byte
True False
3.2.18.
system_uart_swap
void
system_uart_swap (void)
NULL
NULL
3.2.19.
system_adc_read
adc
NULL
Adc
21 / 91
Espressif Systems
February 9, 2015
ESP8266EX
Null
SPI Flash id
3.3.2. spi_flash_erase_sector
Flash
flash Espressif IOT Flash
Typedef enum{
SPI_FLASH_RESULT_OK,
SPI_FLASH_RESULT_ERR,
SPI_FLASH_RESULT_TIMEOUT
}SpiFlashOpResult
3.3.3. spi_flash_write
Flash
flash Espressif IOT Flash
22 / 91
Espressif Systems
February 9, 2015
ESP8266EX
uint32 des_addr
- Flash
Typedef enum{
SPI_FLASH_RESULT_OK,
SPI_FLASH_RESULT_ERR,
SPI_FLASH_RESULT_TIMEOUT
}SpiFlashOpResult
3.3.4. spi_flash_read
flash
flash Espressif IOT Flash
Typedef enum{
SPI_FLASH_RESULT_OK,
23 / 91
Espressif Systems
February 9, 2015
ESP8266EX
SPI_FLASH_RESULT_ERR,
SPI_FLASH_RESULT_TIMEOUT
}SpiFlashOpResult
3.4. WIFI
3.4.1. wifi_get_opmode
wifi
wifi
#define STATION_MODE
0x01
#define SOFTAP_MODE
0x02
#define STATIONAP_MODE
0x03
3.4.2. wifi_set_opmode
wifi STATIONSOFTAPSTATION+SOFTAP
esp_iot_sdk_v0.9.2 v0.9.2
uint8 opmodewifi
24 / 91
Espressif Systems
February 9, 2015
ESP8266EX
#define STATION_MODE
0x01
#define SOFTAP_MODE
0x02
#define STATIONAP_MODE
0x03
True False
3.4.3. wifi_station_get_config
wifi station
True False
3.4.4. wifi_station_set_config
wifi station
user_init wifi_station_set_config
wifi_station_connect
station_config.bssid_set 0
True False
3.4.5. wifi_station_connect
wifi station
25 / 91
Espressif Systems
February 9, 2015
ESP8266EX
wifi_station_disconnect
wifi_station_connect
bool wifi_station_connect(void)
True False
3.4.6. wifi_station_disconnect
wifi station
bool wifi_station_disconnect(void)
True False
3.4.7. wifi_station_get_connect_status
wifi station AP
enum{
STATION_IDLE = 0,
STATION_CONNECTING,
STATION_WRONG_PASSWORD,
26 / 91
Espressif Systems
February 9, 2015
ESP8266EX
STATION_NO_AP_FOUND,
STATION_CONNECT_FAIL,
STATION_GOT_IP
};
3.4.8. wifi_station_scan
AP
user_init station
struct scan_config{
uint8 *ssid;
// AP ssid
uint8 *bssid;
// AP bssid
uint8 channel;
//
uint8 show_hidden;
// ssid AP
};
config NULL AP
config ssidbssid NULL channel
channel AP
config ssid bssid NULLchannel 0
AP
scan_done_cb_t cb - AP function
True False
27 / 91
Espressif Systems
February 9, 2015
ESP8266EX
3.4.9. scan_done_cb_t
scan function
wifi_station_scan(&config, scan_done);
static void ICACHE_FLASH_ATTR
scan_done(void *arg, STATUS status)
{
if (status == OK)
{
struct bss_info *bss_link = (struct bss_info *)arg;
bss_link = bss_link->next.stqe_next;//ignore first
}
}
3.4.10.
wifi_station_ap_number_set
ESP8266 station AP
Espressif Systems
February 9, 2015
ESP8266EX
True False
3.4.11.
wifi_station_get_ap_info
ESP8266 station AP 5
AP
3.4.12.
wifi_station_ap_change
ESP8266 station AP
uint8 current_ap_id AP 0
True False
3.4.13.
wifi_station_get_current_ap_id
APESP8266 AP
29 / 91
Espressif Systems
February 9, 2015
ESP8266EX
0 AP ESP8266
AP
AP id AP ESP8266
3.4.14.
wifi_station_get_auto_connect
ESP8266 station AP ()
uint8 wifi_station_get_auto_connect(void)
Null
0 0
3.4.15.
wifi_station_set_auto_connect
ESP8266 station AP ()
api user_init
uint8 set 01
True False
30 / 91
Espressif Systems
February 9, 2015
ESP8266EX
3.4.16.
wifi_station_dhcpc_start
bool wifi_station_dhcpc_start(void)
Null
True False
3.4.17.
wifi_station_dhcpc_stop
bool wifi_station_dhcpc_stop(void)
Null
True False
3.4.18.
wifi_station_dhcpc_status
Null
enum dhcp_status {
31 / 91
Espressif Systems
February 9, 2015
ESP8266EX
DHCP_STOPPED,
DHCP_STARTED
};
3.4.19.
wifi_softap_get_config
wifi softap
True False
3.4.20.
wifi_softap_set_config
wifi softap
True False
3.4.21.
wifi_softap_get_station_info
32 / 91
Espressif Systems
February 9, 2015
ESP8266EX
3.4.22.
wifi_softap_free_station_info
macip
"MACSTR",
ip
"IPSTR"\n",
MAC2STR(station->bssid), IP2STR(&station->ip));
next_station = STAILQ_NEXT(station, next);
os_free(station);
//
station = next_station;
}
Espressif Systems
February 9, 2015
ESP8266EX
station = STAILQ_NEXT(station, next);
}
wifi_softap_free_station_info(); //
3.4.23.
wifi_softap_dhcps_start
bool wifi_softap_dhcps_start(void)
Null
True False
3.4.24.
wifi_softap_dhcps_stop
bool wifi_softap_dhcps_stop(void)
Null
True False
3.4.25.
wifi_softap_set_dhcps_lease
Espressif Systems
February 9, 2015
ESP8266EX
struct dhcps_lease {
uint32 start_ip;
uint32 end_ip;
};
True False
3.4.26.
wifi_softap_dhcps_status
NULL
enum dhcp_status {
DHCP_STOPPED,
DHCP_STARTED
};
3.4.27.
wifi_set_phy_mode
ESP8266 802.11b/g/n.
ESP8266 softAP bg
Espressif Systems
February 9, 2015
ESP8266EX
PHY_MODE_11G = 2,
PHY_MODE_11N = 3
};
True False
3.4.28.
wifi_get_phy_mode
ESP8266 802.11b/g/n
Null
enum phy_mode{
PHY_MODE_11B = 1,
PHY_MODE_11G = 2,
PHY_MODE_11N = 3
};
3.4.29.
wifi_get_ip_info
Espressif Systems
February 9, 2015
ESP8266EX
SOFTAP_IF 0x01
struct ip_info *info ip
True False
3.4.30.
wifi_set_ip_info
ip
0x00
#define SOFTAP_IF
0x01
ip
True False
37 / 91
Espressif Systems
February 9, 2015
ESP8266EX
3.4.31.
wifi_set_macaddr
mac
user_init mac
uint8 *macaddr
#define STATION_IF
0x00
#define SOFTAP_IF
0x01
mac
wifi_set_macaddr(SOFTAP_IF, sofap_mac);
wifi_set_macaddr(STATION_IF, sta_mac);
True False
3.4.32.
wifi_get_macaddr
38 / 91
Espressif Systems
February 9, 2015
ESP8266EX
True False
3.4.33.
wifi_set_sleep_type
NONE_SLEEP_T
ESP8266 station Modem sleeplight
sleepdeep sleep Modem sleep Deep sleep
system_deep_sleep
True False
3.4.34.
wifi_get_sleep_type
NULL
Enum sleep_type{
NONE_SLEEP_T = 0;
LIGHT_SLEEP_T,
MODEM_SLEEP_T
};
39 / 91
Espressif Systems
February 9, 2015
ESP8266EX
3.4.35.
wifi_status_led_install
uint8 gpio_idgpio
uint8 gpio_namegpio mux
uint8 gpio_funcgpio
PERIPHS_IO_MUX_GPIO0_U
#define HUMITURE_WIFI_LED_IO_NUM
#define HUMITURE_WIFI_LED_IO_FUNC
FUNC_GPIO0
wifi_status_led_install(HUMITURE_WIFI_LED_IO_NUM,
HUMITURE_WIFI_LED_IO_MUX, HUMITURE_WIFI_LED_IO_FUNC)
3.4.36.
wifi_status_led_uninstall
Void wifi_status_led_uninstall ()
NULL
NULL
40 / 91
Espressif Systems
February 9, 2015
ESP8266EX
3.5.
3.5.1. system_upgrade_userbin_check
firmware user1 user2
uint8 system_upgrade_userbin_check()
3.5.2. system_upgrade_flag_set
upgrade flag
system_upgrade_start Espressif
SDK flag
spi_flash_write
UPGRADE_FLAG_FINISH system_upgrade_reboot
uint8 flag
#define UPGRADE_FLAG_IDLE
0x00
41 / 91
Espressif Systems
February 9, 2015
ESP8266EX
3.5.3. system_upgrade_flag_check
upgrade flag
uint8 system_upgrade_flag_check()
#define UPGRADE_FLAG_IDLE
0x00
3.5.4. system_upgrade_start
True
False
upgrade start
3.5.5. system_upgrade_reboot
42 / 91
Espressif Systems
February 9, 2015
ESP8266EX
3.6. sniffer
3.6.1. wifi_promiscuous_enable
sniffer
3.6.2. wifi_set_promiscuous_rx_cb
wifi call back
wifi_promiscuous_cb_t cb
3.6.3. wifi_get_channel
sniffer
43 / 91
Espressif Systems
February 9, 2015
ESP8266EX
3.6.4. wifi_set_channel
sniffer
uint8 channel
True False
Espressif Systems
February 9, 2015
ESP8266EX
struct station_config
True False
void ICACHE_FLASH_ATTR
smartconfig_done(void *data)
{
struct station_config *sta_conf = data;
wifi_station_set_config(sta_conf);
wifi_station_disconnect();
wifi_station_connect();
user_devicefind_init();
user_esp_platform_init();
}
smartconfig_start(SC_TYPE_ESPTOUCH,smartconfig_done);
3.7.2. smartconfig_stop
smartconfig_start
AP
bool smartconfig_stop(void)
NULL
True False
45 / 91
Espressif Systems
February 9, 2015
ESP8266EX
3.7.3. get_smartconfig_status
smartconfig_stop smartconfig_stop
sc_status get_smartconfig_status(void)
NULL
typedef enum
SC_STATUS_FIND_CHANNEL = 0,
SC_STATUS_GETTING_SSID_PSWD,
SC_STATUS_GOT_SSID_PSWD,
SC_STATUS_LINK,
} sc_status;
3.8.
\include\espconn.h
TCP UDP
TCP TCP
UDP UDP
3.8.1.
3.8.1.1.
espconn_delete
TCP espconn_accept ,
UDPespconn_create
46 / 91
Espressif Systems
February 9, 2015
ESP8266EX
Sin8 espconn_delete(struct espconn *espconn)
0-
3.8.1.2.
succeed#define ESPCONN_OK 0
Erro espconn.h
espconn_gethostbyname
Err_tESPCONN_OK
ESPCONN_INPROGRESS
ESPCONN_ARG
IoT Demo
ip_addr_t esp_server_ip;
LOCAL void ICACHE_FLASH_ATTR
user_esp_platform_dns_found(const char *name, ip_addr_t *ipaddr, void *arg)
{
struct espconn *pespconn = (struct espconn *)arg;
47 / 91
Espressif Systems
February 9, 2015
ESP8266EX
os_printf("user_esp_platform_dns_found %d.%d.%d.%d\n",
*((uint8 *)&ipaddr->addr), *((uint8 *)&ipaddr->addr + 1),
*((uint8 *)&ipaddr->addr + 2), *((uint8 *)&ipaddr->addr + 3));
}
Void dns_test(void)
{
espconn_gethostbyname(pespconn,iot.espressif.cn,&esp_server_ip,user_es
p_platform_dns_found);
}
3.8.1.3.
espconn_port
uint32 espconn_port(void);
uint32
3.8.1.4.
espconn_regist_sentcb
Sint8
espconn_regist_sentcb(struct
espconn
*espconn,
espconn_sent_callback sent_cb)
Espressif Systems
February 9, 2015
ESP8266EX
espconn_sent_callback sent_cb
0-
3.8.1.5.
succeed#define ESPCONN_OK 0
Erro espconn.h
espconn_regist_recvcb
Sint8
espconn_regist_recvcb(struct
espconn
*espconn,
espconn_recv_callback recv_cb)
0-
3.8.1.6.
succeed#define ESPCONN_OK 0
Erro espconn.h
espconn_sent_callback
void *arg
49 / 91
Espressif Systems
February 9, 2015
ESP8266EX
3.8.1.7.
espconn_recv_callback
void *arg
char *pdata
unsigned short len
3.8.1.8.
espconn_sent
espconn_sent_callback
espconn_sent
0-
50 / 91
succeed#define ESPCONN_OK 0
Erro espconn.h
Espressif Systems
February 9, 2015
ESP8266EX
3.8.2. TCP
3.8.2.1.
espconn_accept
TCP server
0-
3.8.2.2.
succeed#define ESPCONN_OK 0
Erro espconn.h
espconn_secure_accept
0-
3.8.2.3.
succeed#define ESPCONN_OK 0
Erro espconn.h
espconn_regist_time
51 / 91
Espressif Systems
February 9, 2015
ESP8266EX
Sin8 espconn_regist_time(struct espconn *espconn, uint32 interval, uint8
type_flag)
01
0-
3.8.2.4.
succeed#define ESPCONN_OK 0
Erro espconn.h
espconn_get_connection_info
0 server1ssl server
0-
52 / 91
succeed#define ESPCONN_OK 0
Erro espconn.h
Espressif Systems
February 9, 2015
ESP8266EX
3.8.2.5.
espconn_connect
0-
3.8.2.6.
succeed#define ESPCONN_OK 0
Erro espconn.h
espconn_connect_callback
TCP
void *arg
3.8.2.7.
espconn_set_opt
TCP
Espressif Systems
February 9, 2015
ESP8266EX
uint8 opt 0, TCP 2min
1 TCP nalgo
0-
succeed#define ESPCONN_OK 0
Erro espconn.h
3.8.2.8.
espconn_disconnect
TCP
0-
3.8.2.9.
succeed#define ESPCONN_OK 0
Erro espconn.h
espconn_regist_connectcb
TCP
Sint8
espconn_regist_connectcb(struct
espconn
*espconn,
espconn_connect_callback connect_cb)
54 / 91
Espressif Systems
February 9, 2015
ESP8266EX
struct espconn *espconn
espconn_connect_callback connect_cb
0-
succeed#define ESPCONN_OK 0
Erro espconn.h
3.8.2.10. espconn_regist_reconcb
TCP
reconnect callback
reconnect callbackespconn_sent
reconnect callback reconnect callback
Sint8
espconn_regist_reconcb(struct
espconn
*espconn,
espconn_connect_callback recon_cb)
0-
succeed#define ESPCONN_OK 0
Erro espconn.h
3.8.2.11. espconn_regist_disconcb
TCP
Sint8
espconn_regist_disconcb(struct
espconn
*espconn,
espconn_connect_callback discon_cb)
55 / 91
Espressif Systems
February 9, 2015
ESP8266EX
0-
succeed#define ESPCONN_OK 0
Erro espconn.h
3.8.2.12. espconn_secure_connect
ESP8266 TCP client TCP SSL
0-
succeed#define ESPCONN_OK 0
Erro espconn.h
3.8.2.13. espconn_secure_sent
TCP SSL
Espressif Systems
February 9, 2015
ESP8266EX
uint16 lengthsent
0-
succeed#define ESPCONN_OK 0
Erro espconn.h
3.8.2.14. espconn_secure_disconnect
TCP SSL
0-
succeed#define ESPCONN_OK 0
Erro espconn.h
3.8.2.15. espconn_tcp_get_max_con
TCP
uint8 espconn_tcp_get_max_con(void)
TCP
3.8.2.16. espconn_tcp_set_max_con
TCP
57 / 91
Espressif Systems
February 9, 2015
ESP8266EX
Sint8 espconn_tcp_set_max_con(uint8 num)
0-
succeed#define ESPCONN_OK 0
Erro espconn.h
3.8.2.17. espconn_tcp_get_max_con_allow
ESP8266 TCP server TCP client
3.8.2.18. espconn_tcp_set_max_con_allow
ESP8266 TCP server TCP client
058 / 91
succeed#define ESPCONN_OK 0
Erro espconn.h
Espressif Systems
February 9, 2015
ESP8266EX
3.8.2.19. espconn_recv_hold
TCP
tcp 1460*5
Byte
0-
succeed#define ESPCONN_OK 0
Erro espconn.h ESPCONN_ARG ,
espconn tcp .
3.8.2.20. espconn_recv_unhold
TCP
0-
succeed#define ESPCONN_OK 0
Erro espconn.h ESPCONN_ARG ,
espconn tcp .
59 / 91
Espressif Systems
February 9, 2015
ESP8266EX
3.8.3. UDP
3.8.3.1.
espconn_create
UDP
0-
3.8.3.2.
succeed#define ESPCONN_OK 0
Erro espconn.h
espconn_igmp_join
ip_addr_t *host_ip ip
ip_addr_t *multicast_ip ip
0-
3.8.3.3.
succeed#define ESPCONN_OK 0
Erro espconn.h
espconn_igmp_leave
60 / 91
Espressif Systems
February 9, 2015
ESP8266EX
ip_addr_t *host_ip ip
ip_addr_t *multicast_ip ip
0-
61 / 91
succeed#define ESPCONN_OK 0
Erro espconn.h
Espressif Systems
February 9, 2015
ESP8266EX
3.9. AT
AT esp_iot_sdk/examples/5.at/user/user_main.c
3.9.1. at_response_ok
OK AT Port (UART0)
void at_response_ok(void)
NULL
NULL
3.9.2. at_response_error
ERROR AT Port (UART0)
void at_response_error(void)
NULL
NULL
3.9.3. at_cmd_array_regist
AT
62 / 91
Espressif Systems
February 9, 2015
ESP8266EX
at_funcation * custom_at_cmd_arrar - AT
uint32 cmd_num -
NULL
esp_iot_sdk/examples/5.at/user/user_main.c
3.9.4. at_get_next_int_dec
AT int
TRUE( True 1)
FALSE 10 bytes\r
-
esp_iot_sdk/examples/5.at/user/user_main.c
3.9.5. at_data_str_copy
AT
char * p_dest -
char ** p_src - *p_src AT
63 / 91
Espressif Systems
February 9, 2015
ESP8266EX
int32 max_len -
-1
esp_iot_sdk/examples/5.at/user/user_main.c
3.9.6. at_init
AT
NULL
NULL
esp_iot_sdk/examples/5.at/user/user_main.c
3.9.7. at_port_print
AT PORT(UART0)
NULL
esp_iot_sdk/examples/5.at/user/user_main.c
64 / 91
Espressif Systems
February 9, 2015
ESP8266EX
3.10.1.
jsonparse_setup
json
3.10.2.
jsonparse_next
json
int
3.10.3.
jsonparse_copy_value
65 / 91
Espressif Systems
February 9, 2015
ESP8266EX
Int jsonparse_copy_value(struct jsonparse_state *state, char *str, int size)
int
3.10.4.
jsonparse_get_value_as_int
json
int
3.10.5.
jsonparse_get_value_as_long
json
long
3.10.6.
jsonparse_get_len
json
66 / 91
Espressif Systems
February 9, 2015
ESP8266EX
Int jsonparse_get_value_len(struct jsonparse_state *state)
int json
3.10.7.
jsonparse_get_value_as_type
json
intjson
3.10.8.
jsonparse_strcmp_value
json
int
3.10.9.
jsontree_set_up
json
Espressif Systems
February 9, 2015
ESP8266EX
struct jsontree_value *root, int (* putchar)(int))
3.10.10. jsontree_reset
json
3.10.11. jsontree_path_name
json
char*
68 / 91
Espressif Systems
February 9, 2015
ESP8266EX
3.10.12. jsontree_write_int
json
3.10.13. jsontree_write_int_array
json
3.10.14. jsontree_write_string
json
69 / 91
Espressif Systems
February 9, 2015
ESP8266EX
struct jsontree_context *js_ctxjson
const char* text
3.10.15. jsontree_print_next
json
intjson
3.10.16. jsontree_find_next
json
70 / 91
Espressif Systems
February 9, 2015
ESP8266EX
4.
4.1.
typedef void ETSTimerFunc(void *timer_arg);
*timer_next;
uint32_t
timer_expire;
uint32_t
timer_period;
ETSTimerFunc
void
*timer_func;
*timer_arg;
} ETSTimer;
4.2. wifi
4.2.1. station
struct station_config {
uint8 ssid[32];
uint8 password[64];
uint8 bssid_set;
uint8 bssid[6];
};
71 / 91
Espressif Systems
February 9, 2015
ESP8266EX
4.2.2. softap
typedef enum _auth_mode {
AUTH_OPEN
= 0,
AUTH_WEP,
AUTH_WPA_PSK,
AUTH_WPA2_PSK,
AUTH_WPA_WPA2_PSK
} AUTH_MODE;
struct softap_config {
uint8 ssid[32];
uint8 password[64];
uint8 ssid_len;
uint8 channel;
uint8 authmode;
uint8 ssid_hidden;
uint8 max_connection;
uint8 beacon_interval;
};
4.2.3. scan
struct scan_config {
uint8 *ssid;
uint8 *bssid;
uint8 channel;
uint8 show_hidden; // ssid AP
72 / 91
Espressif Systems
February 9, 2015
ESP8266EX
};
struct bss_info {
STAILQ_ENTRY(bss_info)
next;
u8 bssid[6];
u8 ssid[32];
u8 channel;
s8 rssi;
u8 authmode;
uint8 is_hidden; // AP SSID .
};
typedef void (* scan_done_cb_t)(void *arg, STATUS status);
SC_STATUS_FIND_CHANNEL = 0,
SC_STATUS_GETTING_SSID_PSWD,
SC_STATUS_GOT_SSID_PSWD,
SC_STATUS_LINK,
} sc_status;
typedef enum
SC_TYPE_ESPTOUCH = 0,
SC_TYPE_AIRKISS,
} sc_type;
73 / 91
Espressif Systems
February 9, 2015
ESP8266EX
4.4. json
4.3.1. json
struct jsontree_value {
uint8_t type;
};
struct jsontree_pair {
const char *name;
struct jsontree_value *value;
};
struct jsontree_context {
struct jsontree_value *values[JSONTREE_MAX_DEPTH];
uint16_t index[JSONTREE_MAX_DEPTH];
int (* putchar)(int);
uint8_t depth;
uint8_t path;
int callback_state;
};
struct jsontree_callback {
uint8_t type;
int (* output)(struct jsontree_context *js_ctx);
int (* set)(struct jsontree_context *js_ctx, struct jsonparse_state *parser);
};
struct jsontree_object {
74 / 91
Espressif Systems
February 9, 2015
ESP8266EX
uint8_t type;
uint8_t count;
struct jsontree_pair *pairs;
};
struct jsontree_array {
uint8_t type;
uint8_t count;
struct jsontree_value **values;
};
struct jsonparse_state {
const char *json;
int pos;
int len;
int depth;
int vstart;
int vlen;
char vtype;
char error;
char stack[JSONPARSE_MAX_DEPTH];
};
4.3.2. json
#define
JSONTREE_OBJECT(name,
...)
\
static struct jsontree_pair jsontree_pair_##name[] = {__VA_ARGS__};
75 / 91
Espressif Systems
February 9, 2015
ESP8266EX
JSON_TYPE_OBJECT,
sizeof(jsontree_pair_##name)/sizeof(struct jsontree_pair),
jsontree_pair_##name }
JSONTREE_ARRAY(name,
...)
\
static struct jsontree_value* jsontree_value_##name[] = {__VA_ARGS__};
static struct jsontree_array name = {
JSON_TYPE_ARRAY,
\
\
sizeof(jsontree_value_##name)/sizeof(struct jsontree_value*),
jsontree_value_##name }
4.5. espconn
4.4.1 function
/** callback prototype to inform about events for a espconn */
typedef void (* espconn_recv_callback)(void *arg, char *pdata, unsigned short
len);
typedef void (* espconn_callback)(void *arg, char *pdata, unsigned short len);
typedef void (* espconn_connect_callback)(void *arg);
4.4.2 espconn
typedef void* espconn_handle;
typedef struct _esp_tcp {
int client_port;
int server_port;
char ipaddr[4];
espconn_connect_callback connect_callback;
76 / 91
Espressif Systems
February 9, 2015
ESP8266EX
espconn_connect_callback reconnect_callback;
espconn_connect_callback disconnect_callback;
} esp_tcp;
= 0,
/* ESPCONN_TCP Group */
ESPCONN_TCP
= 0x10,
/* ESPCONN_UDP Group */
ESPCONN_UDP
= 0x20,
};
/** Current state of the espconn. Non-TCP espconn are always in state
ESPCONN_NONE! */
enum espconn_state {
ESPCONN_NONE,
ESPCONN_WAIT,
ESPCONN_LISTEN,
ESPCONN_CONNECT,
ESPCONN_WRITE,
ESPCONN_READ,
ESPCONN_CLOSE
};
77 / 91
Espressif Systems
February 9, 2015
ESP8266EX
78 / 91
Espressif Systems
February 9, 2015
ESP8266EX
5.
5.1. GPIO API
gpio API \user\ user_plug.c
5.1.1. PIN
PIN_PULLUP_DIS(PIN_NAME)
PIN_PULLUP_EN(PIN_NAME)
PIN_PULLDWN_DIS(PIN_NAME)
PIN_PULLDWN_EN(PIN_NAME)
PIN_FUNC_SELECT(PIN_NAME, FUNC)
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U,
FUNC_GPIO12);
MTDI GPIO12
5.1.2. gpio_output_set
gpio
void
gpio_output_set(uint32
set_mask,
uint32
clear_mask,
uint32
uint32 set_mask 1 0
79 / 91
Espressif Systems
February 9, 2015
ESP8266EX
uint32 clear_mask 1
0
uint32 enable_mask
uint32 disable_mask
5.1.3. GPIO
GPIO_OUTPUT_SET(gpio_no, bit_value)
gpio_no bit_value 5.1.2
GPIO_DIS_OUTPUT(gpio_no)
gpio_no 5.1.2
GPIO_INPUT_GET(gpio_no)
gpio_no
5.1.4. GPIO
ETS_GPIO_INTR_ATTACH(func, arg)
GPIO
ETS_GPIO_INTR_DISABLE()
GPIO
ETS_GPIO_INTR_ENABLE()
GPIO
80 / 91
Espressif Systems
February 9, 2015
ESP8266EX
5.1.5. gpio_pin_intr_state_set
gpio
typedef enum{
GPIO_PIN_INTR_DISABLE = 0,
GPIO_PIN_INTR_POSEDGE= 1,
GPIO_PIN_INTR_NEGEDGE= 2,
GPIO_PIN_INTR_ANYEGDE=3,
GPIO_PIN_INTR_LOLEVEL= 4,
GPIO_PIN_INTR_HILEVEL = 5
}GPIO_INT_TYPE;
5.1.6. GPIO
GPIO
uint32 gpio_status;
gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
//clear interrupt status
GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status);
81 / 91
Espressif Systems
February 9, 2015
ESP8266EX
5.2.1. uart_init
uart uart
UartBautRate uart0_bruart0
UartBautRate uart1_bruart1
typedef enum {
BIT_RATE_9600
= 9600,
BIT_RATE_19200 = 19200,
BIT_RATE_38400 = 38400,
BIT_RATE_57600 = 57600,
BIT_RATE_74880 = 74880,
BIT_RATE_115200 = 115200,
BIT_RATE_230400 = 230400,
BIT_RATE_460800 = 460800,
BIT_RATE_921600 = 921600
} UartBautRate;
5.2.2. uart0_tx_buffer
UART0
Uint8 *buf
Uint16 len
82 / 91
Espressif Systems
February 9, 2015
ESP8266EX
5.2.3. uart0_rx_intr_handler
UART0
0x100 0x100
Void*para RcvMsgBuff
GPIO open-drain)
GPIO I2C data clock
5.3.1. i2c_master_gpio_init
i2c master GPIO
83 / 91
Espressif Systems
February 9, 2015
ESP8266EX
5.3.2. i2c_master_init
i2c
Void i2c_master_init(void)
5.3.3. i2c_master_start
i2c
Void i2c_master_start(void)
5.3.4. i2c_master_stop
i2c
Void i2c_master_stop(void)
84 / 91
Espressif Systems
February 9, 2015
ESP8266EX
5.3.5. i2c_master_send_ack
i2c ACK
NULL
5.3.6. i2c_master_send_nack
i2c NACK
NULL
5.3.7. i2c_master_checkAck
slave ACK
NULL
85 / 91
Espressif Systems
February 9, 2015
ESP8266EX
5.3.8. i2c_master_readByte
slave
uint8
5.3.9. i2c_master_writeByte
slave
uint8 wrdata
86 / 91
Espressif Systems
February 9, 2015
ESP8266EX
5.4. pwm
4 PWM pwm.h GPIO
5.4.1. pwm_init
pwm gpio
Uint16 freqpwm
uint8 *duty
5.4.2. pwm_start
pwm pwm
5.4.3. pwm_set_duty
uint8 duty
87 / 91
Espressif Systems
February 9, 2015
ESP8266EX
uint8 channel
5.4.4. pwm_set_freq
pwm
Uint16 freqpwm
5.4.5. pwm_get_duty
uint8
5.4.6. pwm_get_freq
pwm
Uint16 pwm_get_freq(void)
88 / 91
Espressif Systems
February 9, 2015
ESP8266EX
Uint16
6.
A. ESPCONN
ESP8266 TCP client TCP server
A.1.2.
1) espconn
2) connect recv
3) espconn_connect TCP server
4) connect
disconnect
5) recv sent disconnect
Espressif Systems
February 9, 2015
ESP8266EX
server
ESP8266 softap server
A.2.2.
1) espconn
2) connect recv
3) espconn_accept host
connect
B. RTC
RTC system_restart
RTC memory
void user_init(void)
{
// RTC
//
// RTC memory
if( system_rtc_mem_read(0, &rtc_reg_val, 4) ){
os_printf("rtc mem val : 0x%08x\n\r",rtc_reg_val);
}else{
90 / 91
Espressif Systems
February 9, 2015
ESP8266EX
os_printf("rtc mem val error\n\r");
}
rtc_reg_val++;
os_printf("rtc mem val write\n\r");
system_rtc_mem_write(0, &rtc_reg_val, 4) ; // RTC memory
rtc_time2 = system_get_rtc_time();
stime2 = system_get_time();
os_delay_us(500000);
system_restart();
91 / 91
Espressif Systems
February 9, 2015