Closed OtisHarrison24 closed 7 years ago
Hi @OtisHarrison24 ,
Thanks for providing the code snippet.
AVRLibc does not really let you to convert a float number to string. As an alternative, you will need to use dtostrf(...)
to do it separately. That's why you are seeing dtostrf(reportedTemp, 4, 1, float_buf)
and sprintf_P(...)
in the SDK example.
Note that you need to be careful about the precision you want for your float number. You also need to make sure that you are providing enough buffer space to hold the output string. For more details, you can checkout the API description here: http://www.atmel.com/webdoc/AVRLibcReferenceManual/group__avr__stdlib_1ga060c998e77fb5fc0d3168b3ce8771d42.html
Ideally, you should be able to reuse the buffer to convert the float number to string. As mentioned earlier, you will need to make sure that the size of the buffer is always enough.
Thanks, Liusu
@liuszeng When I try use the above code I get a setup error. Does a random float need more space?
Hi @OtisHarrison24 ,
Can you provide the following information?
random()
, it is returning a long type number. Check out the precision used here and whether your buffer is enough for that. Right now the input parameters you specified for dtostrf
says that the minimum field width length for the converted string is 4 and the precision is 1 (0.1).Thanks, Liusu
Wanted to add a few extra variables to the json but keep getting an error. Am i treating the different variable correctly