diff --git a/src/app/esp32-extra/app.fth b/src/app/esp32-extra/app.fth index 50835b4..b04aae7 100755 --- a/src/app/esp32-extra/app.fth +++ b/src/app/esp32-extra/app.fth @@ -39,26 +39,24 @@ alias m-init noop then #3 / ; - f# 0 fvalue us-start \ Must be updated after set-system-time - : system-time>f ( us seconds -- ) ( f: -- us ) s" s>d d>f f# 1000000 f* s>d d>f f+ " evaluate ; immediate : usf@ ( f: -- us ) s" dup dup sp@ get-system-time! system-time>f" evaluate ; immediate -: ms@ ( -- ms ) - f# .001 usf@ us-start f- f* f>d drop ; +: ms@ ( -- ms ) f# .001 usf@ f* f>d drop ; alias get-msecs ms@ -: ms ( ms -- ) - s>d d>f f# 1000 f* usf@ f+ +: fus ( f: us - ) + usf@ f+ begin fdup usf@ f- f# 100000000 f> while #100000000 us repeat - usf@ f- f>d drop abs us -; + usf@ f- f>d drop abs us ; + +: ms ( ms -- ) s>d d>f f# 1000 f* fus ; fl wifi.fth @@ -83,7 +81,6 @@ fl tools/extra.fth : load-startup-file ( -- ior ) " start" ['] included catch ; : app ( - ) \ Sometimes SPIFFS or a wifi connection causes an error. A reboot solves that. - usf@ to us-start banner hex interrupt? 0= if s" start" file-exist? if load-startup-file diff --git a/src/app/esp32-extra/tests/test_time.fth b/src/app/esp32-extra/tests/test_time.fth new file mode 100755 index 0000000..5739c0c --- /dev/null +++ b/src/app/esp32-extra/tests/test_time.fth @@ -0,0 +1,111 @@ +\ test_time.fth 05-12-2023 + +DECIMAL + +: code-in-minutes ( $hrs count - coded-min ) single? #60 * 16bneg + ; +: add-coded-w ( n - ) s" #" tmp$ +lplace (.) tmp$ +lplace s" w, " tmp$ +lplace ; +: add-coded-c ( n - ) s" #" tmp$ +lplace (.) tmp$ +lplace s" c, " tmp$ +lplace ; + +: List-weekdays + ." 0:sunday 1:monday 2:tuesday 3:wednesday" + cr ." 4:thursday 5:fryday 6:saterday" ; + +: .last-input-tz ( - ) \ As long as tmp$ is not changes + cr ." The new summertime would last for: " cr + .tz-header cr + tmp$ lcount s" create " nip /string bl NextString evaluate + 2023 .summer-time + cr cr ." If OK then: Paste the following code into timezones.f" + cr tmp$ lcount type cr ; + +: Dst-input ( - ) + ." change at LOCAL [UUMM] : " 4 enter-input extract-time + 60 * + 16bneg + nip add-coded-w \ 5) Add change time that day. In local time + List-weekdays cr 9 to-column + ." Day number of the involved weekday : " + 1 enter-input single? \ Ask #weekday + ." Index of the involved weekday in it's month : " + 4 enter-input single? 16bneg + add-coded-w \ 6) Add occurence in month + add-coded-c 35 to-column \ 7) Add #weekday + ." In month : " 2 enter-input single? add-coded-c \ 8) Add month + ." Number of days before the involved weekday : " + 1 enter-input single? add-coded-c ; \ 9) Add subtract #weekdays + +: init-timezone ( - coded-minutes ) + tmp$ + if tmp$ off + else 255 allocate drop to tmp$ + then + cr s" create " tmp$ lplace \ 1) Add create + cr ." Max 34 pos for name : " 34 enter-input tmp$ +lplace \ 2) Add name + s" incr-tz " tmp$ +lplace 10 to-column \ Increment #tz during compiing + ." Utc offset : " 3 enter-input code-in-minutes ; + +: input-tz-rule ( - ) \ Input for extra timezones that observe DST + init-timezone add-coded-w \ 3) Add Utc offset + 5 to-column ." Shift in minutes: " 3 enter-input + single? 16bneg + add-coded-w \ 4) Add shift + cr ." For Dst START, " Dst-input + cr ." For Dst END, " Dst-input + tmp$ lcount evaluate \ Test the code of the input + -1 #tz +! .last-input-tz ; \ Show the Forth code for timezones.f + +: time-list-zoom-meeting ( sec mm hh dd mm yyyy-GMT -- ) + cr utctics-from-time&date greenwich-mean-time + 0 lmargin ! #60 rmargin ! #13 tabstops ! ??cr + ." Local times for the zoom meeting at:" + fdup .time-from-utctics + fdup space .date-from-utctics ." UTC" cr + tz-Endlist #tz @ 0 + do ?cr >link link@ + 2dup >body fdup convert-to-tz bold .time-from-utctics norm space + dup >name$ shorten-tz-name type + loop + 2drop fdrop cr ; + +\ Use : 0 0 13 9 12 2023 time-list-zoom-meeting + + +: world-clock ( - ) + 0 lmargin ! #86 rmargin ! #13 tabstops ! ??cr + greenwich-mean-time tz-Endlist + #tz @ 0 + do ?cr >link link@ tuck >name$ shorten-tz-name type ." :" + 2dup swap >body @time convert-to-tz + fdup .date-from-utctics + bold .time-from-utctics norm + swap 30 .tab + fdepth 0< abort" Floating Point Stack Underflow" + loop + 2drop cr ; + +: watch-world-clock ( - ) + hide-cursor 0 7 at-xy world-clock show-cursor ; + +\ Use: cls 18 set-precision f# 1 fsec>fus ' watch-world-clock execute-until-escape + +0 [if] +Notes: + 2023 .list-summer-times \ To list all timezones in timezones.fth + Europe/Amsterdam 2023 .summer-time \ Lists just 1 + +\ Conversions between time zones at the current local time: + local-time-now europe/amsterdam america/chicago convert-to-tz .time-from-utctics + local-time-now europe/amsterdam america/chicago convert-to-tz .Date-from-utctics + +\ Conversions between time zones at a specified time: + 0 3 13 28 8 2023 utctics-from-time&date greenwich-mean-time + europe/amsterdam convert-to-tz .time-from-utctics + +2038 tests: +0 14 07 19 1 2037 UtcTics-from-Time&Date f.s fdup .Date-from-utctics .time-from-utctics +0 14 07 19 1 2038 UtcTics-from-Time&Date f.s fdup .Date-from-utctics .time-from-utctics +0 14 07 19 1 2100 UtcTics-from-Time&Date f.s fdup .Date-from-utctics .time-from-utctics + +Under esp-idf v3.x.x the time of the esp32 is not handled right beyond 2038 +From: https://github.com/espressif/esp-idf/issues/584 +Subtract 883612800 seconds and dates and weekdays are the same again! +The 2038 problem is solved in v5 + +[then] + diff --git a/src/app/esp32-extra/tools/extra.fth b/src/app/esp32-extra/tools/extra.fth index e856614..15f9f5b 100755 --- a/src/app/esp32-extra/tools/extra.fth +++ b/src/app/esp32-extra/tools/extra.fth @@ -1,4 +1,4 @@ -marker -extra.fth cr lastacf .name #19 to-column .( 11-11-2023 ) \ By J.v.d.Ven +marker -extra.fth cr lastacf .name #19 to-column .( 25-11-2023 ) \ By J.v.d.Ven \ Additional words I often use. alias b bye @@ -104,9 +104,6 @@ test-1second : .elapsed ( - ) usf@ (time-start) 2@ us-elapsed fus>fsec fe. ." sec." ; -: us-to-deadline ( us-start us-later - us-to-later ) - f+ usf@ f- f# 0 fmax ; - create-timer: tTotal 0 value stages- f# 0 fvalue tcycle @@ -132,8 +129,11 @@ f# 180e3 fvalue next-measurement [then] -: bold ( -- ) .esc[ '1' (emit 'm' (emit ; \ VT100 -: norm ( -- ) .esc[ '0' (emit 'm' (emit ; \ VT100 +: bold ( -- ) .esc[ '1' (emit 'm' (emit ; \ VT100 +: norm ( -- ) .esc[ '0' (emit 'm' (emit ; +: hide-cursor ( -- ) #out @ .esc[ s" ?25l" type #out ! ; +: show-cursor ( -- ) #out @ .esc[ s" ?25h" type #out ! ; + : lcount ( addr -- addr' count ) dup cell + swap @ ; : +lplace ( addr len dest -- ) 2dup >r >r lcount + swap cmove r> r> +! ; : lplace ( addr len dest -- ) 0 over ! +lplace ; @@ -190,11 +190,46 @@ patch check-conditional here ( adr -- adr' ) @ + ; : field: ( n1 <"name"> -- n2 ) ( addr -- 'addr ) aligned cell +field ; +: bfield: ( n1 <"name"> -- n2 ) ( addr -- 'addr ) 1 +field ; +: wfield: ( n1 <"name"> -- n2 ) ( addr -- 'addr ) 2 +field ; : xfield: ( n1 <"name"> -- n2 ) ( addr -- 'addr ) 8 +field ; : f2dup ( fs: r1 r2 -- r1 r2 r1 r2 ) fover fover ; : perform ( adr - ) s" @ execute " evaluate ; immediate +#27 constant escape +: escape? ( - flag ) + key? + if key escape = + if true + else + begin key? + while key drop + repeat + false + then + else 0 + then ; + +: us-to-deadline ( f: us-base us-incr - us-wait ) + f+ usf@ f- f# 0 fmax ; \ us-base + us-incr should be > then usf@ + +: find-deadline ( addr-fus-base addr-fus-timeout - ) ( f: - us-to-deadline ) + over f@ f@ f2dup f+ f! us-to-deadline ; + +: execute-until-escape ( xt -- ) ( f: #ms-timeout - ) + 0 0 { xt &#ms-timeout &usstrt -- } + /f allocate drop dup to &#ms-timeout f! + /f allocate drop dup usf@ fus>fsec fround fsec>fus to &usstrt f! + begin xt execute + &usstrt &#ms-timeout find-deadline + fus \ No drift in the software +\ fdrop 1000 ms \ Replace the previous line with this line and it drifts +\ usf@ &usstrt f@ f- fe. ." us deviation. " \ Show the drift + escape? + until + &#ms-timeout free drop &usstrt free drop ; + begin-structure /circular field: >(cbuf-count) field: >max-records @@ -370,7 +405,7 @@ char , value seperator : SendHtmlPage ( - ) HtmlPage$ lcount dup 0> - if lsock lwip-write drop 20 ms + if lsock lwip-write drop else 2drop then ; @@ -492,14 +527,13 @@ char , value seperator create TcpPort$ ," 8080" create UdpPort$ ," 8899" - : UdpWrite ( send$ cnt ip-server$ - ) count UdpPort$ count 2swap udp-connect >r r@ lwip-write 50 ms r> lwip-close drop ; : TcpWrite ( bufer cnt ip-server$ - ) >r #1000 TcpPort$ count r> count stream-connect >r - r@ lwip-write drop + r@ lwip-write drop 50 ms r> lwip-close ; \ After "WiFi station connection failed": diff --git a/src/app/esp32-extra/tools/schedule-tool.f b/src/app/esp32-extra/tools/schedule-tool.f index bbb184f..fb065fd 100755 --- a/src/app/esp32-extra/tools/schedule-tool.f +++ b/src/app/esp32-extra/tools/schedule-tool.f @@ -1,5 +1,5 @@ marker -schedule-tool.f s" cforth" ENVIRONMENT? - [IF] drop cr lastacf .name #19 to-column .( 11-11-2023 ) \ By J.v.d.Ven + [IF] drop cr lastacf .name #19 to-column .( 05-12-2023 ) \ By J.v.d.Ven [THEN] 0 [if] @@ -69,7 +69,6 @@ f# 0.0e0 fvalue boot-time -: .mmhh ( mmhh - ) s>d <# # # [char] : hold # # #> type ; : next-scheduled-time ( - mmhh ) scheduled @ 1+ n>sched.time@ ; : /schedule-file ( - #records ) @@ -244,19 +243,19 @@ 60 60 * value seconds-before-sunset : sleep-seconds-before-sunset ( SecondsBeforeSunset - ) - UtcSunSet @time f- s>f f- fdup f0> + UtcSunSet local-time-now f- s>f f- fdup f0> if cr .date .time ." Needed sleep " f>d drop #seconds-deep-sleeping else fdrop cr .date .time ." No sleep needed." false to WaitForSleeping- - then - ; + then ; -: pass-this-second ( - ) usf@ f# 1e6 us-to-deadline f>d drop us ; +: ftime-till-next-second ( - ) + usf@ fus>fsec fround fsec>fus [ f# 1 fsec>fus ] fliteral us-to-deadline ; : scheduled-wakeup ( - #seconds ) cr .date .time ." sleep-schedule deep-sleep time:" - next-scheduled-time 2359 min #NsTill Nanoseconds f/ f>s - pass-this-second ; + next-scheduled-time 2359 min UtcTill f>s + ftime-till-next-second fus ; : (sleeping-schedule) ( - ) next-scheduled-time 2359 min time>mmhh > @@ -289,7 +288,7 @@ : (sleep-at-boot) ( - ) boot-time date-from-utc-time date>jjjjmmdd - @time date-from-utc-time date>jjjjmmdd = \ Only today + local-time-now date-from-utc-time date>jjjjmmdd = \ Only today if 0 n>sched.option@ Sleep-till-sunset-option = \ Is sleep-at-boot the FIRST entry in the schedule? if (sleep-till-sunset) diff --git a/src/app/esp32-extra/tools/timediff.fth b/src/app/esp32-extra/tools/timediff.fth index 0a4f6b0..d1e73d2 100755 --- a/src/app/esp32-extra/tools/timediff.fth +++ b/src/app/esp32-extra/tools/timediff.fth @@ -1,8 +1,5 @@ -marker -timediff.fth cr lastacf .name #19 to-column .( 11-11-2023 ) \ By J.v.d.Ven -\ Time calculations. Time specifications like ( ss mm uu JD - ) are in UTC -\ unless otherwise indicated like: ( hhmmTargetLocal -- ) or ( f: UtcTics - ss mm uu dd mm yearLocal ) +marker -timediff.fth cr lastacf .name #19 to-column .( 05-12-2023 ) \ By J.v.d.Ven -f# -1 fvalue UtcOffset \ Time zone depended f# -1 fvalue UtcSunRise f# -1 fvalue UtcSunSet @@ -63,7 +60,7 @@ f# 86400. fconstant #SecondsOneDay r@ #400 /_ + r> #365 * + ; -: gregorian-from-fixed ( fixed-date -- month day year ) +: gregorian-from-fixed ( fixed-date -- day month year ) dup gregorian-year-from-fixed >r ( r: year) dup 1 ( jan ) 1 r@ fixed-from-gregorian - ( date prior-days) over 3 ( mar ) 1 r@ fixed-from-gregorian < not if @@ -71,14 +68,13 @@ f# 86400. fconstant #SecondsOneDay then #12 * #373 + #367 / >r ( date)( r: year month) 2r@ 1 rot fixed-from-gregorian - 1+ ( day) - r> swap r> ( month day year) ; - - -: LocalTics-from-UtcTics ( f: UtcTics - LocalTics ) UtcOffset f+ ; -: UtcTics-from-LocalTics ( f: UtcTics - LocalTics ) UtcOffset f- ; + r> r> ( day month year) ; : Jd-from-UtcTics ( f: UtcTics - fjd ) #SecondsOneDay f/ f# 2440588 f+ ; +: 0UtcTics-from-Jd&Time ( ss mm uu JD - ) ( f: - UtcTics ) + #2440588 - s>f #SecondsOneDay f* #SecondsOneHour * swap #60 * + + s>f f+ ; + : UtcTics-from-Jd&Time ( ss mm uu JD - ) ( f: - UtcTics ) #2440588 - s>f #SecondsOneDay f* #SecondsOneHour * swap #60 * + + s>f f+ ; @@ -93,75 +89,254 @@ f# 86400. fconstant #SecondsOneDay f# -1721424.5E0 f+ ; \ -1721424.5E0 = JD-Start : Date-from-jd ( f: fjd - ) ( - dd mm year ) - ftrunc Moment-from-JD f>s Gregorian-from-Fixed >r swap r> ; + ftrunc Moment-from-JD f>s Gregorian-from-Fixed ; + +: Date-from-UtcTics ( f: UtcTics - ) ( - dd mm year ) + Jd-from-UtcTics Date-from-jd ; : week-day ( Julian-day - day ) ftrunc f>s 1+ 7 mod ; \ 0=Sunday +: Day-of-Week-from-Fixed ( fixed-date -- day-of-week ) + 7 _mod ; + +: Weekday-on-or-Before ( date k -- date' ) + over swap - day-of-week-from-fixed - ; + +: Weekday-After ( date k -- date' ) + swap 7 + swap weekday-on-or-before ; + +: Weekday-Before ( date k -- date' ) + swap 1- swap weekday-on-or-before ; + +: 'th-Weekday ( n k month day year -- date ) + Fixed-from-Gregorian ( n k date) + swap rot >r ( date k)( R: n) + r@ 0< if Weekday-After else Weekday-Before then ( date) + r> 7 * + ; + +: last-day-month ( month year - day ) + over #12 = + if #31 -rot + else swap 1+ swap 2>r + 0 0 0 1 2r> UtcTics-from-Time&Date #SecondsOneDay f- + Date-from-UtcTics + then + 2drop ; + +: 'th-Weekday-in-month ( THi|LAST-i #weekday month year -- fixed-date ) + >r 2 pick 0< + if dup r@ last-day-month + else 1 + then + r> 'th-Weekday ; + +: utc-from-fixed ( fixed - utctics-at-00:00 ) + >r 0 0 0 r> gregorian-from-fixed UtcTics-from-Time&Date ; + +: unsigned>f ( unsigned - ) ( f: - n ) + dup 0< + if s>d drop 1 + else s>d + then + d>f ; + +: .## ( - n ) s>d <# # # #> type ; +: .- ( n - ) .## ." -" ; +: get-secs ( - UtcTics ) dup dup sp@ get-system-time! nip ; \ 05-12-2023 In UTC! +: @time ( - f: #secs ) get-secs unsigned>f ; \ +: .(date) ( d m y - ) base @ >r decimal >r swap .- .- r> (.) type r> base ! ; +: .Date-from-utctics ( f: UtcTics - ) Date-from-UtcTics .(date) ; + +begin-structure /tz \ Only 18 +wfield: >tz-utc +wfield: >tz-Shift + +wfield: >tz-time-start +wfield: >tz-weekday-date-start +bfield: >tz-index-weekday-start +bfield: >tz-month-start +bfield: >tz-weekdays-subtract-start + +wfield: >tz-time-end +wfield: >tz-weekday-date-end +bfield: >tz-index-weekday-end +bfield: >tz-month-end +bfield: >tz-weekdays-subtract-end +end-structure + +: utc-only? ( coded-minutes - flag ) $7000 < ; \ Below $7000 ? + +: ms-from-w-minutes ( tz-minutes - ms ) + dup utc-only? + if $5fff + else 16bneg + then + - #60 * ; + +: @dst-start ( tz-list-item - utc-offset ) + dup >tz-Shift w@ ms-from-w-minutes swap + >tz-utc w@ ms-from-w-minutes + ; \ utc-offset januari + +: current-year ( &tz-list-item - year ) + @time @dst-start s>f f+ Date-from-UtcTics nip nip ; + +: @dst-date ( &weekday-date year - fixed-date ) + >r dup>r w@ 16bneg - r@ 2 + c@ r@ 4 + c@ - r> 3 + c@ + r> 'th-Weekday-in-month ; + +: utc-offset-from-tzdata ( &weekday-date year - ) ( f: - utc00:00 ) + @dst-date utc-from-fixed ; + +: @utc_offset ( &tz - utc-offset ) >tz-utc w@ ms-from-w-minutes ; + +: Dst-start ( &tz - shift+utc-offset ) ( f: utc00:00 - utc00:00+utc_time ) + dup>r >tz-time-start w@ ms-from-w-minutes s>f f+ + r@ >tz-Shift w@ ms-from-w-minutes + r> @utc_offset + ; + +: Dst-end ( &tz - shift+utc-offset ) ( f: utc00:00 - utc00:00+utc_time ) + dup>r >tz-time-start w@ ms-from-w-minutes s>f f+ r> @utc_offset ; + +: find-utc-offset-in-year ( tz-list-item year - utc-offset ) + swap >r + r@ >tz-weekday-date-start over utc-offset-from-tzdata + r@ Dst-start f> \ beyond start? + r@ >tz-weekday-date-end 3 roll utc-offset-from-tzdata + r> Dst-end f< \ before end? + rot and + if drop + else nip + then ; + +: current-year-from-utc-tics ( &tz-list-item - year ) ( f: utc-tics - ) + @dst-start s>f f+ Jd-from-UtcTics Date-from-jd nip nip ; + +: find-utc-offset-at-utc ( tz-list-item - ) ( f: utc-tics - utc-offset ) + dup w@ utc-only? + if fdrop w@ ms-from-w-minutes + else fdup dup fdup current-year-from-utc-tics \ current-year *** offset adr year + find-utc-offset-in-year + then + s>f ; \ f# 10000 europe/amsterdam debug find-utc-offset-at-utc find-utc-offset-at-utc + +: find-utc-offset ( tz-list-item - ) ( f: - utc-offset ) + dup w@ utc-only? + if fdrop w@ ms-from-w-minutes + else @time fdup r@ current-year + find-utc-offset-in-year + then + s>f ; -: .- ( n - ) (u.) type ." -" ; +: convert-to-tz ( tz-source tz-destination - ) ( f: utc-local-time-source - utc-destination ) + swap fdup find-utc-offset-at-utc f- \ gmt + fdup find-utc-offset-at-utc f+ ; -: date-from-utc-time ( F: UtcTics - dd mm yearLocal ) - LocalTics-from-UtcTics Jd-from-UtcTics Date-from-jd ; -: get-secs ( - UtcTics ) dup dup sp@ get-system-time! nip ; -: date-now ( - dd mm yearLocal ) get-secs s>f date-from-utc-time ; -: date>jjjjmmdd ( d m j - jjjjmmdd ) #10000 * swap #100 * + + ; +: LocalTics-from-UtcTics ( f: UtcTics - LocalTics ) tz-local find-utc-offset f+ ; +: UtcTics-from-LocalTics ( f: UtcTics - LocalTics ) tz-local find-utc-offset f- ; -: GotTime? ( - flag ) date-now nip nip #2022 > ; +: date-from-utc-time ( F: UtcTics - ) ( - dd mm yearLocal ) + LocalTics-from-UtcTics Date-from-UtcTics ; -: @time ( - f: #secs ) get-secs s>f ; +: date-now ( - dd mm yearLocal ) @time date-from-utc-time ; -: local-time-now ( - f: UtcTics ) @time LocalTics-from-UtcTics ; +: .mmhh ( mmhh - ) s>d <# # # [char] : hold # # #> type ; +: .signed ( n - ) + dup 0= + if space + else dup 0> + if [char] + emit + then + then + . ; + +: .tz-header ( - ) + ." Time zone" #25 spaces + ." UTC Shift #wkd - Starts Time #wkd - Ends Time" ; + +: .time-date-dst ( &tz-weekday-date year - ) + over swap + @dst-date gregorian-from-fixed .(date) space + 2 - w@ 16bneg - #100 * #60 / .mmhh ; + +: .summer-time ( tz-list-item year - ) + >r dup body> >name$ type #34 to-column + dup >tz-utc w@ dup ms-from-w-minutes #3600 / dup abs #10 < + if space + then + .signed #39 to-column + utc-only? + if r> 2drop + else dup >tz-Shift w@ 16bneg - .signed #44 to-column 2 spaces + dup >tz-index-weekday-start c@ . space + dup >tz-weekdays-subtract-start c@ . + dup >tz-weekday-date-start r@ .time-date-dst 2 spaces + dup >tz-index-weekday-end c@ . space + dup >tz-weekdays-subtract-end c@ . + >tz-weekday-date-end r> .time-date-dst + then ; + +: .list-summer-times { year -- } + cr year . cr .tz-header + tz-Endlist #tz @ 0 + do cr >link link@ dup >body year .summer-time + loop + drop cr ; + +: shorten-tz-name ( addr-tz/city cnt - short-tz-name cnt ) + 2dup [char] / scan dup + if 1 /string 2swap 3 min pad lplace + s" /" pad +lplace pad +lplace + else 2drop pad lplace + then s" " pad +lplace pad lcount #14 min ; + +: date>jjjjmmdd ( d m j - jjjjmmdd ) #10000 * swap #100 * + + ; +: GotTime? ( - flag ) date-now nip nip #2022 > ; +: local-time-now ( - f: #secs-local ) @time LocalTics-from-UtcTics ; : UtcTics-from-Time-today ( ss mm uu - f: UtcTics ) - date-now UtcTics-from-Time&Date ; + date-now UtcTics-from-Time&Date ; f# 1e9 fconstant Nanoseconds f# 86400e0 fconstant #SecondsToDay : UtcTics-from-hm ( hhmmTodayUTC - ) ( f: - UtcTics ) - #100 /mod 0 -rot date-now UtcTics-from-Time&Date ; + #100 /mod 0 -rot date-now UtcTics-from-Time&Date ; -: #NsTill ( hhmmTargetLocal -- ) ( F: -- NanosecondsUtc ) - UtcTics-from-hm UtcTics-from-LocalTics @time f2dup f< - if fswap #SecondsToDay f+ fswap \ Next day when the time has past today - then - f- Nanoseconds f* ; +: UtcTill ( hhmmTargetLocal -- ) ( F: -- UtcTics ) + UtcTics-from-hm UtcTics-from-LocalTics @time f2dup f< + if fswap #SecondsToDay f+ fswap \ Next day when the time has past today + then + f- ; : time>mmhh ( - mmhh ) local-time-now time-from-utctics #100 * + nip ; -: .Html-Time-from-UtcTics ( f: UtcTics - ) - base @ >r decimal fdup f0>= - if bl - else fabs [char] - - then - >r Time-from-UtcTics - r> swap ##$ +html +: .Html-Time-from-UtcTics ( f: UtcTics - ) + base @ decimal + Time-from-UtcTics + bl swap ##$ +html 2 0 do [char] : swap ##$ +html loop - r> base ! ; + base ! ; -: .Time-from-UtcTics ( f: UtcTics - ) - base @ >r decimal fdup f0>= - if bl - else fabs [char] - - then - >r Time-from-UtcTics - r> swap ##$ type +: .Time-from-UtcTics ( f: UtcTics - ) + base @ decimal + Time-from-UtcTics + bl swap ##$ type 2 0 do [char] : swap ##$ type loop - r> base ! ; + base ! ; -: .time ( - ) local-time-now .Time-from-UtcTics ; -: .date ( - ) date-now base @ >r decimal >r swap .- .- r> . r> base ! ; +: .time ( - ) local-time-now .Time-from-UtcTics ; +: .date ( - ) date-now .(date) ; : Time&Date-from-UtcTics ( f: UtcTics - ss mm uu dd mm yearUtc ) - fdup Time-from-UtcTics Jd-from-UtcTics Date-from-jd ; + fdup Time-from-UtcTics Date-from-UtcTics ; : Time&DateLocal-from-UtcTics ( f: UtcTics - ss mm uu dd mm yearLocal ) LocalTics-from-UtcTics Time&Date-from-UtcTics ; : Time&Date ( - ss mm uu dd mm yearLocal ) - local-time-now Time&DateLocal-from-UtcTics ; + local-time-now Time&Date-from-UtcTics ; 0 value time-server$ \ Pointer to the ip address that responds to GetTcpTime @@ -171,16 +346,15 @@ f# 86400e0 fconstant #SecondsToDay s" Ask_time" HtmlPage$ +lplace HtmlPage$ lcount time-server$ TcpWrite ; -: SetLocalTime ( UtcTics UtcOffset sunrise sunset - ) - s>f to UtcSunSet s>f to UtcSunRise s>f to UtcOffset - set-system-time usf@ to us-start ; +: SetLocalTime ( LocalTics UtcOffset sunrise sunset - ) + s>f to UtcSunSet s>f to UtcSunRise drop + s>f UtcTics-from-LocalTics f>s set-system-time ; \ 05-12-2023 In UTC! : AskTime ( - ) \ Adapt if needed! time-server$ 0<> if gettcptime \ To get the UTC-time from an RPI then ; -\ Note: set-tcptime-to-0 is used when no local time server is available. \ When gettcptime is used the time server should respond with a tcp packet like: \ GET 1671279235 3600 1671259560 1671287340 TcpTime HTTP/1.1 \ That packet is handled by the word TcpTime. @@ -195,7 +369,7 @@ f# 86400e0 fconstant #SecondsToDay \ Manual input: -: single? ( n$ cnt -- n ) (number?) 0= if ." Bad number" then d>s ; +: single? ( n$ cnt -- n ) (number?) 0= if ." Bad number" quit then d>s ; : extract-time ( hhmm[ss]$ cnt - seconds minutes hours ) dup 6 = -rot 2>r @@ -213,7 +387,17 @@ f# 86400e0 fconstant #SecondsToDay : enter-input ( length -- string cnt ) pad dup rot accept ; -: enter-date-time ( -- ss mm uu dd mm yearLocal flag ) +: enter-timezone/UTC-time-offset ( - UTC-offset) + 3 enter-input (number?) + if d>s #3600 * + else 2drop tz-local dup find-utc-offset + body> >name$ ." tz-local is deferred to: " type f>s + then ; + + +\ defer tz-local to the right timezone in your app. + +: enter-date-time ( -- ss mm uu dd mm yearLocal utc-offset flag ) cr ." Date ddmmyyyy: " #8 dup >r enter-input dup r> <> dup 0= s>f if cr ." Date needs 8 positions. Like 21092023. " @@ -225,14 +409,20 @@ f# 86400e0 fconstant #SecondsToDay dup #4 < dup 0= s>f if cr ." Time needs at least 4 positions. Like 1245. " then - extract-time 2r> r> f>s f>s and ; + extract-time 2r> r> f>s f>s and + ." Enter 't' for time zone or the UTC time offset: " + enter-timezone/UTC-time-offset + swap ; -: set-time ( - ) \ Manual input for time +: set-time ( - ) \ Manual input for time base @ decimal - enter-date-time - if UtcTics-from-Time&Date f>s - 0 0 0 SetLocalTime \ UtcOffset sunrise and sunset are ignored. - cr .date .time - else 3drop 3drop cr ." Bad Time/date." + enter-date-time \ Got the time in LOCAL time + if >r UtcTics-from-Time&Date f>s + r> 0 0 SetLocalTime \ sunrise and sunset are ignored here. + space .date .time + else 3drop 3drop drop cr ." Bad Time/date." then space base ! ; + +: SetLocalTime-from-network ( UtcTics UtcOffset sunrise sunset - ) \ For TcpTime + 2swap tuck + swap 2swap SetLocalTime ; \ \s diff --git a/src/app/esp32-extra/tools/timezones.f b/src/app/esp32-extra/tools/timezones.f new file mode 100755 index 0000000..42faba1 --- /dev/null +++ b/src/app/esp32-extra/tools/timezones.f @@ -0,0 +1,122 @@ +marker -timezones.fth cr cr lastacf .name #19 to-column .( 05-12-2023 ) + +0 [if] +Ref: https://en.wikipedia.org/wiki/Daylight_saving_time_by_country + https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#Time_Zone_abbreviations + https://www.worldtimebuddy.com/ + +Setting the right timezone with minimal memory usage: + +1) For timezones in this file, change the tz-local vector like: + +' Europe/Amsterdam is tz-local + +2) For a country that uses a time zone that is present here with another name: + A) Copy the data ( 2 lines when DST is observed) in your source + B) Remove or disable incr-tz + C) Change the tz-local vector. + EG: Bermuda uses the same time zone as New_York: + +create Bermuda \ incr-tz + #32467 w, #32827 w, #32887 w, #32769 w, #0 c, #3 c, #0 c, #32887 w, #32768 w, #0 c, #11 c, #0 c, +' Bermuda is tz-local + +3) For a new country the does not observe DST. + A) Use create and utc-only, to add the timezone in your source + B) Change the tz-local vector + EG: Dhaka (UTC+06:00) + +create Dhaka 6 utc-only, +' Dhaka is tz-local + + +When you would like to add time zones / countries here: +See input-tz-rule in tests/test_time.fth +The UTC field is filled with the difference in minutes from GMT +Add countries / time zones in reversed alphabetical order. + +Notes: 1) Utc-offset Shift and Change are stored in minutes with an offset + 2) The name length is max 34 positions for America/Argentina/ComodRivadavia + +[then] + +$7fff constant 16bneg variable #tz 0 #tz ! +: incr-tz ( - ) 1 #tz +! ; +: utc-only, ( Utc+ - ) #60 * $5fff + w, ; \ To store the Utc field when NO timesaving are used. + +create South-Africa incr-tz 2 utc-only, + +create Paraguay incr-tz + #32587 w, #32827 w, #32767 w, #32766 w, #0 c, #10 c, #0 c, #32767 w, #32766 w, #0 c, #3 c, #0 c, + +create palestine incr-tz + #32887 w, #32827 w, #32887 w, #32766 w, #6 c, #4 c, #0 c, #32887 w, #32766 w, #0 c, #10 c, #1 c, + +create New_Zealand incr-tz + #33547 w, #32827 w, #32887 w, #32766 w, #0 c, #9 c, #0 c, #32887 w, #32768 w, #0 c, #4 c, #0 c, + +create moldova incr-tz + #32887 w, #32827 w, #32887 w, #32766 w, #0 c, #3 c, #0 c, #32947 w, #32766 w, #0 c, #10 c, #0 c, + +create Lebanon incr-tz + #32887 w, #32827 w, #32767 w, #32766 w, #4 c, #3 c, #0 c, #32767 w, #32766 w, #0 c, #10 c, #0 c, + +create Japan incr-tz 9 utc-only, + +create Israel incr-tz + #32887 w, #32827 w, #32887 w, #32766 w, #0 c, #3 c, #2 c, #32887 w, #32766 w, #0 c, #10 c, #0 c, + +create Greenwich-Mean-Time incr-tz 0 utc-only, + +create Europe/Moscow 3 utc-only, + +create Europe/London incr-tz + #32767 w, #32827 w, #32827 w, #32766 w, #0 c, #3 c, #0 c, #32887 w, #32766 w, #0 c, #10 c, #0 c, + +create Europe/Amsterdam incr-tz + #32827 w, #32827 w, #32887 w, #32766 w, #0 c, #3 c, #0 c, #32947 w, #32766 w, #0 c, #10 c, #0 c, + +create Egypt incr-tz + #32887 w, #32827 w, #32767 w, #32766 w, #5 c, #3 c, #0 c, #34207 w, #32766 w, #4 c, #10 c, #0 c, + +create cuba incr-tz + #32467 w, #32827 w, #32767 w, #32769 w, #0 c, #3 c, #0 c, #32827 w, #32768 w, #0 c, #11 c, #0 c, + +create China incr-tz 8 utc-only, + +create Chile incr-tz + #32587 w, #32827 w, #34207 w, #32768 w, #6 c, #9 c, #0 c, #34207 w, #32768 w, #6 c, #4 c, #0 c, + +create Australia/Melbourne incr-tz + #33427 w, #32827 w, #32887 w, #32768 w, #0 c, #10 c, #0 c, #32947 w, #32768 w, #0 c, #4 c, #0 c, + +create Australia/Lord-Howe-Island incr-tz + #33427 w, #32797 w, #32887 w, #32768 w, #0 c, #10 c, #0 c, #32887 w, #32768 w, #0 c, #4 c, #0 c, + +create America/Sao_Paulo incr-tz -3 utc-only, + +create America/New_York incr-tz + #32467 w, #32827 w, #32887 w, #32769 w, #0 c, #3 c, #0 c, #32887 w, #32768 w, #0 c, #11 c, #0 c, + +create America/Arizona incr-tz -7 utc-only, + +create America/Chicago ( - ) \ Input by hand: + incr-tz \ Increase #tz for a list in .list-summer-times + #-6 #60 * 16bneg + w, \ Utc-offset for utc+N in minutes with an extra offset + #1 #60 * 16bneg + w, \ Shift dst start + #2 #60 * 16bneg + w, \ Starts at: 02:00 UTC + #2 16bneg + w, #0 c, #3 c, \ Date dst starts: Second sunday in march + 0 c, \ Subtract #weekdays + #2 #60 * 16bneg + w, \ Ends at: 02:00 UTC + #1 16bneg + w, #0 c, #11 c, \ Date dst ends: First sunday in november + 0 c, \ Subtract #weekdays + +\ Add new time zones BEFORE this line in reversed alphabetical order. + +marker (tz-Endlist) +: tz-Endlist ( - tz-Endlist ) ['] (tz-Endlist) ; + +\ tz-Endlist >link link@ >name$ type \ Types the last added time zone. +defer tz-local ' Europe/Amsterdam is tz-local \ Change it in your app. +\ 2023 .list-summer-times \ lists them +\ \s diff --git a/src/app/esp32-extra/tools/webcontrols.fth b/src/app/esp32-extra/tools/webcontrols.fth index 9c80edc..35b4822 100755 --- a/src/app/esp32-extra/tools/webcontrols.fth +++ b/src/app/esp32-extra/tools/webcontrols.fth @@ -1,4 +1,4 @@ -marker -webcontrols.fth cr lastacf .name #19 to-column .( 11-11-2023 ) \ By J.v.d.Ven +marker -webcontrols.fth cr lastacf .name #19 to-column .( 05-12-2023 ) \ By J.v.d.Ven needs /circular extra.fth @@ -358,12 +358,15 @@ $1006 constant SO_RCVTIMEO : SetSolOpt ( tcp-sock optval p2 p1 size - ) >r pad 2! r> pad rot SOL_SOCKET 4 roll setsockopt drop ; +\ Set SO_LINGER so lwip-close does not discard any pending data +: linger-tcp ( handle - ) SO_LINGER 1 sp@ [ 2 cells ] literal SetSolOpt ; + : recv ( sock -- length|-1 ) dup >r SO_RCVTIMEO #200 1 [ 2 cells ] literal SetSolOpt req-buf /req-buf r> lwip-read ; : http-responder ( sock - ) - dup to lsock recv dup 0> + dup to lsock dup linger-tcp recv dup 0> if req-buf swap handle-request else drop then diff --git a/src/app/ntc-web/app.fth b/src/app/ntc-web/app.fth index 6a3ad5d..6b1a479 100755 --- a/src/app/ntc-web/app.fth +++ b/src/app/ntc-web/app.fth @@ -39,38 +39,24 @@ alias m-init noop then #3 / ; - f# 0 fvalue us-start \ Must be updated after set-system-time - : system-time>f ( us seconds -- ) ( f: -- us ) s" s>d d>f f# 1000000 f* s>d d>f f+ " evaluate ; immediate : usf@ ( f: -- us ) s" dup dup sp@ get-system-time! system-time>f" evaluate ; immediate -: ms@ ( -- ms ) - f# .001 usf@ us-start f- f* f>d drop ; +: ms@ ( -- ms ) f# .001 usf@ f* f>d drop ; alias get-msecs ms@ -: ms ( ms -- ) - s>d d>f f# 1000 f* usf@ f+ +: fus ( f: us - ) + usf@ f+ begin fdup usf@ f- f# 100000000 f> while #100000000 us repeat - usf@ f- f>d drop abs us -; - -fl wifi.fth - -alias get-msecs ms@ + usf@ f- f>d drop abs us ; -: ms ( ms -- ) - s>d d>f f# 1000 f* usf@ f+ - begin fdup usf@ f- f# 100000000 f> - while #100000000 us - repeat - usf@ f- f>d d>s 0 max us -; +: ms ( ms -- ) s>d d>f f# 1000 f* fus ; fl wifi.fth @@ -87,7 +73,8 @@ fl tasking_rtos.fth \ Preemptive multitasking fl tools/extra.fth fl tools/table_sort.f -fl tools/timediff.fth \ Time calculations. +fl tools/timezones.f +fl tools/timediff.fth \ Time calculations fl tools/webcontrols.fth \ Extra tags in ROM fl tools/svg_plotter.f fl tools/rcvfile.fth @@ -105,7 +92,6 @@ fl ../ntc-web/ntc_steinhart.fth \ For ntc_web.fth : load-startup-file ( -- ior ) " start" ['] included catch ; : app ( - ) \ Sometimes SPIFFS or a wifi connection causes an error. A reboot solves that. - usf@ to us-start banner hex interrupt? 0= if s" start" file-exist? if load-startup-file diff --git a/src/app/ntc-web/ntc_web.fth b/src/app/ntc-web/ntc_web.fth index 5642901..b5f1cfb 100755 --- a/src/app/ntc-web/ntc_web.fth +++ b/src/app/ntc-web/ntc_web.fth @@ -8,7 +8,7 @@ s" MachineSettings.fth" file-exist? \ For sensor-web$ and msg-board$ [if] fl MachineSettings.fth \ if they exist [then] -marker -ntc_web.fth cr lastacf .name #19 to-column .( 11-11-2023 ) \ By J.v.d.Ven +marker -ntc_web.fth cr lastacf .name #19 to-column .( 05-12-2023 ) \ By J.v.d.Ven esp8266? [IF] cr .( Needs an extended version of Cforth on an ESP32. ) @@ -23,13 +23,6 @@ needs Html ../esp/webcontrols.fth needs -svg_plotter.f ../esp/svg_plotter.f needs av-ntc ../esp/ntc_steinhart.fth -0 [if] Copy ntc_steinhart.fth to ~/cforth/src/app/esp - and add the line: -fl ../esp/ntc_steinhart.fth - before the definition of interrupt? - in the file ~/forth/src/app/esp32/apt.fth -[then] - 5 constant adc-channel DataItem: &NtcGraph \ Proporties for the temperature line (color etc) @@ -306,8 +299,8 @@ ALSO TCP/IP DEFINITIONS

