2017년 3월 26일 일요일

Problem: DataTyp Convert with BLE


I have a problem and i don´t know how to solve it on my own.
I want to read out the given temperature by the service: Health Thermometer and the characteristic:Termperatur Measurement (00001809-0000-1000-8000-00805f9b34fb and 00002a1c-0000-1000-8000-00805f9b34fb). I allready made an application with the help of android studios to do the same thing and it works. But i´m not able to do the same with the App Inventor.
The device, which i try to comunicate with, sends the data (in the named service) in hexadecimal notation. for example: 00 A5 00 00 FF, the actual temperatur value is hidden in the A5 which means 165 in decimal notification so its 16.5 °C. The onboard display shows the same temperatur.
Now the question or the problem i have: how can i make my app (now build with app inventor) show me the full hexadecimal notation. if i try the readintValue block with an offset of 0 the app will give me value of 0 which is wrong.
if i set the offset as 1 it gives me the allready converted version of the value (in this case it will show me 165 but i want to see the full 00 A5 00 00 FF). So important for me now is not to get the converted temparatur. i want to have the whole number.

Hope you can help me.    

--
I think you get same question  like me ....to read the bike speed sensor ..... BLE ext ...still have bug ....

--
I think I have the same issue. Or similar. 
Int is seen as 8 bits and you can only look at one at a time by changing the offset. The block IntValueChanged will only get one byte of data and displaying it on Label will be converted to decimal. 

If you want the whole message it seems that only stringValueChanged will read the whole characteristic field in one go. 

The characteristic I'm trying to read is made of:
Timestamp LSB, Timestamp MSB, X axis LSB, X axis MSB, Y axis LSB, Y axis MSB, Z axis LSB, Z axis MSB, (From the WeSu made by ST)

The problem that I'm facing then is to split the string between the different variables that it holds, reconstruct the int16 and then display them.

By using the block "stringValueChanged" I can then use the block "segment text" and then potentially reconstruct the different segments in their correct order.
Unfortunately, I can't find a way to "convert" the newly created text segment to it's hex/decimal value. I only end up with a meaning less character that can't be displayed properly. 

--
Yes, the BLE extension is still experimental and needs improvement. The developers are well aware of it.

for now, your best option is to work with strings, as Alex decided to do.
I do not know exactly what the values are like you are receiving but I think the convert number block should be able to help:
http://appinventor.mit.edu/explore/ai2/support/blocks/math.html#convertnumber

There is also the hexify procedure that Abraham made: https://groups.google.com/forum/#!searchin/mitappinventortest/hexify%7Csort:relevance/mitappinventortest/404FUnScIyY/UoDm3yWpCwAJ
But maybe you do not need that.

Try it out, and report what you find.

--
Thanks for your help!

I tried the convert number but I'm getting Runtime errors... I tried the 4 options just to be sure. 

If I use IntValueChanged with an offset of 3 I read a number going from 0 to 255.
Byte 3 and 4 make an int16 (signed) representing the X axis of the accelerometer.  Value goes from -2048 to +2048. 

I'll have a look at Abraham's procedure. 

--
The runtime error says it is not a binary number. So, what is it? Something else as text with only 1s and 0s in it. Check with DoIt!

--
I tried the DoIt and get the same as what I get displayed on the phone's screen. 

The result shows L and unknown character. If I move the accelerometer, the data will change, and sometimes it will show two unknown characters.

So now if I hard code for example and M, the result would be ML of course. But I want to see 0x4D4C or its decimal equivalent. I tried the convert number block and get a runtime error. 

The block StringValueChanged  will convert all bytes present on the characteristic to a series of Strings (their equivalent Characters) if the byte is above 0x7F, it will show the unknown character symbol.

Now, if reading a whole characteristic (more than 1 byte) requires the use of StringValueChanged block (instead of multiple instances of InValueChanged with different offsets), then I need to find a way to convert each byte (string) to its decimal/hex value. 

Thanks for your help! 

--
I have a problem with this. It seems to me that what you get is already binary, therefore you may like to convert it from binary to decimal, or hex. And maybe not all 4 bytes at the same time, but maybe each byte separately. Did you try that?
--

Yes I tried and I'm getting runtime error.

In order to simplify the problem,I'm now playing with the Micro:bit device. Using the same app, I connect to the UUID of the Button service and the characteristic of Button A (BLE map Micro:bit). If I use the block InValueChanged (offset 0) I can see a value going between 0 (not pressed), 1 (pressed) 2 (long press). 
It is all good and would be sufficient for this particular application since the data is held in a single Byte. 

If I use StringValueChanged instead (which would get all the bytes from this charasteristic, in this instance there is only one) there is nothing showing because 0, 1 and 2 do not represent any characters. 
If for example the Micro:Bit was sending 0x54 instead of 0x01 when button A is pressed, I would see displayed. 

Writing code in C would make this issue so trivial. But it seems that MIT App Inventor 2 is trying so hard to handle Strings and Decimal in the background that I'm left with this simple issue. 

The convert number keeps on throwing runtime errors.

Bottom line: if a byte is equal to 0x01 and you receive it using StringValueChanged how can you display 1 ?

--
 if a byte is equal to 0x01 and you receive it using StringValueChanged how can you display 1 ?
See Italo's solution at

(from the Math section of my FAQ
)

-- 
Thanks a lot for the solution! I'll play around with those blocks and see if I can get a proper representation of the accelerometer axis.

--

댓글 1개:

  1. Ai2 Inventor Forum News: Problem: Datatyp Convert With Ble >>>>> Download Now

    >>>>> Download Full

    Ai2 Inventor Forum News: Problem: Datatyp Convert With Ble >>>>> Download LINK

    >>>>> Download Now

    Ai2 Inventor Forum News: Problem: Datatyp Convert With Ble >>>>> Download Full

    >>>>> Download LINK mA

    답글삭제