Advertisement
Guest User

Untitled

a guest
Sep 27th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <Ethernet.h>
  3.  
  4. //Informacoes de endereco IP, gateway, mascara de rede
  5. byte mac[] = { 0xA4, 0x28, 0x72, 0xCA, 0x55, 0x2F };
  6. byte ip[] = { 192, 168, 1, 200 };
  7. byte gateway[] = { 192, 168, 1, 1 };
  8. byte subnet[] = { 255, 255, 255, 0 };
  9. char server[] = "localhost"; //the ip of the web service
  10.  
  11. EthernetClient client;
  12.  
  13. void setup() {
  14.  
  15. Serial.begin(9600);
  16. while (!Serial) {
  17. ; // wait for serial port to connect. Needed for native USB port only
  18. }
  19.  
  20. // start the Ethernet connection:
  21. if (Ethernet.begin(mac) == 0) {
  22. Serial.println("Failed to configure Ethernet using DHCP");
  23. // try to congifure using IP address instead of DHCP:
  24. Ethernet.begin(mac, ip);
  25. }
  26. // give the Ethernet shield a second to initialize:
  27. delay(1000);
  28. Serial.println("connecting...");
  29.  
  30. // if you get a connection, report back via serial:
  31. if (client.connect(server, 4548)) {
  32. Serial.println("connected");
  33. // Make a HTTP request:
  34. client.println("GET /request?id=12&user=username&pass=password HTTP/1.1");
  35. client.println("Host: localhost");
  36. client.println("Connection: close");
  37. client.println();
  38. } else {
  39. // if you didn't get a connection to the server:
  40. Serial.println("connection failed");
  41. }
  42. }
  43.  
  44. void loop() {
  45. // if there are incoming bytes available
  46. // from the server, read them and print them:
  47. if (client.available()) {
  48. char c = client.read();
  49. Serial.print(c);
  50. }
  51.  
  52. // if the server's disconnected, stop the client:
  53. if (!client.connected()) {
  54. Serial.println();
  55. Serial.println("disconnecting.");
  56. client.stop();
  57.  
  58. // do nothing forevermore:
  59. while (true);
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement