-
Notifications
You must be signed in to change notification settings - Fork 770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Star_Fragment_Lamp code has an issue with sunrise #2609
Comments
hihi- thanks for the serial output. in looking at the code, i'm wondering if it's the rise_time and set_time variables not being reset. can you try adding rise_time = divide_time(sunrise) to looking_for_sunrise (line 229):
and set_time = divide_time(sunset) to the sunset portion (line 188):
|
Thank you for your prompt reply. Much appreciated. I had someone help me in working out how access the serial output, and adding the time stamp to see what is actually happening when relative to my time. I have made the change and let you know the result. |
I also have a second problem with my location and timezone. If I enter my Lat/Long as Perth lat = -31.95224 and even type my location as Australia/Perth location = "Australia/Perth" and power up teh lamp, the correct sunrise and sunset times are pulled from the API, but the star glow is set to false and the lamp is off, even though sunrise has not yet occured : Location set to Perth with timestamp showing Perth Time (2023-08-31) 04:31:33.325 -> �]0;🐍192.168.1.241 | code.py | 8.2.4�\struct_time(tm_year=2023, tm_mon=8, tm_mday=31, tm_hour=4, tm_min=31, tm_sec=36, tm_wday=4, tm_yday=243, tm_isdst=0) Same applies if I set my LAT/LONG and Location to "Asia/Singapore" This means if there is a connection loss and a soft reset after midnight, then the lamp will turn off and track time to sunset. But if I set my LAT/LONG to London and location to "UK/London" then it sees that the sun has not risen, lamp is turned on and time to sunrise is tracked Time Stamp still Perth time (2023-08-31) |
ah okay i think this has to do with the |
Update: 04:55:36.985 -> �]0;🐍Wi-Fi: No IP | Done | 8.2.4� |
Have you been able to investigate this any further? |
I've been working through debugging my Star-Fragment lamp too and it seems like I've come across something that could at least be related or maybe a confounding issue, so I'll add some notes here in case it helps. Brief summary of findings so far: there was some discussion on the Adafruit Forum of a Star-Fragment lamp not working at https://forums.adafruit.com/viewtopic.php?t=204011 and my lamp - which also used to work ok - seemed to have stopped tracking sunset times (it was used mostly as a nightlight before bedtime). If switched on in the evening:
This change seemed to have happened sometime around the end of August 2023. I'm not sure exactly when as we were away travelling and the lamp wasn't being used. In attempting to work out why it wasn't behaving, I checked the log output in the REPL pane of the Mu editor, which (at just after 7pm on 10th September in New Zealand) looked something like:
which looked mostly ok, except the time in the struct_time returned by the IO_HTTP call to AdafruitIO appears to be 12 hours before my local time (Pacific/Auckland). From there the time-to-sunset calculation looks like it's performed correctly, just based on the wrong current time. My understanding is that the IO_HTTP call doesn't take a timezone/location parameter and instead determines the client's timezone by IP address. So in Auckland I would have expected the struct_time to look like
As a follow-up I tried using an alternative method for getting local time, based on an example from the Adafruit Funhouse project at https://learn.adafruit.com/adafruit-funhouse/getting-the-date-time which seemed to be common to several other projects too. Running at approx 2.30pm in Auckland the REPL output looked like
which did match my localtime. User mikeysklar on the Adafruit Forum noted that there's an open bug against the Adafruit_CircuitPython_AdafruitIO library in which io.receive_time() returns a time in UTC https://github.com/adafruit/Adafruit_CircuitPython_AdafruitIO/issues/95 It looks like this behaviour was only intermittent when the bug was originally reported, but the IO_HTTP call in the Star Fragment code has been returning me a time 12 hours earlier than expected (i.e. a time that looks a lot like UTC) every time I've tried it lately, so possibly the bug has resurfaced and it's now consistently returning UTC. The github issue notes that there's a workaround for the issue using a TZIO class (provided), so in the meantime I've had a go at adjusting the Star-Fragment code to use the workaround, i.e.
and this looks like it's now working ok. The struct_time shown in the REPL output matches my local time now, and the lamp is back to brightening for sunset/switching on fully if it's already dark as expected. Hope this helps in the meantime. |
hmm, TL-DR version ...
So, if the io.receive_time() bug has resurfaced and it's sending UTC instead of localtime, options might be:
I've added the TZIO workaround to the code on my lamp and it seems to be back working ok now. Debug messages in MuEdit/REPL show localtimes being returned and used for calculating time-to-sunset etc. |
Thank you @that-fleps . I will add in your TZIO workaround and update on what happens in the morning. It is now after sunset, so I will let it run glowing and monitor the serial port, and update in the morning. I have no problems with the Sunset function, but for me sunrise is the issue. One hour before sunrise the lamp just turns off, no countdown. If there is a soft reboot after midnight and before sunrise, the lamp just reverts back to looking for sunset and ignores the upcoming sunrise. |
I have let the lamp run till 1 hour before sunrise, and time is being calculated correctly, but unfortunately teh TZIO workaround does not correct the issue where instead of switching to counting down and darkening teh LED's one hour before sunrise, it still flips straight to turning the lamp off and tracking time till sunset : 4:56:32.323 -> pinging Open-Meteo Rebooting within the one hour before sunrise the lamp also disregards sunrise time, turns the lamp off and just goes to searching for sunset. |
Do we have an update on the inability to dim the lamp while counting down to sunrise? |
Board flashed with adafruit-circuitpython-adafruit_qtpy_esp32s2-en_GB-8.2.4.uf2
Used CircuitPython 8.x code / library version
The lamp has no issues with determining sunset and approx.one hour outy and slowly increasing brightness till sunset is reached:
17:13:32.913 -> pinging Open-Meteo
17:13:40.931 -> struct_time(tm_year=2023, tm_mon=8, tm_mday=29, tm_hour=17, tm_min=13, tm_sec=40, tm_wday=2, tm_yday=241, tm_isdst=0)
17:13:40.976 -> 0 hour(s) until sunset
17:13:40.976 -> 48 minutes(s) until sunset
17:13:40.976 -> 2023-08-29T18:02
17:13:40.976 -> 0
17:13:40.976 ->
17:13:40.976 -> pinging Open-Meteo
17:13:48.915 -> struct_time(tm_year=2023, tm_mon=8, tm_mday=29, tm_hour=17, tm_min=13, tm_sec=47, tm_wday=2, tm_yday=241, tm_isdst=0)
17:13:48.959 -> 0 hour(s) until sunset
17:13:48.959 -> 48 minutes(s) until sunset <<--approx one hour hout it goes into teh countown loop increasing LED brightness
17:13:48.959 -> 2023-08-29T18:02
17:13:48.959 -> 47.5424
17:13:48.959 ->
Once sunset time is reached "the star is glowing" waits till after midnight to look for sunrise:
18:00:03.974 -> pinging Open-Meteo
18:00:11.164 -> struct_time(tm_year=2023, tm_mon=8, tm_mday=29, tm_hour=18, tm_min=0, tm_sec=10, tm_wday=2, tm_yday=241, tm_isdst=0)
18:00:11.164 -> 0 hour(s) until sunset
18:00:11.164 -> 1 minutes(s) until sunset
18:00:11.164 -> 2023-08-29T18:02
18:00:11.164 -> 229.068
18:00:11.164 ->
18:05:04.015 -> pinging Open-Meteo
18:05:11.282 -> struct_time(tm_year=2023, tm_mon=8, tm_mday=29, tm_hour=18, tm_min=5, tm_sec=10, tm_wday=2, tm_yday=241, tm_isdst=0)
18:05:11.315 -> 23 hour(s) until sunset
18:05:11.315 -> 56 minutes(s) until sunset
18:05:11.315 -> 2023-08-29T18:02
18:05:11.315 -> 250.678
18:05:11.315 ->
18:05:11.315 -> star is glowing
18:30:06.932 -> not looking for sunrise
18:30:06.979 -> struct_time(tm_year=2023, tm_mon=8, tm_mday=29, tm_hour=18, tm_min=30, tm_sec=6, tm_wday=2, tm_yday=241, tm_isdst=0)
18:30:06.979 ->
The trouble is that approx. 1 hour out from sunrise, instead of counting down to sunrise and decreasing brightness, the star is instead turned off and the lamp goes back to looking for sunset:
05:26:57.051 ->
05:41:49.895 -> pinging Open-Meteo
05:41:57.433 -> struct_time(tm_year=2023, tm_mon=8, tm_mday=29, tm_hour=5, tm_min=41, tm_sec=57, tm_wday=2, tm_yday=241, tm_isdst=0)
05:41:57.479 -> 0 hour(s) until sunrise
05:41:57.479 -> 59 minutes(s) until sunrise
05:41:57.479 -> 2023-08-29T06:40
05:41:57.479 -> struct_time(tm_year=2023, tm_mon=8, tm_mday=29, tm_hour=5, tm_min=41, tm_sec=57, tm_wday=2, tm_yday=241, tm_isdst=0)
05:41:57.479 -> 05:41:57.479 -> 0 hour(s) until sunrise
05:41:57.479 -> 59 minutes(s) until sunrise
05:41:57.479 -> 2023-08-29T06:40
05:41:57.479 -> struct_time(tm_year=2023, tm_mon=8, tm_mday=29, tm_hour=5, tm_min=41, tm_sec=57, tm_wday=2, tm_yday=241, tm_isdst=0)
05:41:57.479 ->
05:41:57.479 -> star is off <<-- one hour out instead of counting down the lamp is turned off
05:56:49.925 -> pinging Open-Meteo
05:56:57.751 -> struct_time(tm_year=2023, tm_mon=8, tm_mday=29, tm_hour=5, tm_min=56, tm_sec=56, tm_wday=2, tm_yday=241, tm_isdst=0)
05:56:57.751 -> 12 hour(s) until sunset
05:56:57.751 -> 4 minutes(s) until sunset
05:56:57.751 -> 2023-08-29T18:02
05:56:57.751 -> 0
The text was updated successfully, but these errors were encountered: