can be expressed as
with substitution of
from now it's just matter of applying some standard high-school math to solve the equation for L into form that can be easily calculated on MCU. That is for calculating latitude.
I thought calculating longitude is trivial, but as usual it's not quite like that. When oversimplifying reality, it's just counting how many hours of difference is between local noon and noon at Greenwich; being roughly at 12:00 UTC and multiply this number by 15 degrees for every hour. The key word here is the 'roughly' word. Trying to synchronize clock to sun over the length of year is a bit more complicated, because simple looking movement of Earth versus the Sun is somehow more complicated by axial tilt and its eccentricity, bringing error of a few minutes into the sync. This doesn't look like too much, but it can mean a few hundred of kilometers error for longitude calculation. So, I have to take this effect, named equation of time into account. Fortunately, it can be calculated as sum of two sine functions with different periods as
where is d is day of year, starting at 1 at first of January. This difference should be subtracted from measured local solar noon and then scaled to 15 degrees per hour. This is quite good approximation for my needs, so I decided to move on.
I did some more work on LLG hardware, got myself to implement proper segment mapping table, so I'm finally able to display some meaningful messages.
Above that, I reorganized my measured data so I can import it into my source files for LLG and adjusted the sources so that LLG calculates the geographical position from the data - is if the LLG would sit at the place and capturing data on its own. The calculations ran on real hardware, being outputted via serial link from MCU.
At first I imported daylight data from my own place, got set of latitude/longitude pairs, entered them into custom map at google maps and here is how it looks. I started with my own place, as this is where I have the most of data
The orange home icon is where the logger really was, the blue points are determined locations from LLG. I can see the latitude to be more dispersed than longitude, but otherwise half of the measurements got into 75km circle, average accuracy being around 100km.
The logger on another side of my country was somehow worse, especially in determining the longitude. I assume that's because it was placed on window of tall building, casting shadows during phases of day, shifting the results.
Interesting is what happed to measurement from Spain.
The three results are almost perfectly aligned, with differences within a few kilometers. Though all being shifted from real location - that is probably due to sunrise/sunset zenith angle being determined slightly wrong, but I didn't want to change the algorithm to fit the data, that would be cheating. The error in zenith angle didn't show in other examples, as those had much less repeatability due to suboptimal logger placement.
The difference between the last result and the previous two is that measurement in Spain took place in minimal light smog, open view to sky; unlike the previous ones, with buildings, trees and other obstacles in view. Even worse were measurement made by valuable contributor @davedarko in Germany
Both longitudes and latitudes quite far away from original place, but consider conditions where the measurement was done: