Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails or disconnects after a month #106

Open
droidblastnz opened this issue Oct 14, 2024 · 2 comments
Open

Fails or disconnects after a month #106

droidblastnz opened this issue Oct 14, 2024 · 2 comments

Comments

@droidblastnz
Copy link

droidblastnz commented Oct 14, 2024

Deployed a T-SIM7600 board which has been running for close to the entire month. I have code that reconnects the SIM if it shows its disconnected. The T-SIM7600 is currently 4hrs drive away so not a easy fix.

Prior to deploying it to the remote site hence why I needed this type of 4G connectivity I disabled the debugging serial as this is now the second time I had experienced this issue.

Setup code that if it receives a call from cell A it will kick off a reboot or a call from cell B place it into deep sleep that only the ESP not the modem as I couldn't get the code to work for the modem as well.

If I ring the remote T-SIM7600 board it goes straight to answer phone so I am guessing this means its off line or off 4G connectivity?

I also setup code that if it receives a text with a exact code number and task it could reboot, deep sleep, arm or disarm.

There is also code running to check SIM credit balance every 23hrs and this stopped a few days ago as I can see the history logs in the SIM carry portal.

Note the way I have coded is T-SIM7600 board runs a process with timers to check x at different intervals. I do remember seeing some where issues with running timers over a long periods?

Example:

void Update_temp()                                                                   
{
  TempCount++;                                                                       
  if (TempCount >= 43200) {                                                          
    TempCount = 0;
    temp = modem.getTemperature();                                                   
    char tempString[8];                                                              
    dtostrf(temp, 1, 2, tempString);
    mqtt.publish(topicTemperature, tempString);                                      
  }
}

So my question is as follows:

  • Is the T-SIM7600 board off line as in disconnected from the carrier?
  • How do I now fault find if it takes literally a month to enter the fault state.

Any advice on how to move forward please?

Revised the code for another issue
#40

if (!mqtt.connected()) {
    SerialMon.println("MQTT NOT CONNECTED! ");
    SerialMon.print("Disconnecting from: ");
    SerialMon.println(broker);
    mqtt.disconnect(); // Disconnect from MQTT  //added 08/04/2023
    delay(500);
    SerialMon.print("Network State is: ");
    SerialMon.println(modem.isGprsConnected()); //added 08/04/2023

    // Reconnect every 10 seconds
    uint32_t t = millis();
    if (t - lastReconnectAttempt > 10000L) {
        lastReconnectAttempt = t;
        if (!modem.isGprsConnected()) {
            // Reconnect to GPRS network if not connected
            SerialMon.println("GPRS not connected, reconnecting...");
            if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
                SerialMon.println("GPRS reconnect failed");
                delay(10000);
                return;
            }
        }

        if (mqttConnect()) {
            lastReconnectAttempt = 0;
        }
    }
    delay(100);
    return;
}
@lewisxhe
Copy link
Contributor

If the system needs to run continuously for a month before a failure occurs, logging to SD may be the only solution.

@droidblastnz
Copy link
Author

droidblastnz commented Oct 14, 2024

If the system needs to run continuously for a month before a failure occurs, logging to SD may be the only solution.

Thanks @lewisxhe - I ring the remote T-SIM7600 board it goes straight to answer phone so I am guessing this means its off line or off 4G connectivity? what is your view on this? Normally you could ring wait for x times until it meets the threshold and answer. The fact it answers straight away?

if (SerialAT.available()) {
  String response = SerialAT.readString();
  if (response.indexOf("RING") != -1) {                                            // Incoming call detected   
    String phoneNumber = response.substring(response.indexOf("+CLIP: ") + 7, response.indexOf("+CLIP: ") + 18);  // Retrieve the phone number of the incoming call
    phoneNumber.trim();                                                            // Trim leading/trailing spaces
    SerialMon.print("Incoming call from: ");
    SerialMon.println(phoneNumber.substring(1, phoneNumber.length()));
    phoneNumber = (phoneNumber.substring(1, phoneNumber.length()));

This to me seems that it T-SIM7600 board is not answering which must mean the modem is either off 4G, hung or other or its not running my code above - what is the default behavior here?

Q. If the T-SIM7600 has a connection but the ESP has hung will it answer a incoming call immediately?

I run multiple functions with a timer.

int TempCount = 0;

void Update_temp()                                                                   
{
  TempCount++;                                                                       
  if (TempCount >= 43200) {                                                          
    TempCount = 0;
    temp = modem.getTemperature();                                                   
    char tempString[8];                                                              
    dtostrf(temp, 1, 2, tempString);
    mqtt.publish(topicTemperature, tempString);                                      
  }
}

Some take a lot of values and some do not. Some update every 4 hrs some ever 24hrs.

If TempCount is unsigned int (16-bit unsigned): An unsigned int can hold a maximum value of 65,535. With Update_temp() called once per second: The counter would overflow after 65,535 seconds.

Converting this to days:
65,535 seconds ÷ (60 × 60) = ~18.2 hours.
So, using unsigned int would extend the overflow time to about 18 hours, but this is still far less than 23 days, leading to communication loss well before the end of the period.

If TempCount is unsigned long (32-bit unsigned):
An unsigned long can hold values up to 4,294,967,295.
With Update_temp() called once per second: The counter would overflow after 4,294,967,295 seconds.

Using an unsigned long would give a much longer time before overflow, and the 23 days of operation is well within the capacity of this data type.

Unsigned long: Use for counters that need to handle long time periods (e.g., over several days or weeks).

Unsigned int: If you know that a counter will never exceed 65,535 (around 18 hours for 1-second increments), you could consider using unsigned int instead to save memory (if your microcontroller has limited RAM).

Change to ...

Using unsigned long allows these counters to handle much larger values (up to 4,294,967,295) without risk of overflow for an extended period (years, depending on increment frequency).

example

int TempCount = 0;
int TempCount2 = 0;
int OverTempCount = 0;
int DelaytempCount = 0;
int CheckBalanceCount = 0; 
int VoltagePSCount = 0; 
int VoltagePSCount2 = 0;
int SDCardCount = 0;
int SDCardCount2 = 0;
int csq2; 
int CSGtempCount = 0; 
int CSQThreshold = 0; 
int Check_SMSCount = 0;
int CR = 0x1A;
int PAlarm = LOW;
int LStatus = LOW;
int PoffStatus = LOW;
int Ponoff = LOW;
int SIMConnectedStatus = 0; 
int RestartStatus = 0;
int DeepSleepStatus = 0;
int RefreshStatus = 0; 

Suspect I need to change from int to long and or bool?

unsigned long TempCount = 0;
unsigned long TempCount2 = 0;
unsigned long OverTempCount = 0;
unsigned long DelaytempCount = 0;
unsigned long CheckBalanceCount = 0; 
unsigned long VoltagePSCount = 0; 
unsigned long VoltagePSCount2 = 0;
unsigned long SDCardCount = 0;
unsigned long SDCardCount2 = 0;
unsigned long CSGtempCount = 0; 
unsigned long Check_SMSCount = 0;
bool PAlarm = LOW;
bool LStatus = LOW;
bool PoffStatus = LOW;
bool Ponoff = LOW;

So am I heading in the right direction?

bool is used for simple true/false decisions.
unsigned int is used for medium-range positive numbers, up to 65,535 on most microcontrollers (or higher on 32-bit systems).
unsigned long is used when you need a larger range of positive numbers, up to 4.2 billion, such as for long-duration timers or large counters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants