Enno Posted September 30 Share Posted September 30 (edited) 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 September 30 by Enno Quote Translate Revert translation? English (American) Finnish French German Italian Portuguese (European) Spanish Link to comment Share on other sites More sharing options...
Martin G Posted September 30 Share Posted September 30 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) Quote Translate Revert translation? English (American) Finnish French German Italian Portuguese (European) Spanish Link to comment Share on other sites More sharing options...
Enno Posted October 3 Author Share Posted October 3 Hi Martin, thanks for your replay. I followed your advice and it works, but it doesn't feel right. Has anybody a proper solution to handling these kinds of asynchronous tasks? Regards, Enno Quote Translate Revert translation? English (American) Finnish French German Italian Portuguese (European) Spanish Link to comment Share on other sites More sharing options...
Batat Posted October 4 Share Posted October 4 "Proper" solution is Promises or async functions which Shelly explicitly mentions they do not support. Quote Translate Revert translation? English (American) Finnish French German Italian Portuguese (European) Spanish Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.