daily pastebin goal
50%
SHARE
TWEET

Untitled

a guest Apr 1st, 2016 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include
  2. #include
  3. #include          
  4. #include
  5. #include
  6. int porta_rele = 9; //Rele ligado a porta 9 do arduino
  7.  
  8. byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
  9. byte ip[] = { 192, 168, 0, 100 };
  10. IPAddress pingAddr(192,168,0,1); // ip address to ping
  11.  
  12. SOCKET pingSocket = 0;
  13.  
  14. char buffer [256];
  15. ICMPPing ping(pingSocket, (uint16_t)random(0, 255));
  16.    
  17. EthernetServer server(80);
  18.  
  19. String readString;
  20. int Pin = 9;
  21.  
  22. void setup(){
  23.   pinMode(Pin, OUTPUT);
  24.   Ethernet.begin(mac, ip);
  25.   server.begin();
  26.   Serial.begin(9600);
  27. }
  28.  
  29. void loop(){
  30.   ICMPEchoReply echoReply = ping(pingAddr, 4);
  31.   if (echoReply.status == SUCCESS)
  32.   {
  33.    sprintf(buffer,"Reply[%d] from: %d.%d.%d.%d: bytes=%d time=%ldms TTL=%d",
  34.             echoReply.data.seq,
  35.             echoReply.addr[0],
  36.             echoReply.addr[1],
  37.             echoReply.addr[2],
  38.             echoReply.addr[3],
  39.             REQ_DATASIZE,
  40.             millis() - echoReply.data.time,
  41.             echoReply.ttl);
  42.              
  43.   //Aguarda 2 segundo e repete o processo
  44.   delay (2000);
  45.   }
  46.   else
  47.   {
  48.     sprintf(buffer, "Echo request failed; %d", echoReply.status);
  49.     digitalWrite(porta_rele,HIGH); //Liga o led vermelho
  50.     Serial.println(" REINICIANDO EQUIPAMENTOS ");
  51.     delay(5000);
  52.     digitalWrite(porta_rele,LOW); // Desliga o led
  53.   }
  54.  
  55.   EthernetClient client = server.available();
  56.   if (client) {
  57.     while (client.connected()) {
  58.       if (client.available()) {
  59.         char c = client.read();
  60.  
  61.         if (readString.length() < 100) {
  62.           readString += c;            
  63.         }
  64.  
  65.         if (c == '\n') {
  66.           client.println("HTTP/1.1 200 OK");
  67.           client.println("Content-Type: text/html");
  68.           client.println();
  69.            
  70.           client.println("");
  71.           client.println("");
  72.           client.println("Acende LED");
  73.           client.println("");
  74.           client.println("");
  75.            
  76.           client.println("<a>Ligar o led</a>");
  77.           client.println("<a>Desligar o led</a>");  
  78.            
  79.           client.println("");
  80.           client.println("");
  81.            
  82.           delay(1);
  83.           client.stop();
  84.            
  85.           if(readString.indexOf("?ledon") &gt; 0)
  86.           {
  87.             digitalWrite(Pin, HIGH);
  88.           }
  89.           else {
  90.             if(readString.indexOf("?ledoff") &gt; 0)
  91.             {
  92.               digitalWrite(Pin, LOW);
  93.             }
  94.           }
  95.           readString="";    
  96.         }
  97.       }
  98.     }
  99.   }
  100.   delay(1000);
  101.   Serial.println(buffer);
  102.  delay(5000); // Tempo para liga o radio
  103.  
  104. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top