You are on page 1of 91

ESP8266EX

Espressif IoT SDK

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)

SDK json API

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

Void os_timer_disarm(ETSTimer *ptimer)

ETSTimer *ptimer 4.1

11 / 91

Espressif Systems

February 9, 2015

ESP8266EX

3.1.3. os_timer_setfn

Void os_timer_setfn(ETSTimer *ptimer, ETSTimerFunc *pfunction, void


*parg)

ETSTimer *ptimer 4.1


TESTimerFunc *pfunction
void*parg

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

Void system_timer_reinit (void)

3.2.4. system_init_done_cb
user_init
wifi_station_scan station

void system_init_done_cb(init_done_cb_t cb)

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

void system_deep_sleep(uint32 time_in_us)

uint32 time_in_us us

XPD_DCDC 0R EXT_RSTB Deep sleep


14 / 91

Espressif Systems

February 9, 2015

ESP8266EX

system_deep_sleep(0) GPIO RST

3.2.7. system_deep_sleep_set_option
deep sleep deep sleep
init esp_init_data_default.bin

bool system_deep_sleep_set_option(uint8 option)

uint8 option

- option=0 init byte 108


option>0 init byte 108

deep_sleep_set_option(0) init byte 108 deep sleep


RF_CAL
deep_sleep_set_option(1) deep sleep
RF_CAL
deep_sleep_set_option(2) deep sleep RF_cal
deep_sleep_set_option(4) deep sleep RF modem
sleep

TrueFalse

3.2.8. system_set_os_print
log

Void system_set_os_print(uint8 onoff)

Uint8 onoff /
15 / 91

Espressif Systems

February 9, 2015

ESP8266EX
0x00
0x01

3.2.9. system_print_meminfo
data/rodata/bss/heap

Void system_print_meminfo (void)

3.2.10.

system_get_free_heap_size

heap

Uint32 system_get_free_heap_size(void)

Uint32 heap

3.2.11.

system_os_task

bool system_os_task(os_task_t task, uint8 prio, os_event_t *queue, uint8


qlen)
16 / 91

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

bool system_os_post (uint8 prio, os_signal_t sig, os_param_t par)

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

RTC usbit11 bit0


RTC

3.2.16.

system_rtc_mem_write

deep sleep RTC RTC


memory user data 512 bytes
19 / 91

Espressif Systems

February 9, 2015

ESP8266EX
|_ _ _ _ _system data _ _ _ _ _|_ _ _ _ _ _ _ _ _ user data _ _ _ _ _ _ _ _ _|
|

256 bytes

512 bytes

RTC memory 4 des_addr block


number4 block user data des_addr
256/4 = 64save size

bool system_rtc_mem_write (uint32 des_addr, void * src_addr, uint32


save_size)

uint32 des_addr rtc memory des_addr >=64


void * src_addr
uint32 save_size byte

True False

3.2.17.

system_rtc_mem_read

RTC memory user data 512 bytes

|_ _ _ _ _system data _ _ _ _ _|_ _ _ _ _ _ _ _ _ user data _ _ _ _ _ _ _ _ _|


|

256 bytes

512 bytes

RTC memory 4 src_addr block


number4 block user data src_addr
256/4 = 64save size

bool system_rtc_mem_read (uint32 src_addr, void * des_addr, uint32


save_size)

uint32 src_addr rtc memory src_addr >=64


void * des_addr
20 / 91

Espressif Systems

February 9, 2015

ESP8266EX
uint32 save_size byte

True False

3.2.18.

system_uart_swap

UART0 MTCK UART0 RXMTDO UART0 TX


MTDO(U0CTS) MTCK(U0RTS) UART0
UART0 ROM LOG

void

system_uart_swap (void)

NULL

NULL

3.2.19.

system_adc_read

adc

Uint16 system_adc_read (void)

NULL

Adc

21 / 91

Espressif Systems

February 9, 2015

ESP8266EX

3.3. SPI Flash


3.3.1. spi_flash_get_id
spi flash id

Uint32 spi_flash_get_id (void)

Null

SPI Flash id

3.3.2. spi_flash_erase_sector
Flash
flash Espressif IOT Flash

SpiFlashOpResult spi_flash_erase_sector (uint16 sec)

uint16 sec 0 4KB

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

SpiFlashOpResult spi_flash_write (uint32 des_addr, uint32 *src_addr,


uint32 size)

uint32 des_addr

- Flash

uint32 *src_addr - Flash


Uint32 size -

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

SpiFlashOpResult spi_flash_read(uint32 src_addr, uint32 * des_addr,


uint32 size)

uint32 src_addr - Flash


uint32 * des_addr
Uint32 size -

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

uint8 wifi_get_opmode (void)

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

bool wifi_set_opmode (uint8 opmode)

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

bool wifi_station_get_config (struct station_config *config)

struct station_config *configwifi 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

bool wifi_station_set_config (struct station_config *config)

struct station_config *configwifi station

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

uint8 wifi_station_get_connect_status (void)

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

bool wifi_station_scan (struct scan_config *config, scan_done_cb_t cb);

struct scan_config{
uint8 *ssid;

// AP ssid

uint8 *bssid;

// AP bssid

uint8 channel;

//

uint8 show_hidden;

// ssid AP

};

struct scan_config *config AP NULL

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

void scan_done_cb_t (void *arg, STATUS status);

void *arg AP arg struct


bss_info AP AP
struct bss_info
STATUS status

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

bool wifi_station_ap_number_set (uint8 ap_number);


28 / 91

Espressif Systems

February 9, 2015

ESP8266EX

uint8 ap_number AP MAX: 5

True False

3.4.11.

wifi_station_get_ap_info

ESP8266 station AP 5

uint8 wifi_station_get_ap_info(struct station_config config[])

struct station_config config[] AP 5


5

AP

struct station_config config[5];


int i = wifi_station_get_ap_info(config);

3.4.12.

wifi_station_ap_change

ESP8266 station AP

bool wifi_station_ap_change (uint8 current_ap_id);

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

Uint8 wifi_station_get_current_ap_id ();

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

bool wifi_station_set_auto_connect(uint8 set)

uint8 set 01

True False

30 / 91

Espressif Systems

February 9, 2015

ESP8266EX

3.4.16.

wifi_station_dhcpc_start

ESP8266 station dhcp client.


dhcp

bool wifi_station_dhcpc_start(void)

Null

True False

3.4.17.

wifi_station_dhcpc_stop

ESP8266 station dhcp client.


dhcp

bool wifi_station_dhcpc_stop(void)

Null

True False

3.4.18.

wifi_station_dhcpc_status

ESP8266 station dhcp client

enum dhcp_status wifi_station_dhcpc_status(void)

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

bool wifi_softap_get_config(struct softap_config *config)

struct softap_config *configwifi softap


softap_config

True False

3.4.20.

wifi_softap_set_config

wifi softap

bool wifi_softap_set_config (struct softap_config *config)

struct softap_config *configwifi softap


softap_config

True False

3.4.21.

wifi_softap_get_station_info

softap station mac ip

struct station_info * wifi_softap_get_station_info(void)

32 / 91

Espressif Systems

February 9, 2015

ESP8266EX

struct station_info * station

3.4.22.

wifi_softap_free_station_info

wifi_softap_get_station_info struct station_info

void wifi_softap_free_station_info (void)

macip

struct station_info * station = wifi_softap_get_station_info();


struct station_info * next_station;
while(station){
os_printf("bssid

"MACSTR",

ip

"IPSTR"\n",

MAC2STR(station->bssid), IP2STR(&station->ip));
next_station = STAILQ_NEXT(station, next);
os_free(station);

//

station = next_station;
}

struct station_info * station = wifi_softap_get_station_info();


while(station){
os_printf("bssid : "MACSTR", ip : "IPSTR"\n", MAC2STR(station->bssid),
IP2STR(&station->ip));
33 / 91

Espressif Systems

February 9, 2015

ESP8266EX
station = STAILQ_NEXT(station, next);
}
wifi_softap_free_station_info(); //

3.4.23.

wifi_softap_dhcps_start

ESP8266 softAP dhcp server.


dhcp

bool wifi_softap_dhcps_start(void)

Null

True False

3.4.24.

wifi_softap_dhcps_stop

ESP8266 softAP dhcp server.


dhcp

bool wifi_softap_dhcps_stop(void)

Null

True False

