Page 1 of 1

Sunrise and sunset...

Posted: Sat May 15, 2021 3:56 pm
by PANNO
Hi,

Anyone with a annex code for this?

Re: Sunrise and sunset...

Posted: Sat May 15, 2021 6:41 pm
by AndyGadget
Probably the simplest way is to use the API at https://sunrise-sunset.org/api .
Also, the OpenWeatherMap API will give you sunrise and sunset for a location along with weather information.

If you want to do this by purely mathematical means without web access then there is a discussion thread here :
https://picaxeforum.co.uk/threads/sunri ... 8m2.30114/
(Hint - It's extremely complex.)

Cicciocb, I hope you don't mind a link to an alternative microcontroller forum. Please delete if you do.
Picaxe has it's uses but ESP8266 / ESP32 has WIFI :D

Re: Sunrise and sunset...

Posted: Sat May 15, 2021 7:58 pm
by Fernando Perez
Panno, this was already covered in the old forum:
https://groups.google.com/g/annex_wifi_ ... KUZG3EAwAJ

As AndyGadget says, I think the system that pointed fu-ma ... @ berlin.de is the most suitable.
And the one suggested by Electroguard, the simplest.
I provide you with a simple code that can help you. You must take into account that you have to add the hours of difference of your place, in my case two.

Code: [Local Link Removed for Guests]

' In memory of M.R. James
lat$ = "43.0275"
lng$ = "0.570833"
r$ = wget$("api.sunrise-sunset.org/json?lat="+lat$+"&lng="+lng$, 80)
' wlog r$
sunrise$ = json$(r$,"sunrise")
sunset$ = json$(r$,"sunset")
wlog "sunrise at "; sunrise$
wlog "sunset  at "; sunset$

This only returns data for the current day, but you will see that it is easy to interrogate the API with future days on the original site:
https://sunrise-sunset.org/api