Sunrise and sunset...

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

Sunrise and sunset...

Post by PANNO »

Hi,

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

Re: Sunrise and sunset...

Post 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
User avatar
Fernando Perez
Posts: 378
Joined: Mon Feb 15, 2021 10:09 pm
Location: Santander (Spain)
Has thanked: 195 times
Been thanked: 267 times

Re: Sunrise and sunset...

Post 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
Post Reply