Open ozett opened 4 years ago
Hi @ozett ! Can you share how you make it work? I keep getting the following error when an alarm input is triggered in my DVR Hikvision 7208:
TypeError: Cannot read property '0' of undefined
at /home/julian/.node-red/node_modules/node-hikvision-api/Hikvision.js:191:85
at Parser.
Thank you!
check firmware (latest for me, i guess)
check alarm settings per camera...must be a hikvision, i guess
that should send the alarm-events to nodered debug.log
maybe another check with curl on command-line? see -> https://github.com/henry-spanka/node-red-contrib-hikvision/issues/10#issuecomment-645567127
Hi @ozett ! Can you share how you make it work? I keep getting the following error when an alarm input is triggered in my DVR Hikvision 7208:
TypeError: Cannot read property '0' of undefined at /home/julian/.node-red/node_modules/node-hikvision-api/Hikvision.js:191:85 at Parser. (/home/julian/.node-red/node_modules/xml2js/lib/parser.js:304:18) ...
I'm getting this same error as well when an alarm is triggered on my Hikvision NVR. This crashes my node red instance each time.
What I found was that the NVR changes the html tag from 'channelID' to 'dynChannelID' when an alarm is sent on one of the channels.
To get around this issue for now, I changed line 191 in the Hikvision.js file from this:
const index = parseInt(result['EventNotificationAlert']['channelID'][0]);
to this:
var index = 0;
if ('channelID' in result['EventNotificationAlert']) {
index = parseInt(result['EventNotificationAlert']['channelID'][0]);
}
if ('dynChannelID' in result['EventNotificationAlert']) {
index = parseInt(result['EventNotificationAlert']['dynChannelID'][0]);
}
There's cleaner ways of handling it, but this got me going again for now.
maybe the developer henry can update the source here?
Added support for dynChannelId in https://github.com/henry-spanka/node-hikvision-api/commit/c346e89f81e31482676a21a1f80295581396ab62
Added support for dynChannelId in henry-spanka/node-hikvision-api@c346e89
That looks like it should handle the issue. Thank you!
I had forgotten about this. Your solution didn't fix my problem, but I did find mine, and it's similar. I was using the alarm input, not the motion detection from a camera. So the problem is that there is no channelID tag in that alarm, instead it is called inputIOPortID. So when wanting to parse and not find it, it failed
I modified the line from the above solution as follows, and was successful: const index = parseInt('channelID' in result['EventNotificationAlert'] ? result['EventNotificationAlert']['channelID'][0] : result['EventNotificationAlert']['inputIOPortID'][0]);
As the dev was active after a longer period may he put this also in for completion? or this is another start for some feature upgrades? 😄
@henry-spanka , I had another issue with the NVR where I was missing events. Most of the time this was not an issue since there are usually multiple chances to emit events with each alarm from the NVR, but the problem was much more noticeable for shorter alarms.
What I found was that the valid XML data sent to the Hikvision.js/handleData() method would usually be preceded by the following text:
--boundary Content-Type: application/xml; charset="UTF-8" Content-Length: 467
This would often cause parser.parseString on line 187 to fail with the error: "Error: Non-whitespace before first tag, Line: 0, Column: 1, Char: -", and the handleData() method would silently fail to process the message.
My workaround fix was to add the following code before the "parser.parseString(data, (err, result) => {" on line 187:
let xmlStart = data.indexOf("<");
if (xmlStart > 0) {
data = data.toString().substring(xmlStart);
}
With this change above, the parser no longer fails to process the alarms and I no longer appear to be missing messages. The odd part is, I would have thought the parser would always fail with this issue, but it is able to parse the message with the extra text about half the time.
I had forgotten about this. Your solution didn't fix my problem, but I did find mine, and it's similar. I was using the alarm input, not the motion detection from a camera. So the problem is that there is no channelID tag in that alarm, instead it is called inputIOPortID. So when wanting to parse and not find it, it failed
I modified the line from the above solution as follows, and was successful: const index = parseInt('channelID' in result['EventNotificationAlert'] ? result['EventNotificationAlert']['channelID'][0] : result['EventNotificationAlert']['inputIOPortID'][0]);
Hi JulianCaruso
can you guide where you made these changes. i cant find any relevant code in line 191 or anywhere else in the code. I have the same problem.
@henry-spanka
Just trying this on my iDS-7208HUHI-K1 / 4S(B) DVR. If I trigger an alarm input wired directly to the back of the dvr, it doesnt report and causes this error. Seems related to problems above. Any ideas anyone ?
7 Oct 17:08:30 - [red] Uncaught Exception:
7 Oct 17:08:30 - TypeError: Cannot read property '0' of undefined
at /home/pi/.node-red/node_modules/node-hikvision-api/Hikvision.js:191:189
at Parser.
I guess we also need to check IOPortID. I am currently on vacation so if anyone likes to create a PR I would appreciate it. Otherwise I will fix it next week.
GREAT! i tried and had success. the index-nr is the camera-channel on the hikvision-dvr. credentials are the hikvision-dvr credentials. i had to activate the notifications per channel in the dvr (not in the camera)