Page 72 - MDP2020-2
P. 72

|    인천전자마이스터고등학교  ·············································································································
            66


                                                     else{
                                                             display.value  =  "error;"
                                                     }
                                             });
                                     else                                                                                                //암호가  다르면

               fetch("/key/wrong")
                                             .then(response=>  {  console.log(response);  return  response.text()})
                                             .then(data=>  {
                                                     console.log(data);
                                                     let  result  =  document.querySelector("#result");
                                                     if(data=="ok"){
                                                             display.value  =  "잘  못  된  암호입니다.";
                                                             setTimeout(function()  {
                                                             display.value=  ""
                                                             },  5000);                                                              //5초  후  글씨  삭제
                                                     }else{
                                                             display.value  =  "error;"
                                                     }
                                             });

                                     flag  =  false;
                             }
                             function  door(){                                                                                //문  열기
                                     var  start  =  new  Date().getTime();
                                     fetch("/house/led/open")
                                     .then(response=>  {  console.log(response);  return  response.text()})
                                     .then(data=>  {
                                             console.log(data);
                                             let  result  =  document.querySelector("#result");
                                             if(data=="ok"){
                                                     sleep(7000);                                                                //7초  딜레이
                                                     door_d();                                                                      //PIR센서  감지
                                                     door_c();                                                                      //문  닫기
                                             }else{
                                                     result.innerHTML  =  "<h1>error</h1>";
                                             }
                                     });
                             }
                             function  door_c(){                                                                            //문  닫기
                                     fetch("/house/led/open/c")
                                     .then(response=>  {  console.log(response);  return  response.text()})
                                     .then(data=>  {
                                             console.log(data);
                                             let  result  =  document.querySelector("#result");
                                             if(data=="fail"){
                                                     result.innerHTML  =  "<h1>에러가  발생하였습니다</h1>"
                                             }
                                     });
                             }
                             function  sleep  (delay)  {                                                                //딜레이  함수
                                     var  start  =  new  Date().getTime();
                                     while  (new  Date().getTime()  <  start  +  delay);
                             }
                             function  door_d(){                                                                            //PIR센서  감지
                                     fetch("/house/led/open/d")
                                     .then(response=>  {  console.log(response);  return  response.text()})
                                     .then(data=>  {
                                             console.log(data);
                                             let  result  =  document.querySelector("#result");
                                             if(data=="ok"){
                                                     return  door();
   67   68   69   70   71   72   73   74   75   76   77