Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <Ethernet.h>
- //Informacoes de endereco IP, gateway, mascara de rede
- byte mac[] = { 0xA4, 0x28, 0x72, 0xCA, 0x55, 0x2F };
- byte ip[] = { 192, 168, 1, 200 };
- byte gateway[] = { 192, 168, 1, 1 };
- byte subnet[] = { 255, 255, 255, 0 };
- char server[] = "localhost"; //the ip of the web service
- 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, 4548)) {
- Serial.println("connected");
- // Make a HTTP request:
- client.println("GET /request?id=12&user=username&pass=password HTTP/1.1");
- client.println("Host: localhost");
- client.println("Connection: close");
- client.println();
- } else {
- // if you didn't get a connection to the server:
- Serial.println("connection failed");
- }
- }
- void loop() {
- // if there are incoming bytes available
- // from the server, read them and print them:
- if (client.available()) {
- char c = client.read();
- Serial.print(c);
- }
- // if the server's disconnected, stop the client:
- if (!client.connected()) {
- Serial.println();
- Serial.println("disconnecting.");
- client.stop();
- // do nothing forevermore:
- while (true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement