NEWS
JS-MQTT DP eines Bildes (JFIF) in Datei schreiben (jpg)
-
direkt über den Reolink Kamera Befehl:
http://IP:Port/cgi-bin/api.cgi?cmd=Snap&channel=0&user=XXXX&password=XXXX
-
Basierend auf der Idee, die Snapshots von der Kamera zu holen, habe ich mir gedacht, dass das auch mit Frigate gehen könnte.
request('http://cctv-prod.fritz.box:5000/clips/carport-1662213375.272777-0mdq87.jpg', async function (error, response, result) { }
Ich habe nur leider keinen Schimmer, wie ich die Datei via E-Mail versende.
An die Clip ID komme ich via MQTT ran.PS: Wen müsste man ansprechen, damit das Auslesen des Bildes via MQTT klappt?
-
@coyote @SidM
Moin,
ich habe mich weiter an den Bildern versucht.
Bin mit meinem Ergebnis als ersten Schuss zufrieden.
(Eigentlich aber nicht wirklich, ich hätte gerne die Clips inkludiert.)Hier mein Code:
var fs = require('fs'); var dest_path = '/var/lib/iobroker_files/'; var whole_path = ''; function extractEventData(message) { const parsedMessage = JSON.parse(message); let extractedJSON = {}; extractedJSON.eventtype = parsedMessage.type; extractedJSON.beforecamera = parsedMessage.before.camera; extractedJSON.beforelabel = parsedMessage.before.label; extractedJSON.beforesnapshot_time = parsedMessage.before.snapshot_time; extractedJSON.beforeid = parsedMessage.before.id; extractedJSON.beforecurrentzones = parsedMessage.before.current_zones; extractedJSON.beforeenteredzones = parsedMessage.before.entered_zones; extractedJSON.aftercamera = parsedMessage.after.camera; extractedJSON.afterlabel = parsedMessage.after.label; extractedJSON.aftersnapshot_time = parsedMessage.after.snapshot_time; extractedJSON.afterid = parsedMessage.after.id; //extractedJSON.before.entered_zones {}; //parsedMessage.before.entered_zones.forEach(zone => { // extractedJSON.before.entered_zones[zone.ZoneName] = zone.value.value; //}); return extractedJSON; } on({id: [].concat(['mqtt.0.frigate.events']), change: "ne" }, function (obj) { var value = obj.state.val; var oldValue = obj.oldState.val; const extractedJSON = extractEventData(obj.state.val); const beforecamera = extractedJSON.beforecamera; const beforelabel = extractedJSON.beforelabel; const beforesnapshot_time = extractedJSON.beforesnapshot_time; const beforeid = extractedJSON.beforeid; const aftercamera = extractedJSON.aftercamera; const afterlabel = extractedJSON.afterlabel; const aftersnapshot_time = extractedJSON.aftersnapshot_time; const afterid = extractedJSON.afterid; const eventtype = extractedJSON.eventtype; //var data = getState('mqtt.0.frigate.carport.person.snapshot').val; if (eventtype == 'update') {console.log('Script: Status_cctv Event: | '+eventtype+' | '+beforecamera+' | '+beforeid+' | '+beforelabel);} if (eventtype == 'end') {console.log('Script: Status_cctv Event: | '+eventtype+' | '+beforecamera+' | '+beforeid+' | '+beforelabel);} if (eventtype == 'new') { exec('wget -O /var/lib/iobroker_files/'+beforeid+'.jpg http://cctv-prod.fritz.box:5000/api/events/'+beforeid+'/snapshot.jpg'); exec('wget -O /var/lib/iobroker_files/'+beforecamera+'-'+beforeid+'.jpg http://cctv-prod.fritz.box:5000/clips/'+beforecamera+'-'+beforeid+'.jpg'); whole_path = dest_path; whole_path += beforecamera; whole_path += '-'; whole_path += beforeid; whole_path += '.jpg'; sendTo("email", "send", { text: (['Script: Status_cctv Event: '+eventtype,'\n','Label:'+beforelabel,'\n','Camera:'+beforecamera,'\n','Eventtype:'+eventtype].join('')), to: 'john@doe.cc', subject: 'Script: Status_cctv Event: '+eventtype+' Camera:'+beforecamera+' Label:'+beforelabel+' v6', attachments:[ {path: '/var/lib/iobroker_files/'+beforecamera+'-'+beforeid+'.jpg', cid: "file1"}, {path: '/var/lib/iobroker_files/'+beforeid+'.jpg', cid: "file2"}, ] }); console.log('Script: Status_cctv Event: | '+eventtype+' | '+beforecamera+' | '+beforeid+' | '+beforelabel); } }); //************************ Events ************************
-
@kuumaur hm, heißt du schnappst dir den Snapshot direkt von frigate und schickst ihn dir per Mail, richtig?
Das muss ich mal testen, anstatt per Mail schicke ich ihn dann per Telegram.
Clips wäre natürlich richtig cool -
@coyote @SidM
Ja genau, inspiriert durch den Aufruf bei den Reolink-Kameras. Die Http-Api von Frigate ist ja recht umfangreich.Bei den Clips bin ich mir nicht sicher, warum ich die nicht bekomme. Entweder habe ich einen Tippfehler, den ich nicht sehe oder die Clip Dateien werden erst etwas später geschrieben und liegen noch nicht vor.
-
@kuumaur
Oh, ich merke gerade, dass ich schon lange nicht mehr in die frigate Docu geschaut habe. Wusste gar nicht, dass ich mittlerweile den Snap über http anfragen kann
Ja das kann sein, dass es etwas dauert bis die clips zu Verfügung stehen -
@coyote @SidM
Mit dieser Version bin ich fast zufrieden. Die E-Mails kommen noch doppelt an, ohne dass ich den Grund erkenne.var fs = require('fs'); var dest_path = '/var/lib/iobroker_files/'; var whole_path = ''; function extractEventData(message) { const parsedMessage = JSON.parse(message); let extractedJSON = {}; extractedJSON.eventtype = parsedMessage.type; extractedJSON.beforecamera = parsedMessage.before.camera; extractedJSON.beforelabel = parsedMessage.before.label; extractedJSON.beforeid = parsedMessage.before.id; extractedJSON.beforecurrentzones = parsedMessage.before.current_zones; extractedJSON.beforeenteredzones = parsedMessage.before.entered_zones; extractedJSON.beforeframetime = parsedMessage.before.frame_time; extractedJSON.beforesnapshottime = parsedMessage.before.snapshot_time; extractedJSON.aftercamera = parsedMessage.after.camera; extractedJSON.afterlabel = parsedMessage.after.label; extractedJSON.aftersnapshot_time = parsedMessage.after.snapshot_time; extractedJSON.afterid = parsedMessage.after.id; //extractedJSON.before.entered_zones {}; //parsedMessage.before.entered_zones.forEach(zone => { // extractedJSON.before.entered_zones[zone.ZoneName] = zone.value.value; //}); return extractedJSON; } on({id: [].concat(['mqtt.0.frigate.events']), change: "ne" }, function (obj) { var value = obj.state.val; var oldValue = obj.oldState.val; const extractedJSON = extractEventData(obj.state.val); const beforecamera = extractedJSON.beforecamera; const beforelabel = extractedJSON.beforelabel; const beforeid = extractedJSON.beforeid; const beforeframetime = extractedJSON.beforeframetime; const beforesnapshottime = extractedJSON.beforesnapshottime; const aftercamera = extractedJSON.aftercamera; const afterlabel = extractedJSON.afterlabel; const aftersnapshot_time = extractedJSON.aftersnapshot_time; const afterid = extractedJSON.afterid; const eventtype = extractedJSON.eventtype; //var data = getState('mqtt.0.frigate.carport.person.snapshot').val; if (eventtype == 'update') {console.log('Script: Status_cctv Event: | '+eventtype+' | '+beforecamera+' | '+beforeid+' | '+beforelabel+' | '+beforeframetime+' | '+beforesnapshottime);} if (eventtype == 'new') {console.log('Script: Status_cctv Event: | '+eventtype+' | '+beforecamera+' | '+beforeid+' | '+beforelabel+' | '+beforeframetime+' | '+beforesnapshottime);} if (eventtype == 'end') { exec('wget -O '+dest_path+beforeid+'.jpg http://cctv-prod.fritz.box:5000/api/events/'+beforeid+'/snapshot.jpg'); exec('wget -O '+dest_path+beforecamera+'-'+beforeid+'.jpg http://cctv-prod.fritz.box:5000/clips/'+beforecamera+'-'+beforeid+'.jpg'); //getBinaryState(idPic, async function (err, data){ // fs.writeFile('test.jpg', data, function (err) { // if(err) log('Fehler!'); // }); //}); whole_path = dest_path; whole_path += beforecamera; whole_path += '-'; whole_path += beforeid; whole_path += '.jpg'; //fs.writeFile(whole_path, data, (err) => {if (err) throw err;console.log('File written ' + whole_path);}); sendTo("email", "send", { text: (['Script: Status_cctv Event: '+eventtype,'\n','Label:'+beforelabel,'\n','Camera:'+beforecamera,'\n','Eventtype:'+eventtype,'\n','Frame Time:'+beforeframetime,'\n','Snapshot Time:'+beforesnapshottime].join('')), to: 'john@doe.cc', subject: 'Script: Status_cctv Event: '+eventtype+' Camera:'+beforecamera+' Label:'+beforelabel+' v9', attachments:[ {path: dest_path+beforecamera+'-'+beforeid+'.jpg', cid: "file1"} //{path: dest_path+beforeid+'.jpg', cid: "file2"}, ] }); console.log('Script: Status_cctv Event: | '+eventtype+' | '+beforecamera+' | '+beforeid+' | '+beforelabel+' | '+beforeframetime+' | '+beforesnapshottime); exec('/usr/bin/rm -f '+dest_path+beforecamera+'-'+beforeid+'.jpg'); exec('/usr/bin/rm -f '+dest_path+beforeid+'.jpg'); //sendTo("pushover.0", "send", { // message: 'Script: Status_cctv Event: changed', // sound: "" //}); } });
-
Hi all, has anyone managed to make this work?
For months I have been using a an MQTT topic change trigger to send an image (via Telegram) that was fetched via HTTP from http://frigate/api/myCam/latest.jpg?bbox=1 Works well, but...
I have just done a lot of work adding new cameras and configuration to Frigate and want to take advantage of it's MQTT image publishing. It seems silly to fetch something via HTTP when an image can be pushed via MQTT is all.
Surely there is an easy solution? So why can I not find it?
-
@rob_in ,
if you can make your frigate folder available in ioBroker (mount, samba, etc.) you can use that. -
@rob_in said in JS-MQTT DP eines Bildes (JFIF) in Datei schreiben (jpg):
For months I have been using a an MQTT topic change trigger to send an image (via Telegram) that was fetched via HTTP from http://frigate/api/myCam/latest.jpg?bbox=1 Works well, but...
I have just done a lot of work adding new cameras and configuration to Frigate and want to take advantage of it's MQTT image publishing. It seems silly to fetch something via HTTP when an image can be pushed via MQTT is all.
Surely there is an easy solution? So why can I not find it?
Having messed around with this a bit have discovered I was doing it correctly in the first place.
Turns out that images published through MQTT are not what I want anyhow so best ignored. Doh!