Skip to content

mkcfdc/reolink-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Reolink Client Module Example

This module demonstrates how to use the @mkcfdc/reolink-client to interact with your Reolink camera. You can use this example to log in, fetch device information, control PTZ, activate alarms, and manage White LED settings.

Prerequisites

  • Deno installed
  • A Reolink camera accessible via network with the appropriate credentials

Installation

Install the Reolink client package using npm or yarn:

deno add jsr:@mkcfdc/reolink-client

Usage

Below is an example demonstrating how to initialize the client, execute several commands, and then gracefully log out.

import { ReolinkClient } from "jsr:@mkcfdc/reolink-client";

const cameraIp = "backyard.home"; // Your camera's IP address
const username = "admin";         // Your camera's username
const password = "";              // Your camera's password

async function test() {

  const client = new ReolinkClient({ cameraIp, username, password });

  try {
    console.log("Logging in...");
    await client.login();
    console.log("Token acquired:", client.token);

    console.log("Fetching device information...");
    const devInfo = await client.getDeviceInfo();
    const name = devInfo[0].value.DevInfo.name;
    console.log('name: ', name);

    console.log("Fetching encoding configuration...");
    const encConfig = await client.getEnc(0);
    console.log("Encoding Configuration:", JSON.stringify(encConfig, null, 2));

    console.log("Fetching current time...");
    const timeInfo = await client.getTime();
    console.log("Time Info:", JSON.stringify(timeInfo, null, 2));

    console.log("Fetching device abilities...");
    const ptz = await client.ptzControl({ op: "Up" });
    console.log("Moving Camera Up:", JSON.stringify(ptz, null, 2));

    console.log("Sending PTZ control command...");
    const ptzResp = await client.ptzControl({ op:"ToPos", id: 0 });
    console.log("PTZ Control Response:", JSON.stringify(ptzResp, null, 2));


    console.log("Get Presets...");
    const ptzPresets = await client.getPtzPresets();
    console.log("PTZ Pesets Response:", JSON.stringify(ptzPresets, null, 2));

    console.log("Activating Alarm...");
    const activeAlarm = await client.audioAlarmPlay();
    console.log("Alarm Activated!", JSON.stringify(activeAlarm, null, 2));


    console.log("Activate White LED...");
    const whiteLED = await client.setWhiteLed("off", 0);
    console.log("Activate Command sent...", JSON.stringify(whiteLED, null, 2));

    console.log("Checking White LED Status...");
    const statusWhiteLED = await client.getWhiteLed();
    console.log("White LED Status:", JSON.stringify(statusWhiteLED, null, 2));

  } catch (error) {
    console.error("Error during testing:", error);
  } finally {
    try {
      console.log("Logging out...");
      await client.logout();
      console.log("Logged out successfully!");
    } catch (logoutError) {
      console.error("Error during logout:", logoutError);
    }
  }
}

test();

Module Functions

The ReolinkClient module exposes various methods to interact with your camera:

  • Authentication:

    • client.login(): Log in to the camera and obtain an authentication token.
    • client.logout(): Log out and invalidate the current session.
  • Device Information:

    • client.getDeviceInfo(): Retrieve information about the device (e.g., model, firmware, etc.).
    • client.getEncodingConfiguration(): Get the current encoding configuration.
    • client.getTime(): Fetch the current time from the device.
  • PTZ (Pan-Tilt-Zoom) Control:

    • client.ptzControl({ op, id, channel, speed }): Control camera movement.
  • Presets and Alarms:

    • client.getPtzPresets(): Retrieve preset PTZ positions.
    • client.audioAlarmPlay(): Activate the camera's audio alarm.
    • client.setWhiteLed(state, channel): Turn the White LED on or off.
    • client.getWhiteLed(): Retrieve the status of the White LED.

Customization & Best Practices

  • Selective Execution: Uncomment sections of the example as needed.
  • Error Handling: Ensure proper try-catch blocks for exception management.
  • Secure Credentials: Use environment variables for sensitive credentials.
  • Extensibility: Modify and extend commands based on your needs.

Contributing

If you have any suggestions, issues, or improvements, feel free to open an issue or submit a pull request.

License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors