Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. JS-MQTT DP eines Bildes (JFIF) in Datei schreiben (jpg)

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    JS-MQTT DP eines Bildes (JFIF) in Datei schreiben (jpg)

    This topic has been deleted. Only users with topic management privileges can see it.
    • K
      kuumaur @SidM last edited by

      @sidm @coyote
      Wie kommt Ihr an den Snapshot ran?

      coyote 1 Reply Last reply Reply Quote 0
      • coyote
        coyote Most Active @kuumaur last edited by

        @kuumaur

        direkt über den Reolink Kamera Befehl:

        http://IP:Port/cgi-bin/api.cgi?cmd=Snap&channel=0&user=XXXX&password=XXXX
        
        K 1 Reply Last reply Reply Quote 0
        • K
          kuumaur @coyote last edited by

          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?

          K 1 Reply Last reply Reply Quote 0
          • K
            kuumaur @kuumaur last edited by

            @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 ************************
            
            coyote 1 Reply Last reply Reply Quote 0
            • coyote
              coyote Most Active @kuumaur last edited by

              @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

              K 1 Reply Last reply Reply Quote 0
              • K
                kuumaur @coyote last edited by

                @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.

                coyote 1 Reply Last reply Reply Quote 0
                • coyote
                  coyote Most Active @kuumaur last edited by

                  @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

                  K 1 Reply Last reply Reply Quote 0
                  • K
                    kuumaur @coyote last edited by kuumaur

                    @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: ""
                        //});
                    
                        }
                    });
                    
                    Rob_in 1 Reply Last reply Reply Quote 0
                    • Rob_in
                      Rob_in @kuumaur last edited by

                      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? 😞

                      Wal Rob_in 2 Replies Last reply Reply Quote 0
                      • Wal
                        Wal Developer @Rob_in last edited by

                        @rob_in ,
                        if you can make your frigate folder available in ioBroker (mount, samba, etc.) you can use that.

                        1 Reply Last reply Reply Quote 0
                        • Rob_in
                          Rob_in @Rob_in last edited by

                          @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!

                          See: https://github.com/blakeblackshear/frigate/issues/6241

                          raintonr created this issue in blakeblackshear/frigate

                          closed Option to save/publish via MQTT snapshots of all identified targets even when event is in progress #6241

                          1 Reply Last reply Reply Quote 0
                          • First post
                            Last post

                          Support us

                          ioBroker
                          Community Adapters
                          Donate

                          838
                          Online

                          31.9k
                          Users

                          80.1k
                          Topics

                          1.3m
                          Posts

                          javascript
                          7
                          41
                          3539
                          Loading More Posts
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes
                          Reply
                          • Reply as topic
                          Log in to reply
                          Community
                          Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
                          The ioBroker Community 2014-2023
                          logo