Jump to content
NOTICE / HINWEIS: iOS 18 Update and Today Widgets ×

Script is not waiting for HTTP.GET response


Enno

Recommended Posts

Hi all,

 

i am an absolute beginner in shelly scripting, so please be patient with me 🙂

 

I'm running a script for a dew point controlled ventilation system on a Shelly Plus 1 PM (let's call it "master").

To get the temperature and humidity from outside, a DHT22-Sensor is hooked up to a Shelly Plus 1 (let's call ist "slave") via Addon.

The script is running every 15 minutes on the master. The master shall read the sensor data from the slave.

 

The following script is shortened to show my problem:

let Temp = 0;

print("START, Temp =", Temp);

Shelly.call("HTTP.Get", {url: "http://<IP of the Slave Shelly>/rpc/temperature.GetStatus?id=100"}, function(result, error_code, error_message)
{
  if (error_code !== 0)
  {
    Temp = 99;
    print("reading error, Temp =", Temp);
  }
  else
  {
    jsonData = JSON.parse(result.body);
    Temp = jsonData.tC;
    print("Temp =", Temp);
  }
});

print("DONE, Temp =", Temp);

The console log looks like this:

START, Temp = 0
DONE, Temp = 0
Temp = 13.7

As you can see, the response from the "Shelly.call" is printed after the final "print" command.

I want the script to wait for the HTTP.Get response and continue afterwards, because otherwise my script always works with outdated sensor data.

How could i realize this?

 

Thanks in advance

Enno

Edited by Enno
Link to comment
Share on other sites

Hello,

The Shelly.call runs in parallel. It is kind of launching another process while continuing with the rest of the script.

If you want further instructions to be treated in sequence, after the Shelly.call completes, you must include them in the return function (in the else of

if (error_code !== 0)
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...