Wednesday 15 February 2012

android - Send data over BLE with RFDuino -


I have attached the sensor to RFDuno and want to send the readings to the BLE for the Android app. <

  const int censor pin = 2; Int sensor value = 0; Zero setup () {serial.begin (9600); RFduinoBLE.begin (); } Zero loop () {sensorValue = analogRead (sensor pins); Float voltage = sensor value * (3.3 / 1023.0); Serial. Print ("UV sensor ="); Serial.println (voltage); RFduinoBLE.sendFloat (voltage); Delay (1000); }  

In the console I see values ​​like 0.2 . But in the app it translates something like 00-00-A4-41 but I do not find the logic behind it. How do I properly convert the value sent from RFDuino?

RFduino floats in a little endian. Your Android app will receive it as 4 bytes, and in order to change the order of the bytes and change the float, you have to convert it to large endian. There are many threads on this topic, like And what you used to have

It should be read immediately on the endearance and floating point format to understand the logic about it. But basically, the bytes in 4 byte float are stored in each other's reverse order in small vs. large endions. When you reverse 4 bytes in small bytes, then it becomes a big end and you're doing well to go for your situation.


No comments:

Post a Comment