Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

664 lines
18 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
6 years ago
  1. /*
  2. WIFI MODULE
  3. Copyright (C) 2016-2018 by Xose Pérez <xose dot perez at gmail dot com>
  4. Module key prefix: wifi
  5. */
  6. #include "JustWifi.h"
  7. #include <Ticker.h>
  8. uint32_t _wifi_scan_client_id = 0;
  9. bool _wifi_wps_running = false;
  10. bool _wifi_smartconfig_running = false;
  11. uint8_t _wifi_ap_mode = WIFI_AP_FALLBACK;
  12. // -----------------------------------------------------------------------------
  13. // PRIVATE
  14. // -----------------------------------------------------------------------------
  15. void _wifiCheckAP() {
  16. if ((WIFI_AP_FALLBACK == _wifi_ap_mode) &&
  17. (jw.connected()) &&
  18. ((WiFi.getMode() & WIFI_AP) > 0) &&
  19. (WiFi.softAPgetStationNum() == 0)
  20. ) {
  21. jw.enableAP(false);
  22. }
  23. }
  24. void _wifiConfigure() {
  25. jw.setHostname(getHostname().c_str());
  26. #if USE_PASSWORD
  27. jw.setSoftAP(getHostname().c_str(), getPassword().c_str());
  28. #else
  29. jw.setSoftAP(getHostname().c_str());
  30. #endif
  31. jw.setConnectTimeout(WIFI_CONNECT_TIMEOUT);
  32. wifiReconnectCheck();
  33. jw.enableAPFallback(true);
  34. jw.cleanNetworks();
  35. _wifi_ap_mode = getSetting("wifiMode", WIFI_AP_FALLBACK).toInt();
  36. // If system is flagged unstable we do not init wifi networks
  37. #if SYSTEM_CHECK_ENABLED
  38. if (!systemCheck()) return;
  39. #endif
  40. // Clean settings
  41. _wifiClean(WIFI_MAX_NETWORKS);
  42. int i;
  43. for (i = 0; i< WIFI_MAX_NETWORKS; i++) {
  44. if (!hasSetting("wifiName", i)) break;
  45. if (hasSetting("wifiIP", i)) {
  46. jw.addNetwork(
  47. getSetting("wifiName", i, "").c_str(),
  48. getSetting("wifiPass", i, "").c_str(),
  49. getSetting("wifiIP", i, "").c_str(),
  50. getSetting("wifiGW", i, "").c_str(),
  51. getSetting("wifiMask", i, "").c_str(),
  52. getSetting("wifiDNS", i, "").c_str()
  53. );
  54. } else {
  55. jw.addNetwork(
  56. getSetting("wifiName", i, "").c_str(),
  57. getSetting("wifiPass", i, "").c_str()
  58. );
  59. }
  60. }
  61. jw.enableScan(getSetting("wifiScan", WIFI_SCAN_NETWORKS).toInt() == 1);
  62. }
  63. void _wifiScan(uint32_t client_id = 0) {
  64. DEBUG_MSG_P(PSTR("[WIFI] Start scanning\n"));
  65. #if WEB_SUPPORT
  66. String output;
  67. #endif
  68. unsigned char result = WiFi.scanNetworks();
  69. if (result == WIFI_SCAN_FAILED) {
  70. DEBUG_MSG_P(PSTR("[WIFI] Scan failed\n"));
  71. #if WEB_SUPPORT
  72. output = String("Failed scan");
  73. #endif
  74. } else if (result == 0) {
  75. DEBUG_MSG_P(PSTR("[WIFI] No networks found\n"));
  76. #if WEB_SUPPORT
  77. output = String("No networks found");
  78. #endif
  79. } else {
  80. DEBUG_MSG_P(PSTR("[WIFI] %d networks found:\n"), result);
  81. // Populate defined networks with scan data
  82. for (int8_t i = 0; i < result; ++i) {
  83. String ssid_scan;
  84. int32_t rssi_scan;
  85. uint8_t sec_scan;
  86. uint8_t* BSSID_scan;
  87. int32_t chan_scan;
  88. bool hidden_scan;
  89. char buffer[128];
  90. WiFi.getNetworkInfo(i, ssid_scan, sec_scan, rssi_scan, BSSID_scan, chan_scan, hidden_scan);
  91. snprintf_P(buffer, sizeof(buffer),
  92. PSTR("BSSID: %02X:%02X:%02X:%02X:%02X:%02X SEC: %s RSSI: %3d CH: %2d SSID: %s"),
  93. BSSID_scan[1], BSSID_scan[2], BSSID_scan[3], BSSID_scan[4], BSSID_scan[5], BSSID_scan[6],
  94. (sec_scan != ENC_TYPE_NONE ? "YES" : "NO "),
  95. rssi_scan,
  96. chan_scan,
  97. (char *) ssid_scan.c_str()
  98. );
  99. DEBUG_MSG_P(PSTR("[WIFI] > %s\n"), buffer);
  100. #if WEB_SUPPORT
  101. if (client_id > 0) output = output + String(buffer) + String("<br />");
  102. #endif
  103. }
  104. }
  105. #if WEB_SUPPORT
  106. if (client_id > 0) {
  107. output = String("{\"scanResult\": \"") + output + String("\"}");
  108. wsSend(client_id, output.c_str());
  109. }
  110. #endif
  111. WiFi.scanDelete();
  112. }
  113. bool _wifiClean(unsigned char num) {
  114. bool changed = false;
  115. int i = 0;
  116. // Clean defined settings
  117. while (i < num) {
  118. // Skip on first non-defined setting
  119. if (!hasSetting("wifiName", i)) {
  120. delSetting("wifiName", i);
  121. break;
  122. }
  123. // Delete empty values
  124. if (!hasSetting("wifiPass", i)) delSetting("wifiPass", i);
  125. if (!hasSetting("wifiIP", i)) delSetting("wifiIP", i);
  126. if (!hasSetting("wifiGW", i)) delSetting("wifiGW", i);
  127. if (!hasSetting("wifiMask", i)) delSetting("wifiMask", i);
  128. if (!hasSetting("wifiDNS", i)) delSetting("wifiDNS", i);
  129. ++i;
  130. }
  131. // Delete all other settings
  132. while (i < WIFI_MAX_NETWORKS) {
  133. changed = hasSetting("wifiName", i);
  134. delSetting("wifiName", i);
  135. delSetting("wifiPass", i);
  136. delSetting("wifiIP", i);
  137. delSetting("wifiGW", i);
  138. delSetting("wifiMask", i);
  139. delSetting("wifiDNS", i);
  140. ++i;
  141. }
  142. return changed;
  143. }
  144. // Inject hardcoded networks
  145. void _wifiInject() {
  146. if (strlen(WIFI1_SSID)) {
  147. if (!hasSetting("wifiName", 0)) {
  148. setSetting("wifiName", 0, WIFI1_SSID);
  149. setSetting("wifiPass", 0, WIFI1_PASS);
  150. setSetting("wifiIP", 0, WIFI1_IP);
  151. setSetting("wifiGW", 0, WIFI1_GW);
  152. setSetting("wifiMask", 0, WIFI1_MASK);
  153. setSetting("wifiDNS", 0, WIFI1_DNS);
  154. }
  155. if (strlen(WIFI2_SSID)) {
  156. if (!hasSetting("wifiName", 1)) {
  157. setSetting("wifiName", 1, WIFI2_SSID);
  158. setSetting("wifiPass", 1, WIFI2_PASS);
  159. setSetting("wifiIP", 1, WIFI2_IP);
  160. setSetting("wifiGW", 1, WIFI2_GW);
  161. setSetting("wifiMask", 1, WIFI2_MASK);
  162. setSetting("wifiDNS", 1, WIFI2_DNS);
  163. }
  164. }
  165. }
  166. }
  167. void _wifiCallback(justwifi_messages_t code, char * parameter) {
  168. if (MESSAGE_WPS_START == code) {
  169. _wifi_wps_running = true;
  170. }
  171. if (MESSAGE_SMARTCONFIG_START == code) {
  172. _wifi_smartconfig_running = true;
  173. }
  174. if (MESSAGE_WPS_ERROR == code || MESSAGE_SMARTCONFIG_ERROR == code) {
  175. _wifi_wps_running = false;
  176. _wifi_smartconfig_running = false;
  177. jw.enableAP(true);
  178. }
  179. if (MESSAGE_WPS_SUCCESS == code || MESSAGE_SMARTCONFIG_SUCCESS == code) {
  180. String ssid = WiFi.SSID();
  181. String pass = WiFi.psk();
  182. // Look for the same SSID
  183. uint8_t count = 0;
  184. while (count < WIFI_MAX_NETWORKS) {
  185. if (!hasSetting("wifiName", count)) break;
  186. if (ssid.equals(getSetting("wifiName", count, ""))) break;
  187. count++;
  188. }
  189. // If we have reached the max we overwrite the first one
  190. if (WIFI_MAX_NETWORKS == count) count = 0;
  191. setSetting("wifiName", count, ssid);
  192. setSetting("wifiPass", count, pass);
  193. _wifi_wps_running = false;
  194. _wifi_smartconfig_running = false;
  195. jw.enableAP(true);
  196. }
  197. }
  198. #if WIFI_AP_CAPTIVE
  199. #include "DNSServer.h"
  200. DNSServer _wifi_dnsServer;
  201. void _wifiCaptivePortal(justwifi_messages_t code, char * parameter) {
  202. if (MESSAGE_ACCESSPOINT_CREATED == code) {
  203. _wifi_dnsServer.setErrorReplyCode(DNSReplyCode::NoError);
  204. _wifi_dnsServer.start(53, "*", WiFi.softAPIP());
  205. DEBUG_MSG_P(PSTR("[WIFI] Captive portal enabled\n"));
  206. }
  207. if (MESSAGE_CONNECTED == code) {
  208. _wifi_dnsServer.stop();
  209. DEBUG_MSG_P(PSTR("[WIFI] Captive portal disabled\n"));
  210. }
  211. }
  212. #endif // WIFI_AP_CAPTIVE
  213. #if DEBUG_SUPPORT
  214. void _wifiDebugCallback(justwifi_messages_t code, char * parameter) {
  215. // -------------------------------------------------------------------------
  216. if (code == MESSAGE_SCANNING) {
  217. DEBUG_MSG_P(PSTR("[WIFI] Scanning\n"));
  218. }
  219. if (code == MESSAGE_SCAN_FAILED) {
  220. DEBUG_MSG_P(PSTR("[WIFI] Scan failed\n"));
  221. }
  222. if (code == MESSAGE_NO_NETWORKS) {
  223. DEBUG_MSG_P(PSTR("[WIFI] No networks found\n"));
  224. }
  225. if (code == MESSAGE_NO_KNOWN_NETWORKS) {
  226. DEBUG_MSG_P(PSTR("[WIFI] No known networks found\n"));
  227. }
  228. if (code == MESSAGE_FOUND_NETWORK) {
  229. DEBUG_MSG_P(PSTR("[WIFI] %s\n"), parameter);
  230. }
  231. // -------------------------------------------------------------------------
  232. if (code == MESSAGE_CONNECTING) {
  233. DEBUG_MSG_P(PSTR("[WIFI] Connecting to %s\n"), parameter);
  234. }
  235. if (code == MESSAGE_CONNECT_WAITING) {
  236. // too much noise
  237. }
  238. if (code == MESSAGE_CONNECT_FAILED) {
  239. DEBUG_MSG_P(PSTR("[WIFI] Could not connect to %s\n"), parameter);
  240. }
  241. if (code == MESSAGE_CONNECTED) {
  242. wifiDebug(WIFI_STA);
  243. }
  244. if (code == MESSAGE_DISCONNECTED) {
  245. DEBUG_MSG_P(PSTR("[WIFI] Disconnected\n"));
  246. }
  247. // -------------------------------------------------------------------------
  248. if (code == MESSAGE_ACCESSPOINT_CREATING) {
  249. DEBUG_MSG_P(PSTR("[WIFI] Creating access point\n"));
  250. }
  251. if (code == MESSAGE_ACCESSPOINT_CREATED) {
  252. wifiDebug(WIFI_AP);
  253. }
  254. if (code == MESSAGE_ACCESSPOINT_FAILED) {
  255. DEBUG_MSG_P(PSTR("[WIFI] Could not create access point\n"));
  256. }
  257. if (code == MESSAGE_ACCESSPOINT_DESTROYED) {
  258. DEBUG_MSG_P(PSTR("[WIFI] Access point destroyed\n"));
  259. }
  260. // -------------------------------------------------------------------------
  261. if (code == MESSAGE_WPS_START) {
  262. DEBUG_MSG_P(PSTR("[WIFI] WPS started\n"));
  263. }
  264. if (code == MESSAGE_WPS_SUCCESS) {
  265. DEBUG_MSG_P(PSTR("[WIFI] WPS succeded!\n"));
  266. }
  267. if (code == MESSAGE_WPS_ERROR) {
  268. DEBUG_MSG_P(PSTR("[WIFI] WPS failed\n"));
  269. }
  270. // ------------------------------------------------------------------------
  271. if (code == MESSAGE_SMARTCONFIG_START) {
  272. DEBUG_MSG_P(PSTR("[WIFI] Smart Config started\n"));
  273. }
  274. if (code == MESSAGE_SMARTCONFIG_SUCCESS) {
  275. DEBUG_MSG_P(PSTR("[WIFI] Smart Config succeded!\n"));
  276. }
  277. if (code == MESSAGE_SMARTCONFIG_ERROR) {
  278. DEBUG_MSG_P(PSTR("[WIFI] Smart Config failed\n"));
  279. }
  280. }
  281. #endif // DEBUG_SUPPORT
  282. // -----------------------------------------------------------------------------
  283. // SETTINGS
  284. // -----------------------------------------------------------------------------
  285. #if TERMINAL_SUPPORT
  286. void _wifiInitCommands() {
  287. settingsRegisterCommand(F("WIFI.RESET"), [](Embedis* e) {
  288. _wifiConfigure();
  289. wifiDisconnect();
  290. DEBUG_MSG_P(PSTR("+OK\n"));
  291. });
  292. settingsRegisterCommand(F("WIFI.AP"), [](Embedis* e) {
  293. wifiStartAP();
  294. DEBUG_MSG_P(PSTR("+OK\n"));
  295. });
  296. #if defined(JUSTWIFI_ENABLE_WPS)
  297. settingsRegisterCommand(F("WIFI.WPS"), [](Embedis* e) {
  298. wifiStartWPS();
  299. DEBUG_MSG_P(PSTR("+OK\n"));
  300. });
  301. #endif // defined(JUSTWIFI_ENABLE_WPS)
  302. #if defined(JUSTWIFI_ENABLE_SMARTCONFIG)
  303. settingsRegisterCommand(F("WIFI.SMARTCONFIG"), [](Embedis* e) {
  304. wifiStartSmartConfig();
  305. DEBUG_MSG_P(PSTR("+OK\n"));
  306. });
  307. #endif // defined(JUSTWIFI_ENABLE_SMARTCONFIG)
  308. settingsRegisterCommand(F("WIFI.SCAN"), [](Embedis* e) {
  309. _wifiScan();
  310. DEBUG_MSG_P(PSTR("+OK\n"));
  311. });
  312. }
  313. #endif
  314. // -----------------------------------------------------------------------------
  315. // WEB
  316. // -----------------------------------------------------------------------------
  317. #if WEB_SUPPORT
  318. void _wifiWebSocketOnSend(JsonObject& root) {
  319. root["maxNetworks"] = WIFI_MAX_NETWORKS;
  320. root["wifiScan"] = getSetting("wifiScan", WIFI_SCAN_NETWORKS).toInt() == 1;
  321. JsonArray& wifi = root.createNestedArray("wifi");
  322. for (byte i=0; i<WIFI_MAX_NETWORKS; i++) {
  323. if (!hasSetting("wifiName", i)) break;
  324. JsonObject& network = wifi.createNestedObject();
  325. network["wifiName"] = getSetting("wifiName", i, "");
  326. network["wifiPass"] = getSetting("wifiPass", i, "");
  327. network["wifiIP"] = getSetting("wifiIP", i, "");
  328. network["wifiGW"] = getSetting("wifiGW", i, "");
  329. network["wifiMask"] = getSetting("wifiMask", i, "");
  330. network["wifiDNS"] = getSetting("wifiDNS", i, "");
  331. }
  332. }
  333. void _wifiWebSocketOnAction(uint32_t client_id, const char * action, JsonObject& data) {
  334. if (strcmp(action, "scan") == 0) _wifi_scan_client_id = client_id;
  335. }
  336. #endif
  337. bool _wifiKeyCheck(const char * key) {
  338. return (strncmp(key, "wifi", 4) == 0);
  339. }
  340. void _wifiBackwards() {
  341. // 1.14.0 - 2018-06-27
  342. moveSettings("ssid", "wifiName");
  343. moveSettings("pass", "wifiPass");
  344. moveSettings("ip", "wifiIP");
  345. moveSettings("gw", "wifiGW");
  346. moveSettings("mask", "wifiMask");
  347. moveSettings("dns", "wifiDNS");
  348. moveSetting("apmode", "wifiMode");
  349. delSetting("wifiGain");
  350. }
  351. // -----------------------------------------------------------------------------
  352. // INFO
  353. // -----------------------------------------------------------------------------
  354. void wifiDebug(WiFiMode_t modes) {
  355. bool footer = false;
  356. if (((modes & WIFI_STA) > 0) && ((WiFi.getMode() & WIFI_STA) > 0)) {
  357. uint8_t * bssid = WiFi.BSSID();
  358. DEBUG_MSG_P(PSTR("[WIFI] ------------------------------------- MODE STA\n"));
  359. DEBUG_MSG_P(PSTR("[WIFI] SSID %s\n"), WiFi.SSID().c_str());
  360. DEBUG_MSG_P(PSTR("[WIFI] IP %s\n"), WiFi.localIP().toString().c_str());
  361. DEBUG_MSG_P(PSTR("[WIFI] MAC %s\n"), WiFi.macAddress().c_str());
  362. DEBUG_MSG_P(PSTR("[WIFI] GW %s\n"), WiFi.gatewayIP().toString().c_str());
  363. DEBUG_MSG_P(PSTR("[WIFI] DNS %s\n"), WiFi.dnsIP().toString().c_str());
  364. DEBUG_MSG_P(PSTR("[WIFI] MASK %s\n"), WiFi.subnetMask().toString().c_str());
  365. DEBUG_MSG_P(PSTR("[WIFI] HOST http://%s.local\n"), WiFi.hostname().c_str());
  366. DEBUG_MSG_P(PSTR("[WIFI] BSSID %02X:%02X:%02X:%02X:%02X:%02X\n"),
  367. bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5], bssid[6]
  368. );
  369. DEBUG_MSG_P(PSTR("[WIFI] CH %d\n"), WiFi.channel());
  370. DEBUG_MSG_P(PSTR("[WIFI] RSSI %d\n"), WiFi.RSSI());
  371. footer = true;
  372. }
  373. if (((modes & WIFI_AP) > 0) && ((WiFi.getMode() & WIFI_AP) > 0)) {
  374. DEBUG_MSG_P(PSTR("[WIFI] -------------------------------------- MODE AP\n"));
  375. DEBUG_MSG_P(PSTR("[WIFI] SSID %s\n"), getHostname().c_str());
  376. DEBUG_MSG_P(PSTR("[WIFI] PASS %s\n"), getPassword().c_str());
  377. DEBUG_MSG_P(PSTR("[WIFI] IP %s\n"), WiFi.softAPIP().toString().c_str());
  378. DEBUG_MSG_P(PSTR("[WIFI] MAC %s\n"), WiFi.softAPmacAddress().c_str());
  379. footer = true;
  380. }
  381. if (WiFi.getMode() == 0) {
  382. DEBUG_MSG_P(PSTR("[WIFI] ------------------------------------- MODE OFF\n"));
  383. DEBUG_MSG_P(PSTR("[WIFI] No connection\n"));
  384. footer = true;
  385. }
  386. if (footer) {
  387. DEBUG_MSG_P(PSTR("[WIFI] ----------------------------------------------\n"));
  388. }
  389. }
  390. void wifiDebug() {
  391. wifiDebug(WIFI_AP_STA);
  392. }
  393. // -----------------------------------------------------------------------------
  394. // API
  395. // -----------------------------------------------------------------------------
  396. String getIP() {
  397. if (WiFi.getMode() == WIFI_AP) {
  398. return WiFi.softAPIP().toString();
  399. }
  400. return WiFi.localIP().toString();
  401. }
  402. String getNetwork() {
  403. if (WiFi.getMode() == WIFI_AP) {
  404. return jw.getAPSSID();
  405. }
  406. return WiFi.SSID();
  407. }
  408. bool wifiConnected() {
  409. return jw.connected();
  410. }
  411. void wifiDisconnect() {
  412. jw.disconnect();
  413. }
  414. void wifiStartAP(bool only) {
  415. if (only) {
  416. jw.enableSTA(false);
  417. jw.disconnect();
  418. jw.resetReconnectTimeout();
  419. }
  420. jw.enableAP(true);
  421. }
  422. void wifiStartAP() {
  423. wifiStartAP(true);
  424. }
  425. #if defined(JUSTWIFI_ENABLE_WPS)
  426. void wifiStartWPS() {
  427. jw.enableAP(false);
  428. jw.disconnect();
  429. jw.startWPS();
  430. }
  431. #endif // defined(JUSTWIFI_ENABLE_WPS)
  432. #if defined(JUSTWIFI_ENABLE_SMARTCONFIG)
  433. void wifiStartSmartConfig() {
  434. jw.enableAP(false);
  435. jw.disconnect();
  436. jw.startSmartConfig();
  437. }
  438. #endif // defined(JUSTWIFI_ENABLE_SMARTCONFIG)
  439. void wifiReconnectCheck() {
  440. bool connected = false;
  441. #if WEB_SUPPORT
  442. if (wsConnected()) connected = true;
  443. #endif
  444. #if TELNET_SUPPORT
  445. if (telnetConnected()) connected = true;
  446. #endif
  447. jw.setReconnectTimeout(connected ? 0 : WIFI_RECONNECT_INTERVAL);
  448. }
  449. uint8_t wifiState() {
  450. uint8_t state = 0;
  451. if (jw.connected()) state += WIFI_STATE_STA;
  452. if (jw.connectable()) state += WIFI_STATE_AP;
  453. if (_wifi_wps_running) state += WIFI_STATE_WPS;
  454. if (_wifi_smartconfig_running) state += WIFI_STATE_SMARTCONFIG;
  455. return state;
  456. }
  457. void wifiRegister(wifi_callback_f callback) {
  458. jw.subscribe(callback);
  459. }
  460. // -----------------------------------------------------------------------------
  461. // INITIALIZATION
  462. // -----------------------------------------------------------------------------
  463. void wifiSetup() {
  464. WiFi.setSleepMode(WIFI_SLEEP_MODE);
  465. _wifiBackwards();
  466. _wifiInject();
  467. _wifiConfigure();
  468. // Message callbacks
  469. wifiRegister(_wifiCallback);
  470. #if WIFI_AP_CAPTIVE
  471. wifiRegister(_wifiCaptivePortal);
  472. #endif
  473. #if DEBUG_SUPPORT
  474. wifiRegister(_wifiDebugCallback);
  475. #endif
  476. #if WEB_SUPPORT
  477. wsOnSendRegister(_wifiWebSocketOnSend);
  478. wsOnAfterParseRegister(_wifiConfigure);
  479. wsOnActionRegister(_wifiWebSocketOnAction);
  480. #endif
  481. #if TERMINAL_SUPPORT
  482. _wifiInitCommands();
  483. #endif
  484. settingsRegisterKeyCheck(_wifiKeyCheck);
  485. // Register loop
  486. espurnaRegisterLoop(wifiLoop);
  487. }
  488. void wifiLoop() {
  489. // Main wifi loop
  490. jw.loop();
  491. // Process captrive portal DNS queries if in AP mode only
  492. #if WIFI_AP_CAPTIVE
  493. if ((WiFi.getMode() & WIFI_AP) == WIFI_AP) {
  494. _wifi_dnsServer.processNextRequest();
  495. }
  496. #endif
  497. // Do we have a pending scan?
  498. if (_wifi_scan_client_id > 0) {
  499. _wifiScan(_wifi_scan_client_id);
  500. _wifi_scan_client_id = 0;
  501. }
  502. // Check if we should disable AP
  503. static unsigned long last = 0;
  504. if (millis() - last > 60000) {
  505. last = millis();
  506. _wifiCheckAP();
  507. }
  508. }