### Install node-anviz Source: https://github.com/whiteaglept/node-anviz/blob/master/README.md Install the node-anviz module using npm. ```sh npm install node-anviz ``` -------------------------------- ### getInformation1 - Get Device Configuration 1 Source: https://context7.com/whiteaglept/node-anviz/llms.txt Retrieves primary device configuration settings including firmware version, communication password, sleep time, and volume. ```APIDOC ## getInformation1 ### Description Retrieves primary device configuration including firmware version, communication password settings, sleep time, volume level, language settings, and attendance state. ### Response - **firmwareVersion** (string) - Device firmware version. - **comPasswordLength** (number) - Length of communication password. - **comPassword** (string|null) - Communication password. - **sleepTime** (number) - Device sleep time in seconds. - **volume** (number) - Device volume level. - **language** (number) - Language code. - **dateTimeFormat** (array) - Date and time format settings. - **attendanceState** (number) - Current attendance state. - **languageSetting** (boolean) - Language setting status. - **commandVersion** (number) - Protocol command version. ``` -------------------------------- ### getInformation2 - Get Device Configuration 2 Source: https://context7.com/whiteaglept/node-anviz/llms.txt Retrieves secondary device configuration including Wiegand settings, relay mode, and memory thresholds. ```APIDOC ## getInformation2 ### Description Retrieves secondary device configuration including Wiegand settings, relay mode, locker delay, memory warning thresholds, and timing parameters. ### Response - **precision** (number) - Device precision setting. - **wiegandOption** (number) - Wiegand configuration option. - **realTimeModeSetting** (number) - Real-time mode configuration. - **relayMode** (number) - Relay mode setting. - **lockerDelay** (number) - Locker delay in seconds. - **lowRecordsMemoryWarn** (number) - Threshold for low memory warning. - **repeatAttendanceDelay** (number) - Delay for repeat attendance in minutes. - **doorSensorDelay** (number) - Door sensor delay in seconds. ``` -------------------------------- ### GET /getServerURL Source: https://github.com/whiteaglept/node-anviz/blob/master/README.md Retrieves the configured server URL from the Anviz device. ```APIDOC ## GET /getServerURL ### Description Retrieves the server URL currently configured on the device. ### Method GET ### Endpoint 0x0A ``` -------------------------------- ### GET /getServerURL - Get Server URL Configuration Source: https://context7.com/whiteaglept/node-anviz/llms.txt Retrieves the configured DNS server and server URL from the device, used for device-initiated connections. ```APIDOC ## GET /getServerURL - Get Server URL Configuration ### Description Retrieves the DNS server and server URL that are currently configured on the Anviz device. This information is typically used for devices that initiate connections to a server (e.g., for push notifications or data synchronization). ### Method GET ### Endpoint `/getServerURL` (This is a conceptual endpoint name based on the function call) ### Parameters None ### Request Example ```javascript const anviz = require("node-anviz"); let request = new anviz.Request("192.168.1.100"); request.execute("getServerURL", 1).then((config) => { console.log("DNS Server:", config.dns); console.log("Server URL:", config.url); // Output: // DNS Server: 8.8.8.8 // Server URL: attendance.example.com request.close(); }, (err) => { console.error("Error:", err); }); ``` ### Response #### Success Response (200) - **dns** (string) - The configured DNS server address. - **url** (string) - The configured server URL. #### Response Example ```json { "dns": "8.8.8.8", "url": "attendance.example.com" } ``` ``` -------------------------------- ### Get Server URL Configuration Source: https://context7.com/whiteaglept/node-anviz/llms.txt Retrieves the DNS server and server URL configured on the device for push mode. ```javascript const anviz = require("node-anviz"); let request = new anviz.Request("192.168.1.100"); request.execute("getServerURL", 1).then((config) => { console.log("DNS Server:", config.dns); console.log("Server URL:", config.url); // Output: // DNS Server: 8.8.8.8 // Server URL: attendance.example.com request.close(); }, (err) => { console.error("Error:", err); }); ``` -------------------------------- ### GET /getDeviceModel - Get Device Model Code Source: https://context7.com/whiteaglept/node-anviz/llms.txt Retrieves the device model identifier string from the Anviz device. ```APIDOC ## GET /getDeviceModel - Get Device Model Code ### Description Retrieves the device model identifier string from the Anviz device. This can be useful for identifying the specific hardware model. ### Method GET ### Endpoint `/getDeviceModel` (This is a conceptual endpoint name based on the function call) ### Parameters None ### Request Example ```javascript const anviz = require("node-anviz"); let request = new anviz.Request("192.168.1.100"); request.execute("getDeviceModel", 1).then((modelCode) => { console.log("Device Model:", modelCode); // Output: Device Model: C2Pro request.close(); }, (err) => { console.error("Error:", err); }); ``` ### Response #### Success Response (200) - **modelCode** (string) - The identifier string for the device model. #### Response Example ```json "C2Pro" ``` ``` -------------------------------- ### Retrieve Device Date and Time Source: https://context7.com/whiteaglept/node-anviz/llms.txt Get the current device time as a JavaScript Date object. ```javascript const anviz = require("node-anviz"); let request = new anviz.Request("192.168.1.100"); request.execute("getDateTime", 1).then((deviceTime) => { console.log("Device Time:", deviceTime); console.log("ISO Format:", deviceTime.toISOString()); console.log("Local String:", deviceTime.toLocaleString()); // Output: // Device Time: 2024-01-15T14:30:00.000Z // ISO Format: 2024-01-15T14:30:00.000Z // Local String: 1/15/2024, 2:30:00 PM request.close(); }, (err) => { console.error("Error:", err); }); ``` -------------------------------- ### getNetworkConfiguration - Get Network Settings Source: https://context7.com/whiteaglept/node-anviz/llms.txt Retrieves detailed network configuration from the Anviz device, including IP, subnet, MAC, gateway, server details, and DHCP status. ```APIDOC ## getNetworkConfiguration - Get Network Settings ### Description Retrieves the device's network configuration including IP address, subnet mask, MAC address, gateway, server IP, port, and DHCP settings. ### Method `execute` (within the `node-anviz` library) ### Parameters - **command** (string) - Required - The command to execute, in this case, "getNetworkConfiguration". - **instance** (number) - Required - Typically `1`. ### Response #### Success Response - **ipAddress** (string) - The device's IP address. - **subnet** (string) - The subnet mask. - **macAddress** (string) - The MAC address. - **defaultGateway** (string) - The default gateway IP address. - **serverIp** (string) - The configured server IP address. - **port** (number) - The server port. - **mode** (number) - Network mode (e.g., 0). - **dhcpPermission** (number) - DHCP status (e.g., 1 for enabled, 0 for disabled). ### Response Example ```json { "ipAddress": "192.168.1.100", "subnet": "255.255.255.0", "macAddress": "001122334455", "defaultGateway": "192.168.1.1", "serverIp": "192.168.1.50", "port": 5010, "mode": 0, "dhcpPermission": 1 } ``` ### Request Example ```javascript const anviz = require("node-anviz"); let request = new anviz.Request("192.168.1.100"); request.execute("getNetworkConfiguration", 1).then((config) => { console.log("IP Address:", config.ipAddress); console.log("Subnet Mask:", config.subnet); console.log("MAC Address:", config.macAddress); console.log("Default Gateway:", config.defaultGateway); console.log("Server IP:", config.serverIp); console.log("Port:", config.port); console.log("Mode:", config.mode); console.log("DHCP Enabled:", config.dhcpPermission); request.close(); }, (err) => { console.error("Error:", err); }); ``` ``` -------------------------------- ### getDateTime - Get Device Date and Time Source: https://context7.com/whiteaglept/node-anviz/llms.txt Retrieves the current date and time from the device as a JavaScript Date object. ```APIDOC ## getDateTime ### Description Retrieves the current date and time from the device. ### Response - **deviceTime** (Date) - A JavaScript Date object representing the device's current time. ``` -------------------------------- ### Get Network Configuration with Node-Anviz Source: https://context7.com/whiteaglept/node-anviz/llms.txt Retrieves detailed network settings from the Anviz device. This includes IP address, subnet mask, MAC address, gateway, server IP, port, and DHCP status. ```javascript const anviz = require("node-anviz"); let request = new anviz.Request("192.168.1.100"); request.execute("getNetworkConfiguration", 1).then((config) => { console.log("IP Address:", config.ipAddress); console.log("Subnet Mask:", config.subnet); console.log("MAC Address:", config.macAddress); console.log("Default Gateway:", config.defaultGateway); console.log("Server IP:", config.serverIp); console.log("Port:", config.port); console.log("Mode:", config.mode); console.log("DHCP Enabled:", config.dhcpPermission); // Output: // IP Address: 192.168.1.100 // Subnet Mask: 255.255.255.0 // MAC Address: 001122334455 // Default Gateway: 192.168.1.1 // Server IP: 192.168.1.50 // Port: 5010 // Mode: 0 // DHCP Enabled: 1 request.close(); }, (err) => { console.error("Error:", err); }); ``` -------------------------------- ### Get Attendance Record Statistics with Node-Anviz Source: https://context7.com/whiteaglept/node-anviz/llms.txt Fetches statistics about stored attendance records on the device. Provides counts for total users, fingerprints, passwords, cards, and attendance records (total and new). ```javascript const anviz = require("node-anviz"); let request = new anviz.Request("192.168.1.100"); request.execute("getRecordInformation", 1).then((info) => { console.log("Total Users:", info.userAmount); console.log("Fingerprints Enrolled:", info.fpAmount); console.log("Passwords Set:", info.passwordAmount); console.log("Cards Registered:", info.cardAmount); console.log("Total Attendance Records:", info.allRecordAmount); console.log("New Records (undownloaded):", info.newRecordAmount); // Output: // Total Users: 150 // Fingerprints Enrolled: 280 // Passwords Set: 45 // Cards Registered: 120 // Total Attendance Records: 15000 // New Records (undownloaded): 250 request.close(); }, (err) => { console.error("Error:", err); }); ``` -------------------------------- ### getRecordInformation - Get Attendance Record Statistics Source: https://context7.com/whiteaglept/node-anviz/llms.txt Fetches statistics about the attendance records stored on the device, including counts for users, fingerprints, passwords, cards, and attendance entries. ```APIDOC ## getRecordInformation - Get Attendance Record Statistics ### Description Retrieves statistics about stored records on the device including total users, fingerprints, passwords, cards, and attendance record counts. ### Method `execute` (within the `node-anviz` library) ### Parameters - **command** (string) - Required - The command to execute, in this case, "getRecordInformation". - **instance** (number) - Required - Typically `1`. ### Response #### Success Response - **userAmount** (number) - Total number of registered users. - **fpAmount** (number) - Total number of enrolled fingerprints. - **passwordAmount** (number) - Total number of set passwords. - **cardAmount** (number) - Total number of registered cards. - **allRecordAmount** (number) - Total count of all attendance records. - **newRecordAmount** (number) - Count of new, undownloaded attendance records. ### Response Example ```json { "userAmount": 150, "fpAmount": 280, "passwordAmount": 45, "cardAmount": 120, "allRecordAmount": 15000, "newRecordAmount": 250 } ``` ### Request Example ```javascript const anviz = require("node-anviz"); let request = new anviz.Request("192.168.1.100"); request.execute("getRecordInformation", 1).then((info) => { console.log("Total Users:", info.userAmount); console.log("Fingerprints Enrolled:", info.fpAmount); console.log("Passwords Set:", info.passwordAmount); console.log("Cards Registered:", info.cardAmount); console.log("Total Attendance Records:", info.allRecordAmount); console.log("New Records (undownloaded):", info.newRecordAmount); request.close(); }, (err) => { console.error("Error:", err); }); ``` ``` -------------------------------- ### Execute Multiple Commands Sequentially with Async/Await Source: https://context7.com/whiteaglept/node-anviz/llms.txt Use async/await to execute multiple Anviz device commands in sequence. This pattern ensures commands are processed one at a time, as required by the protocol, leading to cleaner and more manageable code for querying various device properties. ```javascript const anviz = require("node-anviz"); async function getDeviceStatus() { let request = new anviz.Request("192.168.1.100"); try { // Execute commands sequentially (one at a time as required by protocol) let info1 = await request.execute("getInformation1", 1); let info2 = await request.execute("getInformation2", 1); let network = await request.execute("getNetworkConfiguration", 1); let dateTime = await request.execute("getDateTime", 1); let records = await request.execute("getRecordInformation", 1); let model = await request.execute("getDeviceModel", 1); console.log("=== Device Status Report ==="); console.log("Model:", model); console.log("Firmware:", info1.firmwareVersion); console.log("IP Address:", network.ipAddress); console.log("Device Time:", dateTime.toLocaleString()); console.log("Total Users:", records.userAmount); console.log("Total Records:", records.allRecordAmount); console.log("New Records:", records.newRecordAmount); console.log("Volume:", info1.volume); console.log("Sleep Time:", info1.sleepTime, "seconds"); request.close(); return { info1, info2, network, dateTime, records, model }; } catch (err) { console.error("Error:", err); request.close(); throw err; } } getDeviceStatus(); ``` -------------------------------- ### Async/Await Pattern for Downloading Records Source: https://context7.com/whiteaglept/node-anviz/llms.txt Demonstrates the recommended approach for downloading records using async/await with progress tracking and file saving. ```APIDOC ## Async/Await Pattern for Downloading Records ### Description This endpoint demonstrates how to download attendance records asynchronously using async/await, including progress tracking and saving the records to a file. ### Method Asynchronous function execution ### Endpoint N/A (Client-side execution) ### Parameters None directly for the function, but the `anviz.Request` constructor takes an IP address. ### Request Example ```javascript const anviz = require("node-anviz"); const fs = require("fs"); async function downloadRecordsAsync() { let request = new anviz.Request("192.168.1.100"); let records = []; let page = null; let downloadType = 1; // 1 = all records, 2 = new records only // Get total record count for progress display let recordInfo = await request.execute("getRecordInformation", 1); console.log("Total records to download:", recordInfo.allRecordAmount); do { page = await request.execute("downloadAttendanceRecords", 1, [downloadType, 25]); downloadType = 0; // Switch to "continue" mode for subsequent requests records = records.concat(page); // Display progress let percent = ((records.length / recordInfo.allRecordAmount) * 100).toFixed(2); process.stdout.write(`Downloading: ${records.length} / ${recordInfo.allRecordAmount} (${percent}%)\r"); } while (page && page.length > 0); console.log("\nDownload complete!"); request.close(); // Save records to JSON file fs.writeFileSync("attendance_records.json", JSON.stringify(records, null, 2)); console.log("Records saved to attendance_records.json"); return records; } downloadRecordsAsync().catch(err => console.error("Error:", err)); ``` ### Response #### Success Response Returns the downloaded records as an array of objects and saves them to `attendance_records.json`. #### Response Example ```json [ { "usercode": 101, "timestamp": "2023-10-27T10:00:00.000Z", "type": 0 }, { "usercode": 102, "timestamp": "2023-10-27T10:05:00.000Z", "type": 0 } ] ``` ``` -------------------------------- ### Retrieve Primary Device Configuration Source: https://context7.com/whiteaglept/node-anviz/llms.txt Fetch firmware version, volume, language, and attendance state using the getInformation1 command. ```javascript const anviz = require("node-anviz"); let request = new anviz.Request("192.168.1.100"); request.execute("getInformation1", 1).then((response) => { console.log("Firmware Version:", response.firmwareVersion); console.log("Sleep Time:", response.sleepTime, "seconds"); console.log("Volume Level:", response.volume); console.log("Language Code:", response.language); console.log("Date/Time Format:", response.dateTimeFormat); console.log("Attendance State:", response.attendanceState); console.log("Command Version:", response.commandVersion); // Output: // Firmware Version: V2.3.1.0 // Sleep Time: 30 seconds // Volume Level: 5 // Language Code: 0 // Date/Time Format: [1, 0] // Attendance State: 0 // Command Version: 2 request.close(); }, (err) => { console.error("Error:", err); }); ``` -------------------------------- ### Retrieve Secondary Device Configuration Source: https://context7.com/whiteaglept/node-anviz/llms.txt Fetch Wiegand settings, relay mode, and memory thresholds using the getInformation2 command. ```javascript const anviz = require("node-anviz"); let request = new anviz.Request("192.168.1.100"); request.execute("getInformation2", 1).then((response) => { console.log("Precision:", response.precision); console.log("Wiegand Option:", response.wiegandOption); console.log("Real Time Mode:", response.realTimeModeSetting); console.log("Relay Mode:", response.relayMode); console.log("Locker Delay:", response.lockerDelay, "seconds"); console.log("Low Memory Warning:", response.lowRecordsMemoryWarn, "records"); console.log("Repeat Attendance Delay:", response.repeatAttendanceDelay, "minutes"); console.log("Door Sensor Delay:", response.doorSensorDelay, "seconds"); // Output: // Precision: 1 // Wiegand Option: 0 // Real Time Mode: 1 // Relay Mode: 0 // Locker Delay: 5 seconds // Low Memory Warning: 100 records // Repeat Attendance Delay: 1 minutes // Door Sensor Delay: 3 seconds request.close(); }, (err) => { console.error("Error:", err); }); ``` -------------------------------- ### Execute Anviz Device Method Source: https://github.com/whiteaglept/node-anviz/blob/master/README.md Instantiate a request object with the device IP and execute a method. Ensure proper synchronization as the library does not strictly enforce it. Close the request after execution. ```javascript const anviz = require("node-anviz"); let request = new anviz.Request(""); request.execute("getInformation1", 1).then((res, raw) => { console.info(res, raw); request.close(); }, (err) => { console.info("ERROR", err); }); ``` -------------------------------- ### Device Configuration Commands Source: https://github.com/whiteaglept/node-anviz/blob/master/README.md Commands for retrieving and setting device configuration parameters. ```APIDOC ## GET 0x30 ### Description Get Device Configuration 1 ### Method GET ### Endpoint 0x30 ## GET 0x32 ### Description Get Device Configuration 2 ### Method GET ### Endpoint 0x32 ``` -------------------------------- ### Create Connection to Device Source: https://context7.com/whiteaglept/node-anviz/llms.txt Establishes a TCP connection to an Anviz device using the Request class, which serves as the primary interface for executing commands. ```APIDOC ## TCP Connection ### Description Creates a TCP connection to an Anviz device. The Request class manages the connection lifecycle and provides the execute method for running commands. ### Parameters - **ip** (string) - Required - The IP address of the Anviz device. - **port** (number) - Optional - The TCP port (default: 5010). - **timeout** (number) - Optional - Connection timeout in milliseconds. ### Request Example const request = new anviz.Request("192.168.1.100", 5010, 30000); ``` -------------------------------- ### Set Server URL Configuration Source: https://context7.com/whiteaglept/node-anviz/llms.txt Configures the DNS server and server URL on the device. The URL must not exceed 100 characters. ```javascript const anviz = require("node-anviz"); let request = new anviz.Request("192.168.1.100"); // Set DNS and server URL for device push mode request.execute("setServerURL", 1, "8.8.8.8", "attendance.mycompany.com").then((response) => { console.log("Server URL configured successfully"); request.close(); }, (err) => { console.error("Error:", err); }); ``` -------------------------------- ### Record and Network Management Source: https://github.com/whiteaglept/node-anviz/blob/master/README.md Commands for network configuration and attendance record handling. ```APIDOC ## GET 0x3A ### Description Get Network Configuration ### Method GET ### Endpoint 0x3A ## GET 0x3C ### Description Get Records Info ### Method GET ### Endpoint 0x3C ## GET 0x40 ### Description Download T&A Records ### Method GET ### Endpoint 0x40 ``` -------------------------------- ### Download Attendance Records with Async/Await Source: https://context7.com/whiteaglept/node-anviz/llms.txt Uses an async/await pattern to download records with progress tracking and saves the result to a JSON file. ```javascript const anviz = require("node-anviz"); const fs = require("fs"); async function downloadRecordsAsync() { let request = new anviz.Request("192.168.1.100"); let records = []; let page = null; let downloadType = 1; // 1 = all records, 2 = new records only // Get total record count for progress display let recordInfo = await request.execute("getRecordInformation", 1); console.log("Total records to download:", recordInfo.allRecordAmount); do { page = await request.execute("downloadAttendanceRecords", 1, [downloadType, 25]); downloadType = 0; // Switch to "continue" mode for subsequent requests records = records.concat(page); // Display progress let percent = ((records.length / recordInfo.allRecordAmount) * 100).toFixed(2); process.stdout.write(`Downloading: ${records.length} / ${recordInfo.allRecordAmount} (${percent}%)\r`); } while (page && page.length > 0); console.log("\nDownload complete!"); request.close(); // Save records to JSON file fs.writeFileSync("attendance_records.json", JSON.stringify(records, null, 2)); console.log("Records saved to attendance_records.json"); return records; } downloadRecordsAsync().catch(err => console.error("Error:", err)); ``` -------------------------------- ### Create Connection to Anviz Device Source: https://context7.com/whiteaglept/node-anviz/llms.txt Initialize a Request object to manage the TCP connection. You can specify the IP address, port, and timeout duration. ```javascript const anviz = require("node-anviz"); // Create connection with default port (5010) and no timeout let request = new anviz.Request("192.168.1.100"); // Create connection with custom port and timeout (in milliseconds) let request = new anviz.Request("192.168.1.100", 5010, 30000); // Execute a command and handle response request.execute("getInformation1", 1).then((response, raw) => { console.log("Device Info:", response); // { // firmwareVersion: "V2.3.1.0", // comPasswordLength: 0, // comPassword: null, // sleepTime: 30, // volume: 5, // language: 0, // dateTimeFormat: [1, 0], // attendanceState: 0, // languageSetting: false, // commandVersion: 2 // } request.close(); }, (err) => { console.error("Error:", err); }); ``` -------------------------------- ### Set Device Date and Time with Node-Anviz Source: https://context7.com/whiteaglept/node-anviz/llms.txt Synchronizes the device clock with system time or sets a specific date and time. Requires a JavaScript Date object. ```javascript const anviz = require("node-anviz"); let request = new anviz.Request("192.168.1.100"); // Synchronize device time with current system time request.execute("setDateTime", 1, new Date()).then((response) => { console.log("Time synchronized successfully"); request.close(); }, (err) => { console.error("Error setting time:", err); }); // Set a specific date/time let specificDate = new Date("2024-06-15T09:00:00"); request.execute("setDateTime", 1, specificDate).then((response) => { console.log("Device time set to:", specificDate.toLocaleString()); request.close(); }, (err) => { console.error("Error:", err); }); ``` -------------------------------- ### Date and Time Management Source: https://github.com/whiteaglept/node-anviz/blob/master/README.md Commands to synchronize or retrieve the device date and time. ```APIDOC ## GET 0x38 ### Description Get Device Date/Time ### Method GET ### Endpoint 0x38 ## POST 0x39 ### Description Set Device Date/Time ### Method POST ### Endpoint 0x39 ``` -------------------------------- ### POST /setServerURL - Set Server URL Configuration Source: https://context7.com/whiteaglept/node-anviz/llms.txt Configures the DNS server and server URL on the device. The server URL is limited to 100 characters maximum. ```APIDOC ## POST /setServerURL - Set Server URL Configuration ### Description Configures the DNS server and server URL on the Anviz device. This is used to set up the device for server-initiated communication or push modes. The server URL has a maximum length of 100 characters. ### Method POST ### Endpoint `/setServerURL` (This is a conceptual endpoint name based on the function call) ### Parameters #### Query Parameters - **dns** (string) - Required - The DNS server address to set. - **url** (string) - Required - The server URL to set (max 100 characters). ### Request Example ```javascript const anviz = require("node-anviz"); let request = new anviz.Request("192.168.1.100"); // Set DNS and server URL for device push mode request.execute("setServerURL", 1, "8.8.8.8", "attendance.mycompany.com").then((response) => { console.log("Server URL configured successfully"); request.close(); }, (err) => { console.error("Error:", err); }); ``` ### Response #### Success Response (200) Indicates that the server URL configuration was successful. The response content may vary but typically confirms the operation. #### Response Example ```json { "status": "success", "message": "Configuration updated" } ``` ``` -------------------------------- ### POST /setServerURL Source: https://github.com/whiteaglept/node-anviz/blob/master/README.md Updates the server URL configuration on the Anviz device. ```APIDOC ## POST /setServerURL ### Description Sets the server URL for the device to communicate with. ### Method POST ### Endpoint 0x0B ``` -------------------------------- ### Download Attendance Records in Batches with Node-Anviz Source: https://context7.com/whiteaglept/node-anviz/llms.txt Downloads attendance records from the device in batches. Supports downloading all records, new records only, or continuing subsequent batches. Records are processed recursively. ```javascript const anviz = require("node-anviz"); let request = new anviz.Request("192.168.1.100"); // Download all records using Promise chain function downloadAllRecords(records, downloadType) { request.execute("downloadAttendanceRecords", 1, [downloadType, 25]).then((batch) => { if (batch.length === 0) { console.log("Download complete. Total records:", records.length); records.forEach(record => { console.log(`User: ${record.user}, Time: ${record.time}, Action: ${record.action}`); }); request.close(); } else { downloadAllRecords(batch.concat(records), 0); // 0 = continue downloading } }, (err) => { console.error("Error:", err); }); } // Start download: 1 = all records, 2 = new records only downloadAllRecords([], 1); // Output for each record: // User: 12345, Time: Mon Jan 15 2024 08:30:00 GMT+0000, Action: 0 // User: 12345, Time: Mon Jan 15 2024 17:45:00 GMT+0000, Action: 1 ``` -------------------------------- ### setDateTime - Set Device Date and Time Source: https://context7.com/whiteaglept/node-anviz/llms.txt Synchronizes the device's clock with the provided Date object. Useful for keeping device time accurate with server or system time. ```APIDOC ## setDateTime - Set Device Date and Time ### Description Sets the device's date and time. Pass a JavaScript Date object to synchronize the device clock with your server or system time. ### Method `execute` (within the `node-anviz` library) ### Parameters - **command** (string) - Required - The command to execute, in this case, "setDateTime". - **instance** (number) - Required - Typically `1`. - **dateTime** (Date object) - Required - The JavaScript Date object to set the device time to. ### Request Example ```javascript const anviz = require("node-anviz"); let request = new anviz.Request("192.168.1.100"); // Synchronize device time with current system time request.execute("setDateTime", 1, new Date()).then((response) => { console.log("Time synchronized successfully"); request.close(); }, (err) => { console.error("Error setting time:", err); }); // Set a specific date/time let specificDate = new Date("2024-06-15T09:00:00"); request.execute("setDateTime", 1, specificDate).then((response) => { console.log("Device time set to:", specificDate.toLocaleString()); request.close(); }, (err) => { console.error("Error:", err); }); ``` ### Response - **response** (any) - Indicates success or contains error information. ``` -------------------------------- ### Retrieve Device Model Identifier Source: https://context7.com/whiteaglept/node-anviz/llms.txt Fetches the device model identifier string from the connected Anviz device. ```javascript const anviz = require("node-anviz"); let request = new anviz.Request("192.168.1.100"); request.execute("getDeviceModel", 1).then((modelCode) => { console.log("Device Model:", modelCode); // Output: Device Model: C2Pro request.close(); }, (err) => { console.error("Error:", err); }); ``` -------------------------------- ### Clear New Records Flag Source: https://context7.com/whiteaglept/node-anviz/llms.txt Marks all current records on the device as downloaded by clearing the new records flag. ```javascript const anviz = require("node-anviz"); let request = new anviz.Request("192.168.1.100"); request.execute("eraseNewRecordsFlag", 1).then((response) => { console.log("New records flag cleared successfully"); request.close(); }, (err) => { console.error("Error:", err); }); ``` -------------------------------- ### POST /uploadRecord - Upload Attendance Record Source: https://context7.com/whiteaglept/node-anviz/llms.txt Uploads a new attendance record to the Anviz device. Requires a user code and timestamp. ```APIDOC ## POST /uploadRecord - Upload Attendance Record ### Description Uploads a new attendance record to the device. This method requires a user code and a timestamp for the attendance event. ### Method POST ### Endpoint `/uploadRecord` (This is a conceptual endpoint name based on the function call) ### Parameters #### Request Body - **usercode** (number) - Required - The employee ID or user code. - **date** (Date object or ISO string) - Required - The timestamp of the attendance event. ### Request Example ```javascript const anviz = require("node-anviz"); let request = new anviz.Request("192.168.1.100"); let userCode = 12345; // Upload a record with current timestamp request.execute("uploadRecord", 1, { usercode: userCode, date: new Date() }).then((response) => { console.log("Record uploaded successfully for user:", userCode); request.close(); }, (err) => { console.error("Error uploading record:", err); }); // Upload a record with specific timestamp let checkInTime = new Date("2024-01-15T08:30:00"); request.execute("uploadRecord", 1, { usercode: userCode, date: checkInTime }).then((response) => { console.log("Check-in record uploaded:", checkInTime.toLocaleString()); request.close(); }, (err) => { console.error("Error:", err); }); ``` ### Response #### Success Response (200) Indicates that the record was successfully uploaded. The response content may vary but typically confirms the operation. #### Response Example ```json { "status": "success", "message": "Record uploaded" } ``` ``` -------------------------------- ### downloadAttendanceRecords - Download Attendance Records Source: https://context7.com/whiteaglept/node-anviz/llms.txt Downloads attendance records from the device. Supports downloading all records, new records, or continuing a previous download batch. ```APIDOC ## downloadAttendanceRecords - Download Attendance Records ### Description Downloads time and attendance records from the device. Records are downloaded in batches; use parameter [1, count] for all records or [2, count] for new records only. Use [0, count] to continue downloading subsequent batches. ### Method `execute` (within the `node-anviz` library) ### Parameters - **command** (string) - Required - The command to execute, in this case, "downloadAttendanceRecords". - **instance** (number) - Required - Typically `1`. - **downloadOptions** (array) - Required - An array specifying the download type and batch size. - **downloadOptions[0]** (number) - Required - Download type: `1` for all records, `2` for new records, `0` to continue downloading. - **downloadOptions[1]** (number) - Required - The number of records to attempt to download per batch (e.g., `25`). ### Request Example ```javascript const anviz = require("node-anviz"); let request = new anviz.Request("192.168.1.100"); // Download all records using Promise chain function downloadAllRecords(records, downloadType) { request.execute("downloadAttendanceRecords", 1, [downloadType, 25]).then((batch) => { if (batch.length === 0) { console.log("Download complete. Total records:", records.length); records.forEach(record => { console.log(`User: ${record.user}, Time: ${record.time}, Action: ${record.action}`); }); request.close(); } else { downloadAllRecords(batch.concat(records), 0); // 0 = continue downloading } }, (err) => { console.error("Error:", err); }); } // Start download: 1 = all records, 2 = new records only downloadAllRecords([], 1); ``` ### Response #### Success Response - **batch** (array) - An array of attendance record objects. Each object typically contains: - **user** (string) - The user identifier. - **time** (Date object) - The timestamp of the attendance event. - **action** (number) - The type of action (e.g., 0 for check-in, 1 for check-out). If no more records are available, an empty array is returned. ### Response Example (for each record in the batch) ```json { "user": "12345", "time": "Mon Jan 15 2024 08:30:00 GMT+0000", "action": 0 } ``` ``` -------------------------------- ### Upload Attendance Records Source: https://context7.com/whiteaglept/node-anviz/llms.txt Uploads attendance records to the device using a user code and timestamp. ```javascript const anviz = require("node-anviz"); let request = new anviz.Request("192.168.1.100"); let userCode = 12345; // Employee ID/user code // Upload a record with current timestamp request.execute("uploadRecord", 1, { usercode: userCode, date: new Date() }).then((response) => { console.log("Record uploaded successfully for user:", userCode); request.close(); }, (err) => { console.error("Error uploading record:", err); }); // Upload a record with specific timestamp let checkInTime = new Date("2024-01-15T08:30:00"); request.execute("uploadRecord", 1, { usercode: userCode, date: checkInTime }).then((response) => { console.log("Check-in record uploaded:", checkInTime.toLocaleString()); request.close(); }, (err) => { console.error("Error:", err); }); ``` -------------------------------- ### Anviz ACK Response Codes and Status Check Source: https://context7.com/whiteaglept/node-anviz/llms.txt The Node Anviz library provides predefined ACK (acknowledgment) codes to indicate the status of operations performed on Anviz devices. These codes can be used to check if a command executed successfully or encountered an error. ```javascript const anviz = require("node-anviz"); // Available ACK codes console.log(anviz.ACK); // { // SUCCESS: 0x00, // Operation successful // FAIL: 0x01, // Operation failed // FULL: 0x04, // User storage full // EMPTY: 0x05, // User storage empty // NO_USER: 0x06, // User doesn't exist // TIME_OUT: 0x08, // Operation timeout // USER_OCCUPIED: 0x0A, // User already exists // FINGER_OCCUPIED: 0x0B, // Fingerprint already exists // LOCKED: 0x0F // USB is locked // } // Check response status request.execute("getInformation1", 1).then((response, raw) => { if (raw && raw.ack === anviz.ACK.SUCCESS) { console.log("Command executed successfully"); } request.close(); }); ``` -------------------------------- ### POST /eraseNewRecordsFlag - Clear New Records Flag Source: https://context7.com/whiteaglept/node-anviz/llms.txt Clears the "new record" flag on the device, marking all current records as downloaded. This is useful after successfully downloading and processing new records. ```APIDOC ## POST /eraseNewRecordsFlag - Clear New Records Flag ### Description Clears the "new record" flag on the Anviz device. This action marks all existing records as having been downloaded, preventing them from being re-downloaded in subsequent requests. ### Method POST ### Endpoint `/eraseNewRecordsFlag` (This is a conceptual endpoint name based on the function call) ### Parameters None ### Request Example ```javascript const anviz = require("node-anviz"); let request = new anviz.Request("192.168.1.100"); request.execute("eraseNewRecordsFlag", 1).then((response) => { console.log("New records flag cleared successfully"); request.close(); }, (err) => { console.error("Error:", err); }); ``` ### Response #### Success Response (200) Indicates that the flag was successfully cleared. The response content may vary but typically confirms the operation. #### Response Example ```json { "status": "success", "message": "Flag cleared" } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.