Avatar for SergeP


Member since Nov 2016 • Last active Apr 2019
  • 14 conversations

Most recent activity

  • in ESP32
    Avatar for SergeP

    I hope you can. I am not sure.

  • in ESP32
    Avatar for SergeP

    I've just created pull request with the changes. File in the pull request is slightly different because I try to make it more readable. So I've changed one variable name and removed some unused code.

  • in ESP32
    Avatar for SergeP

    @Gordon, thank you! Now I see jsiLastIdleTime change!
    May be I had written wrong search template.

    @Wilberforce, it looks like it is easiest way to call jswrap_interactive_setTime(). Or may be to implement similar own function if you prefer to set system time with millisecond precision.

  • in ESP32
    Avatar for SergeP

    @Gordon, @Wilberforce
    Now I do not understand why some of my code still works. :)

    I see that jsiLastIdleTime should be changed when we change system time (by any way) to intervals remain in correct state.
    But I do not see the change in code, so I understand why setSNTP does not work, but I do not understand why intervals are not broken after I call setTime() in JS. May be it happens (by some unclear way) because I call it from interval or timeout callback?
    Now it seems to me there is may be a big general bug in Espruino. What do you think about that?

  • in ESP32
    Avatar for SergeP

    Sorry, I was wrong. I had not read jshSetSystemTime() implementation and based on fact that my JS SNTP module calls it and works. Now I see that truth is deeper. Now I do not see where intervals are recalculated after time change.

  • in ESP32
    Avatar for SergeP

    Isn't this because when the espruino starts its at time 0 - 1970 and then you are setting the time - so the intervals immediately expire?

    Yes. And settimeofday() does not correct them, so they try to catch up the time.
    So we need to change it to jshSetSystemTime(), I think. SNTP app allows us to redefine function used to set system time. But I am not sure how to do it with minimal changes.

    What if you set the time first and then set the intervals?

    It depends. Because SNTP subsystem is asynchronous and so time may be really changed before or after intervals setup. It checks connection, for example, and repeats NTP request every few minutes or every hour.

  • in ESP32
    Avatar for SergeP

    I've found bug in setSNTP implementation. Now I have simple example. Also I think I know reason.

    var wifi=require("Wifi");
    var i1=setInterval(()=>console.log(1),2000);­
    var i2=setInterval(()=>console.log(2),3333);­

    After setSNTP call both intervals works as if they are with zero delay.
    I think it happens because SNTP subsystem uses settimeofday() inside by default and so does not change interval times.
    It is possible to redefine SNTP_SET_SYSTEM_TIME macro to call jshSetSystemTime() instead of settimeofday(). I think it will repair the bug. I think also lwipopts.h is good place for it.

  • in ESP32
    Avatar for SergeP

    I've located conditions when the bug appears.
    It happens after setSNTP call. Some intervals start to act like they have zero interval after the call. While dump() shows actual interval data is still correct.
    Broken interval list is different time to time. Sometimes all intervals become spoiled, sometimes only one or two, sometimes no one. But it happens often, each second call or about. changeInterval() call can fix broken interval.
    I've returned js implementation of SNTP to my code, and now everytrhing works.

    Now I'm sure there is a bug in Espruino for ESP32. Unfortunately, I did not find sntp implementation in git repository (while I do not think I will find the bug but I'd want to try). In any case I will be happy to help somebody to locate and kill the bug.
    I've tried to write small test code with only one interval and setSNTP but have no success - the bug does not appear in the environment, so it is not so easy to catch it.
    Could anybody also explain me correct way to report the bug? It seems to me it may be a wellknown Github feature. But I did not used Github so I do not know how it is usually done.

    By the way, I see signs that there is may be one more bug - my code hangs after a short time (usually a few hours) after I have added many console.log() calls (so it is called about 2 times per second now). There is no special console messages before the hang. It seems that the hang appears much faster if ESP32 board is connected via USB (so ESP32 COM port is used for logging). But I did not test it enough.