Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. Hilfe für Javascript Legastheniker und js v8.3.x

    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

    Hilfe für Javascript Legastheniker und js v8.3.x

    This topic has been deleted. Only users with topic management privileges can see it.
    • O
      oFbEQnpoLKKl6mbY5e13 @Homoran last edited by oFbEQnpoLKKl6mbY5e13

      @homoran

      Richtig, options hat der Entwickler als Variable deklariert.

      Homoran 1 Reply Last reply Reply Quote 0
      • Homoran
        Homoran Global Moderator Administrators @oFbEQnpoLKKl6mbY5e13 last edited by

        @ofbeqnpolkkl6mby5e13 sagte in Hilfe für Javascript Legastheniker und js v8.3.x:

        @homoran

        Richtig, options hat der Entwickler als Variable deklariert.

        damit hast du 2x httpGet
        einmal mit direkter Eingabe des url in Zeile 27, mit Ausgabe des response in Zeile 30, und einmal in Zeile 46 mit dem url in der Variable options
        Da wäre es doch interessant

        @tt-tom sagte in Hilfe für Javascript Legastheniker und js v8.3.x:

        Setze das mal in Zeile 48 mit rein, damit du sehen kannst was da kommt.

        ob es da auch ankommt

        O 1 Reply Last reply Reply Quote 0
        • O
          oFbEQnpoLKKl6mbY5e13 @Homoran last edited by oFbEQnpoLKKl6mbY5e13

          @homoran

          Die Funktion updateMuell (Zeile 43) wird nur ausgeführt wenn "schedule('{"time":{"exactTime":true,"start":"12:17"},"period":{"days":1}}'".

          Beim ersten Start muss trotzdem aktualisiert bzw. die Objektstruktur erstellt werden.

          Edit:
          Nee, stimmt nicht. Die wird auch beim Starten ausgeführt.

          Homoran 1 Reply Last reply Reply Quote 0
          • Homoran
            Homoran Global Moderator Administrators @oFbEQnpoLKKl6mbY5e13 last edited by Homoran

            @ofbeqnpolkkl6mby5e13 sagte in Hilfe für Javascript Legastheniker und js v8.3.x:

            Edit

            danke! ich wollte gerade für heute Schluss machen weil ich keine andere Stelle mehr fand 😉

            also mal per log prüfen ob options klappt

            O 1 Reply Last reply Reply Quote 0
            • O
              oFbEQnpoLKKl6mbY5e13 @Homoran last edited by

              @homoran

              httpGet(options), (error, response)
                  console.log(response.statusCode);
                  console.log(response.data);
              

              Wird nichts ausgegeben.

              Homoran paul53 2 Replies Last reply Reply Quote 0
              • Homoran
                Homoran Global Moderator Administrators @oFbEQnpoLKKl6mbY5e13 last edited by

                @ofbeqnpolkkl6mby5e13 sagte in Hilfe für Javascript Legastheniker und js v8.3.x:

                @homoran

                httpGet(options), (error, response)
                    console.log(response.statusCode);
                    console.log(response.data);
                

                Wird nichts ausgegeben.

                dann wird auch nichts angelegt.

                Nur warum?
                ist options nicht korrekt zusammengebaut?

                console.log(options) sagt das gleiche was in Zeile 27 steht?

                O 1 Reply Last reply Reply Quote 0
                • O
                  oFbEQnpoLKKl6mbY5e13 @Homoran last edited by

                  @homoran

                  Wenn ich das mache:

                  httpGet(options), (error, response)
                      console.log(response.statusCode);
                      console.log(response.data);
                      console.log("test");
                  

                  Wird "test" nicht ausgegeben. Das Skript ruft also die Funktion gar nicht auf.

                  Homoran 1 Reply Last reply Reply Quote 0
                  • Homoran
                    Homoran Global Moderator Administrators @oFbEQnpoLKKl6mbY5e13 last edited by

                    @ofbeqnpolkkl6mby5e13
                    Sorry, dann mach ich doch Schluss für heute.
                    mir raucht der Kopf. Das hemmt die Kreativität

                    Mal sehen was abdere bis morgen rausfinden

                    1 Reply Last reply Reply Quote 1
                    • paul53
                      paul53 @oFbEQnpoLKKl6mbY5e13 last edited by

                      @ofbeqnpolkkl6mby5e13 sagte: Wird nichts ausgegeben.

                      Es fehlt auch was.

                      httpGet(options, (error, response) => {
                      
                      O 1 Reply Last reply Reply Quote 0
                      • O
                        oFbEQnpoLKKl6mbY5e13 @paul53 last edited by oFbEQnpoLKKl6mbY5e13

                        @paul53

                        Danke!

                        2024-05-26 22:19:52.596  - info: javascript.0 (3416) Start JavaScript script.js.common._Tests.Test_17 (JavaScript/js)
                        2024-05-26 22:19:52.597  - error: javascript.0 (3416) script.js.common._Tests.Test_17 compile failed:
                        at script.js.common._Tests.Test_17:118
                        2024-05-26 22:19:52.598  - error: javascript.0 (3416) })();
                        2024-05-26 22:19:52.598  - error: javascript.0 (3416)  ^
                        2024-05-26 22:19:52.598  - error: javascript.0 (3416) SyntaxError: Unexpected token ')'
                        2024-05-26 22:19:52.598  - error: javascript.0 (3416)     at new Script (node:vm:99:7)
                        2024-05-26 22:19:52.598  - error: javascript.0 (3416)     at createVM (/opt/iobroker/node_modules/iobroker.javascript/main.js:1917:21)
                        2024-05-26 22:19:52.599  - error: javascript.0 (3416)     at prepareScript (/opt/iobroker/node_modules/iobroker.javascript/main.js:2183:37)
                        2024-05-26 22:19:52.599  - error: javascript.0 (3416)     at /opt/iobroker/node_modules/iobroker.javascript/main.js:2281:17
                        2024-05-26 22:19:52.599  - error: javascript.0 (3416)     at Immediate._onImmediate (/opt/iobroker/node_modules/iobroker.javascript/main.js:1703:17)
                        2024-05-26 22:19:52.599  - error: javascript.0 (3416)     at process.processImmediate (node:internal/timers:478:21)
                        2024-05-26 22:19:55.316  - info: javascript.0 (3416) Stopping script script.js.common._Tests.Test_17
                        
                        

                        An welcher Stelle ist die Klammer zu viel?

                        paul53 1 Reply Last reply Reply Quote 0
                        • paul53
                          paul53 @Homoran last edited by

                          @homoran sagte: nur noch mit timeout of x msec exceeded und nicht mehr die ganzen null Meldungen

                          Blockly_temp.JPG

                          Homoran 1 Reply Last reply Reply Quote 2
                          • paul53
                            paul53 @oFbEQnpoLKKl6mbY5e13 last edited by

                            @ofbeqnpolkkl6mby5e13 sagte: An welcher Stelle ist die Klammer zu viel?

                            ?? Die komplette Testfunktion:

                            httpGet(options, (error, response) => {
                                console.log(response.statusCode);
                                console.log(response.data);
                            });
                            
                            O 1 Reply Last reply Reply Quote 0
                            • O
                              oFbEQnpoLKKl6mbY5e13 @paul53 last edited by

                              @paul53

                              Aber das war nur ein winziger Ausschnitt aus einem größeren Skript:

                              const city_id = XXXXX;
                              const area_id = XXX;
                              const logging = false;
                              const name = 'Müllabfuhr';
                              const numberOfEntries = 69;
                              
                              const instanz = '0_userdata.' + instance + '.muell-test';
                              
                              if (logging) log('starting muell.' + instanz);
                              
                              extendObject(instanz, {
                                     type: "device",
                                     common: {
                                         name: name
                                     }
                                 }, function (err) {
                                     if (err) {
                                         log('could not create device: ', 'warn');
                                         return;
                                     }
                                 
                                 }
                              );
                              let baseData = {};
                              
                              // query names first
                              httpGet('https://mymuell.jumomind.com/mmapp/api.php?r=trash&city_id=' + city_id + '&area_id=' + area_id, { timeout: 2000 }, (error, response) => {
                                 if (!error && response.statusCode == 200) {
                                     console.log(response.statusCode);
                                     console.log(response.data);
                                 } else {
                                     console.error(error);
                                 var data = JSON.parse(response.data);  // info ist ein Objekt
                                         data.forEach((v, i) => {
                                             baseData[v._name] = v;
                                         })
                                 updateMuell();	
                                 }
                              });
                              
                              schedule('{"time":{"exactTime":true,"start":"12:17"},"period":{"days":1}}', updateMuell);
                              
                              function updateMuell() {
                                 var options = 'https://mymuell.jumomind.com/webservice.php?idx=termins&city_id=' + city_id + '&area_id=' + area_id + '&ws=3'
                              
                                 httpGet(options), (error, response) => {
                                 console.log(response.statusCode);
                                 console.log(response.data);
                                 if (!error && response.statusCode == 200) 
                                     var info = JSON.parse(response.data);  // info ist ein Objekt
                                         if (info[0].Ack === 'Success') {
                                             var data = info[0]._data;  // xy ist eine Eigenschaft des Objektes info
                                             let counter = 0;
                                             const date = (new Date())
                                             const todayStr = date.getFullYear() + "-" + ('00' + (date.getMonth() + 1 )).slice(-2) + "-" + ('00' + date.getDate()).slice(-2)
                                             log(todayStr);
                                             data.forEach((v, i) => {
                                                 if (todayStr < v.cal_date && counter <= numberOfEntries) {
                                                     
                                                     const basePath = instanz + '.' + ('000' + counter).slice(-3);
                                                     log(v.cal_date + ' -> ' + basePath, 'debug');
                                                     // States erstellen
                                                     extendObject(basePath, {
                                                             type: "channel",
                                                             common: {
                                                                 name: v.cal_date_normal
                                                             }
                                                         }, function (err) {
                                                             if (err) {
                                                                 log('could not create device: ', 'warn');
                                                                 return;
                                                             }
                                                         
                                                         }
                                                     );
                                                     createState(basePath + '.date', v.cal_date_normal, {
                                                         name: 'Datum',
                                                         desc: 'Datum der Abholung',
                                                         type: 'string',
                                                         read: true,
                                                         write: false
                                                     }, () => {
                                                         setState(basePath + '.date', v.cal_date_normal, true);
                                                     });
                                                     
                                                     createState(basePath + '.desc', baseData[v.cal_garbage_type].title, {
                                                         name: 'Beschreibung',
                                                         desc: 'Beschreibung der Abholung',
                                                         type: 'string',
                                                         read: true,
                                                         write: false
                                                     }, () => {
                                                         setState(basePath + '.desc', baseData[v.cal_garbage_type].title, true);
                                                     });
                                                     createState(basePath + '.color', {
                                                         name: 'Farbe',
                                                         desc: 'Farbe',
                                                         type: 'string',
                                                         role: 'level.color',
                                                         read: true,
                                                         write: false
                                                     }, () => {
                                                         setState(basePath + '.color', baseData[v.cal_garbage_type].color, true);
                                                     });
                              
                                                     counter++;
                                                 }
                                             });
                                         }
                                     };
                                 
                              

                              T 1 Reply Last reply Reply Quote 0
                              • T
                                TT-Tom @oFbEQnpoLKKl6mbY5e13 last edited by

                                @ofbeqnpolkkl6mby5e13 sagte in Hilfe für Javascript Legastheniker und js v8.3.x:

                                httpGet(options), (error, response) => {

                                Zeile 46 hinter options die ) muss weg.

                                O 1 Reply Last reply Reply Quote 0
                                • O
                                  oFbEQnpoLKKl6mbY5e13 @TT-Tom last edited by

                                  @tt-tom

                                  2024-05-26 22:46:45.108  - error: javascript.0 (3416) script.js.common._Tests.Test_17 compile failed:
                                  at script.js.common._Tests.Test_17:111
                                  2024-05-26 22:46:45.109  - error: javascript.0 (3416)         };
                                  2024-05-26 22:46:45.109  - error: javascript.0 (3416)         ^
                                  2024-05-26 22:46:45.109  - error: javascript.0 (3416) SyntaxError: missing ) after argument list
                                  2024-05-26 22:46:45.109  - error: javascript.0 (3416)     at new Script (node:vm:99:7)
                                  2024-05-26 22:46:45.110  - error: javascript.0 (3416)     at createVM (/opt/iobroker/node_modules/iobroker.javascript/main.js:1917:21)
                                  2024-05-26 22:46:45.110  - error: javascript.0 (3416)     at prepareScript (/opt/iobroker/node_modules/iobroker.javascript/main.js:2183:37)
                                  2024-05-26 22:46:45.110  - error: javascript.0 (3416)     at /opt/iobroker/node_modules/iobroker.javascript/main.js:2281:17
                                  2024-05-26 22:46:45.110  - error: javascript.0 (3416)     at Immediate._onImmediate (/opt/iobroker/node_modules/iobroker.javascript/main.js:1703:17)
                                  2024-05-26 22:46:45.111  - error: javascript.0 (3416)     at process.processImmediate (node:internal/timers:478:21)
                                  2024-05-26 22:46:46.955  - info: javascript.0 (3416) Stopping script script.js.common._Tests.Test_17
                                  
                                  T 1 Reply Last reply Reply Quote 0
                                  • T
                                    TT-Tom @oFbEQnpoLKKl6mbY5e13 last edited by TT-Tom

                                    @ofbeqnpolkkl6mby5e13

                                    da fehlen irgendwo noch Klammern, bin grad mal am suchen

                                    Edit: probiere mal das jetzt.

                                    function updateMuell() {
                                        var options = 'https://mymuell.jumomind.com/webservice.php?idx=termins&city_id=' + city_id + '&area_id=' + area_id + '&ws=3'
                                    
                                        httpGet(options, (error, response) => {
                                            console.log(response.statusCode);
                                            console.log(response.data);
                                            if (!error && response.statusCode == 200) {
                                                var info = JSON.parse(response.data);  // info ist ein Objekt
                                                if (info[0].Ack === 'Success') {
                                                    var data = info[0]._data;  // xy ist eine Eigenschaft des Objektes info
                                                    let counter = 0;
                                                    const date = (new Date())
                                                    const todayStr = date.getFullYear() + "-" + ('00' + (date.getMonth() + 1)).slice(-2) + "-" + ('00' + date.getDate()).slice(-2)
                                                    log(todayStr);
                                                    data.forEach((v, i) => {
                                                        if (todayStr < v.cal_date && counter <= numberOfEntries) {
                                    
                                                            const basePath = instanz + '.' + ('000' + counter).slice(-3);
                                                            log(v.cal_date + ' -> ' + basePath, 'debug');
                                                            // States erstellen
                                                            extendObject(basePath, {
                                                                type: "channel",
                                                                common: {
                                                                    name: v.cal_date_normal
                                                                }
                                                            }, function (err) {
                                                                if (err) {
                                                                    log('could not create device: ', 'warn');
                                                                    return;
                                                                }
                                    
                                                            }
                                                            );
                                                            createState(basePath + '.date', v.cal_date_normal, {
                                                                name: 'Datum',
                                                                desc: 'Datum der Abholung',
                                                                type: 'string',
                                                                read: true,
                                                                write: false
                                                            }, () => {
                                                                setState(basePath + '.date', v.cal_date_normal, true);
                                                            });
                                    
                                                            createState(basePath + '.desc', baseData[v.cal_garbage_type].title, {
                                                                name: 'Beschreibung',
                                                                desc: 'Beschreibung der Abholung',
                                                                type: 'string',
                                                                read: true,
                                                                write: false
                                                            }, () => {
                                                                setState(basePath + '.desc', baseData[v.cal_garbage_type].title, true);
                                                            });
                                                            createState(basePath + '.color', {
                                                                name: 'Farbe',
                                                                desc: 'Farbe',
                                                                type: 'string',
                                                                role: 'level.color',
                                                                read: true,
                                                                write: false
                                                            }, () => {
                                                                setState(basePath + '.color', baseData[v.cal_garbage_type].color, true);
                                                            });
                                    
                                                            counter++;
                                                        }
                                                    });
                                                }
                                            };
                                        })
                                    }
                                    
                                    O 1 Reply Last reply Reply Quote 1
                                    • O
                                      oFbEQnpoLKKl6mbY5e13 @TT-Tom last edited by

                                      @tt-tom

                                      Danke, es kommt kein Fehler mehr! Eine Objektstruktur wird weiterhin nicht angelegt.

                                      T 1 Reply Last reply Reply Quote 0
                                      • T
                                        TT-Tom @oFbEQnpoLKKl6mbY5e13 last edited by

                                        @ofbeqnpolkkl6mby5e13
                                        okay dann brauche ich mal das komplette Log vom Start das Script. Muss mir mal die Daten ansehen, die da kommen.

                                        O 1 Reply Last reply Reply Quote 0
                                        • O
                                          oFbEQnpoLKKl6mbY5e13 @TT-Tom last edited by

                                          @tt-tom

                                          2024-05-26 23:06:36.838  - info: javascript.0 (3416) Start JavaScript script.js.common._Tests.Test_17 (JavaScript/js)
                                          2024-05-26 23:06:36.850  - info: javascript.0 (3416) script.js.common._Tests.Test_17: registered 0 subscriptions, 1 schedule, 0 messages, 0 logs and 0 file subscriptions
                                          2024-05-26 23:06:36.925  - info: javascript.0 (3416) script.js.common._Tests.Test_17: 200
                                          2024-05-26 23:06:36.926  - info: javascript.0 (3416) script.js.common._Tests.Test_17: [{"title":"Bioabfall","name":"SZ_BIO","_name":"SZ_BIO","color":"a52a2a"},{"title":"Gelber Sack","name":"SZ_G","_name":"SZ_G","color":"FFFF00"},{"title":"Altpapier (120l, 240l)","name":"SZ_P","_name":"SZ_P","color":"2fc2e8"},{"title":"Restabfall (bis 240l)","name":"SZ_R","_name":"SZ_R","color":"2F4F4F"},{"title":"Weihnachtsbaum","name":"SZ_W","_name":"SZ_W","color":"36b515"}]
                                          2024-05-26 23:14:15.038  - info: javascript.0 (3416) Stopping script script.js.common._Tests.Test_17
                                          
                                          T 1 Reply Last reply Reply Quote 0
                                          • T
                                            TT-Tom @oFbEQnpoLKKl6mbY5e13 last edited by

                                            @ofbeqnpolkkl6mby5e13
                                            der erste teil stimmt auch nicht bzw. ist unlogisch. Hast du noch das original?

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

                                            Support us

                                            ioBroker
                                            Community Adapters
                                            Donate

                                            827
                                            Online

                                            31.8k
                                            Users

                                            80.0k
                                            Topics

                                            1.3m
                                            Posts

                                            8
                                            104
                                            6315
                                            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