NodeRed with Hikvision

Hello everybody

I have a Hikvision recorder at home, now I would like to download a momentary picture via Nodered and send it to my mobile phone .. preferably on Whatsapp .. Does anyone know how to do this?

I have already downloaded these Notes (https://flows.nodered.org/node/node-red-contrib-hikvision-ultimate) and tried them out a little, but I haven't got any further ...

Many Thanks

You might want to compliment with Pushover nodes, not sure how featured the WhatsApp API is, you should also take a look at Telegram.

I decided on Telegram .. And I have already set up Telegram so that I can send messages .. What do I have to do if I want to send a picture?

You have to lookup the documentation for how to do that

1 Like

Something like this in a 'function' node should work...
Screen Shot 06-04-21 at 07.03 PM
Replace 'content' with the path to your image file.
'Caption' could just be... caption: "My caption" (In this example I'm getting it from a flow variable.)

nodered


ssh

it doesnt work, what is wrong?

Does the image open in an image viewer (is it a valid image)?

Attach a debug node to both outputs of the gray camera node - let me see what comes out of it.

Lastly, you dont need to even write a file - you can (potentially) send the image directly to telegram

Is the image actually stored in a directory called 'root'?
that seems very unusual. I see that the owner of the image is 'root' so there may be a permission issue accessing the image.

Can the size of the picture still play a role?

I need to see the debug output - is it a buffer? a base64 string?

Uploading: debug.PNG...

try this...

  • delete file node
  • connect camera node to function
  • changing your function to ...
msg.payload = {
  content: msg.payload, //the image 
  caption: `Image from camera`,
  type : 'photo',
  chatId: "xxxx" // << update this
}
msg.payload.options = { parse_mode : "Markdown" };

return msg;

I just have to adjust the chat ID?

yes, to the correct chat id.

I dont know if it will work with base64 image - give it a go & let me know. If it doesnt work I'll show you how to convert it to a buffer (that will work)

did not work

As i suspected - but worth a try - now we know base64 doesnt work.

there are 2 options...

1. best option

if that gray camera node can return a buffer - change it to return a buffer & it should work


2. alternatively, convert base64 img uri to buffer

change function code to this...

var imgBase64 = msg.payload;
var pos = imgBase64.indexOf("base64,");
imgBase64 = imgBase64.substr(pos + 7);
var imgData = Buffer.from(imgBase64, "base64");

msg.payload = {
  content: imgData,
  caption: `Image from camera`,
  type: 'photo',
  chatId: xxxxx // << update this
}
msg.payload.options = { parse_mode: "Markdown" };
return msg;

didn't work either .. am I doing something wrong?
sdf

you need to return the msg at the end of the function (i assumed you realised that sorry)

add return msg; to the end of the function.

it worked! Thank you so much!