Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.73 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <Ethernet.h>
  3.  
  4.  // Enter a MAC address for your controller below.
  5.  // Newer Ethernet shields have a MAC address printed on a sticker on the shield
  6. byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
  7. // if you don't want to use DNS (and reduce your sketch size)
  8. // use the numeric IP instead of the name for the server:
  9. //IPAddress server(74,125,232,128);  // numeric IP for Google (no DNS)
  10. char server[] = "192.168.178.42";    
  11.  
  12. // Set the static IP address to use if the DHCP fails to assign
  13. IPAddress ip(192, 168, 178, 175);
  14.  
  15. // Initialize the Ethernet client library
  16. // with the IP address and port of the server
  17. // that you want to connect to (port 80 is default for HTTP):
  18. EthernetClient client;
  19.  
  20. void setup() {
  21.     // Open serial communications and wait for port to open:
  22.     Serial.begin(115200);
  23.     while (!Serial) {
  24.         ; // wait for serial port to connect. Needed for native USB port only
  25.     }
  26.  
  27.     Ethernet.begin(mac, ip);
  28.  
  29.     // give the Ethernet shield a second to initialize:
  30.     delay(1000);
  31.     Serial.println("connecting...");
  32.  
  33.     // if you get a connection, report back via serial:
  34.     if (client.connect(server, 49000))
  35.     {
  36.         Serial.println("connected");
  37.         // Make a HTTP request:
  38.         /*
  39.         client.println("GET /tr64desc.xml HTTP/1.1");
  40.         client.println("HOST: 192.168.178.1:49000");
  41.         client.println("CONNECTION: Close");
  42.         client.println("USER-AGENT: AVM UPnP/1.0 Client 1.0");
  43.         client.println();
  44.         */
  45.  
  46.        
  47.        
  48.         client.println("POST /upnp/control/deviceinfo HTTP/1.1");
  49.         client.println("HOST: 192.168.178.42:49000");
  50.         client.println("CONTENT-LENGTH: 267");
  51.         client.println("CONTENT-TYPE: text/xml; charset=\"utf-8\"");
  52.         client.println("SOAPACTION: \"urn:dslforum-org:service:DeviceInfo:1#GetSecurityPort\"");
  53.         client.println("USER-AGENT: AVM UPnP/1.0 Client 1.0");
  54.         client.println();
  55.         client.println("<?xml version=\"1.0\"?>");
  56.         client.println("<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">");
  57.         client.println("<s:Body>");
  58.         client.println("<u:GetSecurityPort xmlns:u=\"urn:dslforum-org:service:DeviceInfo:1\">");
  59.         client.println("</u:GetSecurityPort>");
  60.         client.println("</s:Body>");
  61.         client.println("</s:Envelope>");
  62.        
  63.         Serial.println("connected\nPosted Data via client.println():\n");
  64.         Serial.println("POST /upnp/control/deviceinfo HTTP/1.1");
  65.         Serial.println("HOST: 192.168.178.1:49000");
  66.         Serial.println("CONTENT-LENGTH: 267");
  67.         Serial.println("CONTENT-TYPE: text/xml; charset=\"utf-8\"");
  68.         Serial.println("SOAPACTION: \"urn:dslforum-org:service:DeviceInfo:1#GetSecurityPort\"");
  69.         Serial.println("USER-AGENT: AVM UPnP/1.0 Client 1.0");
  70.         Serial.println();
  71.         Serial.println("<?xml version=\"1.0\"?>");
  72.         Serial.println("<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">");
  73.         Serial.println("<s:Body>");
  74.         Serial.println("<u:GetSecurityPort xmlns:u=\"urn:dslforum-org:service:DeviceInfo:1\">");
  75.         Serial.println("</u:GetSecurityPort>");
  76.         Serial.println("</s:Body>");
  77.         Serial.println("</s:Envelope>");
  78.        
  79.        
  80.  
  81.     }
  82.     else {
  83.         // if you didn't get a connection to the server:
  84.         Serial.println("connection failed");
  85.     }
  86. }
  87.  
  88. void loop() {
  89.     // if there are incoming bytes available
  90.     // from the server, read them and print them:
  91.     if (client.available())
  92.     {
  93.         Serial.println("Response recieved:\n");
  94.         while (client.available())
  95.         {          
  96.             char c = client.read();
  97.             Serial.print(c);
  98.         }      
  99.         Serial.println();
  100.     }
  101.  
  102.  
  103.     // if the server's disconnected, stop the client:
  104.     if (!client.connected()) {
  105.         Serial.println();
  106.         Serial.println("disconnecting.");
  107.         client.stop();
  108.  
  109.         // do nothing forevermore:
  110.         while (true);
  111.     }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement