Okay so I am currently using an arduino-uno to send AT commands to a SIM800l module. I am running a basic TCP socket server on my computer and the SIM800L is initially able to connect to it fine and send a message. After a seemingly random period of time on my serial monitor “NUL” is then displayed at which I am unable to send messages.
(So it is working initially however it seems to suddenly just stop mid process)
bool connectionProcedure()
{
bool result = false;
if(sendATcommand("AT+CIPSHUT", "SHUT OK", 200) == 1)
{
Serial.println("Proceed: AT+CIPMUX=0");
if(sendATcommand("AT+CIPMUX=0", "OK", 1000) == 1 )
{
Serial.println("Proceed: AT+CGATT=1");
if(sendATcommand("AT+CGATT=1", "OK", 1000) == 1 )
{
Serial.println("Proceed: AT+CSTT=\"gifgaff.com\",\"gifgaff\"");
if(sendATcommand("AT+CSTT=\"gifgaff.com\",\"gifgaff\"", "OK", 1000) == 1 )
{
Serial.println("Proceed: AT+CIICR");
if(sendATcommand("AT+CIICR", "OK", 60000) == 1 )
{
Serial.println("Proceed: AT+CIFSR");
if(sendATcommand("AT+CIFSR", ".", 5000) == 1 )
{
Serial.println("Proccess Success!");
result = true;
}
else
{
Serial.println("Error: AT+CIFSR");
}
}
else
{
Serial.println("Error: AT+CIICR");
}
}
else
{
Serial.println("Error: AT+CSTT=\"gifgaff.com\",\"gifgaff\"");
}
}
else
{
Serial.println("Error: AT+CGATT=1");
}
}
else
{
Serial.println("Error: AT+CIPMUX=0");
}
}
else
{
Serial.println("Error: CIPSHUT");
}
return result;
}
– This is then called to check for a connection to the network
void awaitGSMConnection()
{
while( sendATcommand2("AT+CREG?", "+CREG: 0,1", "+CREG: 0,5", 1000) == 0 );
}
– Now the more useful stuff…
void initTCPConnection()
{
unsigned long previous;
unsigned int timeout = 10000;
Serial.println("Starting TCP Connection!");
if(sendATcommand("AT+CIPSTART=\"TCP\"," + tcpIp + "," + tcpPort, "OK", 10000) == 1)
{
Serial.println("Connection Success: Checking for stable connection before handshake!");
String expected = "CLOSED";
uint8_t x=0, answer=0;
char response[100];
memset(response, '\0', 100);
while( mySerial.available() > 0) mySerial.read();
x = 0;
previous = millis();
// Loop waits for the response from SIM800L
do {
if(mySerial.available() != 0) {
response[x] = mySerial.read();
x++;
// check if the desired answer 1 is in the response of the module
if (strstr(response, expected.c_str()) != NULL)
{
answer = 1;
}
}
}
while((answer == 0) && ((millis() - previous) < timeout));
if(answer == 0)
{
Serial.println("No Apparent ISSUE sending handshake!");
if(sendATcommand("AT+CIPSEND", ">", 4000) == 1)
{
Serial.println("SEND-HANDSHAKE");
sendMessage("Handshake");
//sendATcommand("AT+CIPCLOSE","OK",2000);
}
else
{
Serial.println("Error: AT+CIPSEND");
}
}
else
{
Serial.println("Connection test failed: Attempting to RECONNECT!");
}
}
else
{
Serial.println("Connection Error!");
}
}
Serial Monitor - Output
Here is the “NUL” I am talking about, this seems to appear completely randomly sometime during the connection. Random messages being sent from me from the server and being received.
No Apparent ISSUE sending handshake!
AT+CIPSEND
>
SEND-HANDSHAKE
Handshake␚
SEND OK
HELLO
AWESOME
COOL
INSANE
STILL WORKING!!!!
␀
Thanks in advance!