Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <Ethernet.h>
- // Enter a MAC address for your controller below.
- // Newer Ethernet shields have a MAC address printed on a sticker on the shield
- byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
- // if you don't want to use DNS (and reduce your sketch size)
- // use the numeric IP instead of the name for the server:
- //IPAddress server(74,125,232,128); // numeric IP for Google (no DNS)
- char server[] = "192.168.178.42";
- // Set the static IP address to use if the DHCP fails to assign
- IPAddress ip(192, 168, 178, 175);
- // Initialize the Ethernet client library
- // with the IP address and port of the server
- // that you want to connect to (port 80 is default for HTTP):
- EthernetClient client;
- void setup() {
- // Open serial communications and wait for port to open:
- Serial.begin(115200);
- while (!Serial) {
- ; // wait for serial port to connect. Needed for native USB port only
- }
- 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, 49000))
- {
- Serial.println("connected");
- // Make a HTTP request:
- /*
- client.println("GET /tr64desc.xml HTTP/1.1");
- client.println("HOST: 192.168.178.1:49000");
- client.println("CONNECTION: Close");
- client.println("USER-AGENT: AVM UPnP/1.0 Client 1.0");
- client.println();
- */
- client.println("POST /upnp/control/deviceinfo HTTP/1.1");
- client.println("HOST: 192.168.178.42:49000");
- client.println("CONTENT-LENGTH: 267");
- client.println("CONTENT-TYPE: text/xml; charset=\"utf-8\"");
- client.println("SOAPACTION: \"urn:dslforum-org:service:DeviceInfo:1#GetSecurityPort\"");
- client.println("USER-AGENT: AVM UPnP/1.0 Client 1.0");
- client.println();
- client.println("<?xml version=\"1.0\"?>");
- client.println("<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">");
- client.println("<s:Body>");
- client.println("<u:GetSecurityPort xmlns:u=\"urn:dslforum-org:service:DeviceInfo:1\">");
- client.println("</u:GetSecurityPort>");
- client.println("</s:Body>");
- client.println("</s:Envelope>");
- Serial.println("connected\nPosted Data via client.println():\n");
- Serial.println("POST /upnp/control/deviceinfo HTTP/1.1");
- Serial.println("HOST: 192.168.178.1:49000");
- Serial.println("CONTENT-LENGTH: 267");
- Serial.println("CONTENT-TYPE: text/xml; charset=\"utf-8\"");
- Serial.println("SOAPACTION: \"urn:dslforum-org:service:DeviceInfo:1#GetSecurityPort\"");
- Serial.println("USER-AGENT: AVM UPnP/1.0 Client 1.0");
- Serial.println();
- Serial.println("<?xml version=\"1.0\"?>");
- Serial.println("<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">");
- Serial.println("<s:Body>");
- Serial.println("<u:GetSecurityPort xmlns:u=\"urn:dslforum-org:service:DeviceInfo:1\">");
- Serial.println("</u:GetSecurityPort>");
- Serial.println("</s:Body>");
- Serial.println("</s:Envelope>");
- }
- 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())
- {
- Serial.println("Response recieved:\n");
- while (client.available())
- {
- char c = client.read();
- Serial.print(c);
- }
- Serial.println();
- }
- // 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