1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00

Fix mDNS library usage in ESP8266WebServer examples

This commit is contained in:
Ivan Grokhotkov 2015-09-01 00:58:27 +03:00
parent 2a2ecf8d94
commit 143f29bc29
2 changed files with 15 additions and 17 deletions

View File

@ -1,21 +1,21 @@
/* /*
* Copyright (c) 2015, Majenko Technologies * Copyright (c) 2015, Majenko Technologies
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* * Redistributions of source code must retain the above copyright notice, this * * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. * list of conditions and the following disclaimer.
* *
* * Redistributions in binary form must reproduce the above copyright notice, this * * Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or * list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution. * other materials provided with the distribution.
* *
* * Neither the name of Majenko Technologies nor the names of its * * Neither the name of Majenko Technologies nor the names of its
* contributors may be used to endorse or promote products derived from * contributors may be used to endorse or promote products derived from
* this software without specific prior written permission. * this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@ -35,7 +35,6 @@
const char *ssid = "YourSSIDHere"; const char *ssid = "YourSSIDHere";
const char *password = "YourPSKHere"; const char *password = "YourPSKHere";
MDNSResponder mdns;
ESP8266WebServer server ( 80 ); ESP8266WebServer server ( 80 );
@ -109,7 +108,7 @@ void setup ( void ) {
Serial.print ( "IP address: " ); Serial.print ( "IP address: " );
Serial.println ( WiFi.localIP() ); Serial.println ( WiFi.localIP() );
if ( mdns.begin ( "esp8266", WiFi.localIP() ) ) { if ( MDNS.begin ( "esp8266" ) ) {
Serial.println ( "MDNS responder started" ); Serial.println ( "MDNS responder started" );
} }

View File

@ -2,10 +2,9 @@
#include <WiFiClient.h> #include <WiFiClient.h>
#include <ESP8266WebServer.h> #include <ESP8266WebServer.h>
#include <ESP8266mDNS.h> #include <ESP8266mDNS.h>
const char* ssid = "........"; const char* ssid = "........";
const char* password = "........"; const char* password = "........";
MDNSResponder mdns;
ESP8266WebServer server(80); ESP8266WebServer server(80);
@ -33,7 +32,7 @@ void handleNotFound(){
server.send(404, "text/plain", message); server.send(404, "text/plain", message);
digitalWrite(led, 0); digitalWrite(led, 0);
} }
void setup(void){ void setup(void){
pinMode(led, OUTPUT); pinMode(led, OUTPUT);
digitalWrite(led, 0); digitalWrite(led, 0);
@ -51,23 +50,23 @@ void setup(void){
Serial.println(ssid); Serial.println(ssid);
Serial.print("IP address: "); Serial.print("IP address: ");
Serial.println(WiFi.localIP()); Serial.println(WiFi.localIP());
if (mdns.begin("esp8266", WiFi.localIP())) { if (MDNS.begin("esp8266")) {
Serial.println("MDNS responder started"); Serial.println("MDNS responder started");
} }
server.on("/", handleRoot); server.on("/", handleRoot);
server.on("/inline", [](){ server.on("/inline", [](){
server.send(200, "text/plain", "this works as well"); server.send(200, "text/plain", "this works as well");
}); });
server.onNotFound(handleNotFound); server.onNotFound(handleNotFound);
server.begin(); server.begin();
Serial.println("HTTP server started"); Serial.println("HTTP server started");
} }
void loop(void){ void loop(void){
server.handleClient(); server.handleClient();
} }