Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <Ethernet.h>
- int write = 0;
- char response[] = "";
- int i = 0;
- byte mac[] = { 0x1A, 0xE5, 0x95, 0x1B, 0x5C, 0x4B };
- IPAddress server(192,168,100,10);
- IPAddress ip(192, 168, 100, 70);
- EthernetClient client;
- void setup() {
- Serial.begin(9600);
- while (!Serial) {
- ; // wait for serial port to connect. Needed for native USB port only
- }
- // start the Ethernet connection:
- if (Ethernet.begin(mac) == 0) {
- Serial.println("Failed to configure Ethernet using DHCP");
- // try to congifure using IP address instead of DHCP:
- Ethernet.begin(mac, ip);
- }
- // give the Ethernet shield a second to initialize:
- delay(1000);
- Serial.println("connecting...");
- // if you get a connection, report back via serial:
- if (client.connect(server, 80)) {
- Serial.println("connected");
- // Make a HTTP request:
- client.println("GET /school/bachelor/v2/devices/58 HTTP/1.1");
- client.println("Host: 192.168.100.70");
- client.println("Connection: close");
- client.println();
- delay(500);
- if(client.available())
- {
- while(client.available()) {
- char c = client.read();
- if(c == '{')
- write = 1;
- if(write == 1)
- {
- //response[i++] = c;
- Serial.print(c);
- if(c == '}')
- write = 0;
- }
- }
- }
- client.stop();
- Serial.println();
- Serial.println("disconnecting.");
- } else {
- // if you didn't get a connection to the server:
- Serial.println("connection failed");
- }
- }
- void loop() {
- Serial.println("loop");
- delay(25000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement