Hi all, I am really disappointing about one of my project. I am just trying to send a data from mobile app (Delphi) to a ESP32 over BLE.
But problem is that data sent from Delphi is not compatible with Arduino IDE. (you can read full story here).
Main problem is written on this comment
Is there any way to solve this problem that you know or another library that doesn't use value as std::string?
Thanks right now..
data sent from Delphi is not compatible with Arduino IDE
I find that very difficult to believe, but I know nothing about Delphi. If you send a series of bytes via the serial interface then you will be able to read them using an Arduino. The bytes could be ASCII characters representing numbers or pure binary data. As long as you know what format they are in you can read and interpret them.
Can you please give examples of the data coming from Delphi and its format
Also, surely Delphi will let you extract individual characters from a string and tell you how long it is. Given those two things, a simple loop will let you grab chars and send them out of the serial port/BLE interface.
Delphi has multiple ways of representing strings or chars
var
Str1 : Char; // Holds a single character, small alphabet
Str2 : WideChar; // Holds a single character, International alphabet
Str3 : AnsiChar; // Holds a single character, small alphabet
Str4 : ShortString; // Holds a string of up to 255 Char's
Str5 : String; // Holds strings of Char's of any size desired
Str6 : AnsiString; // Holds strings of AnsiChar's any size desired
Str7 : WideString; // Holds strings of WideChar's of any size desired
if you used the String
one, then you are probably using UNICODE encoded in UTF-16 and that's why you probably receive weird stuff.
if you were to use AnsiChar then , you would have exactly one byte per character (and represent any of the characters in the Ansi character set).
For receiving data on the Arduino have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.
The technique in the 3rd example will be the most reliable. It is what I use for Arduino to Arduino and Arduino to PC communication.
You can send data in a compatible format with code like this (or the equivalent in any other programming language)
Serial.print('<'); // start marker
Serial.print(value1);
Serial.print(','); // comma separator
Serial.print(value2);
Serial.println('>'); // end marker
...R
OK. I've solved the problem by jumping over some bridges..
Let me explain in detail : C++ std::string type is 8-Bit AnsiString (as J-M-L pointed and thanks to J-M-L to direct me to right solution) but luckily Delphi doesn't support Ansi char and strings in mobile compilers anymore. (additional info)
So I cannot use 8-Bit strings in Delphi mobile (there are many people they ask "why" to Embarcadero because this means that you cannot use devices that use 8-Bit (many of IoT devices) ) but thank goodness, there are some good people solves this problem with a custom library (you can find the source here).
After adding this library to my app and execute the command like below, problem has been solved;
Characteristics.SetValueAsString(RawByteString('b'));
Thank you everyone for their help..
In addition to UTF8String or RawByteString you could use an array of Byte. The only price you would pay is having to track the length yourself.