ioBroker / ioBroker.javascript

Script engine for JavaScript and Blockly
MIT License
325 stars 120 forks source link

After Upgrade to 6.2.0 -> URL request timing issue? #1252

Closed cat1510 closed 1 year ago

cat1510 commented 1 year ago

Hi,

after upgrade from V6.1.4 to V6.2.0 for me it is not possible to extract JSON data from an URL request.

from a shelly TVR - I take the status JSON and extract the value of POS from there.

try {
  require("request")((['http://',vVENT_IP,'/status'].join(''))).on("error", function (e) {console.error(e);});
} catch (e) { console.error(e); }
await wait(2000);
try {
  require("request")((['http://',vVENT_IP,'/status'].join('')), async function (error, response, result) {
    vJSON_TEMP1 = getAttr((function () { try {return JSON.parse(result);} catch(e) {return {};}})(), 'thermostats');
  vVENT_POS_CURRENT = jsonataExpression(vJSON_TEMP1,'pos');
  console.log(vVENT_POS_CURRENT);
  }).on("error", function (e) {console.error(e);});
} catch (e) { console.error(e); }
console.log("request: " + (['http://',vVENT_IP,'/status'].join('')));

The vVENT_POS_CURRENT is empty.

Steps to reproduce the behavior:

  1. Go to 'V6.2.0' Script not working immediately.
  2. Roll back to V.6.1.4 - works fine as before.

Expected behavior
It should work as before... ;o)

Screenshots & Logfiles
There is no error. The variable is just empty.

Versions:

cat1510 commented 1 year ago

OK - I figured out it is a timing issue?

As soon as I delay with a timeout after the URL block, the request gets a value. Is it a wanted feature that the script doesnt wait for a result?

winnyschuster commented 1 year ago

expression in post #1 is using jsonata which requires now await, see my other post a minute ago #1253