callback error on reboot because of SNTP sync is too late

  • Hi,

    I have a big script, which run correctly one shelly is booted.

    But I Tested the script on reboot and it craches.

    After some investigation it seems, tha is sntp.

    I use Shelly.getComponentStatus("sys"); and return me an null on boot:

    Code
    2022-09-13,09:32:35,Notice,pc-149.home,user,shellyplus1-441793a56dd4,110 2.323 2 0|Subscription callback error: type error
    2022-09-13,09:32:35,Notice,pc-149.home,user,shellyplus1-441793a56dd4,109 2.318 2 0|  at script_3.js:225
    2022-09-13,09:32:35,Notice,pc-149.home,user,shellyplus1-441793a56dd4,108 2.314 2 0|  at script_3.js:774
    2022-09-13,09:32:35,Notice,pc-149.home,user,shellyplus1-441793a56dd4,107 2.311 2 0|  at script_3.js:802
    2022-09-13,09:32:35,Notice,pc-149.home,user,shellyplus1-441793a56dd4,106 2.303 1 0|[POOL_] get_current_time() time: null

    And hi see after that the shelly sync with SNTP server, but it should do this before:

    Code
    2022-09-13,09:32:36,Notice,pc-149.home,user,shellyplus1-441793a56dd4,"120 3.073 2 2|mgos_sntp.c:64          SNTP reply from 192.168.1.101: time 1663054356.152770, local 3.151209, delta 1663054353.001561"

    Here is part of my script that is very simple:

    Code
    let result = Shelly.getComponentStatus("sys"); 
     print("[POOL_] get_current_time() time:", result.time);
     
     let time = result.time; // "HH:MM"
    // compute current time in float format (12h45 -> 12.75)
     let t = JSON.parse(time.slice(0,2)) + JSON.parse(time.slice(3,5)) / 60;

    This call isn't the first in my script, there is many others call before, and perhaps the shelly is busy to make own call on init.

    So I don't know if it's a shelly bug, or find an other solution and perhaps catch this "null" return ?

    extract of complete log:


  • Most sys properties can also have a "null" value, have a look at the api:

    System | Shelly Technical Documentation
    The system component provides information about general device status, resource usage, availability of firmware updates, etc.
    shelly-api-docs.shelly.cloud

    You will need to change your function so that it can also handle null.