-
Notifications
You must be signed in to change notification settings - Fork 0
/
IOTDlabs.h
806 lines (705 loc) · 27.2 KB
/
IOTDlabs.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
/**
* @file IOTDlabs.cpp
* @Xtension for database Connection of class ESP8266.
* @author Adrián Blasco<[email protected]>
* @date 2016.03
*
* @ Copyright:
* Copyright (c) 2016 ITEAD Intelligent Systems Co., Ltd. \n\n
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version. \n\n
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef __IOTDlabs_H__
#define __IOTDlabs_H__
#include "Arduino.h"
#define IOTDlabs_USE_SOFTWARE_SERIAL
#ifdef IOTDlabs_USE_SOFTWARE_SERIAL
#include "SoftwareSerial.h"
#endif
#define VERSION_18 0X18
#define VERSION_22 0X22
#define DEFAULT_PATTERN 3
/**
* You can modify the macro to choose a different version
*/
#define USER_SEL_VERSION VERSION_18
/**
* Provide an easy-to-use way to manipulate IOTDlabs.
*/
class IOTDlabs {
public:
int _baud;
char* ssid;
char* password;
char* _host;
int _porthost;
int _iduser;
char* _user;
int _iddevice;
char* sensormsg;
String _web_dir = "/";
String _web_file = "index.php";
bool _GET_method = true;
bool _POST_method = true;
bool _mux = false;
#ifdef IOTDlabs_USE_SOFTWARE_SERIAL
/*
* Constuctor.
*
* @param uart - an reference of SoftwareSerial object.
* @param baud - the buad rate to communicate with IOTDlabs(default:9600).
*
* @warning parameter baud depends on the AT firmware. 9600 is an common value.
*/
#if (USER_SEL_VERSION == VERSION_22)
IOTDlabs(SoftwareSerial &uart, uint32_t baud );
IOTDlabs(SoftwareSerial &uart, char* network, char* password, int host_port=80, uint32_t baud = 115200);
//IOTDlabs(SoftwareSerial &uart, uint32_t baud = 115200,char* network, char* password, char* host);
#elif (USER_SEL_VERSION == VERSION_18)
IOTDlabs(SoftwareSerial &uart, uint32_t baud = 9600);
IOTDlabs(SoftwareSerial &uart, char* network, char* password, uint32_t baud = 9600);
IOTDlabs(SoftwareSerial &uart,char* network, char* password, char* host, int host_port=80, uint32_t baud = 9600);
#endif /* #if(USER_SEL_VERSION==VERSION_22) */
#else /* HardwareSerial */
/*
* Constuctor.
*
* @param uart - an reference of HardwareSerial object.
* @param baud - the buad rate to communicate with IOTDlabs(default:9600).
*
* @warning parameter baud depends on the AT firmware. 9600 is an common value.
*/
#if (USER_SEL_VERSION == VERSION_22)
IOTDlabs(HardwareSerial &uart, uint32_t baud = 115200);
#elif (USER_SEL_VERSION == VERSION_18)
IOTDlabs(HardwareSerial &uart, uint32_t baud = 9600);
#endif /* #if(USER_SEL_VERSION == VERSION_22) */
#endif /* #ifdef IOTDlabs_USE_SOFTWARE_SERIAL */
/**----------------------------------------------------------------------
-------------------------Properties Definition
--------------------------------------------------------------------------
*/
void set_host(char* host);
void set_port(int port);
void set_webdir(char* webdir);
void set_webfile(char* webfile);
void set_iduser(int iduser);
void set_user(char* user);
void set_idevice(int iddevice);
void set_GET(bool bool_get);
void set_POST(bool bool_post);
/** ---------------------------------------------------------------------
-----------------------Basic IOTDlabs Functions Definition
-----------------------------------------------------------------------
*/
void sniff();
void ping(char* ping);
/** ---------------------------------------------------------------------
-----------------------Complex IOTDlabs Functions Definition
* @retval true - alive.
* @retval false - dead.
-----------------------------------------------------------------------
*/
int init();
void setMode(int mode);
void simpleGET(String line);
void simplePOST(String line);
void sendMSG();
void sendhttpGET();
void sendhttpPOST();
void multipleTCP();
/**------------------------------ ESP8266 Layer ------------------------------------------*/
/**------------------------------ Github Library ------------------------------------------*/
/**------------- https://github.com/itead/ITEADLIB_Arduino_WeeESP8266 ---------------------*/
/**
* Verify IOTDlabs whether live or not.
*
* Actually, this method will send command "AT" to IOTDlabs and waiting for "OK".
*
* @retval true - alive.
* @retval false - dead.
*/
bool kick(void);
/**
* Restart IOTDlabs by "AT+RST".
*
* This method will take 3 seconds or more.
*
* @retval true - success.
* @retval false - failure.
*/
bool restart(void);
/**
* Get the version of AT Command Set.
*
* @return the string of version.
*/
String getVersion(void);
/**
* Start function of deep sleep.
*
* @param time - the sleep time.
* @retval true - success.
* @retval false - failure.
* @note the feature requires hardware support.
*/
bool deepSleep(uint32_t time);
/**
* Switch the echo function.
*
* @param mode - 1 start echo -0 stop echo
* @retval true - success.
* @retval false - failure.
*
*/
bool setEcho(uint8_t mode);
/**
* Restore factory.
* @retval true - success.
* @retval false - failure.
* @note The operation can lead to restart the machine.
*/
bool restore(void);
/**
* Set up a serial port configuration.
*
* @param pattern -1 send "AT+UART=", -2 send "AT+UART_CUR=", -3 send "AT+UART_DEF=".
* @param baudrate - the uart baudrate.
* @retval true - success.
* @retval false - failure.
* @note Only allows baud rate design, for the other parameters:databits- 8,stopbits -1,parity -0,flow control -0 .
*/
bool setUart(uint32_t baudrate,uint8_t pattern);
/**
* Set operation mode to station.
*
* @param pattern1 -1, send "AT+CWMODE_DEF?",-2,send "AT+CWMODE_CUR?",-3,send "AT+CWMODE?".
* @param pattern2 -1, send "AT+CWMODE_DEF=",-2,send "AT+CWMODE_CUR=",-3,send "AT+CWMODE=".
* @retval true - success.
* @retval false - failure.
*
*/
bool setOprToStation(uint8_t pattern1=DEFAULT_PATTERN,uint8_t pattern2=DEFAULT_PATTERN);
/**
* Get the model values list.
*
* @return the list of model.
*/
String getWifiModeList(void);
/**
* Set operation mode to softap.
* @param pattern1 -1, send "AT+CWMODE_DEF?",-2,send "AT+CWMODE_CUR?",-3,send "AT+CWMODE?".
* @param pattern2 -1, send "AT+CWMODE_DEF=",-2,send "AT+CWMODE_CUR=",-3,send "AT+CWMODE=".
*
* @retval true - success.
* @retval false - failure.
*/
bool setOprToSoftAP(uint8_t pattern1=DEFAULT_PATTERN,uint8_t pattern2=DEFAULT_PATTERN);
/**
* Set operation mode to station + softap.
* @param pattern1 -1, send "AT+CWMODE_DEF?",-2,send "AT+CWMODE_CUR?",-3,send "AT+CWMODE?".
* @param pattern2 -1, send "AT+CWMODE_DEF=",-2,send "AT+CWMODE_CUR=",-3,send "AT+CWMODE=".
*
* @retval true - success.
* @retval false - failure.
*/
bool setOprToStationSoftAP(uint8_t pattern1=DEFAULT_PATTERN,uint8_t pattern2=DEFAULT_PATTERN);
/**
* Get the operation mode.
* @param pattern1 -1, send "AT+CWMODE_DEF?",-2,send "AT+CWMODE_CUR?",-3,send "AT+CWMODE?".
*
* @retval 0 - failure.
* @retval 1 - mode Station.
* @retval 2 - mode AP.
* @retval 3 - mode AP + station.
*/
uint8_t getOprMode(uint8_t pattern1=DEFAULT_PATTERN);
/**
* Search available AP list and return it.
*
* @return the list of available APs.
* @note This method will occupy a lot of memeory(hundreds of Bytes to a couple of KBytes).
* Do not call this method unless you must and ensure that your board has enough memery left.
*/
String getAPList(void);
/**
* Search and returns the current connect AP.
*
* @param pattern -1, send "AT+CWJAP_DEF?",-2,send "AT+CWJAP_CUR?",-3,send "AT+CWJAP?".
* @return the ssid of AP connected now.
*/
String getNowConecAp(uint8_t pattern=DEFAULT_PATTERN);
/**
* Join in AP.
*
* @param pattern -1 send "AT+CWJAP_DEF=" -2 send "AT+CWJAP_CUR=" -3 send "AT+CWJAP=".
* @param ssid - SSID of AP to join in.
* @param pwd - Password of AP to join in.
* @retval true - success.
* @retval false - failure.
* @note This method will take a couple of seconds.
*/
bool joinAP(String ssid, String pwd,uint8_t pattern=DEFAULT_PATTERN);
/**
* Leave AP joined before.
*
* @retval true - success.
* @retval false - failure.
*/
bool leaveAP(void);
/**
* Set SoftAP parameters.
*
* @param pattern -1 send "AT+CWSAP_DEF=" -2 send "AT+CWSAP_CUR=" -3 send "AT+CWSAP=".
* @param ssid - SSID of SoftAP.
* @param pwd - PASSWORD of SoftAP.
* @param chl - the channel (1 - 13, default: 7).
* @param ecn - the way of encrypstion (0 - OPEN, 1 - WEP,
* 2 - WPA_PSK, 3 - WPA2_PSK, 4 - WPA_WPA2_PSK, default: 4).
* @retval true - success.
* @retval false - failure.
* @note This method should not be called when station mode.
*/
bool setSoftAPParam(String ssid, String pwd, uint8_t chl = 7, uint8_t ecn = 4,uint8_t pattern=DEFAULT_PATTERN);
/**
* get SoftAP parameters.
*
* @param pattern -1 send "AT+CWSAP_DEF?" -2 send "AT+CWSAP_CUR?" -3 send "AT+CWSAP?".
* @note This method should not be called when station mode.
*/
String getSoftAPParam(uint8_t pattern=DEFAULT_PATTERN);
/**
* Get the IP list of devices connected to SoftAP.
*
* @return the list of IP.
* @note This method should not be called when station mode.
*/
String getJoinedDeviceIP(void);
/**
* Get the current state of DHCP.
*
* @param pattern -1 send "AT+CWDHCP_DEF?" -2 send "AT+CWDHCP_CUR?" -3 send "AT+CWDHCP?".
* @return the state of DHCP.
*
*/
String getDHCP(uint8_t pattern=DEFAULT_PATTERN);
/**
* Set the state of DHCP.
* @param pattern -1 send "AT+CWDHCP_DEF=" -2 send "AT+CWDHCP_CUR=" -3 send "AT+CWDHCP=".
* @param mode - set ap or set station or set ap + station.
* @param en - 0 disable DHCP - 1 enable DHCP.
* @retval true - success.
* @retval false - failure.
*/
bool setDHCP(uint8_t mode, uint8_t en, uint8_t pattern=DEFAULT_PATTERN);
/**
* make boot automatically connected.
* @param en -1 enable -0 disable.
* @retval true - success.
* @retval false - failure.
*/
bool setAutoConnect(uint8_t en);
/**
* Get the station's MAC address.
* @param pattern -1 send "AT+CIPSTAMAC_DEF?=" -2 send "AT+CIPSTAMAC_CUR?" -3 send "AT+CIPSTAMAC?".
* @return mac address.
* @note This method should not be called when ap mode.
*/
String getStationMac(uint8_t pattern=DEFAULT_PATTERN);
/**
* Set the station's MAC address.
* @param pattern -1 send "AT+CIPSTAMAC_DEF=" -2 send "AT+CIPSTAMAC_CUR=" -3 send "AT+CIPSTAMAC=".
* @param mac - the mac address of station.
* @retval true - success.
* @retval false - failure.
*/
bool setStationMac(String mac,uint8_t pattern=DEFAULT_PATTERN);
/**
* Get the station's IP.
* @param pattern -1 send "AT+CIPSTA_DEF?" -2 send "AT+CIPSTA_CUR?" -3 send "AT+CIPSTA?".
* @return the station's IP.
* @note This method should not be called when ap mode.
*/
String getStationIp(uint8_t pattern=DEFAULT_PATTERN);
/**
* Set the station's IP.
* @param pattern -1 send "AT+CIPSTA_DEF=" -2 send "AT+CIPSTA_CUR=" -3 send "AT+CIPSTA=".
* @param ip - the ip of station.
* @param gateway -the gateway of station.
* @param netmask -the netmask of station.
* @retval true - success.
* @retval false - failure.
* @note This method should not be called when ap mode.
*/
bool setStationIp(String ip,String gateway,String netmask,uint8_t pattern=DEFAULT_PATTERN);
/**
* Get the AP's IP.
* @param pattern -1 send "AT+CIPAP_DEF?" -2 send "AT+CIPAP_CUR?" -3 send "AT+CIPAP?".
* @return ap's ip.
* @note This method should not be called when station mode.
*
*/
String getAPIp(uint8_t pattern=DEFAULT_PATTERN);
/**
* Set the AP IP.
* @param pattern -1 send "AT+CIPAP_DEF=" -2 send "AT+CIPAP_CUR=" -3 send "AT+CIPAP=".
* @param ip - the ip of AP.
* @retval true - success.
* @retval false - failure.
* @note This method should not be called when station mode.
*/
bool setAPIp(String ip,uint8_t pattern=DEFAULT_PATTERN);
/**
* start smartconfig.
* @param type -1:ESP_TOUCH -2:AirKiss.
* @retval true - success.
* @retval false - failure.
*/
bool startSmartConfig(uint8_t type);
/**
* stop smartconfig.
*
* @retval true - success.
* @retval false - failure.
*/
bool stopSmartConfig(void);
/**
* Get the current status of connection(UDP and TCP).
*
* @return the status.
*/
String getIPStatus(void);
/**
* Get the IP address of IOTDlabs.
*
* @return the IP list.
*/
String getLocalIP(void);
/**
* Enable IP MUX(multiple connection mode).
*
* In multiple connection mode, a couple of TCP and UDP communication can be builded.
* They can be distinguished by the identifier of TCP or UDP named mux_id.
*
* @retval true - success.
* @retval false - failure.
*/
bool enableMUX(void);
/**
* Disable IP MUX(single connection mode).
*
* In single connection mode, only one TCP or UDP communication can be builded.
*
* @retval true - success.
* @retval false - failure.
*/
bool disableMUX(void);
/**
* Create TCP connection in single mode.
*
* @param addr - the IP or domain name of the target host.
* @param port - the port number of the target host.
* @retval true - success.
* @retval false - failure.
*/
bool createTCP(String addr, uint32_t port);
/**
* Release TCP connection in single mode.
*
* @retval true - success.
* @retval false - failure.
*/
bool releaseTCP(void);
/**
* Register UDP port number in single mode.
*
* @param addr - the IP or domain name of the target host.
* @param port - the port number of the target host.
* @retval true - success.
* @retval false - failure.
*/
bool registerUDP(String addr, uint32_t port);
/**
* Unregister UDP port number in single mode.
*
* @retval true - success.
* @retval false - failure.
*/
bool unregisterUDP(void);
/**
* Create TCP connection in multiple mode.
*
* @param mux_id - the identifier of this TCP(available value: 0 - 4).
* @param addr - the IP or domain name of the target host.
* @param port - the port number of the target host.
* @retval true - success.
* @retval false - failure.
*/
bool createTCP(uint8_t mux_id, String addr, uint32_t port);
/**
* Release TCP connection in multiple mode.
*
* @param mux_id - the identifier of this TCP(available value: 0 - 4).
* @retval true - success.
* @retval false - failure.
*/
bool releaseTCP(uint8_t mux_id);
/**
* Register UDP port number in multiple mode.
*
* @param mux_id - the identifier of this TCP(available value: 0 - 4).
* @param addr - the IP or domain name of the target host.
* @param port - the port number of the target host.
* @retval true - success.
* @retval false - failure.
*/
bool registerUDP(uint8_t mux_id, String addr, uint32_t port);
/**
* Unregister UDP port number in multiple mode.
*
* @param mux_id - the identifier of this TCP(available value: 0 - 4).
* @retval true - success.
* @retval false - failure.
*/
bool unregisterUDP(uint8_t mux_id);
/**
* Set the timeout of TCP Server.
*
* @param timeout - the duration for timeout by second(0 ~ 28800, default:180).
* @retval true - success.
* @retval false - failure.
*/
bool setTCPServerTimeout(uint32_t timeout = 180);
/**
* Start TCP Server(Only in multiple mode).
*
* After started, user should call method: getIPStatus to know the status of TCP connections.
* The methods of receiving data can be called for user's any purpose. After communication,
* release the TCP connection is needed by calling method: releaseTCP with mux_id.
*
* @param port - the port number to listen(default: 333).
* @retval true - success.
* @retval false - failure.
*
* @see String getIPStatus(void);
* @see uint32_t recv(uint8_t *coming_mux_id, uint8_t *buffer, uint32_t len, uint32_t timeout);
* @see bool releaseTCP(uint8_t mux_id);
*/
bool startTCPServer(uint32_t port = 333);
/**
* Stop TCP Server(Only in multiple mode).
*
* @retval true - success.
* @retval false - failure.
*/
bool stopTCPServer(void);
/**
*Set the module transfer mode
*
* @retval true - success.
* @retval false - failure.
*/
bool setCIPMODE(uint8_t mode);
/**
* Start Server(Only in multiple mode).
*
* @param port - the port number to listen(default: 333).
* @retval true - success.
* @retval false - failure.
*
* @see String getIPStatus(void);
* @see uint32_t recv(uint8_t *coming_mux_id, uint8_t *buffer, uint32_t len, uint32_t timeout);
*/
bool startServer(uint32_t port = 333);
/**
* Stop Server(Only in multiple mode).
*
* @retval true - success.
* @retval false - failure.
*/
bool stopServer(void);
/**
* Save the passthrough links
*
* @retval true - success.
* @retval false - failure.
*/
bool saveTransLink (uint8_t mode,String ip,uint32_t port);
/**
* PING COMMAND.
*
* @retval true - success.
* @retval false - failure.
*/
bool setPing(String ip);
/**
* Send data based on TCP or UDP builded already in single mode.
*
* @param buffer - the buffer of data to send.
* @param len - the length of data to send.
* @retval true - success.
* @retval false - failure.
*/
bool send(const uint8_t *buffer, uint32_t len);
/**
* Send data based on one of TCP or UDP builded already in multiple mode.
*
* @param mux_id - the identifier of this TCP(available value: 0 - 4).
* @param buffer - the buffer of data to send.
* @param len - the length of data to send.
* @retval true - success.
* @retval false - failure.
*/
bool send(uint8_t mux_id, const uint8_t *buffer, uint32_t len);
/**
* Send data based on TCP or UDP builded already in single mode.
*
* @param buffer - the buffer of data to send from flash memeory.
* @param len - the length of data to send.
* @retval true - success.
* @retval false - failure.
*/
bool sendFromFlash(const uint8_t *buffer, uint32_t len);
/**
* Send data based on one of TCP or UDP builded already in multiple mode.
*
* @param mux_id - the identifier of this TCP(available value: 0 - 4).
* @param buffer - the buffer of data to send from flash memeory.
* @param len - the length of data to send.
* @retval true - success.
* @retval false - failure.
*/
bool sendFromFlash(uint8_t mux_id, const uint8_t *buffer, uint32_t len);
/**
* Receive data from TCP or UDP builded already in single mode.
*
* @param buffer - the buffer for storing data.
* @param buffer_size - the length of the buffer.
* @param timeout - the time waiting data.
* @return the length of data received actually.
*/
uint32_t recv(uint8_t *buffer, uint32_t buffer_size, uint32_t timeout = 1000);
/**
* Receive data from one of TCP or UDP builded already in multiple mode.
*
* @param mux_id - the identifier of this TCP(available value: 0 - 4).
* @param buffer - the buffer for storing data.
* @param buffer_size - the length of the buffer.
* @param timeout - the time waiting data.
* @return the length of data received actually.
*/
uint32_t recv(uint8_t mux_id, uint8_t *buffer, uint32_t buffer_size, uint32_t timeout = 1000);
/**
* Receive data from all of TCP or UDP builded already in multiple mode.
*
* After return, coming_mux_id store the id of TCP or UDP from which data coming.
* User should read the value of coming_mux_id and decide what next to do.
*
* @param coming_mux_id - the identifier of TCP or UDP.
* @param buffer - the buffer for storing data.
* @param buffer_size - the length of the buffer.
* @param timeout - the time waiting data.
* @return the length of data received actually.
*/
uint32_t recv(uint8_t *coming_mux_id, uint8_t *buffer, uint32_t buffer_size, uint32_t timeout = 1000);
private:
void sendTCP(uint8_t mux_id, String msg, uint32_t timeout = 2000);
/*
* Empty the buffer or UART RX.
*/
void rx_empty(void);
/*
* Recvive data from uart. Return all received data if target found or timeout.
*/
String recvString(String target, uint32_t timeout = 1000);
/*
* Recvive data from uart. Return all received data if one of target1 and target2 found or timeout.
*/
String recvString(String target1, String target2, uint32_t timeout = 1000);
/*
* Recvive data from uart. Return all received data if one of target1, target2 and target3 found or timeout.
*/
String recvString(String target1, String target2, String target3, uint32_t timeout = 1000);
/*
* Recvive data from uart and search first target. Return true if target found, false for timeout.
*/
bool recvFind(String target, uint32_t timeout = 1000);
/*
* Recvive data from uart and search first target and cut out the substring between begin and end(excluding begin and end self).
* Return true if target found, false for timeout.
*/
bool recvFindAndFilter(String target, String begin, String end, String &data, uint32_t timeout = 1000);
/*
* Receive a package from uart.
*
* @param buffer - the buffer storing data.
* @param buffer_size - guess what!
* @param data_len - the length of data actually received(maybe more than buffer_size, the remained data will be abandoned).
* @param timeout - the duration waitting data comming.
* @param coming_mux_id - in single connection mode, should be NULL and not NULL in multiple.
*/
uint32_t recvPkg(uint8_t *buffer, uint32_t buffer_size, uint32_t *data_len, uint32_t timeout, uint8_t *coming_mux_id);
bool eAT(void);
bool eATRST(void);
bool eATGMR(String &version);
bool eATGSLP(uint32_t time);
bool eATE(uint8_t mode);
bool eATRESTORE(void);
bool eATSETUART(uint32_t baudrate,uint8_t pattern);
bool qATCWMODE(uint8_t *mode,uint8_t pattern=3);
bool eATCWMODE(String &list) ;
bool sATCWMODE(uint8_t mode,uint8_t pattern=3);
bool qATCWJAP(String &ssid,uint8_t pattern=3) ;
bool sATCWJAP(String ssid, String pwd,uint8_t pattern=3);
bool eATCWLAP(String &list);
bool eATCWQAP(void);
bool qATCWSAP(String &List,uint8_t pattern=3);
bool sATCWSAP(String ssid, String pwd, uint8_t chl, uint8_t ecn,uint8_t pattern=3);
bool eATCWLIF(String &list);
bool qATCWDHCP(String &List,uint8_t pattern=3);
bool sATCWDHCP(uint8_t mode, uint8_t en, uint8_t pattern=3);
bool eATCWAUTOCONN(uint8_t en);
bool qATCIPSTAMAC(String &mac,uint8_t pattern=3);
bool eATCIPSTAMAC(String mac,uint8_t pattern=3);
bool qATCIPSTAIP(String &ip,uint8_t pattern=3);
bool eATCIPSTAIP(String ip,String gateway,String netmask,uint8_t pattern=3);
bool qATCIPAP(String &ip,uint8_t pattern=3);
bool eATCIPAP(String ip,uint8_t pattern=3);
bool eCWSTARTSMART(uint8_t type);
bool eCWSTOPSMART(void);
bool eATCIPSTATUS(String &list);
bool sATCIPSTARTSingle(String type, String addr, uint32_t port);
bool sATCIPSTARTMultiple(uint8_t mux_id, String type, String addr, uint32_t port);
bool sATCIPSENDSingle(const uint8_t *buffer, uint32_t len);
bool sATCIPSENDMultiple(uint8_t mux_id, const uint8_t *buffer, uint32_t len);
bool sATCIPSENDSingleFromFlash(const uint8_t *buffer, uint32_t len);
bool sATCIPSENDMultipleFromFlash(uint8_t mux_id, const uint8_t *buffer, uint32_t len);
bool sATCIPCLOSEMulitple(uint8_t mux_id);
bool eATCIPCLOSESingle(void);
bool eATCIFSR(String &list);
bool sATCIPMUX(uint8_t mode);
bool sATCIPSERVER(uint8_t mode, uint32_t port = 333);
bool sATCIPMODE(uint8_t mode);
bool eATSAVETRANSLINK(uint8_t mode,String ip,uint32_t port);
bool eATPING(String ip);
bool sATCIPSTO(uint32_t timeout);
/*
* +IPD,len:data
* +IPD,id,len:data
*/
#ifdef IOTDlabs_USE_SOFTWARE_SERIAL
SoftwareSerial *m_puart; /* The UART to communicate with IOTDlabs */
#else
HardwareSerial *m_puart; /* The UART to communicate with IOTDlabs */
#endif
};
#endif /* #ifndef __IOTDlabs_H__ */