Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Ethernet.h>
  2.  
  3. byte mac[] = {0xE8, 0x2A, 0xEA, 0x4B, 0x1F, 0xC3};
  4. IPAddress ip(192, 168, 0, 177);
  5. unsigned int port = 50001;
  6.  
  7. String stringIn;
  8.  
  9. EthernetServer server(port);
  10.  
  11. void setup() {
  12.   Ethernet.begin(mac, ip);
  13.   server.begin();
  14.   Serial.begin(9600);
  15. }
  16.  
  17. void loop() {
  18.   // if an incoming client connects, there will be bytes available to read:
  19.   EthernetClient client = server.available();
  20.  
  21.   if (client.connected()) {
  22.  
  23.     stringIn = "";
  24.     while (client.available()) {
  25.       char c = client.read();
  26.       stringIn = stringIn + c;
  27.     }
  28.  
  29.     if (stringIn == "Test")
  30.     {
  31.       client.print("Message received");
  32.     }
  33.     Serial.println (stringIn);
  34.   }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement