Android Question write characteristics into ESP32 chip

Marco Maria Vilucchi

Active Member
Licensed User
I missed a sub

Sub ByteArrayToString(B() As Byte)

Dim S As String

For I = 0 To B.Length - 1
S = S & " " & Bit.And(B(I), 0xFF)
Next

Return S.Trim

End Sub
 

emexes

Well-Known Member
Licensed User
Dentro SendC314 Messaggio 105 97 224 224
Righto, I'm happy with that. It has translated the "à" characters to their Unicode character number 224, which is as expected.

What does nrf connect now show for that characteristic?

Does it show the four actual byte values?
 

Marco Maria Vilucchi

Active Member
Licensed User
yes.
69 61 E0 E0
this is correct: E0 is 224, but why 224 and not 133? The problem now is in the code, not in the chip or in BLE...
I asc ascii code of à, that is 133 and obtain 224....
 

emexes

Well-Known Member
Licensed User
What does nrf connect now show for that characteristic?
Does it show the four actual byte values?
yes.
69 61 E0 E0
That looks correct to me. They are the same four bytes that were put in to the characteristic, according to:
Dentro SendC314 Messaggio 105 97 224 224
this is correct:
Great minds think alike! :)
E0 is 224, but why 224 and not 133?
E0 hex = 11100000 binary = 128 + 64 + 32 decimal = 224 decimal
That is why E0 is 224.
Why would E0 be 133? 133 decimal = 128 + 5 decimal = 80 + 5 hex = 85 hex.
I think I am not understanding your question here, or perhaps it is losing something in translation (but no worries - your English is heaps better than my Italian ;-)
I asc ascii code of à, that is 133 and obtain 224....
This might be the issue. In B4A, which is based on Java and thus also Unicode, Asc("à") returns the Unicode character number 224.

But if you were using a PC environment or BASIC dialect that does not support Unicode, then Asc("à") will probably instead return the IBM PC Extended ASCII character number 133. But we are in B4A, so we are talking Unicode, so we get 224.
 

emexes

Well-Known Member
Licensed User
ok then.... how can I return from unicode 224 to unicode character?
I do not understand this question.

Perhaps this might inadvertently answer it:
B4X:
Dim CharNumber As Int = Asc("à")
Log(CharNumber)

Dim CharString As String = Chr(CharNumber)    'ie Chr(224)
Log(CharString)
 

emexes

Well-Known Member
Licensed User
tomorrow I try to read from card E0 and display à
That should work ok.

Where you might run into trouble is with Unicode characters outside of 0..255 eg Cyrillic characters are at:

https://en.wikipedia.org/wiki/Cyrillic_(Unicode_block)

and so you might need to redefine this four-byte characteristic to be 8 bytes of UTF-8 so that it can include characters > 255 (by using 2 bytes per character, to repesent characters up to U+07FF cf Cyrillic U+0400..04FF).
 

emexes

Well-Known Member
Licensed User
redefine this four-byte characteristic to be 8 bytes of UTF-8
This page here lists the data types that should be recognizable by generic BLE readers eg NRF Connect:

https://web.archive.org/web/2017010...r.gatt.characteristic_presentation_format.xml

Type 25 is UTF-8 and type 26 is UTF-16.

UTF-8 is more common*, but two bytes of UTF-16 can represent a larger range of characters that two bytes of UTF-8, and that might make it a better choice for a fixed-length field if you are expecting to use Unicode characters beyond U+07FF.


* mostly due to the nice feature that ASCII maps 1:1 to Unicode, ie no conversion required: an ASCII string is also already a UTF-8 string
 
Top