[SOLVED]Arduino ENC28j60 post soap request from ONVIF IP Cam port XXX

Hello,

I have an NVT IP Cam. On the PC i’am testing onvif soap traces on POSTMAN for the controling PTZ actions. Traces works perfectly. But i wanted to control it from arduino, i have ENC28j60 ethernet module, trying to post this soap request by modifiying twitter example skecth but not working, what am i doing wrong?

POSTMAN Request


Request Response


#include <EtherCard.h>

byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };

const char website[] PROGMEM = "192.168.1.10";
static byte hisip[] = { 192,168,1,10 };
static byte session;

byte Ethernet::buffer[750];
Stash stash;

static void sendTo() {
  Serial.println("Sending...");
  byte sd = stash.create();
  stash.print("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n\r");
  stash.print("<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:tptz=\"http://www.onvif.org/ver20/ptz/wsdl\" xmlns:tt=\"http://www.onvif.org/ver10/schema\">\n\r");  
  stash.print("<soap:Body>\n\r");
  stash.print("<tptz:ContinuousMove>\n\r");
  stash.print("<tptz:ProfileToken>000</tptz:ProfileToken>\n\r");
  stash.print("<tptz:Velocity>\n\r");  
  stash.print("<tt:Zoom x=\"1\"/>\n\r");
  stash.print("</tptz:Velocity>\n\r");
  stash.print("</tptz:ContinuousMove>\n\r"); 
  stash.print("</soap:Body>\n\r");
  stash.println("</soap:Envelope>\n\r"); 
  stash.save();
  int stash_size = stash.size();

  // Compose the http POST request, taking the headers below and appending
  // previously created stash in the sd holder.
  Stash::prepare(PSTR("POST http://$F:8899/onvif/PTZ HTTP/1.0" "\r\n"
    "Host: $F" "\r\n"
    "Content-Type: text/xml; charset=utf-8"  "\r\n"  
    "SOAPAction: \"http://192.168.1.10:8899/onvif/PTZ"  "\r\n"
    "Content-Length: $D" "\r\n"
    "\r\n"
    "$H"),
  website, website, stash_size, sd);

  // send the packet - this also releases all stash buffers once done
  // Save the session ID so we can watch for it in the main loop.
  session = ether.tcpSend();
}

void setup () {
  Serial.begin(57600);
  Serial.println("\n[Twitter Client]");

  if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) 
    Serial.println(F("Failed to access Ethernet controller"));
  if (!ether.dhcpSetup())
    Serial.println(F("DHCP failed"));

  ether.printIp("IP:  ", ether.myip);
  ether.printIp("GW:  ", ether.gwip);  
  ether.printIp("DNS: ", ether.dnsip);  

  if (!ether.dnsLookup(website))
    Serial.println(F("DNS failed"));

  ether.printIp("SRV: ", ether.hisip);

  sendTo();
}

void loop () {
  ether.packetLoop(ether.packetReceive());

  const char* reply = ether.tcpReply(session);
  if (reply != 0) {
    Serial.println("Got a response!");
    Serial.println(reply);
  }
}

what am i doing wrong?

I guess you forgot the RAM size. As you didn't specify otherwise I assume you use an Arduino UNO. The UNO has 2kB of RAM. The buffer you allocate and the different strings together cover almost the complete available RAM.

As you didn't tell us what output you got we had to guess that too. Please post the relevant information.

Thank you for warning...

Arduino Serial Monitor

Yes i am using uno, Global variables has caculated as 1720 bytes also ide is already warning me for 2048 byte is maximum memory and "high memory usage may cause a stability problem.."

i may done something wrong on the code lines... specially server and port definition and request comand preperation...

Thank you

Do you really think that 0.0.0.0 is the server's IP address? Is your gateway really listening on 192.168.1.1? Does provide DNS service on that IP?

pylon:
Do you really think that 0.0.0.0 is the server's IP address?

no it is 192.168.1.10 its returning from dns lookup here

if (!ether.dnsLookup(website))
    Serial.println(F("DNS failed"));

  ether.printIp("SRV: ", ether.hisip);

probably i may need help here... i have to assing hisip and hisport manually..

and after that ...

  Stash::prepare(PSTR("POST http://$F:8899/onvif/PTZ HTTP/1.0" "\r\n"
    "Host: $F" "\r\n"
    "Content-Type: text/xml; charset=utf-8"  "\r\n"  
    "SOAPAction: \"http://192.168.1.10:8899/onvif/PTZ"  "\r\n"
    "Content-Length: $D" "\r\n"
    "\r\n"
    "$H"),
  website, website, stash_size, sd);

i may need help here... is it correct or not...

pylon:
Is your gateway really listening on 192.168.1.1?

Yes. Came from DHCP it is stupid ADSL modem..

pylon:
Does provide DNS service on that IP?

I am not sure about that but in web interface there is a network setting but i dont think it is about that... guess if there is not, I could not log in to the web interface, but i am accesing web interface from direct ip adress...

I solved the problem by making some changes...

Removed these lines

if (!ether.dnsLookup(website))
    Serial.println(F("DNS failed"));

  ether.printIp("SRV: ", ether.hisip);

and added these..

  ether.copyIp(ether.hisip, hisip);
  ether.hisport = 8899;

Also changed stash preparing lines like this...

  Stash::prepare(PSTR("POST http://$F HTTP/1.0" "\r\n"
    "Host: $F:8899" "\r\n"
    "Content-Type: application/soap+xml; charset=utf-8"  "\r\n"    
    "Content-Length: $D" "\r\n"
    "\r\n"
    "$H"),
  website, website, stash_size, sd);

i hope it will help some one needed to...