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,9338 silver badges15 bronze badges
asked Mar 27 at 5:44
1
  • Use the AT+CIPSEND=<length> command to specify the number of bytes you will send. Commented Mar 28 at 10:30

1 Answer 1

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
answered Mar 27 at 9:27
3
  • 2
    I assume it requires an idle period surrounding the +++ as analog dial-up modems did? Commented Mar 27 at 14:37
  • 1
    Fun fact: only Hayes modems required the idle period, because Hayes had a patent on it. (Although apparently they licensed it out. But I encountered a modem without the guard time years later, and trolled a friend of mine with the escape sequence.) en.wikipedia.org/wiki/Time_Independent_Escape_Sequence Commented Mar 28 at 3:33
  • 1
    @grawity_u1686 is correct, according to SIM8xx AT-command manual, it requires 1 second pause before and after the escape sequence +++ to prevent the +++ from being treated as part of the data. Commented Mar 28 at 9:10

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.