+HTML|
|

s" Set time" s" nn" - -; + ; + : /home ( - ) time-server$ GotTime? or @@ -324,7 +317,8 @@ ALSO TCP/IP DEFINITIONS : TcpTime ( UtcTics UtcOffset sunrise sunset - ) \ Response to GetTcpTime see timediff.fth - SetLocalTime tTotal start-timer cr .date .time cr usf@ to tcycle ; + SetLocalTime-from-network tTotal start-timer + cr bold .date .time norm cr usf@ to tcycle ; : sys_time_user ( - ) \ Actions after /set_time_form parse-word @@ -357,28 +351,22 @@ ALSO TCP/IP DEFINITIONS FORTH DEFINITIONS TCP/IP +fvariable &us-cum f# 0 &us-cum f! +fvariable &us-timeout f# 1000000 &us-timeout f! + : sensor+http-responder ( timeout -- ) \ Handles ntc + http-responder KEEP - timed-accept ms@ >r stages- + timed-accept stages- if dup abs . then if handle-ntc else http-responder - then - 1000 ms@ r> - 0 max - 200 max ms>ticks to poll-interval ; - - -#27 constant escape + then ; : program-loop ( - ) - begin - poll-interval responder - key? - if key escape = - if exit - else begin key? while key drop repeat - then - then - again ; + usf@ f# 1000 f+ &us-cum f! \ setting the time base + begin &us-cum &us-timeout find-deadline + fus>fms f>s ms>ticks responder escape? + until ; : try-logon ( - ) wifi-logon-state 0<> @@ -429,10 +417,9 @@ FORTH DEFINITIONS TCP/IP sent-temp-hum-to-msgboard Sent-state 100 ms esp-clk-cpu-freq 1000000 / . ." Mhz " - 1000 ms>ticks to poll-interval cr ." The home page of the webserver is:" .homepage-adr cr program-loop \ Contains the loop of the server - +f order cr quit ; + +f order cr decimal quit ; : faster ( - ) f# 1e0 to fcycle-time diff --git a/src/app/sps30/app.fth b/src/app/sps30/app.fth index fc55a2a..2f17ef5 100755 --- a/src/app/sps30/app.fth +++ b/src/app/sps30/app.fth @@ -39,26 +39,24 @@ alias m-init noop then #3 / ; - f# 0 fvalue us-start \ Must be updated after set-system-time - : system-time>f ( us seconds -- ) ( f: -- us ) s" s>d d>f f# 1000000 f* s>d d>f f+ " evaluate ; immediate : usf@ ( f: -- us ) s" dup dup sp@ get-system-time! system-time>f" evaluate ; immediate -: ms@ ( -- ms ) - f# .001 usf@ us-start f- f* f>d drop ; +: ms@ ( -- ms ) f# .001 usf@ f* f>d drop ; alias get-msecs ms@ -: ms ( ms -- ) - s>d d>f f# 1000 f* usf@ f+ +: fus ( f: us - ) + usf@ f+ begin fdup usf@ f- f# 100000000 f> while #100000000 us repeat - usf@ f- f>d drop abs us -; + usf@ f- f>d drop abs us ; + +: ms ( ms -- ) s>d d>f f# 1000 f* fus ; fl wifi.fth @@ -71,11 +69,12 @@ previous fl files.fth fl server.fth -fl tasking_rtos.fth \ Preemptive multitasking +fl tasking_rtos.fth \ Preemptive multitasking fl tools/extra.fth fl tools/table_sort.f -fl tools/timediff.fth \ Time calculations. +fl tools/timezones.f +fl tools/timediff.fth \ Time calculations fl tools/webcontrols.fth \ Extra tags in ROM fl tools/svg_plotter.f fl tools/rcvfile.fth @@ -93,7 +92,6 @@ fl ../sps30/sps30.fth \ For sps30_web.fth : load-startup-file ( -- ior ) " start" ['] included catch ; : app ( - ) \ Sometimes SPIFFS or a wifi connection causes an error. A reboot solves that. - usf@ to us-start banner hex interrupt? 0= if s" start" file-exist? if load-startup-file diff --git a/src/app/sps30/sps30.fth b/src/app/sps30/sps30.fth index 5d5e0bc..5287009 100755 --- a/src/app/sps30/sps30.fth +++ b/src/app/sps30/sps30.fth @@ -1,4 +1,4 @@ -marker -sps30.fth cr lastacf .name #19 to-column .( 11-11-2023 ) \ By J.v.d.Ven +marker -sps30.fth cr lastacf .name #19 to-column .( 05-12-2023 ) \ By J.v.d.Ven 0 value msg-board$ 0 value sensor-web$ @@ -428,7 +428,7 @@ f# 30e6 fvalue warm-up-time stopMeasurement set-next-measurement-sps30 ['] Wait-till-next-measurement SetStage - then ; + then ; : start-sleep ( - ) startSleep (sleeping-schedule) ; diff --git a/src/app/sps30/sps30_web.fth b/src/app/sps30/sps30_web.fth index fe62512..b8bb3e7 100755 --- a/src/app/sps30/sps30_web.fth +++ b/src/app/sps30/sps30_web.fth @@ -1,11 +1,12 @@ s" MachineSettings.fth" file-exist? [if] fl MachineSettings.fth [then] -marker -sps30_web.fth cr lastacf .name #19 to-column .( 11-11-2023 ) \ By J.v.d.Ven +marker -sps30_web.fth cr lastacf .name #19 to-column .( 05-12-2023 ) \ By J.v.d.Ven \ To see the air quality in a web browser. \ The SPS30 should be connected to an extra UART on the ESP32. See sps30.fth \ Needed in ROM: needs /circular tools/extra.fth +needs tz-local tools/timezones.f needs AskTime tools/timediff.fth needs Html tools/webcontrols.fth needs -svg_plotter.f tools/svg_plotter.f @@ -14,7 +15,7 @@ ALSO HTML ALSO SPS30 DEFINITIONS needs handle-sps30 ../sps30/sps30.fth \ Needs also to be compiled in ROM esp8266? [IF] cr .( Needs an extended version of Cforth on an ESP32! ) -cr .( See https://github.com/Jos-Ven/cforth/tree/WIP ) QUIT [THEN] +cr .( See https://github.com/Jos-Ven/cforth ) QUIT [THEN] DECIMAL @@ -312,6 +313,7 @@ create file-schedule-sps30 ," schedule-sps30.dat" 0 n>sched.option@ Sleep-till-sunset-option = \ Sleep option active? Then sleep until the next item! scheduled @ 1+ n>sched.time@ 2359 < and ; \ Current entry inside schedule? + : check-sleep-schedule sleep-needed? \ if true sleep until the next item in the schedule if .pause-msg ." Starting the sleeping-schedule" cr @@ -323,14 +325,14 @@ create file-schedule-sps30 ," schedule-sps30.dat" ALSO TCP/IP DEFINITIONS : TcpTime ( UtcTics UtcOffset sunrise sunset - ) \ Response to GetTcpTime see timediff.fth - SetLocalTime + SetLocalTime-from-network usf@ fdup to start-tic to tcycle tSps30 start-timer tTotal start-timer boot-time f0= - if @time to boot-time + if local-time-now to boot-time then set-next-measurement-sps30 - cr .date .time bl emit tTotal start-timer restart-schedule + cr bold .date .time norm bl emit tTotal start-timer restart-schedule check-sleep-schedule ; : /set_time_form ( - ) @@ -373,7 +375,7 @@ ALSO TCP/IP DEFINITIONS usf@ to start-tic tTotal start-timer restart-schedule check-sleep-schedule then - cr .date .time cr + cr bold .date .time norm cr ['] /home set-page ; @@ -469,7 +471,7 @@ PREVIOUS begin key? if key dup #27 = if drop - 2 ms 3 rtc-clk-cpu-freq-set + \ 2 ms 3 rtc-clk-cpu-freq-set cr esp-clk-cpu-freq 1000000 / . ." Mhz " +f ONLY FORTH ALSO SPS30 order cr quit else set-responder @@ -491,15 +493,10 @@ PREVIOUS 1 value sps30? : send_ask_time ( - ) - time-server$ 0<> - if GotTime? - if check-sleep-schedule - else cr ." Ask time from: " 100 ms time-server$ count type - ms@ >r asktime ms@ r> - dup space . ." ms " 1000 > - if cr ." Stream failed. Rebooting..." 1500 ms 3 DeepSleep - then - then - then ; + cr ." Ask time from: " 100 ms time-server$ count type + ms@ >r asktime ms@ r> - dup space . ." ms " 1000 > + if cr ." Stream failed. Rebooting..." 1500 ms 3 DeepSleep + then ; : .homepage-adr ( - ) bold ." http://" ipaddr@ .ipaddr ." /home " norm ; @@ -517,7 +514,7 @@ PREVIOUS 1000 ms>ticks to poll-interval cr ." The first results appear after 30 seconds in the list." cr time-server$ 0= - if space GotTime? 0= + if space GotTime? 0= if cr ." Enter the date and time in the webserver." then else send_ask_time \ check-time @@ -525,7 +522,7 @@ PREVIOUS cr ." The home page of the webserver is:" .homepage-adr cr ; : start-web-server ( -- ) - cr .date .time + cr .date .time cr htmlpage$ 0= if init-res else ." Listening again."