3.4.25.

wifi_softap_set_dhcps_lease

ESP8266 softAP dhcp server IP


dhcp server

bool wifi_softap_set_dhcps_lease(struct dhcps_lease *please)


34 / 91

Espressif Systems

February 9, 2015

ESP8266EX

struct dhcps_lease {
uint32 start_ip;
uint32 end_ip;
};

True False

3.4.26.

wifi_softap_dhcps_status

ESP8266 softAP dhcp server

enum dhcp_status wifi_softap_dhcps_status(void)

NULL

enum dhcp_status {
DHCP_STOPPED,
DHCP_STARTED
};

3.4.27.

wifi_set_phy_mode

ESP8266 802.11b/g/n.
ESP8266 softAP bg

bool wifi_set_phy_mode(enum phy_mode mode)

enum phy_mode mode


enum phy_mode{
PHY_MODE_11B = 1,
35 / 91

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

Enum phy_mode wifi_get_phy_mode(void)

Null

enum phy_mode{
PHY_MODE_11B = 1,
PHY_MODE_11G = 2,
PHY_MODE_11N = 3
};

3.4.29.

wifi_get_ip_info

wifi station softap ip


station ip 0
DHCP AP() softap ip
192.168.4.1

bool wifi_get_ip_info(uint8 if_index, struct ip_info *info)

uint8 if_index ip STATION_IF 0x00


36 / 91

Espressif Systems

February 9, 2015

ESP8266EX
SOFTAP_IF 0x01
struct ip_info *info ip

True False

3.4.30.

wifi_set_ip_info

ip

bool wifi_set_ip_info(uint8 if_index, struct ip_info *info)

uint8 if_index station ip softAP ip


#define STATION_IF

0x00

#define SOFTAP_IF

0x01

struct ip_info *info

ip

struct ip_info info;

IP4_ADDR(&info.ip, 192, 168, 3, 200);


IP4_ADDR(&info.gw, 192, 168, 3, 1);
IP4_ADDR(&info.netmask, 255, 255, 255, 0);
wifi_set_ip_info(STATION_IF, &info);

IP4_ADDR(&info.ip, 10, 10, 10, 1);


IP4_ADDR(&info.gw, 10, 10, 10, 1);
IP4_ADDR(&info.netmask, 255, 255, 255, 0);
wifi_set_ip_info(SOFTAP_IF, &info);

True False

37 / 91

Espressif Systems

February 9, 2015

ESP8266EX

3.4.31.

wifi_set_macaddr

mac
user_init mac

bool wifi_set_macaddr(uint8 if_index, uint8 *macaddr)

uint8 if_index station mac softAP mac

uint8 *macaddr

#define STATION_IF

0x00

#define SOFTAP_IF

0x01

mac

char sofap_mac[6] = {0x16, 0x34, 0x56, 0x78, 0x90, 0xab};


char sta_mac[6] = {0x12, 0x34, 0x56, 0x78, 0x90, 0xab};

wifi_set_macaddr(SOFTAP_IF, sofap_mac);
wifi_set_macaddr(STATION_IF, sta_mac);

True False

3.4.32.

wifi_get_macaddr

wifi station softap mac

Bool wifi_get_macaddr(uint8 if_index , uint8 *macaddr)

uint8 if_index mac STATION_IF 0x00


SOFTAP_IF 0x01
uint8 *macaddr mac

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

Bool wifi_set_sleep_type(enum sleep_type type)

enum sleep_type type

True False

3.4.34.

wifi_get_sleep_type

Enum sleep_type wifi_get_sleep_type(void)

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

wifi led led

Void wifi_status_led_install (uint8 gpio_id, uint32 gpio_name, uint8


gpio_func)

uint8 gpio_idgpio
uint8 gpio_namegpio mux
uint8 gpio_funcgpio

GPIO0 wifi LED


#define HUMITURE_WIFI_LED_IO_MUX

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

wifi led led

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()

0x00 : UPGRADE_FW_BIN1 user1.bin


0x01 : UPGRADE_FW_BIN2 user2.bin

3.5.2. system_upgrade_flag_set
upgrade flag
system_upgrade_start Espressif
SDK flag
spi_flash_write
UPGRADE_FLAG_FINISH system_upgrade_reboot

void system_upgrade_flag_set(uint8 flag)

uint8 flag
#define UPGRADE_FLAG_IDLE

0x00

#define UPGRADE_FLAG_START 0x01


#define UPGRADE_FLAG_FINISH 0x02

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

#define UPGRADE_FLAG_START 0x01


#define UPGRADE_FLAG_FINISH 0x02

3.5.4. system_upgrade_start

bool system_upgrade_start (struct upgrade_server_info *server)

struct upgrade_server_info *server - server

True

False

upgrade start

3.5.5. system_upgrade_reboot

void system_upgrade_reboot (void)

42 / 91

Espressif Systems

February 9, 2015

ESP8266EX

3.6. sniffer
3.6.1. wifi_promiscuous_enable
sniffer

Void wifi_promiscuous_enable(uint8 promiscuous)

uint8 promiscuous 0, disable promiscuous


1, enable promiscuous

Espressif sniffer demo

3.6.2. wifi_set_promiscuous_rx_cb
wifi call back

Void wifi_set_promiscuous_rx_cb(wifi_promiscuous_cb_t cb)

wifi_promiscuous_cb_t cb

3.6.3. wifi_get_channel
sniffer
43 / 91

Espressif Systems

February 9, 2015

ESP8266EX

Uint8 wifi_get_channel (void)

3.6.4. wifi_set_channel
sniffer

bool wifi_set_channel (uint8 channel)

uint8 channel

True False

3.7. smart config


3.7.1. smartconfig_start
AP
station APP
AP ssid passwordsmartconfig_start
smartconfig_start

bool smartconfig_start(sc_type type, sc_callback_t cb)

sc_type type AirKiss ESP-TOUCH


sc_callback_t cb ssid password
44 / 91

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)

struct espconn *espconn

0-

3.8.1.2.

succeed#define ESPCONN_OK 0
Erro espconn.h

espconn_gethostbyname

Err_t espconn_gethostbyname(struct espconn *pespconn, const char


*hostname, ip_addr_t *addr, dns_found_callback found)

struct espconn *espconn


const char *hostname string
ip_addr_t *addrip
dns_found_callback found

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)

struct espconn *espconn


48 / 91

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)

struct espconn *espconn


espconn_connect_callback connect_cb

0-

3.8.1.6.

succeed#define ESPCONN_OK 0
Erro espconn.h

espconn_sent_callback

void espconn_sent_callback (void *arg)

void *arg

49 / 91

Espressif Systems

February 9, 2015

ESP8266EX

3.8.1.7.

espconn_recv_callback

void espconn_recv_callback (void *arg, char *pdata, unsigned short len)

void *arg
char *pdata
unsigned short len

3.8.1.8.

espconn_sent

espconn_sent_callback
espconn_sent

Sint8 espconn_sent(struct espconn *espconn, uint8 *psent, uint16 length)

struct espconn *espconn


uint8 *psentsent
uint16 lengthsent

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

Sin8 espconn_accept(struct espconn *espconn)

struct espconn *espconn

0-

3.8.2.2.

succeed#define ESPCONN_OK 0
Erro espconn.h

espconn_secure_accept

TCP server SSL

Sint8 espconn_secure_accept(struct espconn *espconn)

struct espconn *espconn

0-

3.8.2.3.

succeed#define ESPCONN_OK 0
Erro espconn.h

espconn_regist_time

ESP8266 TCP Server

51 / 91

Espressif Systems

February 9, 2015

ESP8266EX
Sin8 espconn_regist_time(struct espconn *espconn, uint32 interval, uint8
type_flag)

struct espconn *espconn


uint32 interval 7200
uint8 type_flag

01

0-

3.8.2.4.

succeed#define ESPCONN_OK 0
Erro espconn.h

espconn_get_connection_info

TCP TCP server TCP client

Sin8 espconn_get_connection_info (struct espconn *espconn, remot_info


**pcon_info, uint8 typeflags)

struct espconn *espconn


remot_info **pcon_info client
uint8 typeflags

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

ESP8266 TCP client TCP

Sint8 espconn_connect(struct espconn *espconn)

struct espconn *espconn

0-

3.8.2.6.

succeed#define ESPCONN_OK 0
Erro espconn.h

