@@ -20,7 +20,6 @@ const char* CWifi::firmwareVersion() {
2020 return fw_version;
2121 }
2222 return " 99.99.99" ;
23-
2423}
2524
2625
@@ -54,7 +53,7 @@ int CWifi::begin(const char* ssid, const char *passphrase) {
5453 return WL_CONNECTED;
5554 }
5655 }
57- return WL_CONNECT_FAILED;
56+ return WL_CONNECT_FAILED;
5857}
5958
6059/* passphrase is needed so a default one will be set */
@@ -78,7 +77,7 @@ uint8_t CWifi::beginAP(const char *ssid, const char* passphrase) {
7877
7978/* -------------------------------------------------------------------------- */
8079uint8_t CWifi::beginAP (const char *ssid, const char * passphrase, uint8_t channel) {
81- /* -------------------------------------------------------------------------- */
80+ /* -------------------------------------------------------------------------- */
8281 string res = " " ;
8382 modem.begin ();
8483 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
9796/* -------------------------------------------------------------------------- */
9897void CWifi::config (IPAddress local_ip) {
9998/* -------------------------------------------------------------------------- */
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);
104103}
105104
106105/* -------------------------------------------------------------------------- */
@@ -116,7 +115,7 @@ void CWifi::_config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPA
116115 string gw = to_string (gateway[0 ]) + " ." ;
117116 gw += to_string (gateway[1 ]) + " ." ;
118117 gw += to_string (gateway[2 ]) + " ." ;
119- gw += to_string (gateway[3 ]);
118+ gw += to_string (gateway[3 ]);
120119
121120 string nm = to_string (subnet[0 ]) + " ." ;
122121 nm += to_string (subnet[1 ]) + " ." ;
@@ -127,18 +126,18 @@ void CWifi::_config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPA
127126 _dns1 += to_string (dns1[1 ]) + " ." ;
128127 _dns1 += to_string (dns1[2 ]) + " ." ;
129128 _dns1 += to_string (dns1[3 ]);
130-
129+
131130 string _dns2 = to_string (dns2[0 ]) + " ." ;
132131 _dns2 += to_string (dns2[1 ]) + " ." ;
133132 _dns2 += to_string (dns2[2 ]) + " ." ;
134- _dns2 += to_string (dns2[3 ]);
133+ _dns2 += to_string (dns2[3 ]);
135134
136135 ip_ap = local_ip;
137136 gw_ap = gateway;
138137 nm_ap = subnet;
139138
140139 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 ());
142141}
143142
144143/* -------------------------------------------------------------------------- */
@@ -152,32 +151,32 @@ void CWifi::config(IPAddress local_ip, IPAddress dns_server) {
152151
153152/* -------------------------------------------------------------------------- */
154153void CWifi::config (IPAddress local_ip, IPAddress dns_server, IPAddress gateway) {
155- /* -------------------------------------------------------------------------- */
156-
154+ /* -------------------------------------------------------------------------- */
155+
157156 IPAddress _sm (255 ,255 ,255 ,0 );
158157 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);
160159}
161160
162161/* -------------------------------------------------------------------------- */
163162void CWifi::config (IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet) {
164163/* -------------------------------------------------------------------------- */
165-
164+
166165 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);
168167}
169168
170169/* -------------------------------------------------------------------------- */
171170void CWifi::setDNS (IPAddress dns_server1) {
172171/* -------------------------------------------------------------------------- */
173172 IPAddress dns (0 ,0 ,0 ,0 );
174- return _config (localIP (), gatewayIP (), subnetMask (),dns_server1,dns);
173+ return _config (localIP (), gatewayIP (), subnetMask (),dns_server1,dns);
175174}
176175
177176/* -------------------------------------------------------------------------- */
178177void CWifi::setDNS (IPAddress dns_server1, IPAddress dns_server2) {
179178/* -------------------------------------------------------------------------- */
180- return _config (localIP (), gatewayIP (), subnetMask (),dns_server1,dns_server2);
179+ return _config (localIP (), gatewayIP (), subnetMask (),dns_server1,dns_server2);
181180}
182181
183182/* -------------------------------------------------------------------------- */
@@ -189,20 +188,20 @@ void CWifi::setHostname(const char* name) {
189188
190189/* -------------------------------------------------------------------------- */
191190int CWifi::disconnect () {
192- /* -------------------------------------------------------------------------- */
191+ /* -------------------------------------------------------------------------- */
193192 string res = " " ;
194193 modem.begin ();
195194
196195 if (modem.write (string (PROMPT (_DISCONNECT)),res,CMD (_DISCONNECT))) {
197196 return 1 ;
198- }
197+ }
199198 return 0 ;
200199
201200}
202201
203202/* -------------------------------------------------------------------------- */
204203void CWifi::end (void ) {
205- /* -------------------------------------------------------------------------- */
204+ /* -------------------------------------------------------------------------- */
206205 string res = " " ;
207206 modem.begin ();
208207
@@ -211,7 +210,7 @@ void CWifi::end(void) {
211210
212211
213212static bool macStr2macArray (uint8_t *mac_out, const char *mac_in) {
214- if (mac_in[2 ] != ' :' ||
213+ if (mac_in[2 ] != ' :' ||
215214 mac_in[5 ] != ' :' ||
216215 mac_in[8 ] != ' :' ||
217216 mac_in[11 ] != ' :' ||
@@ -230,10 +229,10 @@ static bool macStr2macArray(uint8_t *mac_out, const char *mac_in) {
230229
231230/* -------------------------------------------------------------------------- */
232231uint8_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))) {
237236 if (atoi (res.c_str ()) == 1 ) {
238237 if (modem.write (string (PROMPT (_MACSTA)),res, " %s" , CMD_READ (_MACSTA))) {
239238 macStr2macArray (_mac, res.c_str ());
@@ -280,7 +279,7 @@ int8_t CWifi::scanNetworks() {
280279 ap.encryption_mode = tokens[4 ];
281280 access_points.push_back (ap);
282281 }
283- }
282+ }
284283 }
285284
286285 return (int8_t )access_points.size ();
@@ -317,7 +316,7 @@ IPAddress CWifi::dnsIP(int n) {
317316 return dns_IP;
318317 }
319318 }
320- return IPAddress (0 ,0 ,0 ,0 );
319+ return IPAddress (0 ,0 ,0 ,0 );
321320}
322321
323322
@@ -334,14 +333,14 @@ IPAddress CWifi::localIP() {
334333 if (modem.write (string (PROMPT (_MODE)),res, " %s" , CMD_READ (_MODE))) {
335334 if (atoi (res.c_str ()) == 1 ) {
336335 if (modem.write (string (PROMPT (_IPSTA)),res, " %s%d\r\n " , CMD_WRITE (_IPSTA), IP_ADDR)) {
337-
336+
338337 local_IP.fromString (res.c_str ());
339-
338+
340339 }
341340 }
342341 else if (atoi (res.c_str ()) == 2 ) {
343342 if (modem.write (string (PROMPT (_IPSOFTAP)),res, CMD (_IPSOFTAP))) {
344-
343+
345344 local_IP.fromString (res.c_str ());
346345 }
347346 }
@@ -376,27 +375,27 @@ IPAddress CWifi::gatewayIP() {
376375 gateway_IP.fromString (res.c_str ());
377376 return gateway_IP;
378377 }
379- return IPAddress (0 ,0 ,0 ,0 );
378+ return IPAddress (0 ,0 ,0 ,0 );
380379}
381380
382381/* -------------------------------------------------------------------------- */
383382const char * CWifi::SSID (uint8_t networkItem) {
384383/* -------------------------------------------------------------------------- */
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 ;
389388}
390- /* -------------------------------------------------------------------------- */
389+ /* -------------------------------------------------------------------------- */
391390
392391/* -------------------------------------------------------------------------- */
393392int32_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 ;
398397}
399- /* -------------------------------------------------------------------------- */
398+ /* -------------------------------------------------------------------------- */
400399
401400static uint8_t Encr2wl_enc (string e) {
402401 if (e == string (" open" )) {
@@ -418,17 +417,17 @@ static uint8_t Encr2wl_enc(string e) {
418417 } else {
419418 return ENC_TYPE_UNKNOWN;
420419 }
421- }
420+ }
422421
423422
424423/* -------------------------------------------------------------------------- */
425424uint8_t CWifi::encryptionType () {
426- /* -------------------------------------------------------------------------- */
425+ /* -------------------------------------------------------------------------- */
427426 scanNetworks ();
428427 string myssid (SSID ());
429428 for (unsigned int i = 0 ; i < access_points.size (); i++) {
430429 if (myssid == access_points[i].ssid ) {
431- return Encr2wl_enc (access_points[i].encryption_mode );
430+ return Encr2wl_enc (access_points[i].encryption_mode );
432431 }
433432 }
434433 return ENC_TYPE_UNKNOWN;
@@ -437,35 +436,35 @@ uint8_t CWifi::encryptionType() {
437436
438437/* -------------------------------------------------------------------------- */
439438uint8_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 ;
444443}
445- /* -------------------------------------------------------------------------- */
444+ /* -------------------------------------------------------------------------- */
446445
447446/* -------------------------------------------------------------------------- */
448447uint8_t * CWifi::BSSID (uint8_t networkItem, uint8_t * bssid) {
449448 if (networkItem < access_points.size ()) {
450449 for (int i = 0 ; i < 6 ; i++) {
451450 *(bssid + i) = access_points[networkItem].uint_bssid [i];
452451 }
453- return bssid;
452+ return bssid;
454453 }
455- return nullptr ;
454+ return nullptr ;
456455}
457- /* -------------------------------------------------------------------------- */
456+ /* -------------------------------------------------------------------------- */
458457
459458/* -------------------------------------------------------------------------- */
460- uint8_t CWifi::channel (uint8_t networkItem) {
459+ uint8_t CWifi::channel (uint8_t networkItem) {
461460 if (networkItem < access_points.size ()) {
462- return atoi (access_points[networkItem].channel .c_str ());
461+ return atoi (access_points[networkItem].channel .c_str ());
463462 }
464463 return 0 ;
465464}
466- /* -------------------------------------------------------------------------- */
465+ /* -------------------------------------------------------------------------- */
467466
468- /* -------------------------------------------------------------------------- */
467+ /* -------------------------------------------------------------------------- */
469468const char * CWifi::SSID () {
470469/* -------------------------------------------------------------------------- */
471470 string res = " " ;
@@ -486,9 +485,9 @@ const char* CWifi::SSID() {
486485 return " " ;
487486}
488487
489- /* -------------------------------------------------------------------------- */
488+ /* -------------------------------------------------------------------------- */
490489uint8_t * CWifi::BSSID (uint8_t * bssid) {
491- /* -------------------------------------------------------------------------- */
490+ /* -------------------------------------------------------------------------- */
492491 string res = " " ;
493492 if (modem.write (string (PROMPT (_GETBSSID)), res, CMD_READ (_GETBSSID))) {
494493 macStr2macArray (bssid, res.c_str ());
@@ -497,7 +496,7 @@ uint8_t* CWifi::BSSID(uint8_t* bssid) {
497496 return nullptr ;
498497}
499498
500- /* -------------------------------------------------------------------------- */
499+ /* -------------------------------------------------------------------------- */
501500int32_t CWifi::RSSI () {
502501/* -------------------------------------------------------------------------- */
503502 string res = " " ;
@@ -507,9 +506,9 @@ int32_t CWifi::RSSI() {
507506 return 0 ;
508507}
509508
510- /* -------------------------------------------------------------------------- */
509+ /* -------------------------------------------------------------------------- */
511510const char * CWifi::softAPSSID () {
512- /* -------------------------------------------------------------------------- */
511+ /* -------------------------------------------------------------------------- */
513512 string res = " " ;
514513 if (modem.write (string (PROMPT (_GETSOFTAPSSID)), res, CMD_READ (_GETSOFTAPSSID))) {
515514 apssid = res;
@@ -520,7 +519,7 @@ const char* CWifi::softAPSSID() {
520519
521520/* -------------------------------------------------------------------------- */
522521uint8_t CWifi::status () {
523- /* -------------------------------------------------------------------------- */
522+ /* -------------------------------------------------------------------------- */
524523 modem.begin ();
525524 string res = " " ;
526525 if (modem.write (string (PROMPT (_GETSTATUS)), res, CMD_READ (_GETSTATUS))) {
@@ -532,7 +531,7 @@ uint8_t CWifi::status() {
532531
533532/* -------------------------------------------------------------------------- */
534533int CWifi::hostByName (const char * aHostname, IPAddress& aResult) {
535- /* -------------------------------------------------------------------------- */
534+ /* -------------------------------------------------------------------------- */
536535 modem.begin ();
537536 string res = " " ;
538537 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) {
545544
546545
547546uint8_t CWifi::reasonCode () {
548- return 0 ;
547+ return 0 ;
549548}
550549
551550unsigned long CWifi::getTime () {
552- return 0 ;
551+ return 0 ;
553552}
554553
555554
0 commit comments