Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local connection / API #61

Open
georg90 opened this issue Dec 6, 2021 · 8 comments
Open

Local connection / API #61

georg90 opened this issue Dec 6, 2021 · 8 comments

Comments

@georg90
Copy link

georg90 commented Dec 6, 2021

I noticed that the app works perfectly fine when only in local lan mode (e.g. blocking connection to the camera via router).
Therefore my question: Did anyone (successfully) ran the library or any commands to the camera via local lan?

I am trying to get the light to work for my L1C using this command gives me "Connection reset" http error in Postman

http://localip?channelNo=1&deviceSerial=E5152222&enable=1 
or
http://localip/switchStatus?channelNo=1&deviceSerial=E5152222&enable=1 

Since the app works fine the camera should support direct connection / api calls?

Info taken from here: https://gist.github.com/BaQs/1c1a2be3e962073094def1e0cc26a14c

@andrewcoo101
Copy link
Contributor

andrewcoo101 commented Dec 8, 2021

The python client and mobile app send these types of http requests to the ezviz cloud service, rather than the cameras themselves.

As far as I'm aware, the only connection that can be made directly to the camera, is an rtsp request to stream the live feed.

@hawkeye217
Copy link

I've also been digging for some ways to control my device locally (I have an Ezviz DB1 doorbell) - specifically the status light.

The python client works great, but I'd prefer to keep my camera from talking outside my local network. I managed to use the Hikvision SDK and their C++ examples to write some code to adjust things like camera exposure time and WDR enable/disable. But I haven't been able to find anything on changing the status LED or IR LEDs.

I've sniffed the packets coming back and forth from the Ezviz cloud to the camera with Wireshark when I use pyezviz to enable/disable the status LED, but the only ASCII I can see in the packet capture is the following string:

/<my serial number>/1001/18699

Has anyone dug any deeper than I have on this? Would love to collaborate if you have.

@thekoma
Copy link

thekoma commented Nov 29, 2022

Same problem. All the features in cloud don't bother me but being able to control the light without passing from the china and back would be very cool

@steelbrain
Copy link

I dug into this a little, there's a "LAN scanning" feature in EZViz application. I tested with a non-internet accessible network that it's able to control basic features (PTZ, Quality switching, RTSP streaming) without EZVIZ Cloud API. Opening up the APK revealed that there's a native library from HIKVision that they use, a version of HCNetSDK.dll for android.

I used Wireshark to capture and replay some requests, seemed to work fine. My technical abilities didn't allow me to go any further but I am sure it's possible if somebody is motivated enough

@steelbrain
Copy link

Played around with some ChatGPT prompting for this, here's what I got
Prompt: How do I use HCNetSDK to connect with a device over the local network and issue PTZ commands? I am familiar with Node.js and Golang

To connect to a Hikvision device over the local network and issue PTZ commands using Node.js or Golang, you'll need to use FFI (Foreign Function Interface) libraries to call the HCNetSDK functions from the compiled C library.

Here's an example of how to use Node.js with the ffi-napi library to connect to a Hikvision device and issue PTZ commands:

Install the necessary dependencies:

npm install ffi-napi ref-napi

Load the HCNetSDK library and set up the FFI bindings:

const ffi = require('ffi-napi');
const ref = require('ref-napi');

const HCNetSDK = ffi.Library('HCNetSDK', {
  'NET_DVR_Init': ['bool', []],
  'NET_DVR_Cleanup': ['bool', []],
  'NET_DVR_Login_V30': ['long', ['pointer', 'pointer']],
  'NET_DVR_PTZControl': ['bool', ['long', 'uint', 'uint']],
  'NET_DVR_PTZControl_Other': ['bool', ['long', 'long', 'uint', 'uint']],
  'NET_DVR_GetLastError': ['int', []],
  // Add other required functions here
});

Define the necessary structures and constants:

const NET_DVR_DEVICEINFO_V30 = ref.types.void;
const PTZ_UP = 21;
const PTZ_DOWN = 22;
const PTZ_LEFT = 23;
const PTZ_RIGHT = 24;
const PTZ_STOP = 25;

const deviceIP = "192.168.1.64";
const userName = "admin";
const password = "your_password";

Initialize the SDK, log in to the device, and issue PTZ commands:

if (!HCNetSDK.NET_DVR_Init()) {
  console.log("NET_DVR_Init failed, error code:", HCNetSDK.NET_DVR_GetLastError());
  process.exit(1);
}

const deviceInfo = ref.alloc(NET_DVR_DEVICEINFO_V30);
const deviceAddress = Buffer.from(deviceIP + '\0', 'ascii');
const userNameBuffer = Buffer.from(userName + '\0', 'ascii');
const passwordBuffer = Buffer.from(password + '\0', 'ascii');

const userID = HCNetSDK.NET_DVR_Login_V30(deviceAddress, 8000, userNameBuffer, passwordBuffer, deviceInfo);

if (userID === -1) {
  console.log("NET_DVR_Login_V30 failed, error code:", HCNetSDK.NET_DVR_GetLastError());
  HCNetSDK.NET_DVR_Cleanup();
  process.exit(1);
}

const channel = 1; // Set to the desired channel
const PTZ_command = PTZ_UP; // Set to the desired PTZ command

if (!HCNetSDK.NET_DVR_PTZControl_Other(userID, channel, PTZ_command, 0)) {
  console.log("NET_DVR_PTZControl_Other failed, error code:", HCNetSDK.NET_DVR_GetLastError());
}

// Issue other PTZ commands if needed

HCNetSDK.NET_DVR_Logout(userID);
HCNetSDK.NET_DVR_Cleanup();

For Golang, you can use the github.com/xlab/c-for-go tool to generate FFI bindings for the HCNetSDK library. Follow the documentation and examples to create the bindings, import the generated package, and use the functions in a similar manner as the Node.js example above.

Keep in mind that the example code provided is just a starting point and may need modification to fit your specific use case. Always refer to the HCNetSDK documentation for more information on how

@hawkeye217
Copy link

As I mentioned in a previous post here, the Hikvision SDK actually has a bunch of code examples, and their documentation is extensive. I've used the examples to write my own code (C++) to control specific aspects of my camera (brightness/contrast/WDR).

The code you posted that ChatGPT generated looks similar to some of their provided examples.

I was unable to find any code that controls the doorbell button ring LEDs or the IR LEDs locally without the Ezviz cloud, and I gave up early last year.

@steelbrain
Copy link

@hawkeye217 Have you tried using the EZVIZ Studio app for Windows? After turning on advanced settings in the studio, I found options for very low level stuff like camera brightness and contrast etc. Here's a video example of using the ezviz studio apps' advanced settings: https://www.youtube.com/watch?v=Lh2_8acG9uk

If you can find the logic for button LEDs there, maybe you can capture the network packets and see what's happening in there

@drzraf
Copy link

drzraf commented Oct 8, 2023

IIUC, assuming that cloud servers communicate with devices through this ISAPI (IP Surveillance API) https://github.com/jvmf1/hikvision/tree/main (Ruby) or https://github.com/openlab-red/hikvision-isapi-cli/ (Python) could be of interest.

Regarding HCNetSDK.dll I think the nearest thing of a Python structures transcription may be this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants