Skip to content

About

A .NET client library for interacting with Hikvision devices using the ISAPI protocol

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Zyga.HikIsapiClient

CI NuGet Downloads codecov License: MIT

A .NET client library for interacting with Hikvision devices using the ISAPI protocol, with integrated Serilog logging via Zyga.SeriRestClient.

Features

  • πŸ” Session Management - Automatic login/logout handling with session keep-alive
  • πŸšͺ Door Control - Remote door control operations
  • πŸ“ Logging - Request/response logging via Zyga.SeriRestClient's Serilog integration
  • πŸ”„ State Management - Smart session state handling with EnsureLoggedIn()
  • πŸ”Œ Dependency Injection - First-class support for Microsoft.Extensions.DependencyInjection
  • 🎯 Keyed Services - Support for multiple Hikvision device instances
  • βš™οΈ Configuration - Easy configuration through IConfiguration

Install

dotnet add package Zyga.HikIsapiClient

Targets .NET 8, .NET 9 and .NET 10.

Usage

Basic Setup

Configure your Hikvision device in appsettings.json:

{
  "HikDevice": {
    "Name": "Main Entrance",
    "Address": "http://192.168.1.100",
    "User": "admin",
    "Password": "your-password",
    "MaxTimeout": 5000
  }
}

Register in your Program.cs or Startup.cs:

using Zyga.HikIsapiClient.ExtensionMethods;

Host.CreateDefaultBuilder(args)
    .AddHikIsapi("HikDevice")
    .Build()
    .Run();

Using the Client

public class MyService
{
    private readonly IIsapi _isapi;

    public MyService(IIsapi isapi)
    {
        _isapi = isapi;
    }

    public void OpenDoor()
    {
        // Check if device is available
        if (!_isapi.IsAvailable())
        {
            throw new Exception("Device is not available");
        }

        // Login and open door #1
        _isapi.Login()
              .DoorOpen(1)
              .LogOut();
    }

    public void MaintainSession()
    {
        // Ensure logged in (will login only if needed)
        var authenticated = _isapi.EnsureLoggedIn();

        // Send heartbeat to keep session alive
        authenticated.SessionHeartBeat();

        // Check heartbeat count
        Console.WriteLine($"Heartbeats sent: {authenticated.HeartBeatCount}");
    }
}

Multiple Devices (Keyed Services)

Register multiple Hikvision devices:

services
    .AddKeyedHikIsapi("entrance", (sp, key) =>
        sp.GetRequiredService<IConfiguration>()
          .GetSection("Devices:Entrance")
          .Get<IsapiConfig>())
    .AddKeyedHikIsapi("parking", (sp, key) =>
        sp.GetRequiredService<IConfiguration>()
          .GetSection("Devices:Parking")
          .Get<IsapiConfig>());

Use keyed services:

public class SecurityService
{
    private readonly IIsapi _entranceDevice;
    private readonly IIsapi _parkingDevice;

    public SecurityService(
        [FromKeyedServices("entrance")] IIsapi entranceDevice,
        [FromKeyedServices("parking")] IIsapi parkingDevice)
    {
        _entranceDevice = entranceDevice;
        _parkingDevice = parkingDevice;
    }
}

API Reference

IIsapi Interface

Method Description
Login() Authenticate and establish a session with the device
EnsureLoggedIn() Login only if not already authenticated
IsAvailable() Check if the device is reachable

IIsapiAuthenticated Interface

Method Description
DoorOpen(int doorNo) Trigger door opening for specified door number
SessionHeartBeat() Send keep-alive signal to maintain session
LogOut() End the current session
HeartBeatCount Get the number of heartbeats sent in current session

IIsapiConfig Interface

Property Description
Name Friendly name for the device
Address Base URL of the Hikvision device (e.g., http://192.168.1.100)
User Username for authentication
Password Password for authentication
MaxTimeout Maximum request timeout in milliseconds (default: 5000)

Sample

A runnable console sample lives in samples/HikIsapiClient.Sample β€” point its appsettings.json at your own device before running it.

Requirements

  • .NET 8, .NET 9, or .NET 10
  • RestSharp 114.0.0+
  • Serilog 4.4.0+
  • Zyga.SeriRestClient 0.1.1+

Contributing

Issues and pull requests are welcome. See CONTRIBUTING.md.

License

MIT

Version

This package uses MinVer for semantic versioning, derived from v-prefixed git tags (e.g. v1.2.3). There is no <Version> element anywhere in the source β€” maintainers cut a release by pushing a tag.

About

A .NET client library for interacting with Hikvision devices using the ISAPI protocol

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages