1

I would like to send an SMS containing Emojis from my GSM Modem with AT Commands.

However, no matter which encoding I try, it never works (Encoding.BigEndianUnicode, Encoding.Unicode or Default) make the SMS unreadable.

My code looks a bit like this:

// [..]
// send message with UCS2
command = "AT+CSCS=\"UCS2\"" + char.ConvertFromUtf32(13);
send(command);   

// [..]
// convert my message (string from a WPF TextBox) to a unicode hex-string
byte[] ba = Encoding.BigEndianUnicode.GetBytes(message);
var hexString = BitConverter.ToString(ba);
hexString = hexString.Replace("-", "");

// send the converted string
command = hexString  + char.ConvertFromUtf32(26);
send(command);
// [..]

The SMS successfully reaches its destination but the message is just some unreadable stuff.

Is this even possible to do? My GSM Modem would also support "HEX" as encoding.

Update: It kinda works if i replace this line:

command = hexString  + char.ConvertFromUtf32(26);

With this:

command = "80 " + hexString + char.ConvertFromUtf32(26);

But then i get this 㣩 letter at the start of the message...

EriCreator
  • 117
  • 1
  • 13
  • 1
    UCS-2 is unable to encode character outside the basic plane, such as emojis. Please edit your question to demonstrate/verify that encoding `"\N{NAUSEATED FACE}"` (U+1F922) into UTF-16BE results in the octets 0xd8 0x3e 0xdd 0x22 and that there is no byte-order mark. – daxim Nov 21 '19 at 06:53

1 Answers1

1

Make sure that your modem uses the correct data coding scheme for the SMS. See this answer and

  1. Set the modem to text mode using AT+CMGF=1
  2. Set the coding scheme to "UCS2" using AT+CSCS="UCS2"
  3. Send AT+CSMP=1,167,0,8 to the modem.
  4. Now in UCS2 mode, the modem needs the recipient number in UCS2 form as well, i.e. for +123456890 send AT+CGMS="002B003100320033003400350036003800390030",145 (145 is type-of-address for numbers with country code, use 129 otherwise.
  5. The modem should respond with a > prompt. Then, send the message in the right encoding i.e. sending the message as what I would describe as an ASCII hex sequence of UCS2/UTF-16 bytes, i.e. encoding the string to UTF-16BE, then taking each byte and formatting it as ASCII HEX characters, i.e. which is U+1F408 becomes D83DDC08 that is sent to the modem, 012ABC becomes 003000310032 004100420043.
drott
  • 752
  • 6
  • 17