Skip to content

Instantly share code, notes, and snippets.

@li2hub
Created February 12, 2019 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save li2hub/76c54b8f4a94fa2b7f887cf65c6f0fc8 to your computer and use it in GitHub Desktop.
Save li2hub/76c54b8f4a94fa2b7f887cf65c6f0fc8 to your computer and use it in GitHub Desktop.
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <ESP8266NetBIOS.h>
const char* ssid = "............";
const char* password = "..............";
ESP8266WebServer wwwserver(80);
String content;
static void handleRoot(void) {
content = F("<!DOCTYPE HTML>\n<html>Hello world from ESP8266");
content += F("<p>");
content += F("</html>");
wwwserver.send(200, F("text/html"), content);
}
void setup() {
Serial.begin(115200);
// Connect to WiFi network
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
wwwserver.on("/", handleRoot);
wwwserver.begin();
NBNS.begin("ESP");
}
void loop() {
wwwserver.handleClient();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment