{"id":7894,"date":"2023-04-14T09:52:57","date_gmt":"2023-04-14T01:52:57","guid":{"rendered":"https:\/\/blog.hoyo.idv.tw\/?p=7894"},"modified":"2023-04-14T09:52:57","modified_gmt":"2023-04-14T01:52:57","slug":"esp8266-%e6%8e%83%e6%8f%8f-wifi-ap","status":"publish","type":"post","link":"https:\/\/blog.hoyo.idv.tw\/?p=7894","title":{"rendered":"ESP8266 - \u6383\u63cf WiFi AP"},"content":{"rendered":"<p>--<\/p>\n<h2>\u53c3\u8003\u8cc7\u6e90<\/h2>\n<ul>\n<li><a href=\"https:\/\/arduino-esp8266.readthedocs.io\/en\/latest\/esp8266wifi\/scan-examples.html\" target=\"_blank\" rel=\"noopener\">Scan \u2014 ESP8266 Arduino Core documentation<\/a><\/li>\n<\/ul>\n<p>--<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"lang:arduino decode:true \">#include \"ESP8266WiFi.h\"\r\n\r\n#define BLINK_PERIOD 250\r\nlong lastBlinkMillis;\r\nboolean ledState;\r\n\r\n#define SCAN_PERIOD 5000\r\nlong lastScanMillis;\r\n\r\nvoid setup()\r\n{\r\n    Serial.begin(115200);\r\n    Serial.println();\r\n\r\n    pinMode(LED_BUILTIN, OUTPUT);\r\n\r\n    WiFi.mode(WIFI_STA);\r\n    WiFi.disconnect();\r\n    delay(100);\r\n}\r\n\r\nvoid loop()\r\n{\r\n    long currentMillis = millis();\r\n\r\n    \/\/ blink LED\r\n    if (currentMillis - lastBlinkMillis &gt; BLINK_PERIOD)\r\n    {\r\n        digitalWrite(LED_BUILTIN, ledState);\r\n        ledState = !ledState;\r\n        lastBlinkMillis = currentMillis;\r\n    }\r\n\r\n    \/\/ trigger Wi-Fi network scan\r\n    if (currentMillis - lastScanMillis &gt; SCAN_PERIOD)\r\n    {\r\n        WiFi.scanNetworks(true);\r\n        Serial.print(\"\\nScan start ... \");\r\n        lastScanMillis = currentMillis;\r\n    }\r\n\r\n    \/\/ print out Wi-Fi network scan result upon completion\r\n    int n = WiFi.scanComplete();\r\n    if (n &gt;= 0)\r\n    {\r\n        Serial.printf(\"%d network(s) found\\n\", n);\r\n        for (int i = 0; i &lt; n; i++)\r\n        {\r\n            Serial.printf(\"%d: %s, Ch:%d (%ddBm) %s\\n\", i + 1, WiFi.SSID(i).c_str(), WiFi.channel(i), WiFi.RSSI(i), WiFi.encryptionType(i) == ENC_TYPE_NONE ? \"open\" : \"\");\r\n        }\r\n        WiFi.scanDelete();\r\n    }\r\n}<\/pre>\n<p>\u7d50\u679c<\/p>\n<pre class=\"lang:default decode:true\">Scan start ... 5 network(s) found\r\n1: YoYoHome, Ch:2 (-50dBm) \r\n2: hoyoWifi-2.4G, Ch:3 (-67dBm) \r\n3: abc, Ch:6 (-80dBm) \r\n4: TEANAwireless, Ch:9 (-84dBm) \r\n5: Home, Ch:11 (-80dBm)<\/pre>\n<p>--<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"7894\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;1,383&nbsp;total views, &nbsp;3&nbsp;views today<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>-- \u53c3\u8003\u8cc7\u6e90 Scan \u2014 ...<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"7894\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;1,383&nbsp;total views, &nbsp;3&nbsp;views today<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[272],"tags":[275,331],"_links":{"self":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/7894"}],"collection":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7894"}],"version-history":[{"count":4,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/7894\/revisions"}],"predecessor-version":[{"id":12043,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/7894\/revisions\/12043"}],"wp:attachment":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7894"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7894"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7894"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}