Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WiFi.h>
- #include <WiFiClient.h>
- #include <ESP8266mDNS.h>
- #include <ESP8266WebServer.h>
- const char* APssid = "iqhtyar";
- const char* APpassword = "12345678";
- const char* ssid = "iqhtyar";
- const char* password = "23456789";
- ESP8266WebServer server(80);
- void handleRoot();
- void handleNotFound();
- void setup() {
- Serial.begin(115200);
- delay(100);
- Serial.println();
- Serial.print("Configuring access point...");
- WiFi.mode(WIFI_AP_STA);
- WiFi.softAP(APssid, APpassword);
- WiFi.disconnect();
- delay(100);
- Serial.println('\n');
- Serial.println("Scanning available WiFi networks...");
- int n = WiFi.scanNetworks();
- if (n == 0) {
- Serial.println("No networks found");
- } else {
- Serial.println("Found networks:");
- for (int i = 0; i < n; ++i) {
- // Print SSID and RSSI for each network found
- Serial.print(i + 1);
- Serial.print(": ");
- Serial.print(WiFi.SSID(i));
- Serial.print(" (");
- Serial.print(WiFi.RSSI(i));
- Serial.print(")");
- Serial.println((WiFi.encryptionType(i) == ENC_TYPE_NONE) ? " " : "*");
- delay(10);
- }
- }
- // Connect to an open WiFi network
- for (int i = 0; i < n; ++i) {
- if (WiFi.encryptionType(i) == ENC_TYPE_NONE) {
- Serial.println("Connecting to open network...");
- WiFi.begin(WiFi.SSID(i), "");
- break;
- }
- }
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- }
- Serial.println("");
- Serial.println("WiFi connected");
- Serial.println("IP address: ");
- Serial.println(WiFi.localIP());
- if (MDNS.begin("esp8266")) {
- Serial.println("mDNS responder started");
- } else {
- Serial.println("Error setting up MDNS responder!");
- }
- server.on("/", handleRoot);
- server.onNotFound(handleNotFound);
- server.begin();
- Serial.println("HTTP server started");
- }
- void loop(void){
- server.handleClient();
- }
- void handleRoot() {
- server.send(200, "text/plain", "Welcome, Node Mcu Esp8266");
- }
- void handleNotFound(){
- server.send(404, "text/plain", "404: Not found");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement