-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLanSwitchToggle.ino
More file actions
110 lines (82 loc) · 2.94 KB
/
LanSwitchToggle.ino
File metadata and controls
110 lines (82 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include<SPI.h>
#include<Ethernet.h>
//const int PowerButtonPin = 3;
//const int RestartButtonPin = 4;
const int PowerRelayTriggerPin = 7;
//const int RestartRelayTriggerPin = 8;
//const int LEDPin = 13;
//int PowerButtonState = 0;
int RelayButtonState = 0;
static byte mac[] = { 0xDE,0xAD, 0xBE, 0xEF, 0xFE, 0xED };
static byte ip[] = { 192, 168, 0, 103};
static byte gateway[] = { 192, 168, 0, 1};
static byte subnet[] = { 255, 255, 255, 0};
String ReadString;
EthernetServer server(80);
void setup()
{
pinMode(PowerRelayTriggerPin, OUTPUT);
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
Serial.begin(9600);
Serial.println(Ethernet.localIP());
}
void loop()
{
EthernetClient client = server.available();
// PowerButtonState = digitalRead(PowerButtonPin);
// RelayButtonState = digitalRead(RestartButtonPin);
if(client)
{
while(client.connected())
{
if (client.available())
{
char c = client.read();
if(ReadString.length() < 100)
{
ReadString += c;
}
if (c == '\n')
{
Serial.println(ReadString);
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println("<HTML>");
client.println("<HEAD>");
client.println("<meta name='apple-mobile-web-app-capable' content='yes' />");
client.println("<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />");
client.println("<link rel='stylesheet' type='text/css' link href='https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css' />");
client.println("<TITLE>Switch Board</TITLE>");
client.println("</HEAD>");
client.println("<BODY class=\"container jumbotron\">");
client.println("<H1 class=\"font-weight-bold\" >SwitchBoard</H1>");
client.println("<br />");
client.println("<hr />");
client.println("<a class=\"col col-lg-2 btn btn-success btn-lg btn-primary\" href=\"/?start\"\">Power</a>");
client.println("<br />");
client.println("<br />");
client.println("<br />");
client.println("</BODY>");
client.println("</HTML>");
delay(1);
client.stop();
if (ReadString.indexOf("?start") >0)
{
//perform toggle funcion hrtr
if(digitalRead(PowerRelayTriggerPin) == HIGH)
{
digitalWrite(PowerRelayTriggerPin, LOW);
}
else
{
digitalWrite(PowerRelayTriggerPin, HIGH);
}
}
ReadString="";
}
}
}
}
}