-
Notifications
You must be signed in to change notification settings - Fork 0
/
Traffic.ino
52 lines (50 loc) · 1.24 KB
/
Traffic.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
#include <ESP8266WiFi.h>
WiFiClient client;
WiFiServer server(80);
# define LED_Red D5
# define LED_Yellow D6
# define LED_Green D7
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
WiFi.begin("Enter-your-username","Enter-password");//Ensure to replace it with correct username & password.( Both are case sensitive)
while(WiFi.status() !=WL_CONNECTED)
{delay(500);
Serial.print(".");
}
Serial.println();
Serial.println("NodeMCU is Connected");
Serial.println(WiFi.localIP());
server.begin();
pinMode(LED_Red, OUTPUT);
pinMode(LED_Yellow, OUTPUT);
pinMode(LED_Green, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
client=server.available();
if(client==1)
{
String request =client.readStringUntil('\n');
Serial.println(request);
request.trim();
if(request =="GET /LED_Red HTTP/1.1")
{
digitalWrite(LED_Red, HIGH);
digitalWrite(LED_Yellow, LOW);
digitalWrite(LED_Green, LOW);
}
if(request =="GET /LED_Yellow HTTP/1.1")
{
digitalWrite(LED_Red, LOW);
digitalWrite(LED_Yellow, HIGH);
digitalWrite(LED_Green, LOW);
}
if(request =="GET /LED_Green HTTP/1.1")
{
digitalWrite(LED_Red, LOW);
digitalWrite(LED_Yellow, LOW);
digitalWrite(LED_Green, HIGH);
}
}
}