Skip to content

Instantly share code, notes, and snippets.

@probonopd
Last active August 29, 2015 14:24
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 probonopd/c86335eac72e9d2e9105 to your computer and use it in GitHub Desktop.
Save probonopd/c86335eac72e9d2e9105 to your computer and use it in GitHub Desktop.
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include "/secrets.h" // Delete this line and populate the following
//const char* ssid = "********";
//const char* password = "********";
ESP8266WebServer server(80);
const int led = 13;
void handleRoot() {
// Print what the client has POSTed
for (uint8_t i = 0; i < server.args(); i++) Serial.printf("ARG[%u]: %s=%s\n", i, server.argName(i).c_str(), server.arg(i).c_str());
Serial.println("Did you see what you POSTed?");
server.send(200, "text/plain", "hello from esp8266!");
}
void setup(void) {
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
server.on("/", handleRoot);
server.begin();
Serial.println("HTTP server started");
Serial.println("Now try to POST using curl:");
Serial.print("curl --data ' { \"username\" : \"e7x4kuCaC8he\" : \"Hello\"}' http://");
Serial.println (WiFi.localIP());
}
void loop(void) {
server.handleClient();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment