Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. Blockly
    5. GELÖST: Base64 Bilddatei per Telegram senden?

    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: Base64 Bilddatei per Telegram senden?

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

      Hallo Zusammen,

      wie man grundsätzlich .JPG Bilder per Telegram versenden kann ist mir klar.
      Nun habe ich den Unifi-Protect Adapter laufen der die Snapshots der Überwachungskamera als Base64 ala "data:image/png;base64 (Buchstabensalat)" Datei in einem Datenpunkt ablegt.
      Wenn ich den Inhalt des DPs so an Telegram übergebe, sagt der, dass die Nachricht zu lang ist (ist sie auch).

      Weiß jemand wie man das versenden hinbekommt?

      Ein möglicher Workaround wäre die Snapshots manuell zu triggern (Zeitgleich mit den automatischen) weil die manuellen in einem Ordner unter /vis.0/unifi-protect/manual/(Kameratoken)/(Timestamp).jpg abgelegt werden.
      Das Problem was ich hier allerdings habe, dass Telegram aus diesem Ordner nichts versenden mag. Hier bekomme ich die Meldung "file must be non-empty"
      Vermutlich keine Zugriffsrechte? Welche müsste man da geben?

      Viele Grüße

      M 1 Reply Last reply Reply Quote 0
      • M
        MCU @900icarD last edited by MCU

        @900icard Bild umwandeln in png

        let dateiname = '/jarvis/ffn.png'
        
        function savePNG(base64String){
            const base64str = base64String.replace(/^data:image\/png;base64,/, '');
            const base64data = Buffer.from(base64str, 'base64');
                
            writeFile('0_userdata.0', dateiname, base64data, (err) => {
                if (!err) {
                    console.info('File written');
                } else {
                    console.error(err);
                }
            });
        }
        
        9 1 Reply Last reply Reply Quote 0
        • 9
          900icarD @MCU last edited by

          @mcu sagte in Base64 Bilddatei per Telegram senden?:

                                                                                                                                      let dateiname = '/jarvis/ffn.png'                                                                                                                                                                                                                                                                                                                                                         function savePNG(base64String){                                                                                                                                                                                const base64str = base64String.replace(/^data:image\/png;base64,/, '');                                                                                                                                                                                const base64data = Buffer.from(base64str, 'base64');                                                                                                                                                                                                                                                                                                                                                                    writeFile('0_userdata.0', dateiname, base64data, (err) => {                                                                                                                                                                                    if (!err) {                                                                                                                                                                                        console.info('File written');                                                                                                                                                                                    } else {                                                                                                                                                                                        console.error(err);                                                                                                                                                                                    }                                                                                                                                                                                });                                                                                                                                                                            }
          

          Hallo @MCU,

          Vielen Dank für das Script zum umwandeln. Leider bin ich im Bereich Javascript nicht bewandert und arbeite daher nur mit Blockly.
          Könntest Du mir bitte das Script so anpassen, dass ich es verwenden kann.

          Der Datenpunkt in dem das base64 Bild drin liegt ist: unifi-protect.0.cameras.6749e0dc01b24a03e4000419.realTimeEvents.motion.snapshot
          Der Datenpunkt wo dann das png landen soll wäre der: 0_userdata.0.Unifi.Kamera_png (Zeichenkette ok?)

          Wäre super wenn Du mir das darstellen könntest wie das angepasste Script dann aussehen müsste.
          Vielen Dank schon mal.

          1 Reply Last reply Reply Quote 0
          • M
            MCU last edited by

            @900icard

            <xml xmlns="https://developers.google.com/blockly/xml">
              <variables>
                <variable id="E%rN7q#/E24cC/v_IN@V">base64String</variable>
                <variable id="-Z^S#?atm^^T0LFTKkwL">dateiname</variable>
              </variables>
              <block type="procedures_defcustomnoreturn" id="1MPnr(os8hBSi|{}j|zA" x="63" y="13">
                <mutation statements="false">
                  <arg name="base64String" varid="E%rN7q#/E24cC/v_IN@V"></arg>
                  <arg name="dateiname" varid="-Z^S#?atm^^T0LFTKkwL"></arg>
                </mutation>
                <field name="NAME">saveBase64ToPNG</field>
                <field name="SCRIPT">Y29uc3QgYmFzZTY0c3RyID0gYmFzZTY0U3RyaW5nLnJlcGxhY2UoL15kYXRhOmltYWdlXC9wbmc7YmFzZTY0LC8sICcnKTsNCmNvbnN0IGJhc2U2NGRhdGEgPSBCdWZmZXIuZnJvbShiYXNlNjRzdHIsICdiYXNlNjQnKTsNCiAgICAgICANCiAgICB3cml0ZUZpbGUoJzBfdXNlcmRhdGEuMCcsIGRhdGVpbmFtZSwgYmFzZTY0ZGF0YSwgKGVycikgPT4gew0KICAgICAgICBpZiAoIWVycikgew0KICAgICAgICAgICAgY29uc29sZS5pbmZvKCdGaWxlIHdyaXR0ZW4nKTsNCiAgICAgICAgICAgIA0KICAgICAgICB9IGVsc2Ugew0KICAgICAgICAgICAgY29uc29sZS5lcnJvcihlcnIpOw0KICAgICAgICAgICANCiAgICAgICAgfQ0KICAgIH0pOw0K</field>
                <comment pinned="false" h="80" w="160">Beschreibe diese Funktion …</comment>
              </block>
              <block type="comment" id="`6I`,K`68E_YjuJ4Bp3R" x="63" y="88">
                <field name="COMMENT">Verzeichnis Unifi vorhanden unter 0_userdata.0 </field>
                <next>
                  <block type="on_ext" id="BA7lZe|T]__C@mQ-7HdK">
                    <mutation xmlns="http://www.w3.org/1999/xhtml" items="1"></mutation>
                    <field name="CONDITION">ne</field>
                    <field name="ACK_CONDITION"></field>
                    <value name="OID0">
                      <shadow type="field_oid" id="y2w*4dQTmCnVJfV!^v9P">
                        <field name="oid">ID auswählen</field>
                      </shadow>
                      <block type="text" id="so{7z(TL,$X=3{wEyo|~">
                        <field name="TEXT">unifi-protect.0.cameras.6749e0dc01b24a03e4000419.realTimeEvents.motion.snapshot</field>
                      </block>
                    </value>
                    <statement name="STATEMENT">
                      <block type="procedures_callcustomnoreturn" id="N]XcZ`N*G9!|,t]jglN2">
                        <mutation name="saveBase64ToPNG">
                          <arg name="base64String"></arg>
                          <arg name="dateiname"></arg>
                        </mutation>
                        <value name="ARG0">
                          <block type="on_source" id="v,63/0W-kYlZi[x8K!_e">
                            <field name="ATTR">state.val</field>
                          </block>
                        </value>
                        <value name="ARG1">
                          <block type="text" id="PH1Pp)}:j[)x:OThOCB`">
                            <field name="TEXT">/Unifi/Kamera.png</field>
                          </block>
                        </value>
                      </block>
                    </statement>
                  </block>
                </next>
              </block>
            </xml>
            

            f258b368-7954-4c5c-b62e-e39c8e406974-image.png

            9 1 Reply Last reply Reply Quote 0
            • 9
              900icarD @MCU last edited by

              @mcu sagte in Base64 Bilddatei per Telegram senden?:

              <xml xmlns="https://developers.google.com/blockly/xml"> <variables> <variable id="E%rN7q#/E24cC/v_IN@V">base64String</variable> <variable id="-Z^S#?atm^^T0LFTKkwL">dateiname</variable> </variables> <block type="procedures_defcustomnoreturn" id="1MPnr(os8hBSi|{}j|zA" x="63" y="13"> <mutation statements="false"> <arg name="base64String" varid="E%rN7q#/E24cC/v_IN@V"></arg> <arg name="dateiname" varid="-Z^S#?atm^^T0LFTKkwL"></arg> </mutation> <field name="NAME">saveBase64ToPNG</field> <field name="SCRIPT">Y29uc3QgYmFzZTY0c3RyID0gYmFzZTY0U3RyaW5nLnJlcGxhY2UoL15kYXRhOmltYWdlXC9wbmc7YmFzZTY0LC8sICcnKTsNCmNvbnN0IGJhc2U2NGRhdGEgPSBCdWZmZXIuZnJvbShiYXNlNjRzdHIsICdiYXNlNjQnKTsNCiAgICAgICANCiAgICB3cml0ZUZpbGUoJzBfdXNlcmRhdGEuMCcsIGRhdGVpbmFtZSwgYmFzZTY0ZGF0YSwgKGVycikgPT4gew0KICAgICAgICBpZiAoIWVycikgew0KICAgICAgICAgICAgY29uc29sZS5pbmZvKCdGaWxlIHdyaXR0ZW4nKTsNCiAgICAgICAgICAgIA0KICAgICAgICB9IGVsc2Ugew0KICAgICAgICAgICAgY29uc29sZS5lcnJvcihlcnIpOw0KICAgICAgICAgICANCiAgICAgICAgfQ0KICAgIH0pOw0K</field> <comment pinned="false" h="80" w="160">Beschreibe diese Funktion …</comment> </block> <block type="comment" id="6I,K68E_YjuJ4Bp3R" x="63" y="88"> <field name="COMMENT">Verzeichnis Unifi vorhanden unter 0_userdata.0 </field> <next> <block type="on_ext" id="BA7lZe|T]__C@mQ-7HdK"> <mutation xmlns="http://www.w3.org/1999/xhtml" items="1"></mutation> <field name="CONDITION">ne</field> <field name="ACK_CONDITION"></field> <value name="OID0"> <shadow type="field_oid" id="y2w*4dQTmCnVJfV!^v9P"> <field name="oid">ID auswählen</field> </shadow> <block type="text" id="so{7z(TL,$X=3{wEyo|~"> <field name="TEXT">unifi-protect.0.cameras.6749e0dc01b24a03e4000419.realTimeEvents.motion.snapshot</field> </block> </value> <statement name="STATEMENT"> <block type="procedures_callcustomnoreturn" id="N]XcZN*G9!|,t]jglN2"> <mutation name="saveBase64ToPNG"> <arg name="base64String"></arg> <arg name="dateiname"></arg> </mutation> <value name="ARG0"> <block type="on_source" id="v,63/0W-kYlZi[x8K!_e"> <field name="ATTR">state.val</field> </block> </value> <value name="ARG1"> <block type="text" id="PH1Pp)}:j[)x:OThOCB`"> <field name="TEXT">/Unifi/Kamera.png</field> </block> </value> </block> </statement> </block> </next> </block> </xml>

              Hallo @MCU,

              Vielen Dank für die Schnelle Reaktion. Leider klappt es noch nicht ganz.
              Das Script/die Funktion läuft durch und es kommt auch als Meldung im Log "File written". Im Datenpunkt steht allerdings nix drin.
              Du hattest als Dateiname /Unifi/Kamera.png drin, das habe ich auf /Unifi/Kamera_png geändert so wie mein DP heißt, geht trotzdem nicht.
              Ich habe auch schon einen DP direkt unter 0_userdata.0. als test angelegt und den Pfad nicht als Variable sondern fix im Script hinterlegt.
              Läuft auch durch mit "File written" aber es kommt im DP nix an.
              DP ist als String so wie der Originale auch.
              Wo könnte ggf. noch ein Fehler sein?

              M 1 Reply Last reply Reply Quote 0
              • M
                MCU @900icarD last edited by

                @900icard Es wird ein png Datei erstellt, die ist nicht im DP sondern unter Files / Dateien
                dfc06d14-bd76-4cd8-9f48-760381556b60-image.png
                3cb1d888-8645-4ea2-9a43-9b5f7b0b70d7-image.png
                Und da muss das Verzeichnis Unifi vorhanden sein.

                9 1 Reply Last reply Reply Quote 0
                • 9
                  900icarD @MCU last edited by

                  @mcu Aaaaaahhhh ... oh, mann wie peinlich. Das hätte ich ja checken müssen als ich den Punkt anstatt dem Unterstrich gesehen habe, tzzz 😵
                  Super, danke. Das funktioniert natürlich.

                  Jetzt habe ich nur noch das Problem, dass wenn ich das per telegram versenden will dann nur der Pfad und nicht das Bild versendet wird.
                  Weder damit /Unifi/Kamera.png noch damit /0_userdata.0/Unifi/Kamera.png funktioniert das.

                  Bisher hatte ich Netatmo Presence Kameras im Einsatz und da habe ich die snapshots mit wget geholt und hier /home/iobroker/presence/last_snapshot.jpg abgespeichert.
                  Diese Pfadangabe mit dem Block "erstelle Text aus" schicken ging, da wurde das Bild gesendet.

                  Am Dateiformat .png kanns nicht liegen oder?
                  Oder wie wäre die korrekte Pfadangabe auf 0_userdata.0/Unifi/....?

                  M 1 Reply Last reply Reply Quote 0
                  • M
                    MCU @900icarD last edited by MCU

                    @900icard

                    <xml xmlns="https://developers.google.com/blockly/xml">
                     <variables>
                       <variable id="E%rN7q#/E24cC/v_IN@V">base64String</variable>
                       <variable id="-Z^S#?atm^^T0LFTKkwL">dateiname</variable>
                       <variable type="timeout" id="timeout">timeout</variable>
                     </variables>
                     <block type="procedures_defcustomnoreturn" id="1MPnr(os8hBSi|{}j|zA" x="63" y="13">
                       <mutation statements="false">
                         <arg name="base64String" varid="E%rN7q#/E24cC/v_IN@V"></arg>
                         <arg name="dateiname" varid="-Z^S#?atm^^T0LFTKkwL"></arg>
                       </mutation>
                       <field name="NAME">saveBase64ToPNG</field>
                       <field name="SCRIPT">Y29uc3QgYmFzZTY0c3RyID0gYmFzZTY0U3RyaW5nLnJlcGxhY2UoL15kYXRhOmltYWdlXC9wbmc7YmFzZTY0LC8sICcnKTsNCmNvbnN0IGJhc2U2NGRhdGEgPSBCdWZmZXIuZnJvbShiYXNlNjRzdHIsICdiYXNlNjQnKTsNCiAgICAgICANCiAgICB3cml0ZUZpbGUoJzBfdXNlcmRhdGEuMCcsIGRhdGVpbmFtZSwgYmFzZTY0ZGF0YSwgKGVycikgPT4gew0KICAgICAgICBpZiAoIWVycikgew0KICAgICAgICAgICAgY29uc29sZS5pbmZvKCdGaWxlIHdyaXR0ZW4nKTsNCiAgICAgICAgICAgIA0KICAgICAgICB9IGVsc2Ugew0KICAgICAgICAgICAgY29uc29sZS5lcnJvcihlcnIpOw0KICAgICAgICAgICANCiAgICAgICAgfQ0KICAgIH0pOw0K</field>
                       <comment pinned="false" h="80" w="160">Beschreibe diese Funktion …</comment>
                     </block>
                     <block type="comment" id="`6I`,K`68E_YjuJ4Bp3R" x="63" y="88">
                       <field name="COMMENT">Verzeichnis Unifi vorhanden unter 0_userdata.0 </field>
                       <next>
                         <block type="on_ext" id="BA7lZe|T]__C@mQ-7HdK">
                           <mutation xmlns="http://www.w3.org/1999/xhtml" items="1"></mutation>
                           <field name="CONDITION">ne</field>
                           <field name="ACK_CONDITION"></field>
                           <value name="OID0">
                             <shadow type="field_oid" id="y2w*4dQTmCnVJfV!^v9P">
                               <field name="oid">ID auswählen</field>
                             </shadow>
                             <block type="text" id="so{7z(TL,$X=3{wEyo|~">
                               <field name="TEXT">unifi-protect.0.cameras.6749e0dc01b24a03e4000419.realTimeEvents.motion.snapshot</field>
                             </block>
                           </value>
                           <statement name="STATEMENT">
                             <block type="procedures_callcustomnoreturn" id="N]XcZ`N*G9!|,t]jglN2">
                               <mutation name="saveBase64ToPNG">
                                 <arg name="base64String"></arg>
                                 <arg name="dateiname"></arg>
                               </mutation>
                               <value name="ARG0">
                                 <block type="on_source" id="v,63/0W-kYlZi[x8K!_e">
                                   <field name="ATTR">state.val</field>
                                 </block>
                               </value>
                               <value name="ARG1">
                                 <block type="text" id="PH1Pp)}:j[)x:OThOCB`">
                                   <field name="TEXT">/Unifi/Kamera.png</field>
                                 </block>
                               </value>
                               <next>
                                 <block type="timeouts_settimeout" id="jf@?gmI;oCllR:?no|TK">
                                   <field name="NAME">timeout</field>
                                   <field name="DELAY">1000</field>
                                   <field name="UNIT">ms</field>
                                   <statement name="STATEMENT">
                                     <block type="sendto_custom" id="m73x[3NqoJ;0KqJd)2+4">
                                       <mutation xmlns="http://www.w3.org/1999/xhtml" items="text,caption"></mutation>
                                       <field name="INSTANCE">telegram.0</field>
                                       <field name="COMMAND">send</field>
                                       <field name="LOG"></field>
                                       <field name="WITH_STATEMENT">FALSE</field>
                                       <value name="ARG0">
                                         <shadow type="text" id="|?3Q|spj,Q`XN=;(2~iM">
                                           <field name="TEXT">/opt/iobroker/iobroker-data/files/0_userdata.0/Unifi/Kamera.png</field>
                                         </shadow>
                                       </value>
                                       <value name="ARG1">
                                         <shadow type="text" id="TS]LiD=Bjxa%=b)5J-?i">
                                           <field name="TEXT">Neues Kamerabild</field>
                                         </shadow>
                                       </value>
                                     </block>
                                   </statement>
                                 </block>
                               </next>
                             </block>
                           </statement>
                         </block>
                       </next>
                     </block>
                    </xml>
                    

                    84d3e01b-bf8f-4c09-80e2-d7b5aa9e63ae-image.png

                    timeout evtl auf 5000 -> 5 Sekunden setzen

                    9 1 Reply Last reply Reply Quote 0
                    • 9
                      900icarD @MCU last edited by

                      @mcu Perfekt! So funktionierts.
                      Vielen, vielen Dank für Deine schnelle und umfangreiche Hilfe 👍 👏 🙏

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

                      Support us

                      ioBroker
                      Community Adapters
                      Donate

                      906
                      Online

                      31.8k
                      Users

                      80.0k
                      Topics

                      1.3m
                      Posts

                      2
                      9
                      294
                      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