ESP8266_RTOS_SDK v1.4.0

- Main Page
- Modules
- Data Structures
- Files

- File List

espconn.h
1 /*
2 * ESPRSSIF MIT License
3 *
4 * Copyright (c) 2015 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
5 *
6 * Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, in which case,
7 * it is free of charge, to any person obtaining a copy of this software and associated
8 * documentation files (the "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the Software is furnished
11 * to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all copies or
14 * substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *
23 */
24
25 #ifndef __ESPCONN_H__
26 #define __ESPCONN_H__
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 typedef sint8 err_t;
33
34 typedef void *espconn_handle;
35
59 typedef void (* espconn_connect_callback)(void *arg);
60
83 typedef void (* espconn_reconnect_callback)(void *arg, sint8 err);
84
85 /* Definitions for error constants. */
86
87 #define ESPCONN_OK 0
88 #define ESPCONN_MEM -1
89 #define ESPCONN_TIMEOUT -3
90 #define ESPCONN_RTE -4
91 #define ESPCONN_INPROGRESS -5
92 #define ESPCONN_MAXNUM -7
94 #define ESPCONN_ABRT -8
95 #define ESPCONN_RST -9
96 #define ESPCONN_CLSD -10
97 #define ESPCONN_CONN -11
99 #define ESPCONN_ARG -12
100 #define ESPCONN_IF -14
101 #define ESPCONN_ISCONN -15
104 enum espconn_type {
105 ESPCONN_INVALID = 0,
106 ESPCONN_TCP = 0x10,
107 ESPCONN_UDP = 0x20,
108 };
109
111 enum espconn_state {
112 ESPCONN_NONE,
113 ESPCONN_WAIT,
114 ESPCONN_LISTEN,
115 ESPCONN_CONNECT,
116 ESPCONN_WRITE,
117 ESPCONN_READ,
118 ESPCONN_CLOSE
119 };
120
121 typedef struct _esp_tcp {
122 int remote_port;
123 int local_port;
124 uint8 local_ip[4];
125 uint8 remote_ip[4];
126 espconn_connect_callback connect_callback;
127 espconn_reconnect_callback reconnect_callback;
128 espconn_connect_callback disconnect_callback;
129 espconn_connect_callback write_finish_fn;
130 } esp_tcp;
131
132 typedef struct _esp_udp {
133 int remote_port;
134 int local_port;
135 uint8 local_ip[4];
136 uint8 remote_ip[4];
137 } esp_udp;
138
139 typedef struct _remot_info {
140 enum espconn_state state;
141 int remote_port;
142 uint8 remote_ip[4];
143 } remot_info;
144
146 typedef void (* espconn_recv_callback)(void *arg, char *pdata, unsigned short len);
147 typedef void (* espconn_sent_callback)(void *arg);
148
150 struct espconn {
151 enum espconn_type type;
152 enum espconn_state state;
153 union {
154 esp_tcp *tcp;
155 esp_udp *udp;
156 } proto;
157 espconn_recv_callback recv_callback;
158 espconn_sent_callback sent_callback;
159 uint8 link_cnt;
160 void *reserve;
161 };
162
163 enum espconn_option {
164 ESPCONN_START = 0x00,
165 ESPCONN_REUSEADDR = 0x01,
166 ESPCONN_NODELAY = 0x02,
167 ESPCONN_COPY = 0x04,
168 ESPCONN_KEEPALIVE = 0x08,
169 ESPCONN_END
170 };
171
172 enum espconn_level {
173 ESPCONN_KEEPIDLE,
174 ESPCONN_KEEPINTVL,
175 ESPCONN_KEEPCNT
176 };
177
178 enum {
179 ESPCONN_IDLE = 0,
180 ESPCONN_CLIENT,
181 ESPCONN_SERVER,
182 ESPCONN_BOTH,
183 ESPCONN_MAX
184 };
185
195 void espconn_init(void);
196
214 sint8 espconn_connect(struct espconn *espconn);
215
229 sint8 espconn_disconnect(struct espconn *espconn);
230
247 sint8 espconn_delete(struct espconn *espconn);
248
261 sint8 espconn_accept(struct espconn *espconn);
262
277 sint8 espconn_create(struct espconn *espconn);
278
286 uint8 espconn_tcp_get_max_con(void);
287
298 sint8 espconn_tcp_set_max_con(uint8 num);
299
310 sint8 espconn_tcp_get_max_con_allow(struct espconn *espconn);
311
323 sint8 espconn_tcp_set_max_con_allow(struct espconn *espconn, uint8 num);
324
345 sint8 espconn_regist_time(struct espconn *espconn, uint32 interval, uint8 type_flag);
346
359 sint8 espconn_get_connection_info(struct espconn *pespconn, remot_info **pcon_info, uint8 typeflags);
360
373 sint8 espconn_regist_sentcb(struct espconn *espconn, espconn_sent_callback sent_cb);
374
398 sint8 espconn_regist_write_finish(struct espconn *espconn, espconn_connect_callback write_finish_fn);
399
419 sint8 espconn_send(struct espconn *espconn, uint8 *psent, uint16 length);
420
442 sint8 espconn_sent(struct espconn *espconn, uint8 *psent, uint16 length);
443
457 sint16 espconn_sendto(struct espconn *espconn, uint8 *psent, uint16 length);
458
470 sint8 espconn_regist_connectcb(struct espconn *espconn, espconn_connect_callback connect_cb);
471
483 sint8 espconn_regist_recvcb(struct espconn *espconn, espconn_recv_callback recv_cb);
484
501 sint8 espconn_regist_reconcb(struct espconn *espconn, espconn_reconnect_callback recon_cb);
502
515 sint8 espconn_regist_disconcb(struct espconn *espconn, espconn_connect_callback discon_cb);
516
524 uint32 espconn_port(void);
525
546 sint8 espconn_set_opt(struct espconn *espconn, uint8 opt);
547
559 sint8 espconn_clear_opt(struct espconn *espconn, uint8 opt);
560
580 sint8 espconn_set_keepalive(struct espconn *espconn, uint8 level, void *optarg);
581
594 sint8 espconn_get_keepalive(struct espconn *espconn, uint8 level, void *optarg);
595
606 typedef void (*dns_found_callback)(const char *name, ip_addr_t *ipaddr, void *callback_arg);
607
624 err_t espconn_gethostbyname(struct espconn *pespconn, const char *hostname, ip_addr_t *addr, dns_found_callback found);
625
638 sint8 espconn_igmp_join(ip_addr_t *host_ip, ip_addr_t *multicast_ip);
639
652 sint8 espconn_igmp_leave(ip_addr_t *host_ip, ip_addr_t *multicast_ip);
653
667 sint8 espconn_recv_hold(struct espconn *pespconn);
668
681 sint8 espconn_recv_unhold(struct espconn *pespconn);
682
694 void espconn_dns_setserver(char numdns, ip_addr_t *dnsserver);
695
700 #ifdef __cplusplus
701 }
702 #endif
703
704 #endif
espconn_recv_callback
void(* espconn_recv_callback)(void *arg, char *pdata, unsigned short len)
Definition: espconn.h:146
espconn_regist_sentcb
sint8 espconn_regist_sentcb(struct espconn *espconn, espconn_sent_callback sent_cb)
Register data sent callback which will be called back when data are successfully sent.
espconn_connect_callback
void(* espconn_connect_callback)(void *arg)
Connect callback.
Definition: espconn.h:59
ESPCONN_TCP
Definition: espconn.h:106
_esp_tcp::connect_callback
espconn_connect_callback connect_callback
Definition: espconn.h:126
_esp_udp
Definition: espconn.h:132
espconn_tcp_set_max_con
sint8 espconn_tcp_set_max_con(uint8 num)
Set the maximum number of how many TCP connection is allowed.
espconn_recv_unhold
sint8 espconn_recv_unhold(struct espconn *pespconn)
Unblock TCP receiving data (i.e. undo espconn_recv_hold).
espconn_dns_setserver
void espconn_dns_setserver(char numdns, ip_addr_t *dnsserver)
Set default DNS server. Two DNS server is allowed to be set.
espconn_create
sint8 espconn_create(struct espconn *espconn)
Create UDP transmission.
_esp_udp::local_port
int local_port
Definition: espconn.h:134
espconn_regist_recvcb
sint8 espconn_regist_recvcb(struct espconn *espconn, espconn_recv_callback recv_cb)
register data receive function which will be called back when data are received.
espconn_disconnect
sint8 espconn_disconnect(struct espconn *espconn)
Disconnect a TCP connection.
ESPCONN_KEEPCNT
Definition: espconn.h:175
espconn_tcp_get_max_con_allow
sint8 espconn_tcp_get_max_con_allow(struct espconn *espconn)
Get the maximum number of TCP clients which are allowed to connect to ESP8266 TCP server...
espconn_igmp_join
sint8 espconn_igmp_join(ip_addr_t *host_ip, ip_addr_t *multicast_ip)
Join a multicast group.
espconn_regist_disconcb
sint8 espconn_regist_disconcb(struct espconn *espconn, espconn_connect_callback discon_cb)
Register disconnection function which will be called back under successful TCP disconnection.
ESPCONN_KEEPIDLE
Definition: espconn.h:173
ESPCONN_WRITE
Definition: espconn.h:116
espconn_regist_reconcb
sint8 espconn_regist_reconcb(struct espconn *espconn, espconn_reconnect_callback recon_cb)
Register reconnect callback.
espconn::sent_callback
espconn_sent_callback sent_callback
Definition: espconn.h:158
_esp_tcp::local_ip
uint8 local_ip[4]
Definition: espconn.h:124
ESPCONN_CLOSE
Definition: espconn.h:118
_remot_info
Definition: espconn.h:139
espconn::reserve
void * reserve
Definition: espconn.h:160
espconn_sendto
sint16 espconn_sendto(struct espconn *espconn, uint8 *psent, uint16 length)
Send UDP data.
ESPCONN_UDP
Definition: espconn.h:107
_remot_info::remote_port
int remote_port
Definition: espconn.h:141
espconn::type
enum espconn_type type
Definition: espconn.h:151
ESPCONN_REUSEADDR
Definition: espconn.h:165
ESPCONN_START
Definition: espconn.h:164
espconn_reconnect_callback
void(* espconn_reconnect_callback)(void *arg, sint8 err)
Reconnect callback.
Definition: espconn.h:83
espconn_regist_connectcb
sint8 espconn_regist_connectcb(struct espconn *espconn, espconn_connect_callback connect_cb)
Register connection function which will be called back under successful TCP connection.
espconn_send
sint8 espconn_send(struct espconn *espconn, uint8 *psent, uint16 length)
Send data through network.
ESPCONN_KEEPALIVE
Definition: espconn.h:168
_esp_tcp::reconnect_callback
espconn_reconnect_callback reconnect_callback
Definition: espconn.h:127
espconn_option
espconn_option
Definition: espconn.h:163
ESPCONN_LISTEN
Definition: espconn.h:114
espconn_set_opt
sint8 espconn_set_opt(struct espconn *espconn, uint8 opt)
Set option of TCP connection.
ESPCONN_END
Definition: espconn.h:169
espconn_type
espconn_type
Definition: espconn.h:104
espconn::recv_callback
espconn_recv_callback recv_callback
Definition: espconn.h:157
_esp_tcp
Definition: espconn.h:121
_esp_tcp::write_finish_fn
espconn_connect_callback write_finish_fn
Definition: espconn.h:129
espconn_accept
sint8 espconn_accept(struct espconn *espconn)
Creates a TCP server (i.e. accepts connections).
_remot_info::remote_ip
uint8 remote_ip[4]
Definition: espconn.h:142
ESPCONN_INVALID
Definition: espconn.h:105
espconn_regist_write_finish
sint8 espconn_regist_write_finish(struct espconn *espconn, espconn_connect_callback write_finish_fn)
Register a callback which will be called when all sending TCP data is completely write into write-buf...
dns_found_callback
void(* dns_found_callback)(const char *name, ip_addr_t *ipaddr, void *callback_arg)
Callback which is invoked when a hostname is found.
Definition: espconn.h:606
ESPCONN_KEEPINTVL
Definition: espconn.h:174
ESPCONN_CONNECT
Definition: espconn.h:115
ESPCONN_NONE
Definition: espconn.h:112
_esp_udp::remote_ip
uint8 remote_ip[4]
Definition: espconn.h:136
espconn_sent
sint8 espconn_sent(struct espconn *espconn, uint8 *psent, uint16 length)
Send data through network.
espconn_regist_time
sint8 espconn_regist_time(struct espconn *espconn, uint32 interval, uint8 type_flag)
Register timeout interval of ESP8266 TCP server.
_esp_udp::remote_port
int remote_port
Definition: espconn.h:133
ESPCONN_WAIT
Definition: espconn.h:113
_esp_tcp::remote_ip
uint8 remote_ip[4]
Definition: espconn.h:125
espconn_get_keepalive
sint8 espconn_get_keepalive(struct espconn *espconn, uint8 level, void *optarg)
Get configuration of TCP keep alive.
espconn::state
enum espconn_state state
Definition: espconn.h:152
ESPCONN_NODELAY
Definition: espconn.h:166
espconn
Definition: espconn.h:150
_esp_tcp::disconnect_callback
espconn_connect_callback disconnect_callback
Definition: espconn.h:128
espconn_connect
sint8 espconn_connect(struct espconn *espconn)
Connect to a TCP server (ESP8266 acting as TCP client).
espconn_tcp_get_max_con
uint8 espconn_tcp_get_max_con(void)
Get maximum number of how many TCP connections are allowed.
ESPCONN_COPY
Definition: espconn.h:167
_esp_udp::local_ip
uint8 local_ip[4]
Definition: espconn.h:135
_esp_tcp::local_port
int local_port
Definition: espconn.h:123
ESPCONN_READ
Definition: espconn.h:117
espconn_igmp_leave
sint8 espconn_igmp_leave(ip_addr_t *host_ip, ip_addr_t *multicast_ip)
Leave a multicast group.
espconn_port
uint32 espconn_port(void)
Get an available port for network.
_esp_tcp::remote_port
int remote_port
Definition: espconn.h:122
espconn_clear_opt
sint8 espconn_clear_opt(struct espconn *espconn, uint8 opt)
Clear option of TCP connection.
espconn_init
void espconn_init(void)
espconn initialization.
espconn_set_keepalive
sint8 espconn_set_keepalive(struct espconn *espconn, uint8 level, void *optarg)
Set configuration of TCP keep alive.
espconn_state
espconn_state
Definition: espconn.h:111
espconn::link_cnt
uint8 link_cnt
Definition: espconn.h:159
espconn_get_connection_info
sint8 espconn_get_connection_info(struct espconn *pespconn, remot_info **pcon_info, uint8 typeflags)
Get the information about a TCP connection or UDP transmission.
espconn_recv_hold
sint8 espconn_recv_hold(struct espconn *pespconn)
Puts in a request to block the TCP receive function.
espconn_tcp_set_max_con_allow
sint8 espconn_tcp_set_max_con_allow(struct espconn *espconn, uint8 num)
Set the maximum number of TCP clients allowed to connect to ESP8266 TCP server.
espconn_level
espconn_level
Definition: espconn.h:172
espconn_delete
sint8 espconn_delete(struct espconn *espconn)
Delete a transmission.
espconn_gethostbyname
err_t espconn_gethostbyname(struct espconn *pespconn, const char *hostname, ip_addr_t *addr, dns_found_callback found)
DNS function.
_remot_info::state
enum espconn_state state
Definition: espconn.h:140