@@ -20,7 +20,6 @@ const char* CWifi::firmwareVersion() {
20
20
return fw_version;
21
21
}
22
22
return " 99.99.99" ;
23
-
24
23
}
25
24
26
25
@@ -54,7 +53,7 @@ int CWifi::begin(const char* ssid, const char *passphrase) {
54
53
return WL_CONNECTED;
55
54
}
56
55
}
57
- return WL_CONNECT_FAILED;
56
+ return WL_CONNECT_FAILED;
58
57
}
59
58
60
59
/* passphrase is needed so a default one will be set */
@@ -78,7 +77,7 @@ uint8_t CWifi::beginAP(const char *ssid, const char* passphrase) {
78
77
79
78
/* -------------------------------------------------------------------------- */
80
79
uint8_t CWifi::beginAP (const char *ssid, const char * passphrase, uint8_t channel) {
81
- /* -------------------------------------------------------------------------- */
80
+ /* -------------------------------------------------------------------------- */
82
81
string res = " " ;
83
82
modem.begin ();
84
83
modem.write (string (PROMPT (_MODE)),res, " %s%d\r\n " , CMD_WRITE (_MODE), 2 );
@@ -97,10 +96,10 @@ uint8_t CWifi::beginAP(const char *ssid, const char* passphrase, uint8_t channel
97
96
/* -------------------------------------------------------------------------- */
98
97
void CWifi::config (IPAddress local_ip) {
99
98
/* -------------------------------------------------------------------------- */
100
- IPAddress _gw (local_ip[0 ],local_ip[1 ], local_ip[2 ], 1 );
101
- IPAddress _sm (255 ,255 ,255 ,0 );
102
- IPAddress dns (0 ,0 ,0 ,0 );
103
- return _config (local_ip, _gw, _sm, _gw, dns);
99
+ IPAddress _gw (local_ip[0 ],local_ip[1 ], local_ip[2 ], 1 );
100
+ IPAddress _sm (255 ,255 ,255 ,0 );
101
+ IPAddress dns (0 ,0 ,0 ,0 );
102
+ return _config (local_ip, _gw, _sm, _gw, dns);
104
103
}
105
104
106
105
/* -------------------------------------------------------------------------- */
@@ -116,7 +115,7 @@ void CWifi::_config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPA
116
115
string gw = to_string (gateway[0 ]) + " ." ;
117
116
gw += to_string (gateway[1 ]) + " ." ;
118
117
gw += to_string (gateway[2 ]) + " ." ;
119
- gw += to_string (gateway[3 ]);
118
+ gw += to_string (gateway[3 ]);
120
119
121
120
string nm = to_string (subnet[0 ]) + " ." ;
122
121
nm += to_string (subnet[1 ]) + " ." ;
@@ -127,18 +126,18 @@ void CWifi::_config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPA
127
126
_dns1 += to_string (dns1[1 ]) + " ." ;
128
127
_dns1 += to_string (dns1[2 ]) + " ." ;
129
128
_dns1 += to_string (dns1[3 ]);
130
-
129
+
131
130
string _dns2 = to_string (dns2[0 ]) + " ." ;
132
131
_dns2 += to_string (dns2[1 ]) + " ." ;
133
132
_dns2 += to_string (dns2[2 ]) + " ." ;
134
- _dns2 += to_string (dns2[3 ]);
133
+ _dns2 += to_string (dns2[3 ]);
135
134
136
135
ip_ap = local_ip;
137
136
gw_ap = gateway;
138
137
nm_ap = subnet;
139
138
140
139
modem.write (PROMPT (_SOFTAPCONFIG),res, " %s%s,%s,%s\r\n " , CMD_WRITE (_SOFTAPCONFIG), ip.c_str (), ip.c_str (), nm.c_str ());
141
- modem.write (string (PROMPT (_SETIP)),res, " %s%s,%s,%s,%s,%s\r\n " , CMD_WRITE (_SETIP), ip.c_str (), gw.c_str (), nm.c_str (),_dns1.c_str (),_dns2.c_str ());
140
+ modem.write (string (PROMPT (_SETIP)),res, " %s%s,%s,%s,%s,%s\r\n " , CMD_WRITE (_SETIP), ip.c_str (), gw.c_str (), nm.c_str (),_dns1.c_str (),_dns2.c_str ());
142
141
}
143
142
144
143
/* -------------------------------------------------------------------------- */
@@ -152,32 +151,32 @@ void CWifi::config(IPAddress local_ip, IPAddress dns_server) {
152
151
153
152
/* -------------------------------------------------------------------------- */
154
153
void CWifi::config (IPAddress local_ip, IPAddress dns_server, IPAddress gateway) {
155
- /* -------------------------------------------------------------------------- */
156
-
154
+ /* -------------------------------------------------------------------------- */
155
+
157
156
IPAddress _sm (255 ,255 ,255 ,0 );
158
157
IPAddress dns (0 ,0 ,0 ,0 );
159
- return _config (local_ip, gateway, _sm,dns_server,dns);
158
+ return _config (local_ip, gateway, _sm,dns_server,dns);
160
159
}
161
160
162
161
/* -------------------------------------------------------------------------- */
163
162
void CWifi::config (IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet) {
164
163
/* -------------------------------------------------------------------------- */
165
-
164
+
166
165
IPAddress dns (0 ,0 ,0 ,0 );
167
- return _config (local_ip, gateway, subnet,dns_server,dns);
166
+ return _config (local_ip, gateway, subnet,dns_server,dns);
168
167
}
169
168
170
169
/* -------------------------------------------------------------------------- */
171
170
void CWifi::setDNS (IPAddress dns_server1) {
172
171
/* -------------------------------------------------------------------------- */
173
172
IPAddress dns (0 ,0 ,0 ,0 );
174
- return _config (localIP (), gatewayIP (), subnetMask (),dns_server1,dns);
173
+ return _config (localIP (), gatewayIP (), subnetMask (),dns_server1,dns);
175
174
}
176
175
177
176
/* -------------------------------------------------------------------------- */
178
177
void CWifi::setDNS (IPAddress dns_server1, IPAddress dns_server2) {
179
178
/* -------------------------------------------------------------------------- */
180
- return _config (localIP (), gatewayIP (), subnetMask (),dns_server1,dns_server2);
179
+ return _config (localIP (), gatewayIP (), subnetMask (),dns_server1,dns_server2);
181
180
}
182
181
183
182
/* -------------------------------------------------------------------------- */
@@ -189,20 +188,20 @@ void CWifi::setHostname(const char* name) {
189
188
190
189
/* -------------------------------------------------------------------------- */
191
190
int CWifi::disconnect () {
192
- /* -------------------------------------------------------------------------- */
191
+ /* -------------------------------------------------------------------------- */
193
192
string res = " " ;
194
193
modem.begin ();
195
194
196
195
if (modem.write (string (PROMPT (_DISCONNECT)),res,CMD (_DISCONNECT))) {
197
196
return 1 ;
198
- }
197
+ }
199
198
return 0 ;
200
199
201
200
}
202
201
203
202
/* -------------------------------------------------------------------------- */
204
203
void CWifi::end (void ) {
205
- /* -------------------------------------------------------------------------- */
204
+ /* -------------------------------------------------------------------------- */
206
205
string res = " " ;
207
206
modem.begin ();
208
207
@@ -211,7 +210,7 @@ void CWifi::end(void) {
211
210
212
211
213
212
static bool macStr2macArray (uint8_t *mac_out, const char *mac_in) {
214
- if (mac_in[2 ] != ' :' ||
213
+ if (mac_in[2 ] != ' :' ||
215
214
mac_in[5 ] != ' :' ||
216
215
mac_in[8 ] != ' :' ||
217
216
mac_in[11 ] != ' :' ||
@@ -230,10 +229,10 @@ static bool macStr2macArray(uint8_t *mac_out, const char *mac_in) {
230
229
231
230
/* -------------------------------------------------------------------------- */
232
231
uint8_t * CWifi::macAddress (uint8_t * _mac) {
233
- /* -------------------------------------------------------------------------- */
234
- string res = " " ;
235
- modem.begin ();
236
- if (modem.write (string (PROMPT (_MODE)),res, " %s" , CMD_READ (_MODE))) {
232
+ /* -------------------------------------------------------------------------- */
233
+ string res = " " ;
234
+ modem.begin ();
235
+ if (modem.write (string (PROMPT (_MODE)),res, " %s" , CMD_READ (_MODE))) {
237
236
if (atoi (res.c_str ()) == 1 ) {
238
237
if (modem.write (string (PROMPT (_MACSTA)),res, " %s" , CMD_READ (_MACSTA))) {
239
238
macStr2macArray (_mac, res.c_str ());
@@ -280,7 +279,7 @@ int8_t CWifi::scanNetworks() {
280
279
ap.encryption_mode = tokens[4 ];
281
280
access_points.push_back (ap);
282
281
}
283
- }
282
+ }
284
283
}
285
284
286
285
return (int8_t )access_points.size ();
@@ -317,7 +316,7 @@ IPAddress CWifi::dnsIP(int n) {
317
316
return dns_IP;
318
317
}
319
318
}
320
- return IPAddress (0 ,0 ,0 ,0 );
319
+ return IPAddress (0 ,0 ,0 ,0 );
321
320
}
322
321
323
322
@@ -334,14 +333,14 @@ IPAddress CWifi::localIP() {
334
333
if (modem.write (string (PROMPT (_MODE)),res, " %s" , CMD_READ (_MODE))) {
335
334
if (atoi (res.c_str ()) == 1 ) {
336
335
if (modem.write (string (PROMPT (_IPSTA)),res, " %s%d\r\n " , CMD_WRITE (_IPSTA), IP_ADDR)) {
337
-
336
+
338
337
local_IP.fromString (res.c_str ());
339
-
338
+
340
339
}
341
340
}
342
341
else if (atoi (res.c_str ()) == 2 ) {
343
342
if (modem.write (string (PROMPT (_IPSOFTAP)),res, CMD (_IPSOFTAP))) {
344
-
343
+
345
344
local_IP.fromString (res.c_str ());
346
345
}
347
346
}
@@ -376,27 +375,27 @@ IPAddress CWifi::gatewayIP() {
376
375
gateway_IP.fromString (res.c_str ());
377
376
return gateway_IP;
378
377
}
379
- return IPAddress (0 ,0 ,0 ,0 );
378
+ return IPAddress (0 ,0 ,0 ,0 );
380
379
}
381
380
382
381
/* -------------------------------------------------------------------------- */
383
382
const char * CWifi::SSID (uint8_t networkItem) {
384
383
/* -------------------------------------------------------------------------- */
385
- if (networkItem < access_points.size ()) {
386
- return access_points[networkItem].ssid .c_str ();
387
- }
388
- return nullptr ;
384
+ if (networkItem < access_points.size ()) {
385
+ return access_points[networkItem].ssid .c_str ();
386
+ }
387
+ return nullptr ;
389
388
}
390
- /* -------------------------------------------------------------------------- */
389
+ /* -------------------------------------------------------------------------- */
391
390
392
391
/* -------------------------------------------------------------------------- */
393
392
int32_t CWifi::RSSI (uint8_t networkItem) {
394
- if (networkItem < access_points.size ()) {
395
- return atoi (access_points[networkItem].rssi .c_str ());
396
- }
397
- return -1000 ;
393
+ if (networkItem < access_points.size ()) {
394
+ return atoi (access_points[networkItem].rssi .c_str ());
395
+ }
396
+ return -1000 ;
398
397
}
399
- /* -------------------------------------------------------------------------- */
398
+ /* -------------------------------------------------------------------------- */
400
399
401
400
static uint8_t Encr2wl_enc (string e) {
402
401
if (e == string (" open" )) {
@@ -418,17 +417,17 @@ static uint8_t Encr2wl_enc(string e) {
418
417
} else {
419
418
return ENC_TYPE_UNKNOWN;
420
419
}
421
- }
420
+ }
422
421
423
422
424
423
/* -------------------------------------------------------------------------- */
425
424
uint8_t CWifi::encryptionType () {
426
- /* -------------------------------------------------------------------------- */
425
+ /* -------------------------------------------------------------------------- */
427
426
scanNetworks ();
428
427
string myssid (SSID ());
429
428
for (unsigned int i = 0 ; i < access_points.size (); i++) {
430
429
if (myssid == access_points[i].ssid ) {
431
- return Encr2wl_enc (access_points[i].encryption_mode );
430
+ return Encr2wl_enc (access_points[i].encryption_mode );
432
431
}
433
432
}
434
433
return ENC_TYPE_UNKNOWN;
@@ -437,35 +436,35 @@ uint8_t CWifi::encryptionType() {
437
436
438
437
/* -------------------------------------------------------------------------- */
439
438
uint8_t CWifi::encryptionType (uint8_t networkItem) {
440
- if (networkItem < access_points.size ()) {
441
- return Encr2wl_enc (access_points[networkItem].encryption_mode );
442
- }
443
- return 0 ;
439
+ if (networkItem < access_points.size ()) {
440
+ return Encr2wl_enc (access_points[networkItem].encryption_mode );
441
+ }
442
+ return 0 ;
444
443
}
445
- /* -------------------------------------------------------------------------- */
444
+ /* -------------------------------------------------------------------------- */
446
445
447
446
/* -------------------------------------------------------------------------- */
448
447
uint8_t * CWifi::BSSID (uint8_t networkItem, uint8_t * bssid) {
449
448
if (networkItem < access_points.size ()) {
450
449
for (int i = 0 ; i < 6 ; i++) {
451
450
*(bssid + i) = access_points[networkItem].uint_bssid [i];
452
451
}
453
- return bssid;
452
+ return bssid;
454
453
}
455
- return nullptr ;
454
+ return nullptr ;
456
455
}
457
- /* -------------------------------------------------------------------------- */
456
+ /* -------------------------------------------------------------------------- */
458
457
459
458
/* -------------------------------------------------------------------------- */
460
- uint8_t CWifi::channel (uint8_t networkItem) {
459
+ uint8_t CWifi::channel (uint8_t networkItem) {
461
460
if (networkItem < access_points.size ()) {
462
- return atoi (access_points[networkItem].channel .c_str ());
461
+ return atoi (access_points[networkItem].channel .c_str ());
463
462
}
464
463
return 0 ;
465
464
}
466
- /* -------------------------------------------------------------------------- */
465
+ /* -------------------------------------------------------------------------- */
467
466
468
- /* -------------------------------------------------------------------------- */
467
+ /* -------------------------------------------------------------------------- */
469
468
const char * CWifi::SSID () {
470
469
/* -------------------------------------------------------------------------- */
471
470
string res = " " ;
@@ -486,9 +485,9 @@ const char* CWifi::SSID() {
486
485
return " " ;
487
486
}
488
487
489
- /* -------------------------------------------------------------------------- */
488
+ /* -------------------------------------------------------------------------- */
490
489
uint8_t * CWifi::BSSID (uint8_t * bssid) {
491
- /* -------------------------------------------------------------------------- */
490
+ /* -------------------------------------------------------------------------- */
492
491
string res = " " ;
493
492
if (modem.write (string (PROMPT (_GETBSSID)), res, CMD_READ (_GETBSSID))) {
494
493
macStr2macArray (bssid, res.c_str ());
@@ -497,7 +496,7 @@ uint8_t* CWifi::BSSID(uint8_t* bssid) {
497
496
return nullptr ;
498
497
}
499
498
500
- /* -------------------------------------------------------------------------- */
499
+ /* -------------------------------------------------------------------------- */
501
500
int32_t CWifi::RSSI () {
502
501
/* -------------------------------------------------------------------------- */
503
502
string res = " " ;
@@ -507,9 +506,9 @@ int32_t CWifi::RSSI() {
507
506
return 0 ;
508
507
}
509
508
510
- /* -------------------------------------------------------------------------- */
509
+ /* -------------------------------------------------------------------------- */
511
510
const char * CWifi::softAPSSID () {
512
- /* -------------------------------------------------------------------------- */
511
+ /* -------------------------------------------------------------------------- */
513
512
string res = " " ;
514
513
if (modem.write (string (PROMPT (_GETSOFTAPSSID)), res, CMD_READ (_GETSOFTAPSSID))) {
515
514
apssid = res;
@@ -520,7 +519,7 @@ const char* CWifi::softAPSSID() {
520
519
521
520
/* -------------------------------------------------------------------------- */
522
521
uint8_t CWifi::status () {
523
- /* -------------------------------------------------------------------------- */
522
+ /* -------------------------------------------------------------------------- */
524
523
modem.begin ();
525
524
string res = " " ;
526
525
if (modem.write (string (PROMPT (_GETSTATUS)), res, CMD_READ (_GETSTATUS))) {
@@ -532,7 +531,7 @@ uint8_t CWifi::status() {
532
531
533
532
/* -------------------------------------------------------------------------- */
534
533
int CWifi::hostByName (const char * aHostname, IPAddress& aResult) {
535
- /* -------------------------------------------------------------------------- */
534
+ /* -------------------------------------------------------------------------- */
536
535
modem.begin ();
537
536
string res = " " ;
538
537
if (modem.write (string (PROMPT (_GETHOSTBYNAME)),res, " %s%s\r\n " , CMD_WRITE (_GETHOSTBYNAME), aHostname)) {
@@ -545,11 +544,11 @@ int CWifi::hostByName(const char* aHostname, IPAddress& aResult) {
545
544
546
545
547
546
uint8_t CWifi::reasonCode () {
548
- return 0 ;
547
+ return 0 ;
549
548
}
550
549
551
550
unsigned long CWifi::getTime () {
552
- return 0 ;
551
+ return 0 ;
553
552
}
554
553
555
554
0 commit comments