ArduinoESP32 DevKit V1Lab virtual

4G HTTP with AT commands (A7670C)

An ESP32 brings up 4G data on an A7670C and fetches a page with the module's own HTTP commands.

4G HTTP with AT commands (A7670C) in Argynix Lab

The code

sketch.inoC++
// An ESP32 on 4G through SIMCom's A7670C, with plain AT commands on Serial2 (RX2 16,
// TX2 17): the SIM, registration, data, then an HTTP GET with AT+HTTP… every 20 s.
#define AT Serial2

String ask(const char *cmd, uint32_t ms = 1000) {
  AT.print(cmd);
  AT.print("\r");
  String got;
  uint32_t t = millis();
  while (millis() - t < ms) while (AT.available()) got += (char)AT.read();
  got.trim();
  Serial.print("> ");
  Serial.println(cmd);
  Serial.println(got);
  return got;
}

void setup() {
  Serial.begin(115200);
  AT.begin(115200, SERIAL_8N1, 16, 17);
  delay(3000);
  ask("ATE0");
  ask("AT+CPIN?");
  ask("AT+CSQ");
  while (ask("AT+CREG?").indexOf(",1") < 0) delay(1000);
  ask("AT+CGDCONT=1,\"IP\",\"internet\"");
  ask("AT+NETOPEN", 2000);
}

void loop() {
  ask("AT+HTTPINIT");
  ask("AT+HTTPPARA=\"URL\",\"http://example.com/time\"");
  ask("AT+HTTPACTION=0", 3000);
  ask("AT+HTTPREAD=0,500", 1500);
  ask("AT+HTTPTERM");
  delay(20000);
}