Timeline for Arduino Sending faster/more data to a web server
Current License: CC BY-SA 3.0
14 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Dec 5, 2016 at 13:25 | comment | added | Code Gorilla | If you need accuracy then you could either user more digits or make a look up table of values that don't work so you can correct them. | |
Dec 5, 2016 at 13:21 | comment | added | Code Gorilla |
That's not my fault :) Its to do with the way floating point values are stored in memory. A floating point number should have an infinite range of values between 0 and 1. Obviously you can't us binary to store this infinite range so you have to have make a compromise and this is where the resolution comes into play. Write a little program in visual studio and add const float a = 0.53f; printf("a = %2.5f\n", a); printf("b = %d\n", (int)(a * 100)); You will get the output 0.53\n52\n !!! If you put a break point in there you will see a == 0.5299999714F.
|
|
Dec 3, 2016 at 16:54 | comment | added | Ralph | hey I just found out that there are some values that doesn't get the right value in encoding, like when the value is -0.53 it returns the result as 52 instead of 53, but it works fine with others, why is this happening? even when I hard code -0.53 it still returns 52 but when I put -0.54 etc it works fine. | |
Dec 2, 2016 at 15:35 | vote | accept | Ralph | ||
Dec 2, 2016 at 9:38 | comment | added | Code Gorilla | Ralph, I've edited my answer with rough encode and decode functions. | |
Dec 2, 2016 at 9:38 | history | edited | Code Gorilla | CC BY-SA 3.0 |
Add encode and decode functions
|
Dec 1, 2016 at 19:42 | comment | added | Ralph |
now I understood what you meant by 2 byte numbers, that means i should use uint16_t right? because the values are greater than 255 (8 bit decimal), but now I don't know how to change this back to decimal when it is a negative number for it has an additional of 128 decimal value
|
|
Dec 1, 2016 at 15:35 | comment | added | Ralph | because this data is going to a web server developed in php, so i should check in php if each hex values has most significant bit then it is negative? I'm a little confused with your statement that i need 2 byte numbers which gives me 4 characters, I'm sorry I can't comprehend that well :( | |
Dec 1, 2016 at 15:17 | comment | added | Code Gorilla | If the most significant bit is set then the number is negative. That's what the 0x80:0x00 is for. You then have 15 bits to hold the value, which is ... oh bugger it isn't enough. You need 2 byte numbers, which give you 4 characters. Sorry. | |
Dec 1, 2016 at 15:10 | comment | added | Ralph | also another one, how would i check if the hex value reflects the negative number? because when i tested it the same number having opposite signs printed the same hex value, thank you so much for the help | |
Dec 1, 2016 at 14:50 | comment | added | Ralph | hello, will i need a separator for this to change it back to decimal numbers? since other hex values are only one character and others are 2 characters. | |
Dec 1, 2016 at 13:35 | comment | added | Ralph | sorry for the late reply, was having a hard time absorbing what you're saying since I'm a newbie. I did option 1 already but yun cannot send that much data using the client.get() function from HttpClient library. After deep thinking on your code I understand it already, or somewhat at least. So first is the number should have a high bit (i guess it is also the msb?) to know if it's positive or negative, then I convert the decimal reading to an int, or remove the decimal place and then convert it to a string? I will definitely give this a try thank you so much for the answer! | |
Dec 1, 2016 at 13:21 | history | edited | Code Gorilla | CC BY-SA 3.0 |
Updated after answers
|
Dec 1, 2016 at 13:09 | history | answered | Code Gorilla | CC BY-SA 3.0 |