AT command not response(sim 4g 7672S)

#include <SoftwareSerial.h>

#include <stdio.h>
#include <string.h>

//Change the API key to yours
String Apikey = "FOONITF25Z929EAN";

#define DEBUG true
#define rx 2
#define tx 3

SoftwareSerial Serial1(tx,rx);

void setup()
{
Serial.begin(115200);
Serial1.begin(115200);
sendData("AT+CCID", 3000);
sendData("AT+CREG?", 3000);
sendData("AT+CGDCONT=1,IP,m9-itelecom", 1000);
sendData("AT+CGACT=1,1", 1000);
sendData("AT+CGATT=1", 1000);

Serial.println("4G HTTP Test Begin!");

delay(1000);

}

void loop()
{
//--------Get temperature and humidity-------------
float t = analogRead(A0);
Serial.print("Temperature: ");
Serial.print(t);
Serial.println("*C");
delay(1000);

//-----------HTTP---------------------
String http_str = "AT+HTTPPARA=\"URL\",\"https://api.thingspeak.com/update?api_key=" + Apikey + "&field1=" + (String)t + "\"\r\n";
Serial.println(http_str);

sendData("AT+HTTPINIT\r\n", 2000);
sendData(http_str, 2000);
sendData("AT+HTTPACTION=0\r\n", 3000);
sendData("AT+HTTPTERM\r\n", 3000);

delay(5000);   

}

String sendData(String toSend, unsigned long milliseconds)
{
String result;
Serial.print("Sending: ");
Serial.println(toSend);
Serial1.println(toSend);
unsigned long startTime = millis();
Serial.print("Received: ");
while (millis() - startTime < milliseconds) {
if (Serial1.available()) {
char c = Serial1.read();
Serial.write(c);
result += c; // append to the result string
}
}
Serial.println(result);
return result;
}

khoa258, welcome to the forum!

Just a suggestion: please wrap all of your code within the CODE tags. That will make it much easier for us to read.

You don't mention which MCU board you are using but unless your connections are really short, 115200 baud is generally too fast for SoftwareSerial. It needs to be reduced to 57600 or even 38400 to work reliably. Of course the SIM board need to operate at the same speed.

I use Arduino uno R3 and it not working with 57600 and 38400

What's the actual serial speed of your SIM module?

Two suggestions:

  1. Make sure that the 4G device and the Arduino are set to the same bit rate. Many devices default to 9600.
  2. Try removing the New Line and Carriage Return characters from the AT commands. A lot of devices don't know what to do with New Line or Carriage Return special characters.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.