Author Topic: Rfduino send two sensors reading - Evothings javascript issue  (Read 38 times)

Simseve

  • RFduino Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Rfduino send two sensors reading - Evothings javascript issue
« 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


tolson

  • Global Moderator
  • *****
  • Posts: 880
  • Karma: +21/-0
    • View Profile
    • Thomas Olson Consulting
Re: Rfduino send two sensors reading - Evothings javascript issue
« Reply #1 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.
« Last Edit: February 13, 2018, 07:49:48 AM by tolson »