Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.65 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <Ethernet.h>
  3.  
  4.  
  5. int write = 0;
  6. char response[] = "";
  7. int i = 0;
  8. byte mac[] = { 0x1A, 0xE5, 0x95, 0x1B, 0x5C, 0x4B };
  9. IPAddress server(192,168,100,10);
  10. IPAddress ip(192, 168, 100, 70);
  11. EthernetClient client;
  12.  
  13. void setup() {
  14.   Serial.begin(9600);
  15.   while (!Serial) {
  16.     ; // wait for serial port to connect. Needed for native USB port only
  17.   }
  18.  
  19.   // start the Ethernet connection:
  20.   if (Ethernet.begin(mac) == 0) {
  21.     Serial.println("Failed to configure Ethernet using DHCP");
  22.     // try to congifure using IP address instead of DHCP:
  23.     Ethernet.begin(mac, ip);
  24.   }
  25.   // give the Ethernet shield a second to initialize:
  26.   delay(1000);
  27.   Serial.println("connecting...");
  28.  
  29.   // if you get a connection, report back via serial:
  30.   if (client.connect(server, 80)) {
  31.     Serial.println("connected");
  32.     // Make a HTTP request:
  33.     client.println("GET /school/bachelor/v2/devices/58 HTTP/1.1");
  34.     client.println("Host: 192.168.100.70");
  35.     client.println("Connection: close");
  36.     client.println();
  37.  
  38.     delay(500);
  39.  
  40.     if(client.available())
  41.     {
  42.       while(client.available()) {
  43.         char c = client.read();
  44.    
  45.         if(c == '{')
  46.           write = 1;
  47.    
  48.         if(write == 1)
  49.         {
  50.           //response[i++] = c;
  51.           Serial.print(c);
  52.          
  53.           if(c == '}')
  54.             write = 0;
  55.         }
  56.       }
  57.     }
  58.  
  59.     client.stop();
  60.     Serial.println();
  61.     Serial.println("disconnecting.");
  62.    
  63.   } else {
  64.     // if you didn't get a connection to the server:
  65.     Serial.println("connection failed");
  66.   }
  67. }
  68.  
  69. void loop() {
  70.   Serial.println("loop");
  71.   delay(25000);
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement