Hallo zusammen,
ich habe ein Problem mit meinem Blockly Skript, das eine URL abfragt und das Ergebnis verarbeitet.
Es sieht so aus, als wenn es wenn es keine Antwort erhält ein Problem bekommt:
` > host.aio 2018-09-30 14:58:18.289 error instance system.adapter.javascript.0 terminated with code 0 (OK)
host.aio 2018-09-30 14:58:18.288 error Caught by controller[1]: at Socket.emit (events.js:188:7)
host.aio 2018-09-30 14:58:18.288 error Caught by controller[1]: at emitOne (events.js:96:13)
host.aio 2018-09-30 14:58:18.288 error Caught by controller[1]: at Socket.socketErrorListener (_http_client.js:314:9)
host.aio 2018-09-30 14:58:18.288 error Caught by controller[1]: at ClientRequest.emit (events.js:188:7)
host.aio 2018-09-30 14:58:18.288 error Caught by controller[1]: at emitOne (events.js:96:13)
host.aio 2018-09-30 14:58:18.288 error Caught by controller[1]: at Request.onRequestError (/opt/iobroker/node_modules/iobroker.javascript/node_modules/request/request.js:877:8)
host.aio 2018-09-30 14:58:18.288 error Caught by controller[1]: at Request.emit (events.js:188:7)
host.aio 2018-09-30 14:58:18.288 error Caught by controller[1]: at emitOne (events.js:101:20)
host.aio 2018-09-30 14:58:18.288 error Caught by controller[1]: at self.callback (/opt/iobroker/node_modules/iobroker.javascript/node_modules/request/request.js:185:22)
host.aio 2018-09-30 14:58:18.288 error Caught by controller[1]: at Request._callback (script.js.MTK.MotionServices:129:19)
host.aio 2018-09-30 14:58:18.288 error Caught by controller[1]: TypeError: Cannot read property 'length' of undefined
host.aio 2018-09-30 14:58:18.288 error Caught by controller[0]: at Socket.emit (events.js:188:7)
host.aio 2018-09-30 14:58:18.288 error Caught by controller[0]: at emitOne (events.js:96:13)
host.aio 2018-09-30 14:58:18.288 error Caught by controller[0]: at Socket.socketErrorListener (_http_client.js:314:9)
host.aio 2018-09-30 14:58:18.288 error Caught by controller[0]: at ClientRequest.emit (events.js:188:7)
host.aio 2018-09-30 14:58:18.288 error Caught by controller[0]: at emitOne (events.js:96:13)
host.aio 2018-09-30 14:58:18.287 error Caught by controller[0]: at Request.onRequestError (/opt/iobroker/node_modules/iobroker.javascript/node_modules/request/request.js:877:8)
host.aio 2018-09-30 14:58:18.287 error Caught by controller[0]: at Request.emit (events.js:188:7)
host.aio 2018-09-30 14:58:18.287 error Caught by controller[0]: at emitOne (events.js:101:20)
host.aio 2018-09-30 14:58:18.287 error Caught by controller[0]: at self.callback (/opt/iobroker/node_modules/iobroker.javascript/node_modules/request/request.js:185:22)
host.aio 2018-09-30 14:58:18.287 error Caught by controller[0]: at Request._callback (script.js.MTK.MotionServices:96:21)
host.aio 2018-09-30 14:58:18.287 error Caught by controller[0]: TypeError: Cannot read property 'length' of undefined `
Das Skipt selber gibt folgende Meldung im Debug aus:
` > Log
15:01:18.259 [error] Caught by controller[0]: at Request._callback (script.js.MTK.MotionServices:96:21)
15:01:18.260 [error] Caught by controller[1]: at Request._callback (script.js.MTK.MotionServices:129:19) `
Die Zeilen um 96 selber lauten:
` > try {
require("request")((String('http://pn2.fritz.box:7999') + String('/1/detection/status')), function (error, response, result) {
if (!!result.length) {
setState("javascript.0.Services.MotionServer.detectionState.3"/detectionState.3/, (result.slice(((result.indexOf('Detection status') + 1) - 1), result.length - 17)), true);
}
}).on("error", function (e) {console.error(e);});
} catch (e) { console.error(e); } `
Ich habe versucht per leerstring zu prüfen, ob ein Ergebnis erhalten wurde, aber das scheint nicht der richtige Weg zu sein, denn JS kann anscheinend keine Länge auf Leerstrings prüfen.
Hier eine textuelle Sicht auf das Blockly Programm:
falls - nicht -result ist leer
mache - aktualisiere detectionState.3 mit - im Text - result suche erstes Auftreten des Begriffs "Detection status" bis von hinten …
Wie fängt mann denn so etwas in Blockly sauber ab?
Beste Grüße
Michael