Post your best Lua script examples here

User avatar
By woodat
#43797 Do beacon frame packets broadcast a time/datestamp? Would it be possible to pull the time out off those so the esp could get the time without actually connecting to the internet (or even a network)?
User avatar
By RFZ
#57695
jim121049 wrote:I've tweaked the SNTP example ( the second one) to automatically determine whether Daylight Saving Time is in effect (in the United States).
Code: Select all    if isDST(hr,dy,mo,yr) then hr=hr+1 end -- Daylight Saving Time is in effect, add one hour
    return hr,mn,sc,mo,dy,yr


Guess you've never been up late at night seeing your watch display 24:03? :roll:

Like the Timezone offset, the DST offset must be added to the timestamp before hour, minute, day etc. is calculated...
User avatar
By marcelstoer
#58347 Nice idea to collect those ideas. If you make sure the code works with the latest firmware it make a valuable addition for https://github.com/nodemcu/nodemcu-firm ... a_examples. You might want to create PR against the dev branch and see what others think?
User avatar
By jim121049
#58362
RFZ wrote:
jim121049 wrote:I've tweaked the SNTP example ( the second one) to automatically determine whether Daylight Saving Time is in effect (in the United States).
Code: Select all    if isDST(hr,dy,mo,yr) then hr=hr+1 end -- Daylight Saving Time is in effect, add one hour
    return hr,mn,sc,mo,dy,yr


Guess you've never been up late at night seeing your watch display 24:03? :roll:

Like the Timezone offset, the DST offset must be added to the timestamp before hour, minute, day etc. is calculated...

You're right of course, as I've since observed. The problem with adding the DST offset to the timestamp before the hour, minute ,day, etc. is calculated is that you need to have the hour, minute, day, etc. to know whether DST is in effect. How about:
Code: Select allif isDST(hr,dy,mo,yr) then hr=(hr+1)%24 end -- Daylight Saving Time is in effect, add one hour
    return hr,mn,sc,mo,dy,yr