74 #include <avr/pgmspace.h>
75 #include <IPAddress.h>
78 #define WIFLY_PROTOCOL_UDP 0x01
79 #define WIFLY_PROTOCOL_TCP 0x02
80 #define WIFLY_PROTOCOL_SECURE 0x04
81 #define WIFLY_PROTOCOL_TCP_CLIENT 0x08
82 #define WIFLY_PROTOCOL_HTTP 0x10
83 #define WIFLY_PROTOCOL_RAW 0x20
84 #define WIFLY_PROTOCOL_SMTP 0x40
87 #define WIFLY_FLAG_TCP_KEEP 0x01
88 #define WIFLY_FLAG_TCP_NODELAY 0x02
89 #define WIFLY_FLAG_TCP_RETRY 0x04
90 #define WIFLY_FLAG_UDP_RETRY 0x08
91 #define WIFLY_FLAG_DNS_CACHING 0x10
92 #define WIFLY_FLAG_ARP_CACHING 0x20
93 #define WIFLY_FLAG_UDP_AUTO_PAIR 0x40
94 #define WIFLY_FLAG_ADD_TIMESTAMP 0x80
97 #define WIFLY_UART_MODE_NOECHO 0x01
98 #define WIFLY_UART_MODE_DATA_TRIGGER 0x02
99 #define WIFLY_UART_MODE_SLEEP_RX_BREAK 0x08
100 #define WIFLY_UART_MODE_RX_BUFFER 0x10
103 #define WIFLY_DHCP_MODE_OFF 0x00
104 #define WIFLY_DHCP_MODE_ON 0x01
105 #define WIFLY_DHCP_MODE_AUTOIP 0x02
106 #define WIFLY_DHCP_MODE_CACHE 0x03
107 #define WIFLY_DHCP_MODE_SERVER 0x04
110 #define WIFLY_WLAN_JOIN_MANUAL 0x00
111 #define WIFLY_WLAN_JOIN_AUTO 0x01
112 #define WIFLY_WLAN_JOIN_ANY 0x02
113 #define WIFLY_WLAN_JOIN_ADHOC 0x04
115 #define WIFLY_DEFAULT_TIMEOUT 500
117 #define WIFLY_MODE_WPA 0
118 #define WIFLY_MODE_WEP 1
123 void begin(Stream *debugPrint);
125 virtual size_t write(uint8_t byte);
126 virtual int read() {
return debug->read(); }
127 virtual int available() {
return debug->available(); }
128 virtual void flush() {
return debug->flush(); }
129 virtual int peek() {
return debug->peek(); }
140 boolean begin(Stream *serialdev, Stream *debugPrint = NULL);
142 char *getSSID(
char *buf,
int size);
144 char *getDeviceID(
char *buf,
int size);
145 char *
getIP(
char *buf,
int size);
147 char *getNetmask(
char *buf,
int size);
148 char *getGateway(
char *buf,
int size);
149 char *getDNS(
char *buf,
int size);
150 char *getMAC(
char *buf,
int size);
151 int8_t getDHCPMode();
155 uint16_t getConnection();
158 bool setJoin(uint8_t
join);
159 boolean setDeviceID(
const char *buf);
160 boolean setBaud(uint32_t baud);
162 uint8_t getUartMode();
163 uint8_t getIpFlags();
164 uint8_t getProtocol();
166 uint8_t getFlushChar();
167 uint16_t getFlushSize();
168 uint16_t getFlushTimeout();
170 char getSpaceReplace(
void);
175 boolean setSSID(
const char *buf);
176 boolean setIP(
const char *buf);
177 boolean setIP(
const __FlashStringHelper *buf);
178 boolean setPort(
const uint16_t port);
179 boolean setNetmask(
const char *buf);
180 boolean setNetmask(
const __FlashStringHelper *buf);
181 boolean setGateway(
const char *buf);
182 boolean setDNS(
const char *buf);
184 boolean setKey(
const char *buf);
187 boolean setDHCP(
const uint8_t mode);
188 boolean setRate(uint32_t rate);
191 boolean setHostIP(
const char *buf);
192 boolean setHostIP(
const __FlashStringHelper *buf);
193 boolean setHostPort(
const uint16_t port);
194 boolean setHost(
const char *buf, uint16_t port);
196 boolean setProtocol(
const uint8_t protocol);
197 boolean setIpProtocol(
const uint8_t protocol);
198 boolean setIpFlags(
const uint8_t flags);
199 boolean setUartMode(
const uint8_t mode);
210 uint16_t getAdhocBeacon();
211 uint16_t getAdhocProbe();
212 uint16_t getAdhocReboot();
217 boolean enableDataTrigger(
const uint16_t flushtime=10,
const char flushChar=0,
const uint16_t flushSize=64);
218 boolean disableDataTrigger();
220 boolean disableUdpAutoPair();
224 char *getTime(
char *buf,
int size);
225 uint32_t getUptime();
226 uint8_t getTimezone();
229 bool getHostByName(
const char *hostname,
char *buf,
int size);
230 boolean ping(
const char *host);
232 boolean enableDHCP();
233 boolean disableDHCP();
236 boolean join(
const char *ssid, uint16_t timeout=20000);
237 boolean join(uint16_t timeout=20000);
238 boolean join(
const char *ssid,
const char *password,
bool dhcp=
true, uint8_t mode=WIFLY_MODE_WPA, uint16_t timeout=20000);
246 boolean sendto(
const uint8_t *data, uint16_t size,
const char *host, uint16_t port);
247 boolean sendto(
const uint8_t *data, uint16_t size, IPAddress host, uint16_t port);
248 boolean sendto(
const char *data,
const char *host, uint16_t port);
249 boolean sendto(
const char *data, IPAddress host, uint16_t port);
250 boolean sendto(
const __FlashStringHelper *data,
const char *host, uint16_t port);
251 boolean sendto(
const __FlashStringHelper *data, IPAddress host, uint16_t port);
256 boolean open(
const char *addr,
int port=80,
boolean block=
true);
257 boolean open(IPAddress addr,
int port=80,
boolean block=
true);
261 boolean isInCommandMode();
263 virtual size_t write(uint8_t byte);
266 virtual void flush();
269 char *
iptoa(IPAddress addr,
char *buf,
int size);
270 IPAddress
atoip(
char *buf);
274 void sendChunk(
const __FlashStringHelper *str);
289 boolean match(
const char *str, uint16_t timeout=WIFLY_DEFAULT_TIMEOUT);
290 boolean match(
const __FlashStringHelper *str, uint16_t timeout=WIFLY_DEFAULT_TIMEOUT);
292 int gets(
char *buf,
int size, uint16_t timeout=WIFLY_DEFAULT_TIMEOUT);
293 int getsTerm(
char *buf,
int size,
char term, uint16_t timeout=WIFLY_DEFAULT_TIMEOUT);
294 void flushRx(
int timeout=WIFLY_DEFAULT_TIMEOUT);
297 boolean setFtpAddress(
const char *addr);
298 boolean setFtpPort(uint16_t port);
299 boolean setFtpDirectory(
const char *dir);
300 boolean setFtpUser(
const char *user);
301 boolean setFtpPassword(
const char *password);
302 boolean setFtpFilename(
const char *filename);
303 boolean setFtpTimer(uint16_t msecs);
304 boolean setFtpMode(uint8_t mode);
310 const char *password,
311 const char *filename);
316 void dump(
const char *str);
321 const __FlashStringHelper *flashData,
325 boolean match_P(
const prog_char *str, uint16_t timeout=WIFLY_DEFAULT_TIMEOUT);
326 int8_t
multiMatch_P(
const prog_char *str[], uint8_t count, uint16_t timeout=WIFLY_DEFAULT_TIMEOUT);
328 void send_P(
const prog_char *str);
329 void send(
const char *str);
330 void send(
const char ch);
331 boolean enterCommandMode();
332 boolean exitCommandMode();
334 boolean getPrompt(uint16_t timeout=WIFLY_DEFAULT_TIMEOUT);
335 boolean checkPrompt(
const char *str);
336 int getResponse(
char *buf,
int size, uint16_t timeout=WIFLY_DEFAULT_TIMEOUT);
337 boolean readTimeout(
char *ch, uint16_t timeout=WIFLY_DEFAULT_TIMEOUT);
338 boolean startCommand();
339 boolean finishCommand();
340 char *getopt(
int opt,
char *buf,
int size);
341 uint32_t getopt(
int opt, uint8_t base=DEC);
342 boolean setopt(
const prog_char *cmd,
const char *buf=NULL,
const __FlashStringHelper *buf_P=NULL,
bool spacesub=
false);
343 boolean setopt(
const prog_char *opt,
const uint32_t value, uint8_t base=DEC);
344 boolean getres(
char *buf,
int size);
346 boolean checkStream(
const prog_char *str,
boolean peeked);
347 boolean checkClose(
boolean peeked);
348 boolean checkOpen(
boolean peeked);
352 boolean inCommandMode;
356 bool restoreHostStored;