probonopd
7/5/2015 - 5:42 PM

post.ino

#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();
}