Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. [Gelöst]Bild von Webcam speichern

    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

    [Gelöst]Bild von Webcam speichern

    This topic has been deleted. Only users with topic management privileges can see it.
    • amg_666
      amg_666 last edited by amg_666

      Hallo,
      ich möchte, wenn jemand an meiner Haustür klingelt, dass die Überwachungskamera einen Snapshot macht und mir den an Telegram sendet. Ich nutze den Telegram Adapter und Kommunikation passt schonmal grundsätzlich.
      Problem ist, dass ich kein Kamerabild gespeichert bekomme.

      Auszug aus javascript:

       request.get({url: url_snapshot, encoding: 'binary'}, function (err, response, body) {
                  fs.writeFile("/tmp/snap.jpg", body, 'binary', function(err) {
                  if (err) {
                      console.error(err);
                       } else {
                      console.log('Snapshot sent');
                      sendTo('telegram.0', {text: '/tmp/snap.jpg', caption: 'Es hat geklingelt !'});
                      }
                  }); 
      

      Die Variable url_snapshot ist mit dem Link auf die Kamera-Snapshotfunktion gefüllt und wenn ich den so im Browser eingebe kommt auch ein Bild.

      var url_snapshot = 'http://192.168.2.31/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=xxxxx&pwd=yyyyyyy';
      

      Im Log kommt der Output, dass gesendet wurde

      2022-01-07 22:13:53.044 - info: javascript.0 (446) Start javascript script.js.Tests.Bild_an_Telegram
      2022-01-07 22:13:53.059 - info: javascript.0 (446) script.js.Tests.Bild_an_Telegram: registered 1 subscription and 0 schedules
      2022-01-07 22:14:03.951 - info: javascript.0 (446) script.js.Tests.Bild_an_Telegram: Snapshot sent
      

      Es kommt aber nix an (auch der Text "Es hat geklingelt" nicht...

      Wenn ich im iobroker Unterverzeichnis tmp nachschaue, dann ist da auch kein Bild gespeichert:

      andreas@iobroker:/opt/iobroker/iobroker-data/tmp$ ls
      telegram_0
      

      Hat jemand hier eine Idee oder einen Tipp, was ich da falsch mache?

      Glasfaser 1 Reply Last reply Reply Quote 0
      • Glasfaser
        Glasfaser @amg_666 last edited by Glasfaser

        @amg_666 sagte in Bild von Webcam speichern:

        so :

         request.get({url: url_snapshot, encoding: 'binary'}, function (err, response, body) {
                    fs.writeFile('/tmp/snap.jpg', body, 'binary', function(err) {
                    if (err) {
                        console.error(err);
                         } else {
                        console.log('Snapshot sent');
                        sendTo('telegram.0', {text: '/tmp/snap.jpg', caption: 'Es hat geklingelt !'});
                        }
                    }); 
        
        
        amg_666 1 Reply Last reply Reply Quote 0
        • amg_666
          amg_666 @Glasfaser last edited by

          @glasfaser sagte in Bild von Webcam speichern:

          fs.writeFile('/tmp/snap.jpg', body, 'binary', function(err) {

          Du hast den Dateinamen in einfache Hochkommas gesetzt, hab ich ausprobiert, kein Effekt...

          Glasfaser 1 Reply Last reply Reply Quote 0
          • Glasfaser
            Glasfaser @amg_666 last edited by Glasfaser

            @amg_666 sagte in Bild von Webcam speichern:

            kein Effekt...

            ich kenn nicht dein ganzes Script , nur dein Schnipsel ... aber es funktioniert !

            hier mal von mir erweitert auf Basis von deinem , ein Bild wird geholt und auch versendet !

            var fs = require('fs');
            
            var url_snapshot = 'http://hiermeinPfadvomBild';//Bild URL
            
            request.get({url: url_snapshot, encoding: 'binary'}, function (err, response, body) {
            
                    fs.writeFile('/tmp/snap.jpg', body, 'binary', function(err) {
            
                        if (err) {
            
                            console.error(err);
            
                             } else {
            
                            console.log('Snapshot sent');
            
                            sendTo('telegram.0', {text: '/tmp/snap.jpg', caption: 'Es hat geklingelt !'});
            
                            }
            
                        }); 
                    });     
            
            
            amg_666 1 Reply Last reply Reply Quote 0
            • amg_666
              amg_666 @Glasfaser last edited by

              @glasfaser sagte in Bild von Webcam speichern:

              ich bastel da noch dran rum, das skript ist garnicht sehr viel länger, hier mal komplett. Ich hab da jetzt deinen Code von eben komplett reinkopiert, jetzt bekomme ich Warnings

              on({id:"hm-rpc.0.MEQ0657107.1.PRESS_SHORT"/*Klingel aktiv*/, val: true, change: 'ne'});
              
              var url_snapshot = 'http://192.168.2.31/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=XXXXX&pwd=YYYYY';
               
              var fs = require('fs');
              
              request.get({url: url_snapshot, encoding: 'binary'}, function (err, response, body) {
                      fs.writeFile('/tmp/snap.jpg', body, 'binary', function(err) {
                          if (err) {
                              console.error(err);
                               } else {
                              console.log('Snapshot sent');
                              sendTo('telegram.0', {text: '/tmp/snap.jpg', caption: 'Es hat geklingelt !'});
                              }
                          }); 
                      });     
              

              Jetzt spuckt er warnungen im log aus

              avascript.0
              	2022-01-08 16:38:18.057	warn	at processImmediate (internal/timers.js:464:21)
              javascript.0
              	2022-01-08 16:38:18.057	warn	at Immediate._onImmediate (/opt/iobroker/node_modules/iobroker.js-controller/lib/adapter.js:5708:41)
              javascript.0
              	2022-01-08 16:38:18.057	warn	at Object.stateChange (/opt/iobroker/node_modules/iobroker.javascript/main.js:530:29)
              javascript.0
              	2022-01-08 16:38:18.057	warn	at Object.callback (/opt/iobroker/node_modules/iobroker.javascript/lib/sandbox.js:1082:38)
              javascript.0
              	2022-01-08 16:38:18.057	warn	at Object.callback (/opt/iobroker/node_modules/iobroker.javascript/lib/sandbox.js:1068:33)
              javascript.0
              	2022-01-08 16:38:18.056	warn	at Object.setState (/opt/iobroker/node_modules/iobroker.javascript/lib/sandbox.js:1437:20)
              javascript.0
              	2022-01-08 16:38:18.055	warn	State "undefined" not found
              
              Glasfaser 1 Reply Last reply Reply Quote 0
              • Glasfaser
                Glasfaser @amg_666 last edited by

                @amg_666 sagte in Bild von Webcam speichern:

                State "undefined" not found

                nimm das raus :

                on({id:"hm-rpc.0.MEQ0657107.1.PRESS_SHORT"/*Klingel aktiv*/, val: true, change: 'ne'});
                

                das Script startet beim einschalten schon , da brauchst du kein Trigger .

                amg_666 1 Reply Last reply Reply Quote 0
                • amg_666
                  amg_666 @Glasfaser last edited by

                  @glasfaser
                  Jetzt läuft es ohne Fehler durch, im log steht "snapshot sent". Aber es ist immer noch kein Bild im tpm Ordner.
                  Das Skript läuft zwar beim Starten direkt durch aber ich will ja ein aktuelles Bild haben, wenn jemand klingelt (?)

                  1 Reply Last reply Reply Quote 0
                  • Glasfaser
                    Glasfaser last edited by Glasfaser

                    @amg_666 sagte in Bild von Webcam speichern:

                    Das Skript läuft zwar beim Starten direkt durch aber ich will ja ein aktuelles Bild haben,

                    Nochmal ...

                    ja das war nur ein Testscript von mir , auf basis von deinem ..

                    Woher soll / sollte ich wissen was du möchtest ...
                    da es eine Vielzahl von fertigen Script hier im Forum gibt zu : Telegram Bild versenden .

                    Wird jetzt ein Bild bei telegram angezeigt , der Ordner ist erstmal uninteressant!?

                    amg_666 1 Reply Last reply Reply Quote 0
                    • amg_666
                      amg_666 @Glasfaser last edited by

                      @glasfaser sagte in Bild von Webcam speichern:

                      Bild bei telegram angezeigt , der Ordner ist erstmal uninteressant!?

                      nein wird es nicht. Und weil das ja mein "Anfangsproblem" ist, wollte ich erstmal prüfen ob überhautp ein Bild (lokal) gespeichert wird

                      Glasfaser 1 Reply Last reply Reply Quote 0
                      • Glasfaser
                        Glasfaser @amg_666 last edited by

                        @amg_666 sagte in Bild von Webcam speichern:

                        ob überhautp ein Bild (lokal) gespeichert wird

                        Prüfe hiermit , das Bild wird im Ordner vis.0 abgelegt :

                        request(
                        
                          {
                        
                            url: "http://ccccccccccccccccccccccc",
                        
                            encoding: null,
                        
                          },
                        
                          (error, response, body) => {
                        
                            if (!error && body) {
                        
                              writeFile("vis.0", "/hugo1.jpg", body);
                        
                            }
                        
                          }
                        
                        );
                        
                        amg_666 1 Reply Last reply Reply Quote 0
                        • amg_666
                          amg_666 @Glasfaser last edited by amg_666

                          @glasfaser Danke für deinen Support. Ich hab den telegram Adapter nochmal neu gestartet (hatte ich eigentlich gestern auch schon) und jetzt funzt es.
                          Im tmp Ordner unter iobroker ist weiterhin kein Bild aber bei Telegram kommt es an
                          -> einmal "find / " mit dem Namen durchlaufen lassen und: Toll, man sollte VORHER nachdenken 🙂 Der speichert den snapshot nicht unter /iobroker/... ab sondern im root-Verzeichnis unter tmp. Macht ja auch Sinn wenn man im Skript /tmp angibt, oh Mann...

                          Hast du noch einen Tipp/eine Idee warum die Warnings kommen, wenn ich meinen Trigger (auf den hm-Klingelkontakt) setze ?

                          Glasfaser 1 Reply Last reply Reply Quote 0
                          • Glasfaser
                            Glasfaser @amg_666 last edited by Glasfaser

                            @amg_666 sagte in Bild von Webcam speichern:

                            wenn ich meinen Trigger (auf den hm-Klingelkontakt) setze ?

                            der hängt in der Luft ...

                            wäre dann so :

                            url_snapshot = 'http://xxxxxxxxxxxxxxxxxxxxxx';
                            
                            on({id: '0_userdata.0.Trigger_Button', val: true}, async function (obj) {
                              var value = obj.state.val;
                              var oldValue = obj.oldState.val;
                              await etwas_tun();
                            });
                            
                            async function etwas_tun() {
                                var fs = require('fs');
                                
                                request.get({url: url_snapshot, encoding: 'binary'}, function (err, response, body) {
                                
                                 
                                
                                        fs.writeFile('/tmp/snap.jpg', body, 'binary', function(err) {
                                
                                 
                                
                                            if (err) {
                                
                                 
                                
                                                console.error(err);
                                
                                 
                                
                                                 } else {
                                
                                 
                                
                                                console.log('Snapshot sent');
                                
                                 
                                
                                                sendTo('telegram.0', {text: '/tmp/snap.jpg', caption: 'Es hat geklingelt !'});
                                
                                 
                                
                                                }
                                
                                 
                                
                                            }); 
                                
                                        });     
                                
                            
                            }
                            
                            
                            
                            amg_666 1 Reply Last reply Reply Quote 0
                            • amg_666
                              amg_666 @Glasfaser last edited by

                              @glasfaser DANKE !!!!

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

                              Support us

                              ioBroker
                              Community Adapters
                              Donate

                              591
                              Online

                              31.8k
                              Users

                              80.0k
                              Topics

                              1.3m
                              Posts

                              javascript
                              2
                              13
                              817
                              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