Skip to content

Instantly share code, notes, and snippets.

@CelliesProjects
Created August 8, 2017 11:50
Show Gist options
  • Save CelliesProjects/f86c5f07f710b7b1d274f2b9809237eb to your computer and use it in GitHub Desktop.
Save CelliesProjects/f86c5f07f710b7b1d274f2b9809237eb to your computer and use it in GitHub Desktop.
Simple ESP32 webserver ported from esp8266 - http://www.fisch.lu/junk/ESP32-WebServer.zip
//https://github.com/espressif/arduino-esp32/issues/425
//http://www.fisch.lu/junk/ESP32-WebServer.zip
//Install webserver zip to ~/Arduino/hardware/espressif/esp32/libraries/
#include "WiFi.h" PROGMEM
#include <ESP32WebServer.h> PROGMEM
ESP32WebServer server(80);
void setup(){
Serial.begin(115200);
WiFi.begin();
Serial.print( "WiFi connecting" );
time_t timeout = millis() + 15000;
while ( millis() < timeout && WiFi.status() != WL_CONNECTED ) {
delay ( 500 );
Serial.print ( F( "." ) );
}
Serial.println( );
// attach handles
server.on("/",handleRoot);
server.on("/test",handleTest);
// start the server
server.begin();
Serial.print( F( "HTTP web server started at IP address: " ) );
Serial.println( WiFi.localIP() );
}
void handleRoot()
{
String html = "You just loaded the root of your ESP WebServer<br><br><a href=\"/test\">Goto /test</a>";
server.setContentLength(html.length());
server.send(200,"text/html",html);
}
void handleTest()
{
String html = "You just entered /test ...";
server.setContentLength(html.length());
server.send(200,"text/html",html);
}
void loop(){
// hanle clients
server.handleClient();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment