Hikvision isapi - email picture at set times

g6swj

n3wb
Nov 15, 2024
3
1
Northamptonshire UK
Hello,

I am new here so forgive me if I have posted in the wrong place. I am using a DS-2CD2386G2-ISU/SL and an Arduino with an ethernet shield.

I can sucessfully update the OSD overlay text so have got to grips with using some aspects of the API.

Manually the only way I have found to email an iamge requries human intervention by toggling the "Enable Alarm Input Handling" enable/disable.

I have been able to control the "alarm type" NC or NO vi the API but cannot seem to set the "Enable Alarm Input Handling" enable/disable.

Any help will be gratefully received - or is there a better way to do this

I did not find the method of using the time schedule enable/disable worked for me

Code:
XML
big_string += "<?xml version=\"1.0\"encoding=\"UTF-8\"?>\n\r";
big_string += "<IOInputPort version=\"2.0\" xmlns=\"http://www.hikvision.com/ver20/XMLSchema\">\n\r";
big_string += "<id>1</id>\n\r";
big_string += "<enabled>true</enabled>\n\r";
big_string += "<triggering>high</triggering>\n\r";
big_string += "</IOInputPort>\n\r";

Regards
Jonathan
 
What you are doing is manual alarm input, which have high and low values,so after sending a "high" trigger value, send "low" to close value, the delay you can add minimum of 1s

I haven't seen manual email send node in entire documentation. Email is an action to an event trigger. So you either trigger an event or alarm input to actually start email send


Other way around for your aplication scenario.

In your application set:
/capture controller- This will be called from either phone, windows, mac, 3rd party whatsoever.
Capture request toward cameras after /capture has been ccalled - http://IP:port/ISAPI/Streaming/channels/<channel number>/picture?videoResolutionWidth=1920&videoResolutionHeight=1080
email framework with attached images
send to mail list of your choice.
 
This may be of use to someone - still work in progress but this Arduino code does the basics


Code:
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = {0x90, 0xA2, 0xDA, 0x00, 0xFF, 0x1D }; / UNIQUE TO BOARD

IPAddress ip(192, 168, 1, 30); /Manufacturer recommended address

IPAddress myDns(1, 1, 1, 1); /Random, not sure if I need to do anything specific here

IPAddress gateway(192, 168, 1, 1); /Random, not sure if I need to do anything specific here

IPAddress subnet(255, 255, 255, 255);

/ initialize the library instance:
EthernetClient client;

/Camera
IPAddress server(192, 168, 1, 115); / (Camera) IPAddress

unsigned long lastConnectionTime = 0; / last time you connected to the server, in milliseconds
const unsigned long postingInterval = 10L * 1000L; / delay between updates, in milliseconds
/ the "L" is needed to use long type numbers

String big_string = "";


void setup() {
  / start serial port:
  Serial.begin(115200);
  while (!Serial) {
    ; / wait for serial port to connect. Needed for native USB port only
  }

  delay(1000);
  / start the Ethernet connection using a fixed IP address and DNS server:
  Ethernet.begin(mac, ip, myDns, gateway, subnet);
  / print the Ethernet board/shield's IP address:
  Serial.print("My IP address: ");
  Serial.println(Ethernet.localIP());
}

void loop() {
  / if there's incoming data from the net connection.
  / send it out the serial port.  This is for debugging
  / purposes only:
  if (client.available()) {
    char c = client.read();
    Serial.write(c);
  }
  / if ten seconds have passed since your last connection,
  / then connect again and send data:
  if (millis() - lastConnectionTime > postingInterval) {
    httpRequestHigh();
    delay(900000ul);
    httpRequestLow();

  }
}

void httpRequestHigh() {
  / close any connection before send a new request.
  / This will free the socket on the WiFi shield
  client.stop();
  / if there's a successful connection:
  if (client.connect(server, 80)) {
    /Prepare big_string  send the posted data.
    big_string += "<?xml version=\"1.0\"encoding=\"UTF-8\"?>\n\r";
    big_string += "<IOInputPort version=\"2.0\" xmlns=\"http://www.hikvision.com/ver20/XMLSchema\">\n\r";
    big_string += "<id>1</id>\n\r";
    big_string += "<enabled>true</enabled>\n\r";
    big_string += "<triggering>high</triggering>\n\r"; /  open
    / big_string += "<name/>\n\r";
    big_string += "</IOInputPort>\n\r";

    Serial.println("connecting...");

    / send the HTTP GET request:

    client.println("PUT /IO/inputs/1 HTTP/1.1");
    client.println("Host: 192.168.1.115");
    client.println("Authorization: Basic ###############="); / amend authenticatrion
    client.println("User-Agent: arduino-ethernet");
    client.print("Content-length: ");
    client.println(big_string.length());
    / tell the server you are done with the header.
    client.println();
    / send the posted data.
    client.print(big_string);
    Serial.println("----------------------------------");
    Serial.println(big_string);
    Serial.println(big_string.length());
    Serial.println("----------------------------------");
    big_string = "";

    /  finish up
    client.println("Connection: close");
    client.println();
    / note the time that the connection was made:
    lastConnectionTime = millis();
  } else {
    / if you couldn't make a connection:
    Serial.println("connection failed");
  }
}

