Value:
65Value:
)====="; * Chương trình máy chủ (master) #include #include #include #include "index.h" #include #define LED //On board LED unsigned int i = 0; //SSID and Password of your WiFi router const char* ssid = "Phong 3"; const char* password = "haiphongthoi"; IPAddress ip(192, 168, 1, 58); //set static ip IPAddress gateway(192, 168, 1, 1); //set getteway IPAddress subnet(255, 255, 255, 0);//set subnet ESP8266WebServer server(80); //Server on port 80 unsigned int now,time_l,d=30,v=3,g=27; String reciver_dt,respont_dt; //============================================================ === // This routine is executed when you open its IP in browser //============================================================ === void handleRoot() { String s = MAIN_page; //Read HTML contents server.send(200, "text/html", s); //Send web page } String dothis_code(String a) { String kq; if(a == "may1|doc"){ Serial.println("may1"); delay(5); Serial.println("doc"); byte buf; while(buf != ']'){ buf = Serial.read(); kq += char(buf); }} else return kq; } 66 void handleLED() { digitalWrite(LED,!digitalRead(LED)); String t_state = server.arg("LEDstate"); //Refer xhttp.open("GET", "setLED?LEDstate="+led, true); reciver_dt = t_state; Serial.println(reciver_dt); respont_dt = dothis_code(reciver_dt); server.send(200, "text/plane", respont_dt); digitalWrite(LED,!digitalRead(LED)); } //============================================================ == // SETUP //============================================================ == void setup(void){ Serial.begin(9600); WiFi.config(ip, gateway, subnet); WiFi.begin(ssid, password); //Connect to your WiFi router Serial.println(""); //Onboard LED port Direction output pinMode(LED,OUTPUT); // Wait for connection while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); digitalWrite(LED,!digitalRead(LED)); } //If connection successful show IP address in serial monitor Serial.println(""); Serial.print("Connected to "); Serial.println(ssid); Serial.print("IP address: "); Serial.println(WiFi.localIP()); //IP address assigned to your ESP server.on("/", handleRoot); //Which routine to handle at root location This is display page server.on("/setLED",handleLED); server.begin(); //Start server Serial.println("HTTP server started"); } //============================================================ == // LOOP //============================================================ == void loop(void){ server.handleClient(); //Handle client requests 67 Chương trình máy trạm (Slave) unsigned char a =30,b=5 #include * int time_counter; unsigned char a =30,b=5,c=25; int a1_res,b1_res,c1_res; int a2_res,b2_res,c2_res; #define led11 #define led21 #define led31 #define led12 #define led22 #define led32 10 void counter_up() { traffic_light(); time_counter++; if(time_counter ==(a+b+c)){time_counter = 0;} } void setup(){ Serial.begin(9600); cli(); pinMode(LED_BUILTIN, OUTPUT); digitalWrite(LED_BUILTIN, LOW); pinMode(led11,OUTPUT); pinMode(led21,OUTPUT); pinMode(led31,OUTPUT); pinMode(led12,OUTPUT); pinMode(led22,OUTPUT); pinMode(led32,OUTPUT); /* Reset Timer/Counter1 */ TCCR1A = 0; TCCR1B = 0; TIMSK1 = 0; /* Setup Timer/Counter1 */ TCCR1B |= (1