Skip to content

Instantly share code, notes, and snippets.

@igrr igrr/Counter.ino Secret
Created Aug 31, 2015

Embed
What would you like to do?
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
const char* ssid = "........";
const char* password = "........";
class Counter {
public:
void begin(ESP8266WebServer* server, const char* uri) {
m_server = server;
server->on(uri, std::bind(&Counter::handleRequest, this));
}
protected:
void handleRequest() {
++m_counter;
String response;
response += m_counter;
m_server->send(200, "text/plain", response);
}
int m_counter = 0;
ESP8266WebServer* m_server;
};
Counter counter;
ESP8266WebServer server(80);
void setup(void){
Serial.begin(115200);
WiFi.begin(ssid, password);
// 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());
counter.begin(&server, "/count");
server.begin();
Serial.println("HTTP server started");
}
void loop(void){
server.handleClient();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.