Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
#include <SPI.h>
#include <Ethernet.h>
#include <FiniteStateMachine.h>
byte mac[] = {
0x02, 0xAA, 0xBB, 0xCC, 0x00, 0x03 };
byte ip[] = {
128, 122, 151, 9 };
byte server[] = {
174,129,212,2 };
Client client(server, 80);
int isConnected = 0;
State readMode = State(doNothing, doReadMode, doNothing);
State pingMode = State(doNothing, doPingMode, doNothing);
FSM machine = FSM(readMode);
int switchPin = 5;
int currentSwitchState = 0; // open
void setup()
{
Ethernet.begin(mac, ip);
Serial.begin(9600);
delay(1000);
Serial.println("ready");
}
void loop()
{
machine.update();
}
void doReadMode(){
if(digitalRead(switchPin) == 1 && currentSwitchState == 0){
Serial.println("switch closed");
currentSwitchState = 1;
machine.transitionTo(pingMode);
}
if(digitalRead(switchPin) == 0 && currentSwitchState == 1){
Serial.println("switch opened");
currentSwitchState = 0;
machine.transitionTo(pingMode);
}
}
void doPingMode(){
if(isConnected){
if (client.available()) {
char c = client.read();
Serial.print(c);
}
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
isConnected = 0;
machine.transitionTo(readMode);
}
}
else {
if (client.connect()) {
Serial.println("connected");
client.println("POST /log HTTP/1.0");
client.println("HOST: istheflooropen.com");
client.println("Content-Type: application/x-www-form-urlencoded");
client.println("Content-Length: 31");
client.println();
if(currentSwitchState == 1){
Serial.println("secret=8t7iekbjaefgi&status=on");
client.println("secret=8t7iekbjaefgi&status=on");
} else {
Serial.println("secret=8t7iekbjaefgi&status=off");
client.println("secret=8t7iekbjaefgi&status=off");
}
client.println();
isConnected = 1;
}
else {
//Serial.println("connection failed");
// machine.transitionTo(readMode);
}
}
}
void doNothing(){}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.