Skip to content

Instantly share code, notes, and snippets.

@mattvenn
Last active September 26, 2015 08:49
Show Gist options
  • Save mattvenn/14fc53f8d1fd58294a0d to your computer and use it in GitHub Desktop.
Save mattvenn/14fc53f8d1fd58294a0d to your computer and use it in GitHub Desktop.
#include <ESP8267WiFi.h>
#include <WiFiClient.h>
#include "secrets.h"
//this will be changed to match oshcamp network
const char *ssid = "WutheringBytes";
WiFiServer server(1337);
#define STROBE 15
void setup()
{
Serial.begin(9600);
pinMode(STROBE, OUTPUT);
//transitor controls nfet so inverted
digitalWrite(STROBE, true);
server.begin();
}
void loop()
{
if (WiFi.status() != WL_CONNECTED)
{
Serial.print("Connecting to ");
Serial.print(ssid);
Serial.println("...");
WiFi.begin(ssid);
if (WiFi.waitForConnectResult() != WL_CONNECTED)
return;
Serial.println("WiFi connected");
Serial.println(WiFi.localIP());
}
// Check if a client has connected
WiFiClient client = server.available();
if(!client)
{
return;
}
// Wait until the client sends some data
Serial.println("new client");
while(!client.available())
{
delay(1);
}
// If this was defcon I'd be worried by this
String req = client.readStringUntil('\n');
Serial.println(req);
client.flush();
// Match the request
String s;
int val;
if(req.indexOf(password) != 0)
{
Serial.println("bad password");
client.print("bad password");
client.stop();
return;
}
if (req.indexOf("strobe_on") != -1)
{
client.print("strobe on");
digitalWrite(STROBE, false);
}
else if (req.indexOf("strobe_off") != -1)
{
client.print("strobe off");
digitalWrite(STROBE, true);
}
else
{
Serial.println("invalid request");
client.print("invalid request");
}
client.flush();
delay(1);
// when the function returns and 'client' object is destroyed
Serial.println("Client disconnected");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment