-
Notifications
You must be signed in to change notification settings - Fork 0
/
ArduinoNanoEthernet_5Out_2InAndWebsite.ino
156 lines (134 loc) · 3.93 KB
/
ArduinoNanoEthernet_5Out_2InAndWebsite.ino
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include <UIPEthernet.h>
//VERSION VOM Jan18
int erstausgang = 4;
int letztausgang = 8;
int ersteingang = A0;
int letzteingang = A1;
byte mac[] = { 0x12, 0x34, 0x56, 0x78, 0x90, 0x12 };
IPAddress ip(192, 168, 2, 42);
EthernetServer server(80);
String readString = String(20);
void setup() {
pinMode(A0, INPUT_PULLUP);
pinMode(A1, INPUT_PULLUP);
Ethernet.begin(mac, ip);
server.begin();
for (int o = erstausgang; o <= letztausgang; o++) {
pinMode(o, OUTPUT);
}
}
void loop() {
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (readString.length() < 20) {
readString = readString + c;
}
if (c == '\n')
{
if (readString.indexOf("4=Ein") > -1)
{
digitalWrite(4, HIGH);
}
if (readString.indexOf("4=Aus") > -1)
{
digitalWrite(4, LOW);
}
if (readString.indexOf("5=Ein") > -1)
{
digitalWrite(5, HIGH);
}
if (readString.indexOf("5=Aus") > -1)
{
digitalWrite(5, LOW);
}
if (readString.indexOf("6=Ein") > -1)
{
digitalWrite(6, HIGH);
}
if (readString.indexOf("6=Aus") > -1)
{
digitalWrite(6, LOW);
}
if (readString.indexOf("7=Ein") > -1)
{
digitalWrite(7, HIGH);
}
if (readString.indexOf("7=Aus") > -1)
{
digitalWrite(7, LOW);
}
if (readString.indexOf("8=Ein") > -1)
{
digitalWrite(8, HIGH);
}
if (readString.indexOf("8=Aus") > -1)
{
digitalWrite(8, LOW);
}
client.println("<!DOCTYPE html><html><head><meta name=viewport content='width=150' /></head><body>");
//<meta http-equiv=refresh content=5; URL=192.168.2.42/>
for (int i = erstausgang; i <= letztausgang; i++) {
// ERSTELLT DIE TASTER
client.print("<br>Zimmer ");
client.print(i - 3);
client.print("<font color='");
if (digitalRead(i) == HIGH) {
client.print("green'> An");
}
else {
client.print("red'> Aus");
}
client.println("</font>");
client.print("<form method=get>");
for (int x = 1; x <= 2; x++) {
client.print("<input type=submit name=");
client.print(i);
client.print(" value='");
if (x == 1) {
client.print("Ein");
}
else {
client.print("Aus");
}
client.print("'>");
}
client.println("</form>");
}
for (int i = ersteingang; i <= letzteingang; i++) {
int y = analogRead(i);
client.print("<br>");
client.print("Eingang ");
client.print(i - 13);
client.print(" <font color='");
if (y > 980) {
client.print("red");
}
else
{
client.print("green");
}
client.print("'> ");
//client.print(y);
if (y > 980) {
client.print("Aus");
}
else
{
client.print("An");
}
client.println("<br></font>");
}
client.println("<br><INPUT TYPE=button onClick=history.go(0) VALUE=Neuladen><p>by Tobias Fritsch</p></body></html>");
// client.println("<br>by Tobias Fritsch</body></html>");
//clearing string for next read
readString = "";
//stopping client
client.stop();
}
}
}
}
}