void httpRequestLow() {
  / close any connection before send a new request.
  / This will free the socket on the WiFi shield
  client.stop();
  / if there's a successful connection:
  if (client.connect(server, 80)) {
    /Prepare big_string  send the posted data.
    big_string += "<?xml version=\"1.0\"encoding=\"UTF-8\"?>\n\r";
    big_string += "<IOInputPort version=\"2.0\" xmlns=\"http://www.hikvision.com/ver20/XMLSchema\">\n\r";
    big_string += "<id>1</id>\n\r";
    big_string += "<enabled>true</enabled>\n\r";
    big_string += "<triggering>low</triggering>\n\r"; /  colsed
    / big_string += "<name/>\n\r";
    big_string += "</IOInputPort>\n\r";

    Serial.println("connecting...");

    / send the HTTP GET request:

    client.println("PUT /IO/inputs/1 HTTP/1.1");
    client.println("Host: 192.168.1.115");
    client.println("Authorization: Basic YWRtaW46TW9sbHlNNSE=");
    client.println("User-Agent: arduino-ethernet");
    client.print("Content-length: ");
    client.println(big_string.length());
    / tell the server you are done with the header.
    client.println();
    / send the posted data.
    client.print(big_string);
    Serial.println("----------------------------------");
    Serial.println(big_string);
    Serial.println(big_string.length());
    Serial.println("----------------------------------");
    big_string = "";

    /  finish up
    client.println("Connection: close");
    client.println();
    / note the time that the connection was made:
    lastConnectionTime = millis();
  } else {
    / if you couldn't make a connection:
    Serial.println("connection failed");
  }
}
 
Code for arduino looks soo messy for me :)
Bit hard on Arduino - my coding a little slopppy :)


Code:
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = {0x90, 0xA2, 0xDA, 0x00, 0xFF, 0x1D }; / UNIQUE TO BOARD

IPAddress ip(192,168,1,30); /Manufacturer recommended address
IPAddress myDns(1, 1, 1, 1); /Random, not sure if I need to do anything specific here
IPAddress gateway(192,168,1,1); /Random, not sure if I need to do anything specific here
IPAddress subnet(255, 255, 255, 255);

EthernetClient client;
IPAddress server(192,168,1,115); / (Camera) IPAddress

unsigned long lastConnectionTime = 0;
const unsigned long postingInterval = 10L * 1000L;
String big_string= "";


/ ****************************************************************************
/  Setup
/ ****************************************************************************

void setup() {
 
  Serial.begin(115200);
  while (!Serial)
  {
    ;
  }
 
  delay(1000);
  Ethernet.begin(mac, ip, myDns, gateway, subnet);
  Serial.print("My IP address: ");
  Serial.println(Ethernet.localIP());
}


/ ****************************************************************************
/  Loop
/ ****************************************************************************

void loop() {
 
  if (client.available()) {
    char c = client.read();
    Serial.write(c);
  }
 
  if (millis() - lastConnectionTime > postingInterval)
  {
    httpRequestHigh();
    delay(900000ul);
    httpRequestLow();
   }
}


/ ****************************************************************************
/  Functions
/ ****************************************************************************

void httpRequestHigh() {
  client.stop();
 
  if (client.connect(server, 80)) {
    big_string += "<?xml version=\"1.0\"encoding=\"UTF-8\"?>\n\r";
    big_string += "<IOInputPort version=\"2.0\" xmlns=\"http://www.hikvision.com/ver20/XMLSchema\">\n\r";
    big_string += "<id>1</id>\n\r";
    big_string += "<enabled>true</enabled>\n\r";
    big_string += "<triggering>high</triggering>\n\r"; /  open
    big_string += "</IOInputPort>\n\r";
        
    Serial.println("connecting...");
  
    client.println("PUT /IO/inputs/1 HTTP/1.1");
    client.println("Host: 192.168.1.115");
    client.println("Authorization: Basic YWRtaW46TW9sbHlNNSE=");
    client.println("User-Agent: arduino-ethernet");
    client.print("Content-length: ");
    client.println(big_string.length());
    client.println();
    client.print(big_string);
    Serial.println("----------------------------------");
    Serial.println(big_string);
    Serial.println(big_string.length());
    Serial.println("----------------------------------");
    big_string="";   

    /  finish up
    client.println("Connection: close");
    client.println();
   lastConnectionTime = millis();
  }
  else
  {
    
    Serial.println("connection failed");
  }
}

void httpRequestLow() {
   client.stop();
   if (client.connect(server, 80)) {
    big_string += "<?xml version=\"1.0\"encoding=\"UTF-8\"?>\n\r";
    big_string += "<IOInputPort version=\"2.0\" xmlns=\"http://www.hikvision.com/ver20/XMLSchema\">\n\r";
    big_string += "<id>1</id>\n\r";
    big_string += "<enabled>true</enabled>\n\r";
    big_string += "<triggering>low</triggering>\n\r"; /  colsed
   / big_string += "<name/>\n\r";
    big_string += "</IOInputPort>\n\r";
        
    Serial.println("connecting...");

    client.println("PUT /IO/inputs/1 HTTP/1.1");
    client.println("Host: 192.168.1.115");
    client.println("Authorization: Basic YWRtaW46TW9sbHlNNSE=");
    client.println("User-Agent: arduino-ethernet");
    client.print("Content-length: ");
    client.println(big_string.length());
    client.println();
    client.print(big_string);
    Serial.println("----------------------------------");
    Serial.println(big_string);
    Serial.println(big_string.length());
    Serial.println("----------------------------------");
    big_string="";   

/  finish up
    client.println("Connection: close");
    client.println();
  
    lastConnectionTime = millis();
  }
  else
  {
    Serial.println("connection failed");
  }
}
 
  • Like
Reactions: trempa92