Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Issue with GSM Pin Connect
#7
(11-16-2023, 02:01 AM)airantoujc Wrote: Arduino settings below and hardware serial cpp changes attached

#define TX2 13
#define RX2 34


void modemHandler() {
  String res;
  SerialMon.println("========INIT========");

  modem.init();


  SerialMon.println("========SIMCOMATI======");
  modem.sendAT("+SIMCOMATI");
  modem.waitResponse(1000L, res);
  res.replace(GSM_NL "OK" GSM_NL, "");
  SerialMon.println(res);
  res = "";
  SerialMon.println("=======================");
  SerialMon.println("=====Preferred mode selection=====");
  modem.sendAT("+CNMP?");
  if (modem.waitResponse(1000L, res) == 1) {
    res.replace(GSM_NL "OK" GSM_NL, "");
    SerialMon.println(res);
  }
  res = "";
  SerialMon.println("=======================");
  SerialMon.println("=====Preferred selection between CAT-M and NB-IoT=====");
  modem.sendAT("+CMNB?");
  if (modem.waitResponse(1000L, res) == 1) {
    res.replace(GSM_NL "OK" GSM_NL, "");
    SerialMon.println(res);
  }
  res = "";
  SerialMon.println("=======================");
  String name = modem.getModemName();
  SerialMon.println("Modem Name: " + name);
  String modemInfo = modem.getModemInfo();
  SerialMon.println("Modem Info: " + modemInfo);
  for (int i = 0; i <= 4; i++) {
    uint8_t network[] = {
      2,  /*Automatic*/
      13, /*GSM only*/
      38, /*LTE only*/
      51  /*GSM and LTE only*/
    };
    SerialMon.printf("Try %d method\n", network[i]);
    modem.setNetworkMode(network[i]);
    delay(1000);
    bool isConnected = false;
    int tryCount = 60;
    while (tryCount--) {
      int16_t signal = modem.getSignalQuality();
      SerialMon.print("Signal: ");
      SerialMon.print(signal);
      SerialMon.print(" ");
      SerialMon.print("isNetworkConnected: ");
      isConnected = modem.isNetworkConnected();
      SerialMon.println(isConnected ? "CONNECT" : "NO CONNECT");
      if (isConnected) {
        break;
      }
      delay(500);
      digitalWrite(LED_PIN, !digitalRead(LED_PIN));
    }
  }
}


void setup() {
  // Set console baud rate
  SerialMon.begin(38400);
  delay(1000);
  pinMode(LED_PIN, OUTPUT);
  //modemPowerOn();
  SerialMon.println("Wait...");
  // Set GSM module baud rate
  SerialAT.begin(UART_BAUD, SERIAL_8N1, RX2, TX2);
  delay(3000);

  SerialMon.println("Initializing modem...");
  modemHandler();
  digitalWrite(LED_PIN, LOW);
  String modemInfo = modem.getModemInfo();
  SerialMon.print("Modem Info: ");
  SerialMon.println(modemInfo);
#if TINY_GSM_USE_GPRS
  // Unlock your SIM card with a PIN if needed
  if (GSM_PIN && modem.getSimStatus() != 3) { modem.simUnlock(GSM_PIN); }
#endif
#if TINY_GSM_USE_WIFI
  // Wifi connection parameters must be set before waiting for the network
  SerialMon.print(F("Setting SSID/password..."));
  if (!modem.networkConnect(wifiSSID, wifiPass)) {
    SerialMon.println(" fail");
    delay(10000);
    return;
  }
  SerialMon.println(" success");
#endif
#if TINY_GSM_USE_GPRS && defined TINY_GSM_MODEM_XBEE
  // The XBee must run the gprsConnect function BEFORE waiting for network!
  modem.gprsConnect(apn, gprsUser, gprsPass);
#endif
  SerialMon.print("Waiting for network...");
  if (!modem.waitForNetwork()) {
    SerialMon.println(" fail");
    delay(10000);
    return;
  }
  SerialMon.println(" success");
  if (modem.isNetworkConnected()) { SerialMon.println("Network connected"); }
#if TINY_GSM_USE_GPRS
  // GPRS connection parameters are usually set after network registration
  SerialMon.print(F("Connecting to "));
  SerialMon.print(apn);
  if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
    SerialMon.println(" fail");
    delay(10000);
    return;
  }
  SerialMon.println(" success");
  if (modem.isGprsConnected()) { SerialMon.println("GPRS connected"); }
#endif
}
void loop() {
  // Make sure we're still registered on the network
  if (!modem.isNetworkConnected()) {
    SerialMon.println("Network disconnected");
    if (!modem.waitForNetwork(180000L, true)) {
      SerialMon.println(" fail");
      delay(10000);
      return;
    }
    if (modem.isNetworkConnected()) {
      SerialMon.println("Network re-connected");
    }
#if TINY_GSM_USE_GPRS
    // and make sure GPRS/EPS is still connected
    if (!modem.isGprsConnected()) {
      SerialMon.println("GPRS disconnected!");
      SerialMon.print(F("Connecting to "));
      SerialMon.print(apn);
      if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
        SerialMon.println(" fail");
        delay(10000);
        return;
      }
      if (modem.isGprsConnected()) { SerialMon.println("GPRS reconnected"); }
    }
#endif
  }
}

#if TINY_GSM_USE_GPRS && not defined TINY_GSM_MODEM_HAS_GPRS
#undef TINY_GSM_USE_GPRS
#undef TINY_GSM_USE_WIFI
#define TINY_GSM_USE_GPRS false
#define TINY_GSM_USE_WIFI true
#endif
#if TINY_GSM_USE_WIFI && not defined TINY_GSM_MODEM_HAS_WIFI
#undef TINY_GSM_USE_GPRS
#undef TINY_GSM_USE_WIFI
#define TINY_GSM_USE_GPRS true
#define TINY_GSM_USE_WIFI false
#endif

my ifdef is using GSM GPRS
https://www.kincony.com/forum/showthread.php?tid=3330   
download  KCS firmware  and test the 4G module.
Reply


Messages In This Thread
Issue with GSM Pin Connect - by airantoujc - 11-15-2023, 01:59 AM
RE: Issue with GSM Pin Connect - by admin - 11-15-2023, 02:04 AM
RE: Issue with GSM Pin Connect - by airantoujc - 11-15-2023, 02:06 AM
RE: Issue with GSM Pin Connect - by admin - 11-15-2023, 02:23 AM
RE: Issue with GSM Pin Connect - by airantoujc - 11-15-2023, 03:01 AM
RE: Issue with GSM Pin Connect - by airantoujc - 11-16-2023, 02:01 AM
RE: Issue with GSM Pin Connect - by KinCony Support - 11-16-2023, 02:30 AM

Forum Jump:


Users browsing this thread:
1 Guest(s)