NEWS

Javascript-Adapter formatDate() erzeugt Fehler



  • TypeError:	06 07:46:36.849	error	at Adapter.formatDate (/opt/iobroker/node_modules/iobroker.js-controller/lib/adapter.js:1661:28)
    TypeError:	06 07:46:36.849	error	isDuration.toLowerCase is not a function
    uncaught	06 07:46:36.846	error	exception: isDuration.toLowerCase is not a function
    

    Fehlermeldung komplett:

    host-ubuntu-1604-dev	06 07:46:36.865	error	instance system.adapter.javascript.1 terminated with code 0 (OK)
    TypeError:	06 07:46:36.849	error	at process._tickCallback (node.js:356:17)
    TypeError:	06 07:46:36.849	error	at nextTickCallbackWith2Args (node.js:442:9)
    TypeError:	06 07:46:36.849	error	at endReadableNT (_stream_readable.js:913:12)
    TypeError:	06 07:46:36.849	error	at IncomingMessage.emit (events.js:166:7)
    TypeError:	06 07:46:36.849	error	at emitNone (events.js:72:20)
    TypeError:	06 07:46:36.849	error	at IncomingMessage. (/opt/iobroker/node_modules/iobroker.javascript/node_modules/request/request.js:988:12)
    TypeError:	06 07:46:36.849	error	at Request.emit (events.js:169:7)
    TypeError:	06 07:46:36.849	error	at emitOne (events.js:82:20)
    TypeError:	06 07:46:36.849	error	at Request. (/opt/iobroker/node_modules/iobroker.javascript/node_modules/request/request.js:1067:10)
    TypeError:	06 07:46:36.849	error	at Request.emit (events.js:172:7)
    TypeError:	06 07:46:36.849	error	at emitTwo (events.js:87:13)
    TypeError:	06 07:46:36.849	error	at Request.self.callback (/opt/iobroker/node_modules/iobroker.javascript/node_modules/request/request.js:200:22)
    TypeError:	06 07:46:36.849	error	at Request._callback (script.js.common.WIFFI:31:13)
    TypeError:	06 07:46:36.849	error	at script.js.common.WIFFI:122:13
    TypeError:	06 07:46:36.849	error	at createDpFromJson (script.js.common.WIFFI:110:42)
    TypeError:	06 07:46:36.849	error	at timeLastData (script.js.common.WIFFI:13:12)
    TypeError:	06 07:46:36.849	error	at sandbox.formatDate (/opt/iobroker/node_modules/iobroker.javascript/javascript.js:1759:32)
    TypeError:	06 07:46:36.849	error	at Adapter.formatDate (/opt/iobroker/node_modules/iobroker.js-controller/lib/adapter.js:1661:28)
    TypeError:	06 07:46:36.849	error	isDuration.toLowerCase is not a function
    uncaught	06 07:46:36.846	error	exception: isDuration.toLowerCase is not a function
    

    Skript:

    var request = require("request");
    var pfad    = "WIFFI" + ".Arbeitszimmer.";
    var url     = 'http://172.16.130.195/?json:';
    // TODO:
    //
     function timeLastData() {
        return formatDate(new Date(), "DD.MM, hh:mm:ss");
    }
     function parseJson(text) {
        if (text === "") return {};
        try {
            json = JSON.parse(text);
        } catch (ex) {
            json = {};
        }
        if(!json) json = {};
        return json;
    }
     function readJson(url, callback) {
        request(url, function (err, state, body){
            if (body) {
                var json = parseJson(body);
                callback(null, json);
            } else {
                var error = "(" + err + ") ERROR bei Abfrage von: " + url;
                log(error, "warn");
                callback(error, null);
            }
        });
    }
     function readVars() {
        readJson(url, function(err,json) {
            if(!err) {
                var myJson = json;
                var dPname, init;
                var anzahlVars = myJson.vars.length;
                for (var i = 1; i < anzahlVars; i++) {
                    dPname = pfad + myJson.vars[i].homematic_name;
                    init = myJson.vars[i].value;
                    setState(dPname, init);
                }
                for (var systeminfo in myJson.Systeminfo) {
                    dPname = pfad + "Systeminfo." + systeminfo;
                    init = myJson.Systeminfo[systeminfo];
                    setState(dPname, init);
                }
                setState(pfad + "LetzteAbfrage",timeLastData());
                var statusNe = getState(pfad + "Last_State_Count").val;
                if (statusNe < 0) {
                    setState(pfad + "Last_State_Count",0);
                } else {
                    setState(pfad + "Last_State_Count",statusNe + 1);
                }
                log("WIFFI Daten aktualisiert: " + url,"debug");
            } else {
                log("Fehler beim Auslesen des JSON. Keine Daten erhalten.","warn");
                if (statusNe > 0) {
                    setState(pfad + "Last_State_Count",0);
                } else {
                    setState(pfad + "Last_State_Count",statusNe - 1);
                }
            }
        });
    }
     function createDpFromJson(myJson) {
        var dpname = "";
        var name = "";
        var forceCreation = true;
        var common;
        var init;
        var type, desc, unit;
        var anzahlVars = myJson.vars.length;
        for (var i = 1; i < anzahlVars; i++) {
            dPname = pfad + myJson.vars[i].homematic_name;
            init = myJson.vars[i].value;
            type = myJson.vars[i].type;
            desc = myJson.vars[i].desc;
            name = desc;
            unit = myJson.vars[i].unit.replace('grad','°');
            common = '{"desc":"' + desc + '","type":"' + type + '","unit":"' + unit + '","role":"value"' +',"name":"' + name + '"}';
            common = JSON.parse(common);
            createState(dPname, init , forceCreation, common);
            //createState(dPname, init);
            log("neuer Datenpunkt: " + dPname + ": " + init +", common: " + common,"debug");
        }
        for (var systeminfo in myJson.Systeminfo) {
            dPname = pfad + "Systeminfo." + systeminfo;
            init = myJson.Systeminfo[systeminfo];
            common = '{"name":"'+systeminfo+'","desc":"'+systeminfo+'","role":"value"}';
            common = JSON.parse(common);
            log("neuer Datenpunkt: " + dPname + ": " + init +", common: " + common,"info");
            createState(dPname, init , forceCreation, common);
        }
        createState(pfad + "System.Modultyp",myJson.modultyp);
        createState(pfad + "System.url",url.replace("json:","xpert:0:"));
        createState(pfad + "Last_State_Count",0,true);
        createState(pfad + "LetzteAbfrage"  ,timeLastData());
        createState(pfad + "Skriptstart"    ,timeLastData()),true;
        createState(pfad + "Control_GetData",false,true,        {"name":"Daten mit true manuell abrufen","type":"boolean","role":"value"});
        log("Datenpunkte für WIFI in "+ pfad +" angelegt.");
    }
     function createDp() {
        readJson(url, function (err,json) {
            if(!err) {
                var myJson = json;
                createDpFromJson(myJson);
                log("WIFFI Datenpunkte angelegt/aktualisiert");
            } else {
                log("Fehler beim Auslesen des JSON. Keine Daten erhalten.","error");
                log("Keine Datenpunkte angelegt. Skript beendet","error");
                return;
            }
        });
    }
     function createOn() {
        var dpId = "javascript." + instance + "." + pfad + "Control_GetData";
        on({id: dpId ,change:'any'}, function (obj) {
            log(obj.state.val,"warn");
            if(obj.state.val) {
                readVars();
            }
        });
         schedule("*/1 * * * *", function () { // jede Minute die Werte abfragen
            readVars();
        });
     }
     function main() {
        readVars();
    }
     // Skriptstart
     createDp();
    setTimeout(createOn,    3000);
    setTimeout(main,        3000);
    

  • Forum Testing Most Active Global Moderator Administrators

    Ist das das Gleiche, nach dem ich http://forum.iobroker.net/viewtopic.php?f=36&t=2789#p25195 schon gefragt habe??

    Dann liegt es diesmal ausnahmsweise nicht an meinem Unwissen?

    Gruß

    Rainer



  • ja. sieht nach dem gleichen Thema aus.

    Gesendet von iPhone mit Tapatalk



  • Hallo,

    habe das auch schon festgestellt und deshalb in einige meiner Skripte workarounds eingebaut.

    Gruß

    Pix



  • @ruhr70:

    TypeError:	06 07:46:36.849	error	at Adapter.formatDate (/opt/iobroker/node_modules/iobroker.js-controller/lib/adapter.js:1661:28)
    TypeError:	06 07:46:36.849	error	isDuration.toLowerCase is not a function
    uncaught	06 07:46:36.846	error	exception: isDuration.toLowerCase is not a function
    

    Fehlermeldung komplett:

    ! ````
    host-ubuntu-1604-dev 06 07:46:36.865 error instance system.adapter.javascript.1 terminated with code 0 (OK)
    TypeError: 06 07:46:36.849 error at process._tickCallback (node.js:356:17)
    TypeError: 06 07:46:36.849 error at nextTickCallbackWith2Args (node.js:442:9)
    TypeError: 06 07:46:36.849 error at endReadableNT (_stream_readable.js:913:12)
    TypeError: 06 07:46:36.849 error at IncomingMessage.emit (events.js:166:7)
    TypeError: 06 07:46:36.849 error at emitNone (events.js:72:20)
    TypeError: 06 07:46:36.849 error at IncomingMessage. (/opt/iobroker/node_modules/iobroker.javascript/node_modules/request/request.js:988:12)
    TypeError: 06 07:46:36.849 error at Request.emit (events.js:169:7)
    TypeError: 06 07:46:36.849 error at emitOne (events.js:82:20)
    TypeError: 06 07:46:36.849 error at Request. (/opt/iobroker/node_modules/iobroker.javascript/node_modules/request/request.js:1067:10)
    TypeError: 06 07:46:36.849 error at Request.emit (events.js:172:7)
    TypeError: 06 07:46:36.849 error at emitTwo (events.js:87:13)
    TypeError: 06 07:46:36.849 error at Request.self.callback (/opt/iobroker/node_modules/iobroker.javascript/node_modules/request/request.js:200:22)
    TypeError: 06 07:46:36.849 error at Request._callback (script.js.common.WIFFI:31:13)
    TypeError: 06 07:46:36.849 error at script.js.common.WIFFI:122:13
    TypeError: 06 07:46:36.849 error at createDpFromJson (script.js.common.WIFFI:110:42)
    TypeError: 06 07:46:36.849 error at timeLastData (script.js.common.WIFFI:13:12)
    TypeError: 06 07:46:36.849 error at sandbox.formatDate (/opt/iobroker/node_modules/iobroker.javascript/javascript.js:1759:32)
    TypeError: 06 07:46:36.849 error at Adapter.formatDate (/opt/iobroker/node_modules/iobroker.js-controller/lib/adapter.js:1661:28)
    TypeError: 06 07:46:36.849 error isDuration.toLowerCase is not a function
    uncaught 06 07:46:36.846 error exception: isDuration.toLowerCase is not a function

    
    Skript:
    
    >! ```
    `var request = require("request");
    >! var pfad    = "WIFFI" + ".Arbeitszimmer.";
    var url     = 'http://172.16.130.195/?json:';
    >! // TODO:
    //
    >! function timeLastData() {
        return formatDate(new Date(), "DD.MM, hh:mm:ss");
    }
    >! function parseJson(text) {
        if (text === "") return {};
        try {
            json = JSON.parse(text);
        } catch (ex) {
            json = {};
        }
        if(!json) json = {};
        return json;
    }
    >! function readJson(url, callback) {
        request(url, function (err, state, body){
            if (body) {
                var json = parseJson(body);
                callback(null, json);
            } else {
                var error = "(" + err + ") ERROR bei Abfrage von: " + url;
                log(error, "warn");
                callback(error, null);
            }
        });
    }
    >! function readVars() {
        readJson(url, function(err,json) {
            if(!err) {
                var myJson = json;
                var dPname, init;
                var anzahlVars = myJson.vars.length;
                for (var i = 1; i < anzahlVars; i++) {
                    dPname = pfad + myJson.vars[i].homematic_name;
                    init = myJson.vars[i].value;
                    setState(dPname, init);
                }
                for (var systeminfo in myJson.Systeminfo) {
                    dPname = pfad + "Systeminfo." + systeminfo;
                    init = myJson.Systeminfo[systeminfo];
                    setState(dPname, init);
                }
                setState(pfad + "LetzteAbfrage",timeLastData());
                var statusNe = getState(pfad + "Last_State_Count").val;
                if (statusNe < 0) {
                    setState(pfad + "Last_State_Count",0);
                } else {
                    setState(pfad + "Last_State_Count",statusNe + 1);
                }
                log("WIFFI Daten aktualisiert: " + url,"debug");
            } else {
                log("Fehler beim Auslesen des JSON. Keine Daten erhalten.","warn");
                if (statusNe > 0) {
                    setState(pfad + "Last_State_Count",0);
                } else {
                    setState(pfad + "Last_State_Count",statusNe - 1);
                }
            }
        });
    }
    >! function createDpFromJson(myJson) {
        var dpname = "";
        var name = "";
        var forceCreation = true;
        var common;
        var init;
        var type, desc, unit;
        var anzahlVars = myJson.vars.length;
        for (var i = 1; i < anzahlVars; i++) {
            dPname = pfad + myJson.vars[i].homematic_name;
            init = myJson.vars[i].value;
            type = myJson.vars[i].type;
            desc = myJson.vars[i].desc;
            name = desc;
            unit = myJson.vars[i].unit.replace('grad','°');
            common = '{"desc":"' + desc + '","type":"' + type + '","unit":"' + unit + '","role":"value"' +',"name":"' + name + '"}';
            common = JSON.parse(common);
            createState(dPname, init , forceCreation, common);
            //createState(dPname, init);
            log("neuer Datenpunkt: " + dPname + ": " + init +", common: " + common,"debug");
        }
        for (var systeminfo in myJson.Systeminfo) {
            dPname = pfad + "Systeminfo." + systeminfo;
            init = myJson.Systeminfo[systeminfo];
            common = '{"name":"'+systeminfo+'","desc":"'+systeminfo+'","role":"value"}';
            common = JSON.parse(common);
            log("neuer Datenpunkt: " + dPname + ": " + init +", common: " + common,"info");
            createState(dPname, init , forceCreation, common);
        }
        createState(pfad + "System.Modultyp",myJson.modultyp);
        createState(pfad + "System.url",url.replace("json:","xpert:0:"));
        createState(pfad + "Last_State_Count",0,true);
        createState(pfad + "LetzteAbfrage"  ,timeLastData());
        createState(pfad + "Skriptstart"    ,timeLastData()),true;
        createState(pfad + "Control_GetData",false,true,        {"name":"Daten mit true manuell abrufen","type":"boolean","role":"value"});
        log("Datenpunkte für WIFI in "+ pfad +" angelegt.");
    }
    >! function createDp() {
        readJson(url, function (err,json) {
            if(!err) {
                var myJson = json;
                createDpFromJson(myJson);
                log("WIFFI Datenpunkte angelegt/aktualisiert");
            } else {
                log("Fehler beim Auslesen des JSON. Keine Daten erhalten.","error");
                log("Keine Datenpunkte angelegt. Skript beendet","error");
                return;
            }
        });
    }
    >! function createOn() {
        var dpId = "javascript." + instance + "." + pfad + "Control_GetData";
        on({id: dpId ,change:'any'}, function (obj) {
            log(obj.state.val,"warn");
            if(obj.state.val) {
                readVars();
            }
        });
    >!     schedule("*/1 * * * *", function () { // jede Minute die Werte abfragen
            readVars();
        });
    >! }
    >! function main() {
        readVars();
    }
    >! // Skriptstart
    >! createDp();
    setTimeout(createOn,    3000);
    setTimeout(main,        3000);` 
    Sollte am Git gefixt sein. Danke fürs Melden.[/i][/i][/i][/i][/i][/i][/i]
    ``` ` 


  • @Bluefox:

    Sollte am Git gefixt sein. Danke fürs Melden. `

    Jetzt muss ich wieder blöd nachfragen… :oops:

    Der Javascript Adapter ist auf Git immer noch der 2.0.6.

    Was muss ich denn aktualisieren?



  • @ruhr70:

    Was muss ich denn aktualisieren? `
    /opt/iobroker/node_modules/iobroker.js-controller/lib/adapter.js


  • Forum Testing Most Active Global Moderator Administrators

    und anschließend

    sudo chmod 777 * -R
    

    nicht vergessen, sonst hagelt es Schimpfe!

    EDIT: Seltsam, ./iobroker restart startet iobroker - dann Error2 cannot start, aber ioBroker läuft?

    Gruß

    Rainer



  • @ruhr70:

    • im Admin/Adapter werden nur die installierten Adapter angezeigt (ggf. wg. meiner Vorgehensweise oben) `

    Sind wieder von alleine da.



  • @Homoran:

    und anschließend

    sudo chmod 777 * -R
    

    nicht vergessen, sonst hagelt es Schimpfe!

    EDIT: Seltsam, ./iobroker restart startet iobroker - dann Error2 cannot start, aber ioBroker läuft?

    Gruß

    Rainer `

    zu spät gesehen.

    Hab Schimpfe verdient.

    Lief auch ohne :oops:

    habe ich nachträglich ausgeführt


Log in to reply
 

Suggested Topics

1.8k
Online

32.1k
Users

38.7k
Topics

525.3k
Posts