Skip to content
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

Longitude & Latitude failing to set properly for values between 0 & -1 #5386

Closed
ggaavv opened this issue Mar 3, 2019 · 8 comments
Closed
Labels
awaiting feedback Action - Waiting for response or more information bug Type - Confirmated Bug fixed Result - The work on the issue has ended

Comments

@ggaavv
Copy link

ggaavv commented Mar 3, 2019

Longitude Latitude failing to set properly for values between 0 & -1.
Working for number below -1

14:11:54 RSL: STATUS2 = {"StatusFWR":{"Version":"6.4.1(sonoff)","BuildDateTime":"2018-12-24T14:41:00","Boot":31,"Core":"2_4_2","SDK":"2.2.1(cfd48f3)"}}

Failing above -1

14:25:39 CMD: latitude -0.2
14:25:39 RSL: Received Topic /latitude, Data Size 4, Data -0.2
14:25:39 RSL: Group 0, Index 1, Command LATITUDE, Data -0.2
14:25:39 RSL: RESULT = {"Latitude":"0.200000"}

14:25:59 CMD: Longitude -0.2
14:25:59 RSL: Received Topic /Longitude, Data Size 4, Data -0.2
14:25:59 RSL: Group 0, Index 1, Command LONGITUDE, Data -0.2
14:25:59 RSL: RESULT = {"Longitude":"0.200000"}

Working below -1

14:25:49 CMD: latitude -1.2
14:25:49 RSL: Received Topic /latitude, Data Size 4, Data -1.2
14:25:49 RSL: Group 0, Index 1, Command LATITUDE, Data -1.2
14:25:49 RSL: RESULT = {"Latitude":"-1.200000"}

14:26:04 CMD: Longitude -1.2
14:26:04 RSL: Received Topic /Longitude, Data Size 4, Data -1.2
14:26:04 RSL: Group 0, Index 1, Command LONGITUDE, Data -1.2
14:26:04 RSL: RESULT = {"Longitude":"-1.200000"}

@curzon01
Copy link
Contributor

curzon01 commented Mar 5, 2019

True, but thats more or less a theoretical bug - these positions (0 to -0.999) are @ Atlantic ocean 700 km next to an island in the middle of nowhere

@ggaavv
Copy link
Author

ggaavv commented Mar 5, 2019

A longitude band and a latitude band, rather than a single tiny point. The worst case is about a 15 minute sunset/sunrise error. The UK sits right in the middle of the band. My location is latitude -0.89 which got taken as 0.89 so almost worst case.

@ascillato2 ascillato2 added the bug Type - Confirmated Bug label Mar 6, 2019
@gemu2015
Copy link
Contributor

gemu2015 commented Mar 6, 2019

this solves the issue

// better char to double
double CharToDouble(char *str) {
// simple ascii to double, because atof or strtod are too large
char strbuf[24];
strlcpy(strbuf, str, sizeof(strbuf));
char *pt=strbuf;
double left,right;
signed char sign=1;
if (*pt=='-') sign=-1;
if (*pt=='-' || *pt=='+') pt++;
if (*pt=='.') {
// .xxx notation
left=0;
goto gright;
}
// get left part
left = atoi(pt);
// skip number
while (*pt>='0' && *pt<='9') pt++;
if (*pt=='.') {
// decimal part
gright:
pt++;
right = atoi(pt);
while (*pt>='0' && *pt<='9') {
pt++;
right /= 10.0;
}
} else {
right=0;
}
double result = (left + right);
if (sign>=0) return result;
else return -result;
}

@curzon01
Copy link
Contributor

curzon01 commented Mar 6, 2019

@ggaavv - your are right, I was too sick, sorry

@arendst arendst self-assigned this Mar 6, 2019
@arendst
Copy link
Owner

arendst commented Mar 6, 2019

Testing gemu suggestion

arendst added a commit that referenced this issue Mar 6, 2019
Fix float calculations in range from 0 to -1 (#5386)
@arendst arendst added the awaiting feedback Action - Waiting for response or more information label Mar 6, 2019
@arendst arendst removed their assignment Mar 6, 2019
@arendst
Copy link
Owner

arendst commented Mar 6, 2019

Just implemented a fix. Pls test and report back.

@ascillato2 ascillato2 added the fixed Result - The work on the issue has ended label Mar 6, 2019
@ascillato2
Copy link
Collaborator

@ggaavv

Hi,

The issue has been fixed. Please, test it and if the issue is solved, please close this issue. Thanks

@ggaavv
Copy link
Author

ggaavv commented Mar 9, 2019

Thanks for the quick fix. Working perfectly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting feedback Action - Waiting for response or more information bug Type - Confirmated Bug fixed Result - The work on the issue has ended
Projects
None yet
Development

No branches or pull requests

5 participants