espconn_connect_callback

TCP

Void espconn_connect_callback (void *arg)

void *arg

3.8.2.7.

espconn_set_opt

TCP

sint8 espconn_set_opt(struct espconn *espconn, uint8 opt)

struct espconn *espconn


53 / 91

Espressif Systems

February 9, 2015

ESP8266EX
uint8 opt 0, TCP 2min
1 TCP nalgo

0-

succeed#define ESPCONN_OK 0
Erro espconn.h

espconn_set_opt(espconn, 0) connected callback


espconn_set_opt(espconn, 1) disconnect

3.8.2.8.

espconn_disconnect

TCP

Sin8 espconn_disconnect(struct espconn *espconn);

struct espconn *espconn

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)

struct espconn *espconn


espconn_connect_callback connect_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

struct espconn *espconn


espconn_connect_callback connect_cb

0-

succeed#define ESPCONN_OK 0
Erro espconn.h

3.8.2.12. espconn_secure_connect
ESP8266 TCP client TCP SSL

Sint8 espconn_secure_connect (struct espconn *espconn)

struct espconn *espconn

0-

succeed#define ESPCONN_OK 0
Erro espconn.h

3.8.2.13. espconn_secure_sent
TCP SSL

Sint8 espconn_secure_sent (struct espconn *espconn, uint8 *psent, uint16


length)

struct espconn *espconn


uint8 *psentsent
56 / 91

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

Sint8 espconn_secure_disconnect(struct espconn *espconn)

struct espconn *espconn

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)

uint8 num TCP

0-

succeed#define ESPCONN_OK 0
Erro espconn.h

3.8.2.17. espconn_tcp_get_max_con_allow
ESP8266 TCP server TCP client

Sint8 espconn_tcp_get_max_con_allow(struct espconn *espconn)

struct espconn *espconn

TCP server TCP client

3.8.2.18. espconn_tcp_set_max_con_allow
ESP8266 TCP server TCP client

Sint8 espconn_tcp_set_max_con_allow(struct espconn *espconn, uint8


num)

struct espconn *espconn


uint8 num -- 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

Sint8 espconn_recv_hold(struct espconn *espconn)

struct espconn *espconn

0-

succeed#define ESPCONN_OK 0
Erro espconn.h ESPCONN_ARG ,

espconn tcp .

3.8.2.20. espconn_recv_unhold
TCP

Sint8 espconn_recv_unhold(struct espconn *espconn)

struct espconn *espconn

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

Sin8 espconn_create(struct espconn *espconn)

struct espconn *espconn

0-

3.8.3.2.

succeed#define ESPCONN_OK 0
Erro espconn.h

espconn_igmp_join

Sin8 espconn_igmp_join(ip_addr_t *host_ip, ip_addr_t *multicast_ip)

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

Sin8 espconn_igmp_leave(ip_addr_t *host_ip, ip_addr_t *multicast_ip)

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

void at_cmd_array_regist (at_funcation * custom_at_cmd_arrar, uint32


cmd_num)

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

bool at_get_next_int_dec (char **p_src,int* result,int* err)

char **p_src - *p_src at


int* result - int
int* err -
1 1
3- 3

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

Int32 at_data_str_copy (char * p_dest, char ** p_src,int32 max_len)

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

void at_init (void)

NULL

NULL
esp_iot_sdk/examples/5.at/user/user_main.c

3.9.7. at_port_print
AT PORT(UART0)

void at_port_print(const char *str)

const char *str -

NULL
esp_iot_sdk/examples/5.at/user/user_main.c

64 / 91

Espressif Systems

February 9, 2015

ESP8266EX

3.10. json API


jsonparse \include\json\jsonparse.h
jsontree \include\json\jsontree.h

3.10.1.

jsonparse_setup

json

void jsonparse_setup(struct jsonparse_state *state, const char *json,int


len)

struct jsonparse_state *statejson


const char *jsonjson
int len

3.10.2.

jsonparse_next

json

Int jsonparse_next(struct jsonparse_state *state)

struct jsonparse_state *statejson

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)

struct jsonparse_state *statejson


char *str
int size

int

3.10.4.

jsonparse_get_value_as_int

json

Int jsonparse_get_value_as_int(struct jsonparse_state *state)

