1 | /*
|
2 | Web client
|
3 |
|
4 | This sketch connects to a website (http://www.google.com)
|
5 | using an Arduino Wiznet Ethernet shield.
|
6 |
|
7 | Circuit:
|
8 | * Ethernet shield attached to pins 10, 11, 12, 13
|
9 |
|
10 | created 18 Dec 2009
|
11 | by David A. Mellis
|
12 | modified 9 Apr 2012
|
13 | by Tom Igoe, based on work by Adrian McEwen
|
14 |
|
15 | */
|
16 |
|
17 | #include <SPI.h>
|
18 | #include <Ethernet.h>
|
19 |
|
20 | // Enter a MAC address for your controller below.
|
21 | // Newer Ethernet shields have a MAC address printed on a sticker on the shield
|
22 | byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
|
23 | byte gateway[] = { 192,168,1,254};
|
24 | // the subnet:
|
25 | byte subnet[] = { 255, 255, 255, 0 };
|
26 | String str="";
|
27 |
|
28 | // if you don't want to use DNS (and reduce your sketch size)
|
29 | // use the numeric IP instead of the name for the server:
|
30 | IPAddress server(192,168,1,212);
|
31 |
|
32 | // numeric IP for Google (no DNS)
|
33 | //char server[] = "www.google.com"; // name address for Google (using DNS)
|
34 | //char server[] = "www.augilabs.de"; // name address for Google (using DNS)
|
35 |
|
36 |
|
37 | // Set the static IP address to use if the DHCP fails to assign
|
38 | IPAddress ip(192,168,1,177);
|
39 |
|
40 | // Initialize the Ethernet client library
|
41 | // with the IP address and port of the server
|
42 | // that you want to connect to (port 80 is default for HTTP):
|
43 | EthernetClient client;
|
44 |
|
45 | void setup() {
|
46 | // Open serial communications and wait for port to open:
|
47 | Serial.begin(9600);
|
48 | // while (!Serial) {
|
49 | // ; // wait for serial port to connect. Needed for Leonardo only
|
50 | // }
|
51 |
|
52 | // start the Ethernet connection:
|
53 | /*
|
54 | if (Ethernet.begin(mac) == 0) {
|
55 | Serial.println("Failed to configure Ethernet using DHCP");
|
56 | // no point in carrying on, so do nothing forevermore:
|
57 | // try to congifure using IP address instead of DHCP:
|
58 | Ethernet.begin(mac, ip);
|
59 | }
|
60 | */
|
61 | // initialize the ethernet device
|
62 | Ethernet.begin(mac, ip, gateway, subnet);
|
63 | // Ethernet.begin(mac, ip);
|
64 |
|
65 | // give the Ethernet shield a second to initialize:
|
66 | delay(1000);
|
67 | Serial.println("connecting...");
|
68 |
|
69 | // if you get a connection, report back via serial:
|
70 |
|
71 | if (client.connect(server, 80)) {
|
72 | Serial.print("connected to");
|
73 | Serial.println(server);
|
74 |
|
75 | // Make a HTTP request:
|
76 | /*
|
77 | client.print("GET /tgi/control.tgi?login");
|
78 | client.print("=");
|
79 | client.print("p:admin:admin");
|
80 | client.print("&port=list");
|
81 | client.println(" HTTP/1.1");
|
82 | client.println("User-Agent: Arduino");
|
83 | client.println("Accept: text/html,application/xhtml+xml,application/xml;q=0.9;q=0.8");
|
84 | client.println();
|
85 | client.stop();
|
86 | */
|
87 | client.println("GET /tgi/control.tgi?login=p:admin:admin&port=0110 HTTP/1.1 ");
|
88 |
|
89 | }
|
90 | else {
|
91 | // kf you didn't get a connection to the server:
|
92 | Serial.println("connection failed");
|
93 | }
|
94 |
|
95 | }
|
96 |
|
97 | void loop()
|
98 | {
|
99 | // Serial.println("Ich bin im LOOP");
|
100 |
|
101 | // if there are incoming bytes available
|
102 | // from the server, read them and print them:
|
103 | if (client.available()) {
|
104 | char c = client.read();
|
105 | Serial.print(c);
|
106 | }
|
107 |
|
108 | // if the server's disconnected, stop the client:
|
109 | if (!client.connected()) {
|
110 | Serial.println();
|
111 | Serial.println("disconnecting.");
|
112 | client.stop();
|
113 |
|
114 | // do nothing forevermore:
|
115 | while(true);
|
116 | }
|
117 | }
|