Advertisement
Guest User

Untitled

a guest
Jan 26th, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <SPI.h>
  2. #include <Ethernet2.h>
  3.  
  4. // Enter a MAC address and IP address for your controller below.
  5. // The IP address will be dependent on your local network:
  6. byte mac[] = {
  7.   0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
  8. };
  9. IPAddress ip(192, 168, 178, 177);
  10.  
  11. // Initialize the Ethernet server library
  12. // with the IP address and port you want to use
  13. // (port 80 is default for HTTP):
  14. EthernetServer server(80);
  15.  
  16. void setup() {
  17.   // Open serial communications and wait for port to open:
  18.   Serial.begin(9600);
  19.   while (!Serial) {
  20.     ; // wait for serial port to connect. Needed for Leonardo only
  21.   }
  22.  
  23.  
  24.   // start the Ethernet connection and the server:
  25.   Ethernet.begin(mac, ip);
  26.   server.begin();
  27.   Serial.print("server is at ");
  28.   Serial.println(Ethernet.localIP());
  29. }
  30.  
  31. String buffer ="";
  32. char antwort[10];
  33. int index=0;
  34. bool stat;
  35.  
  36. void loop() {
  37.  
  38.   EthernetClient client = server.available();
  39.   while(client.connected())
  40.   {
  41.     while(client.available())
  42.     {
  43.       char c=client.read();
  44.       buffer+=c;
  45.       if (c=='\n'){buffer="";}
  46.       else if (c=='\r')
  47.       {
  48.          if (buffer.indexOf("GET /?on">=0)) {
  49.             Serial.print("es funktioniert");
  50.             buffer ="";
  51.         }
  52.       }
  53.  
  54.     }
  55.  
  56.   }
  57.  
  58. }
  59.  
  60. boolean getData(EthernetClient c)
  61. {
  62.   while(c.available())
  63.     {
  64.       char dataRec=c.read();
  65.       if (index<=9)
  66.  
  67.       {      
  68.         antwort[index++]=dataRec;
  69.       }
  70.       else{
  71.         stat = true;
  72.       }
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement