vshymanskyy / TinyGSM

A small Arduino library for GSM modules, that just works
GNU Lesser General Public License v3.0
1.91k stars 709 forks source link

SIM7600 does not seem to get registered to the network. #676

Open github0013 opened 1 year ago

github0013 commented 1 year ago

[x ] I have read the Troubleshooting section of the ReadMe

Ensure stable data & power connection

Using M1 Macbook air as the power source. The other port is not occupied. Tried 2.5A and 2.1A usb blocks, but the results are the same. The usb cable is about 20cm long.

Baud rates

Fixed baud rate, 115200.

Broken initial configuration

factoryDefault is not implemented in TinyGsmClientSIM7600.

you may need to set an initial APN to connect to the cellular network

Tried modem.gprsConnect(apn) before modem.waitForNetwork(), and I get +NETOPEN: 1.

Failed connection or no data received

The signal quality is excellent (always around +CSQ: 25,99). Tried for 15 mins on waitForNetwork.

What type of issues is this?

[ ] Request to support a new module

[ ] Bug or problem compiling the library [ ] Bug or issue with library functionality (ie, sending data over TCP/IP) [x ] Question or request for help

What are you working with?

Modem: Manufacturer: SIMCOM INCORPORATED Model: SIMCOM_SIM7600JC-H Revision: SIM7600JC-H_V1.1

Main processor board: ESP32 TinyGSM version: 0.11.5

#define SerialMon Serial
#define SerialAT Serial1

static const char *TAG = "SIM LTE";
const char *apn = "YOUR APN";
const char *gprsUser = "YOUR USER";
const char *gprsPass = "YOUR PASS";

#include <Ticker.h>
Ticker tick;

#define uS_TO_S_FACTOR 1000000ULL
#define TIME_TO_SLEEP 60

#define PIN_TX 27
#define PIN_RX 26
#define UART_BAUD 115200
#define PWR_PIN 4
#define LED_PIN 12
#define POWER_PIN 25
#define IND_PIN 36

#define TINY_GSM_DEBUG SerialMon
#define TINY_GSM_MODEM_SIM7600
#include <TinyGsmClient.h>

#include <StreamDebugger.h>
StreamDebugger debugger(SerialAT, SerialMon);
TinyGsm modem(debugger);

void setup() {
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, HIGH);

  SerialMon.begin(115200);
  delay(5000);

  // POWER_PIN : This pin controls the power supply of the SIM7600
  pinMode(POWER_PIN, OUTPUT);
  digitalWrite(POWER_PIN, HIGH);
  delay(1000);
  ESP_LOGD(TAG, "power supplied to SIM7600");

  // PWR_PIN : This Pin is the PWR-KEY of the SIM7600
  // The time of active low level impulse of PWRKEY pin to power on module ,
  // type 500 ms
  pinMode(PWR_PIN, OUTPUT);
  digitalWrite(PWR_PIN, HIGH);
  delay(500);
  digitalWrite(PWR_PIN, LOW);
  ESP_LOGD(TAG, "PWRKEY low");

  SerialAT.begin(UART_BAUD, SERIAL_8N1, PIN_RX, PIN_TX);
  delay(5000);

  ESP_LOGD(TAG, "initializing");
  if (!modem.init()) {
    ESP_LOGD(TAG, "init FAILED");
    return;
  }

  ESP_LOGD(TAG, "Model Name: %s", modem.getModemName().c_str());
  ESP_LOGD(TAG, "Model Info: %s", modem.getModemInfo().c_str());
  ESP_LOGD(TAG, "SIM Status: %d", modem.getSimStatus());

  modem.setPhoneFunctionality(1);

  ESP_LOGD(TAG, "setting network mode");
  do {
    delay(500);
  } while (!modem.setNetworkMode(2));

  modem.gprsConnect(apn);
  tick.attach_ms(1000, []() { digitalWrite(LED_PIN, !digitalRead(LED_PIN)); });
  ESP_LOGD(TAG, "waiting for network");
  if (!modem.waitForNetwork(60000L * 15, true)) {
    ESP_LOGD(TAG, "waitForNetwork FAILED");
    return;
  }
  tick.detach();
  tick.attach_ms(500, []() { digitalWrite(LED_PIN, !digitalRead(LED_PIN)); });

  ESP_LOGD(TAG, "connecting to: %s", apn);
  if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
    return;
  }
  tick.detach();
  tick.attach_ms(100, []() { digitalWrite(LED_PIN, !digitalRead(LED_PIN)); });

  bool res = modem.isGprsConnected();
  ESP_LOGD(TAG, "GPRS status: %s", res ? "connected" : "NOT connected");

  IPAddress local = modem.localIP();
  ESP_LOGD(TAG, "Local IP: %s", local.toString().c_str());

  int csq = modem.getSignalQuality();
  ESP_LOGD(TAG, "Signal quality: %d", csq);

  modem.poweroff();
  ESP_LOGD(TAG, "power off");
}

void loop() {
  esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
  delay(200);
  esp_deep_sleep_start();
}

Scenario, steps to reproduce

I am using an iPhone SE2, and the SIM card is LTE (not data only SIM). I am testing my device with this SIM card.

  1. connect the esp32 module
  2. upload the built code through vscode platformio
  3. watch the serial monitor logs

Expected result

SIM gets registered to the network and show the IP address.

Actual result

It stops at modem.waitForNetwork(). It seems it's always getting REG_SEARCHING of RegStatus.

Debug and AT command log

 *  Executing task: platformio device monitor 

--- Terminal on /dev/cu.usbmodem537D0225881 | 115200 8-N-1
--- Available filters and text transformations: colorize, debug, default, direct, esp32_exception_decoder, hexlify, log2file, nocontrol, printable, send_on_enter, time
--- More details at https://bit.ly/pio-monitor-filters
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H
[  6016][D][main.cpp:42] setup(): [SIM LTE] power supplied to SIM7600
[  6517][D][main.cpp:51] setup(): [SIM LTE] PWRKEY low
[ 11518][D][main.cpp:56] setup(): [SIM LTE] initializing
[11519] ### TinyGSM Version: 0.11.5
[11519] ### TinyGSM Compiled Module:  TinyGsmClientSIM7600
AT
AT
AT
AT
AT
AT
AT
AT
AT
AT
AT
AT
AT
AT
AT
AT
AT
AT
AT
AT
AT
AT
AT
AT
AT

RDY
[18954] ### Unhandled: RDY
AT
AT
OK
ATE0
ATE0
OK
AT+CMEE=2

OK
AT+CGMM

SIMCOM_SIM7600JC-H

OK
[19074] ### Modem: SIMCOM SIM7600JC-H
[19074] ### Modem: SIMCOM SIM7600JC-H
AT+CTZR=0

OK
AT+CTZU=1

OK
AT+CPIN?

+CME ERROR: SIM busy
AT+CPIN?

+CPIN: READY

SMS DONE

PB DONE

+CPIN: READY

OK
AT+CGMM

SIMCOM_SIM7600JC-H

OK
[20103] ### Modem: SIMCOM SIM7600JC-H
[ 20096][D][main.cpp:62] setup(): [SIM LTE] Model Name: SIMCOM SIM7600JC-H
ATI

Manufacturer: SIMCOM INCORPORATED
Model: SIMCOM_SIM7600JC-H
Revision: SIM7600JC-H_V1.1
IMEI: 999999999999999
+GCAP: +CGSM

OK
[ 20104][D][main.cpp:63] setup(): [SIM LTE] Model Info: Manufacturer: SIMCOM INCORPORATED Model: SIMCOM_SIM7600JC-H Revision: SIM7600JC-H_V1.1 IMEI: 999999999999999 +GCAP: +CGSM
AT+CPIN?

+CPIN: READY

OK
[ 20133][D][main.cpp:64] setup(): [SIM LTE] SIM Status: 1
AT+CFUN=1

OK
[ 20153][D][main.cpp:68] setup(): [SIM LTE] setting network mode
AT+CNMP=2

OK
AT+NETCLOSE

+NETCLOSE: 2

ERROR
AT+CGDCONT=1,"IP","***actual apn***","0.0.0.0",0,0

OK
AT+CIPMODE=0

OK
AT+CIPSENDMODE=0

OK
AT+CIPCCFG=10,0,0,0,1,0,75000

OK
AT+CIPTIMEOUT=75000,15000,15000

OK
AT+NETOPEN

OK

+NETOPEN: 1
[95720] ### Unhandled: OK

+NETOPEN: 1
[ 95720][D][main.cpp:75] setup(): [SIM LTE] waiting for network
AT+CSQ

+CSQ: 26,99

OK
AT+CGREG?

+CGREG: 0,2

OK
AT+CSQ

+CSQ: 26,99

OK
AT+CGREG?

+CGREG: 0,2

OK
AT+CSQ

+CSQ: 26,99

OK
AT+CGREG?

+CGREG: 0,2

OK
AT+CSQ

+CSQ: 26,99

OK
AT+CGREG?

+CGREG: 0,2

OK
AT+CSQ

+CSQ: 26,99

OK
AT+CGREG?

+CGREG: 0,2

OK
AT+CSQ

+CSQ: 26,99

OK
AT+CGREG?

+CGREG: 0,2

OK
AT+CSQ

+CSQ: 26,99

OK
AT+CGREG?

+CGREG: 0,2

OK
AT+CSQ

+CSQ: 26,99

OK
AT+CGREG?

+CGREG: 0,2

OK
AT+CSQ

+CSQ: 26,99

OK
AT+CGREG?

+CGREG: 0,2

OK
AT+CSQ

+CSQ: 26,99

OK
AT+CGREG?

+CGREG: 0,2

OK
AT+CSQ

+CSQ: 26,99

OK
AT+CGREG?

+CGREG: 0,2

OK
AT+CSQ

+CSQ: 26,99

OK
AT+CGREG?

+CGREG: 0,2

OK
AT+CSQ

+CSQ: 26,99

OK
AT+CGREG?

+CGREG: 0,2

OK
AT+CSQ

+CSQ: 26,99

OK
AT+CGREG?

+CGREG: 0,2

OK
AT+CSQ

+CSQ: 26,99

OK
AT+CGREG?

+CGREG: 0,2

OK
AT+CSQ

+CSQ: 26,99

OK
AT+CGREG?

+CGREG: 0,2

OK
AT+CSQ

+CSQ: 26,99

OK
AT+CGREG?

+CGREG: 0,2

OK
AT+CSQ

+CSQ: 26,99

OK
AT+CGREG?

+CGREG: 0,2

OK
AT+CSQ

+CSQ: 26,99

OK
AT+CGREG?

+CGREG: 0,2

OK
AT+CSQ

+CSQ: 26,99

OK
AT+CGREG?

+CGREG: 0,2

OK
AT+CSQ

+CSQ: 26,99

OK
AT+CGREG?

+CGREG: 0,2

OK
AT+CSQ

+CSQ: 26,99

OK
AT+CGREG?

+CGREG: 0,2

OK
AT+CSQ

+CSQ: 26,99

OK
AT+CGREG?

+CGREG: 0,2

OK
AT+CSQ

+CSQ: 26,99

OK
AT+CGREG?

+CGREG: 0,2

OK

+CGREG goes on forever until the timeout.

github0013 commented 1 year ago

I think "AT+CGAUTH" params are not properly set. https://github.com/vshymanskyy/TinyGSM/blob/3356c1d5c7bbde4a8440021b591453545ffccbde/src/TinyGsmClientSIM7600.h#L319 When cid is set, the password should come first before the user.

Here's the reason. https://github.com/vshymanskyy/TinyGSM/pull/678

I edited TinyGsmClientSIM7600.h like this, and the same main.cpp is working just fine.

sendAT(GF("+CGAUTH=1,0,\""), pwd, GF("\",\""), user, '"');