1

I'm making a SMS sending function for at project i'm working on. The code works just fine, but when i send the letters 'æ-ø-å-Æ-Ø-Å' it turns to 'f-x-e-F-X-E'.

How do i change the encoding so that I can send these letters?

This is my code:

<?php
include "php_serial.class.php";

$html = $_POST['msg'];

$serial = new phpSerial;
$serial->deviceSet("/dev/cu.HUAWEIMobile-Modem");
$serial->deviceOpen();

$serial->sendMessage("ATZ\n\r");
// Wait and read from the port
var_dump($serial -> readPort());

$serial->sendMessage("ATE0\n\r");
// Wait and read from the port
var_dump($serial -> readPort());

// To write into
$serial->sendMessage("AT+cmgf=1;+cnmi=2,1,0,1,0\n\r");//
$serial->sendMessage("AT+cmgs=\"+45{$_POST['number']}\"\n\r");
$serial->sendMessage("{$html}\n\r");
$serial->sendMessage(chr(26));

//wait for modem to send message
sleep(3);

$read=$serial->readPort();
$serial->deviceClose();

$read = preg_replace('/\s+/', '', $read);
$read = substr($read, -2);

if($read == "OK") {
    header("location: index.php?send=1");
} else {
    header("location: index.php?send=2");
}
?>
XerXeX
  • 784
  • 4
  • 16

1 Answers1

1

First of all, you must seriously redo your AT command handling to

  • Read and parse the every single response line given back from the modem until you get a final result code for every single command line invocation, no exceptions whatsoever. See this answer for more details.
  • For AT+CMGS specifically you also MUST wait for the "\n\r> " response before sending data, see this answer for more details.

Now to answer your question about æøå turning into fxe, this is a classical stripping of the most significant bit of ISO 8859-1 encoding (which I had almost forgotten about). This is probably caused the default character encoding, but since you always should be explicit and set the character encoding you want to use in any case, investigating that further is of no value. The character encoding used for strings to AT commands is controlled by the AT+CSCS command (see this answer for more details), run AT+CSCS=? to get a list of options.

Based on your information you seem to using ISO 8859-1, so running AT+CSCS="8859-1" will stop zeroing the MSB. You might be satisfied with just that, but I strongly recommend using character encoding UTF-8 instead, it is just so vastly superior to 8859-1.

All of that failing I am quite sure that at least one of the GMS or IRA encodings should supports the æøå characters, but then you have to do some very custom translation, those characters will have binary values very different from what is common in text elsewhere.

Community
  • 1
  • 1
hlovdal
  • 26,565
  • 10
  • 94
  • 165