3

I am using a SIM868 module with an Arduino Mega, where the SIM868 is connected to Serial1.

After establishing a TCP connection, I need to send the following byte stream:

{0x60, 0x1A, 0x9D, 0x01, 0x00, 0x00, 0x07}

I am attempting to send this data using:

byte message[] = {0x60, 0x1A, 0x9D, 0x01, 0x00, 0x00, 0x07};
Serial1.write(message, sizeof(message));

However, only the first byte (0x60) is transmitted. The transmission stops at 0x1A, because 0x1A (Ctrl-Z) is interpreted by SIM868 as the end-of-data signal.

How can I send the entire byte array without SIM868 treating 0x1A as a termination character?

hcheung
  • 1,933
  • 8
  • 15

1 Answers1

5

For normal TCP AT commands, the SIM modules (not only applicable to SIM868 but other SIM modules as well) use CTRL-Z(i.e. 0x1A) as the termination of a message payload. The SIM module switched from Command mode to Data mode when AT+CIPSEND command is sent and a prompt > signified that it ready to accept the data, and a CTRL-Z would terminate the data mode. A typical TCP operation would look like this.

AT+CGATT?             // GPRS Service’s status
+CGATT: 1
OK

AT+CSTT=”CMNET” // Start task and set APN. OK // The default APN is “CMNET”, // with no username or password.

AT+CIICR // Bring up wireless connection OK

AT+CIFSR // Get local IP address 10.78.245.128

AT+CIPSTART=”TCP”,”116.228.221.51”,“8500" // Start up the TCP connection OK CONNECT OK // The TCP connection established

AT+CIPSEND // Send data to remote server, CTRL+Z (0x1a) to send. > hello TCP serve // User should only write data after receiving the promot “>”

SEND OK // data has been sent out and received // successfully by the remote server Hello SIM800 // Received data from remote server CLOSED // Server closed the connection

In order to send 0x1A as part of data payload, you can config the module to operate in "Transparent Mode" which allows you to send the special ASCII such as 0x1A as part of data. You can enable the "Transparent Mode" by sending the command AT+CIPMODE=1, the prompt for entering data mode is different from the normal TCP operation, the prompt > is replaced with CONNECT to signify the beginning of data, and to terminate the data, it needs to send +++ to exit the data mode.

AT+CGATT?             // GPRS Service’s status
+CGATT: 1
OK

AT+CIPMODE=1 // Enable Transparent Mode OK

AT+CSTT=”CMNET” // Start task and set APN. OK

AT+CIICR // Bring up wireless connection OK

AT+CIFSR // Get local IP address 10.78.245.128

AT+CIPSTART=”TCP”,”116.228.221.51”,“8500" // Start up the TCP connection OK CONNECT // TCP connection established

.... // Input data to serial port, no echo, so can't see input data // Quit data mode by enter "+++" or pull DTR (if hardware flow control is available) OK

ATO // Return to data mode CONNECT Hello SIM800 // Received data from remote server CLOSED // Server closed the connection

hcheung
  • 1,933
  • 8
  • 15