RFduino Forum

RFduino => Support => Topic started by: Simseve on February 12, 2018, 11:34:35 PM

Title: Rfduino send two sensors reading - Evothings javascript issue
Post by: Simseve on February 12, 2018, 11:34:35 PM
Hi guys,
 here is where I am stuck.

I managed to pack the reading of two sensors (float) into a 8 byte array with a union (dtostrf is not working).

union cvt {
float val;
unsigned char b[4];
} x;

x.val= 4828.9038;

I successfully send the combined array to evothings/mobileapp but I'm not sure on how to:

1. Split the array back into 2x4bytes sub arrays. Tried with a for cycle but was empty.
2. Reconvert to float. I might be able to recalculate it back but wondering if there is a function.

From evothings I create the following file:
12/02/2018, 20:23:32 1518459812603 27.9847928 -26.0080767 0 6870e640919eef41
12/02/2018, 20:23:35 1518459815310 27.9847928 -26.0080767 0 a128e540919eef41
12/02/2018, 20:23:38 1518459818399 27.9847928 -26.0080767 0 2550e54088b4ef41

I basically need to split myString = "6870e640919eef41" into sensor1="6870e640" and sensor2="919eef41" then to convert them back into float.

Thanks
S

Title: Re: Rfduino send two sensors reading - Evothings javascript issue
Post by: tolson on February 13, 2018, 07:41:08 AM
You need to use struct, not union.
The union would be 4 bytes not 8.

As far as dtostrf... I think that is an AVR specific function. RFduino is ARM.