I try to convert an array of byte to a float value.
I found on many posts over the internet that union is the right choice for that.
However when I try to publish my float (using sprintf) I get 0,0 instead of 60.8
union test
{
unsigned char buf[4];
float number;
}test;
test.buf[0] = 0x42;
test.buf[1] = 0x73;
test.buf[2] = 0x33;
test.buf[3] = 0x34;
PublishBuf(test.buf, 4); //function to publish an array of byte
char StringValue[10];
sprintf(StringValue, "%.2f", test.number );
Particle.publish("Value", StringValue);
test.number is correctly published, I get the right value.
Anybody understand what I’m doing wrong ?