-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWifiTest.ino
80 lines (67 loc) · 1.85 KB
/
WifiTest.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
#include <SPI.h>
#include <WiFiNINA.h> //https://github.com/arduino-libraries/WiFiNINA
#define led 9
char ssid[] = "test"; //change this
char pass[] = ""; //change this
int keyIndex = 0;
int status = WL_IDLE_STATUS;
WiFiServer server(80);
String readString;
void setup() {
pinMode(led, OUTPUT);
Serial.begin(9600);
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to Network named: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass);
delay(10000);
}
server.begin();
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
}
void loop() {
WiFiClient client = server.available();
if (client)
{
Serial.println("new client");
while (client.connected())
{
if (client.available())
{
char c = client.read();
if (readString.length() < 100)
{
readString += c;
Serial.write(c);
if (c == '\n') {
client.println("<a href=\"/?lighton\"\">Turn On Light</a>");
client.println("<br />");
client.println("<br />");
client.println("<a href=\"/?lightoff\"\">Turn Off Light</a><br />");
delay(1);
if(readString.indexOf("?lighton") > 0)
{
digitalWrite(led, HIGH);
delay(1);
}
else{
if(readString.indexOf("?lightoff") > 0)
{
digitalWrite(led, LOW);
delay(1);
}
}
readString="";
delay(1);
client.stop();
Serial.println("client disonnected");
}
}
}
}
}
}