Skip to content

Instantly share code, notes, and snippets.

@igrr

igrr/Counter.ino Secret

Created August 31, 2015 21: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 igrr/0a7783b7611aad9169af to your computer and use it in GitHub Desktop.
Save igrr/0a7783b7611aad9169af to your computer and use it in GitHub Desktop.
#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