dahua-rpc2-camera
v1.0.0
Published
Fork Dahua RPC Client Library for camers
Downloads
7
Readme
Dahua RPC Client Library
This is a Node.js library to interact with Dahua devices using the RPC protocol. The library enables communication with Dahua devices such as cameras and parking systems by handling authentication and providing utility methods for device management.
Installation
To install the package, run:
npm install dahua-rpc2-cameraUsage
Here is a basic example demonstrating how to use the library to log in and retrieve traffic information.
Example
import { DahuaRpc } from "dahua-rpc2-camera";
(async () => {
const dahuaRpc = new DahuaRpc("192.168.1.100", "admin", "your_password");
try {
// Login to the Dahua device
await dahuaRpc.login();
// Get current device time
const currentTime = await dahuaRpc.getCurrentTime();
console.log("Device Current Time:", currentTime);
} catch (error) {
console.error("Error:", error.message);
}
})();Available Methods
login(): Logs into the device and retrieves a session ID.keepAlive(): Sends a keep-alive request to the device to maintain the session.startFind(objectId): Starts a search for traffic events.doFind(objectId): Performs a search for traffic events.getCurrentTime(): Gets the current time from the device.ntpSync(address, port, timeZone): Synchronizes time with the NTP server.
Error Handling
Each method throws errors if the request fails, providing detailed information about the failure. Use try/catch blocks to handle these errors.
try {
await dahuaRpc.login();
} catch (error) {
console.error("Login failed:", error.message);
}Contributions
Feel free to contribute by opening issues or submitting pull requests to improve the library.
License
MIT License.