struct jsonparse_state *statejson

int

3.10.5.

jsonparse_get_value_as_long

json

Long jsonparse_get_value_as_long(struct jsonparse_state *state)

struct jsonparse_state *statejson

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)

struct jsonparse_state *statejson

int json

3.10.7.

jsonparse_get_value_as_type

json

Int jsonparse_get_value_as_type(struct jsonparse_state *state)

struct jsonparse_state *statejson

intjson

3.10.8.

jsonparse_strcmp_value

json

Int jsonparse_strcmp_value(struct jsonparse_state *state, const char *str)

struct jsonparse_state *statejson


const char *str

int

3.10.9.

jsontree_set_up

json

void jsontree_setup(struct jsontree_context *js_ctx,


67 / 91

Espressif Systems

February 9, 2015

ESP8266EX
struct jsontree_value *root, int (* putchar)(int))

struct jsontree_context *js_ctxjson


struct jsontree_value *root
int (* putchar)(int)

3.10.10. jsontree_reset
json

void jsontree_reset(struct jsontree_context *js_ctx)

struct jsontree_context *js_ctxjson

3.10.11. jsontree_path_name
json

const char *jsontree_path_name(const struct jsontree_cotext *js_ctx,int


depth)

struct jsontree_context *js_ctxjson


int depthjson

char*

68 / 91

Espressif Systems

February 9, 2015

ESP8266EX

3.10.12. jsontree_write_int
json

void jsontree_write_int(const struct jsontree_context *js_ctx, int value)

struct jsontree_context *js_ctxjson


int value

3.10.13. jsontree_write_int_array
json

void jsontree_write_int_array(const struct jsontree_context *js_ctx, const


int *text, uint32 length)

struct jsontree_context *js_ctxjson


int *text
uint32 length

3.10.14. jsontree_write_string
json

void jsontree_write_string(const struct jsontree_context *js_ctx, const char


*text)

69 / 91

Espressif Systems

February 9, 2015

ESP8266EX
struct jsontree_context *js_ctxjson
const char* text

3.10.15. jsontree_print_next
json

int jsontree_print_next(struct jsontree_context *js_ctx)

struct jsontree_context *js_ctxjson

intjson

3.10.16. jsontree_find_next
json

struct jsontree_value *jsontree_find_next(struct jsontree_context *js_ctx,


int type)

struct jsontree_context *js_ctxjson


int

struct jsontree_value *json

70 / 91

Espressif Systems

February 9, 2015

ESP8266EX

4.
4.1.
typedef void ETSTimerFunc(void *timer_arg);

typedef struct _ETSTIMER_ {


struct _ETSTIMER_

*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];
};

bssid AP ssid bssid


bssid_set 1 bssid
bssid_set 0 ssid

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;

// 100 ~ 60000 ms, default 100

};

struct softap_config ssid_len 0 ssid


ssid_len 0 ssid_len ssid

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);

4.3. smart config


typedef enum

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__};

static struct jsontree_object name = {

75 / 91

Espressif Systems

February 9, 2015

ESP8266EX
JSON_TYPE_OBJECT,

sizeof(jsontree_pair_##name)/sizeof(struct jsontree_pair),

jsontree_pair_##name }

#define JSONTREE_PAIR_ARRAY(value) (struct jsontree_value *)(value)


#define

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;

typedef struct _esp_udp {


int _port;
char ipaddr[4];
} esp_udp;

/** Protocol family and type of the espconn */


enum espconn_type {
ESPCONN_INVALID

= 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

/** A espconn descriptor */


struct espconn {
/** type of the espconn (TCP, UDP) */
enum espconn_type type;
/** current state of the espconn */
enum espconn_state state;
union {
esp_tcp *tcp;
esp_udp *udp;
} proto;
/** A callback function that is informed about events for this espconn */
espconn_recv_callback recv_callback;
espconn_sent_callback sent_callback;
espconn_handle esp_pcb;
uint8 *ptrbuf;
uint16 cntr;
};

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

enable_mask, uint32 disable_mask)

uint32 set_mask 1 0

79 / 91

Espressif Systems

February 9, 2015

ESP8266EX
uint32 clear_mask 1
0
uint32 enable_mask
uint32 disable_mask

GPIO12 gpio_output_set(BIT12, 0, BIT12, 0);


GPIO12 gpio_output_set(0, BIT12, BIT12, 0);
GPIO12 GPIO13
gpio_output_set(BIT12, BIT13, BIT12|BIT13, 0);
GPIO12 gpio_output_set(0, 0, 0, BIT12);

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

void gpio_pin_intr_state_set(uint32 i, GPIO_INT_TYPE intr_state)

uint32 iGPIO ID GPIO14 GPIO_ID_PIN(14)


GPIO_INT_TYPE intr_state

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);

5.2. UART API


UART0 debug UART
UART0 UART1 debug

81 / 91

Espressif Systems

February 9, 2015

ESP8266EX

5.2.1. uart_init
uart uart

void uart_init(UartBautRate uart0_br, UartBautRate uart1_br)

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

Void uart0_tx_buffer(uint8 *buf, uint16 len)

Uint8 *buf
Uint16 len

82 / 91

Espressif Systems

February 9, 2015

ESP8266EX

5.2.3. uart0_rx_intr_handler
UART0
0x100 0x100

Void uart0_rx_intr_handler(void *para)

Void*para RcvMsgBuff

5.3. i2c master


ESP8266 I2C I2C I2C

GPIO open-drain)
GPIO I2C data clock

5.3.1. i2c_master_gpio_init
i2c master GPIO

Void i2c_master_gpio_init (void)

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

Void i2c_master_send_ack (void)

NULL

5.3.6. i2c_master_send_nack
i2c NACK

Void i2c_master_send_nack (void)

NULL

5.3.7. i2c_master_checkAck
slave ACK

bool i2c_master_checkAck (void)

NULL

TRUE slave ACK


FALSE slave NACK

85 / 91

Espressif Systems

February 9, 2015

ESP8266EX

5.3.8. i2c_master_readByte
slave

Uint8 i2c_master_readByte (void)

uint8

5.3.9. i2c_master_writeByte
slave

Void i2c_master_writeByte (uint8 wrdata)

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

Void pwm_init(uint16 freq, uint8 *duty)

Uint16 freqpwm
uint8 *duty

5.4.2. pwm_start
pwm pwm

Void pwm_start (void)

5.4.3. pwm_set_duty

Void pwm_set_duty(uint8 duty, uint8 channel)

uint8 duty
87 / 91

Espressif Systems

February 9, 2015

ESP8266EX
uint8 channel

5.4.4. pwm_set_freq
pwm

Void pwm_set_freq(uint16 freq)

Uint16 freqpwm

5.4.5. pwm_get_duty

uint8 pwm_get_duty(uint8 channel)

uint8 channel channel

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. TCP client


A.1.1.
ESP8266 Station ESP8266 AP()
IP client
ESP8266 softap ESP8266 ip
client

A.1.2.
1) espconn
2) connect recv
3) espconn_connect TCP server
4) connect
disconnect
5) recv sent disconnect

A.2. TCP server


A.2.1.
ESP8266 Station ESP8266 IP
89 / 91

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)
{

os_printf("clk cal : %d \n\r",system_rtc_clock_cali_proc()>>12);


uint32 rtc_time = 0, rtc_reg_val = 0,stime = 0,rtc_time2 = 0,stime2 = 0;
rtc_time = system_get_rtc_time();
stime = system_get_time();

// RTC

//

os_printf("rtc time : %d \n\r",rtc_time);


os_printf("system time : %d \n\r",stime);

// 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

if( system_rtc_mem_read(0, &rtc_reg_val, 4) ){


os_printf("rtc mem val : 0x%08x\n\r",rtc_reg_val);
}else{
os_printf("rtc mem val error\n\r");
}

rtc_time2 = system_get_rtc_time();
stime2 = system_get_time();

os_printf("rtc time : %d \n\r",rtc_time2);


os_printf("system time : %d \n\r",stime2);

os_printf("delta time rtc: %d \n\r",rtc_time2-rtc_time);


os_printf("delta system time rtc: %d \n\r",stime2-stime);

os_printf("clk cal : %d \n\r",system_rtc_clock_cali_proc()>>12);

os_delay_us(500000);
system_restart();

91 / 91

Espressif Systems

February 9, 2015

You might also like