Sunrise and sunset...

If doesn't fit into any other category ....
Post Reply
User avatar
PANNO
Posts: 57
Joined: Thu Feb 25, 2021 4:03 am
Has thanked: 51 times
Been thanked: 9 times

Sunrise and sunset...

Post by PANNO »

Hi,

Anyone with a annex code for this?
AndyGadget
Posts: 63
Joined: Mon Feb 15, 2021 1:44 pm
Has thanked: 24 times
Been thanked: 54 times

Re: Sunrise and sunset...

Post by AndyGadget »

Probably the simplest way is to use the API at [External Link Removed for Guests] .
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 :
[External Link Removed for Guests]
(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
User avatar
Fernando Perez
Posts: 106
Joined: Mon Feb 15, 2021 10:09 pm
Location: Santander (Spain)
Has thanked: 55 times
Been thanked: 54 times

Re: Sunrise and sunset...

Post by Fernando Perez »

Panno, this was already covered in the old forum:
[External Link Removed for Guests]

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:
[External Link Removed for Guests]
Post Reply