3.5 KiB
3.5 KiB
SVC-HCM-CRAWLER
Hikvision Device Crawling Service for HCM Bridge
This service crawls Hikvision access control devices and sends events to the svc-hcmbridge service.
Features
- Automatically crawls Hikvision devices configured for crawling (flag=1 or iscrawling=1)
- Fetches device MAC address from device info endpoint
- Handles HTTP Digest authentication
- Duplicate event detection
- Sends events to
svc-hcmbridgeat/api/dooraccess/logs - PM2 deployment ready
Prerequisites
- Node.js 20+
- MySQL database (same as svc-hcmbridge)
- PM2 (for deployment)
entitypackage (from parent directory)
Installation
- Install dependencies:
npm install
- Link the entity package:
cd ../entity
npm install
cd ../svc-hcm-crawler
- Build the project:
npm run build
Configuration
Edit config/default.json or config/prod.json:
{
"database": {
"hcm": {
"host": "127.0.0.1",
"port": "3306",
"username": "root",
"password": "your_password",
"database": "tt_hcm"
}
},
"bridge": {
"host": "127.0.0.1",
"port": "3000",
"endpoint": "/api/dooraccess/logs"
},
"hikvision": {
"defaultUsername": "admin",
"defaultPassword": "Passwordhik_1",
"defaultPort": 80
},
"crawler": {
"interval": "*/1 * * * *"
}
}
Development
Run in development mode:
npm run dev
Deployment with PM2
- Build the project:
npm run build
- Start with PM2:
npm run pm2:start
Or manually:
pm2 start ecosystem.config.js
- Check status:
pm2 list
pm2 logs svc-hcm-crawler
- Stop the service:
npm run pm2:stop
# or
pm2 stop svc-hcm-crawler
- Restart the service:
npm run pm2:restart
# or
pm2 restart svc-hcm-crawler
- Delete from PM2:
npm run pm2:delete
# or
pm2 delete svc-hcm-crawler
PM2 Commands
npm run pm2:start- Start the servicenpm run pm2:stop- Stop the servicenpm run pm2:restart- Restart the servicenpm run pm2:delete- Delete from PM2npm run pm2:logs- View logs
How It Works
- The service runs on a cron schedule (default: every 1 minute)
- It queries
tbl_deviceinfofor devices with:brand = 'HIKVISION'flag = 1ORiscrawling = 1isdeleted = 0
- For each device:
- Fetches MAC address from device info endpoint
- Makes authenticated requests to
/ISAPI/AccessControl/AcsEvent - Maps events to webhook format
- Checks for duplicates
- Sends events to
svc-hcmbridgeat/api/dooraccess/logs
Logs
Logs are stored in:
- PM2 logs:
./logs/pm2-out.logand./logs/pm2-error.log - Console output (when running with
npm start)
Troubleshooting
-
Database connection issues:
- Check database credentials in config
- Ensure database is accessible
- Check if
entitypackage is properly linked
-
Bridge service not responding:
- Ensure
svc-hcmbridgeis running - Check bridge host/port in config
- Verify endpoint path is correct
- Ensure
-
Device connection issues:
- Check device IP addresses in
tbl_deviceinfo - Verify device credentials
- Check network connectivity to devices
- Check device IP addresses in
-
MAC address not being saved:
- Check logs for XML parsing errors
- Verify device info endpoint is accessible
- Check device returns valid XML
Environment Variables
Set NODE_ENV to prod for production:
export NODE_ENV=prod
Or use PM2 ecosystem config which sets it automatically.
License
ISC