I'm trying to convert a Unicode String to UTF-16 on Arduino to send SMS messages in Greek (using the USC2 mode on the Sim800).
It requires that you provide the message in UTF16 format. For example you need to convert "Καλημέρα" (Good morning for the curious) to "039a03b103bb03b703bc03ad03c103b1" (\u039a\u03b1\u03bb\u03b7\u03bc\u03ad\u03c1\u03b1)
What I've accomplished so far, is to be able to convert a hardcoded wchar_t array to the correct format using this:
String stringtoHex() {
const wchar_t arr[] = L"Καλημέρα";
int len = sizeof(arr)/sizeof(wchar_t);
String hexString = "";
for(int idx = 0; idx <len-1; idx ++ ){
int c_val = arr[idx];
char tempstring[4];
sprintf( tempstring, "%04X", c_val );
hexString += tempstring;
}
Serial.print(hexString);
return hexString;
}
Now this works perfectly, but I need to be able to actually take a String parameter in the function and use that. And here is my problem:
I cannot find how to convert the unicode String to a wchar_t array in Arduino. Anyone has an idea how this will work?
So basically I need to make the function accept as a parameter a Unicode String, then convert it to a string of UTF16 and return it.
String stringtoHex(String message) {
String hexString = "";
......
//parse message and convert it to UTF16
......
return hexString;
}