0
\$\begingroup\$

Well, I'm developing a system for reading sensors and sending them to a server.

I'm using a GSM LTE module to do this sending. At first it worked well, but after a while the system stopped sending messages to the server. We can see this clearly in the images below.

First behavior stop

In this first image we see a post request being made by the GSM after information from the sensor arrives, but after a while it starts behaving like in the second image.

Second behavior stop

After another period of time, he also stops his second behavior.

Third behavior stop

The Serial 2 logs are from the system with the problem, while the Serial 1 logs are the debug of my sensor.

Here the information is arriving, it starts the sending procedure as shown by the Vp logs, but crashes when sending the JSON information, then starts again and crashes and so on.

My firmware does the following, it reads data from lora, this data can be either a struct called VibrationPackage or one called DataPackage, they are identified and stored in the external FRAM memory and also a char is stored in an array of indices in the internal memory.

This array is used for the commands in the execution loop to know which is the next struct to be sent to the server.

The program reads the first FRAM address, knowing which struct it is from the array of indices, takes the information, transforms it into JSON, sends it and clears the item from the FRAM.

loop main:

uint8_t nextScript = 0;
void loop() {
    //char *vibrationJSON = generateTransmissionVibrationPackageJSON(
    //      &vibrationPackage);
    //GSM_Send_HTTP_POST(vibrationJSON);

    //READ_MSP_Serial_Commands();

    if (dataIndicesSize > 0 && gsmStatus == FREE) {
        nextScript = 0;
        reorganizeStartAddress = BEHAVIOR_Send_Next_Struct_In_FRAM(BEHAVIOR_GET_Next_Send_Item());
        if(nextScript){
            BEHAVIOR_REMOVE_First_Item_From_DataIndices();
            BEHAVIOR_Reorganize_FRAM();
        }
    }
    HAL_Delay(1500);
}

Read and Send:

uint16_t BEHAVIOR_Send_Next_Struct_In_FRAM(char next) {
    uint16_t address = 0;

    if (next == 'D') {
        DEBUG_PRINT("Data\r\n");
        Transmission_Data data = defaultTransmissionData();
        if (FRAM_ReadStruct(&hi2c1, 0, &data, sizeof(Transmission_Data))
                == HAL_OK) {

            address = sizeof(Transmission_Data);

            cJSON *data_json = transmission_vibrationpackage_to_json(&data);
            char *json = cJSON_PrintUnformatted(data_json);

            HAL_Delay(250);

            GSM_Send_HTTP_POST(json);

            HAL_Delay(250);
            cJSON_Delete(data_json);
            free(json);
            nextScript = 1;
        }else
            DEBUG_PRINT("MEM EXCEPTION D\r\n");
    } else if (next == 'P') {
        DEBUG_PRINT("Vp\r\n");
        Transmission_VibrationPackage vibrationPackage =
                defaultTransmissionVibrationPackage();
        if (FRAM_ReadStruct(&hi2c1, 0, &vibrationPackage,
                sizeof(Transmission_VibrationPackage)) == HAL_OK) {
            DEBUG_PRINT("Vp Read\r\n");
            address = sizeof(Transmission_VibrationPackage);

            cJSON *vib_data_json = transmission_vibrationpackage_to_json(
                    &vibrationPackage);
            char *json = cJSON_PrintUnformatted(vib_data_json);

            DEBUG_PRINT("Vp Converted\r\n");

            HAL_Delay(250);

            GSM_Send_HTTP_POST(json);

            HAL_Delay(250);
            cJSON_Delete(vib_data_json);
            free(json);
            nextScript = 1;
        }else
            DEBUG_PRINT("MEM EXCEPTION VP\r\n");
    } else {
        DEBUG_PRINT("CHAR_NOT_FOUND_EXCEPTION\r\n");
        CHAR_NOT_FOUND_EXCEPTION();
    }

    return address;
}

HTTP Post:

char* GSM_Send_HTTP_POST(char *json) {
    int length = strlen(json);
    uint8_t *jsonAsUint8 = malloc(length);

    if (jsonAsUint8 == NULL) {
        return NULL;
    }

    memcpy(jsonAsUint8, (uint8_t*) json, length);
    uint8_t httpINITisOK = 0;

    if (sendAT("AT+HTTPINIT\r\n", "OK")) {
        httpINITisOK = 1;
        DEBUG_PRINT("HTTP Init!\r\n");
    }

    if (httpINITisOK) {

        sendAT(
                "AT+HTTPPARA=\"URL\",\"compute.amazonaws.com:8080/data/register\"\r\n",
                "OK");

        sendAT("AT+HTTPPARA=\"CONTENT\",\"application/json\"\r\n", "OK");

        HAL_Delay(50);

        GSM_HTTP_Send(json);

        sendAT("AT+HTTPACTION=1\r\n", "OK");
        DEBUG_PRINT((char* )GSM_RX_Buffer);

        sendAT("AT+HTTPHEAD\r\n", "OK");
        DEBUG_PRINT((char* )GSM_RX_Buffer);

        //sendAT("AT+HTTPREAD\r\n", "OK");
        //DEBUG_PRINT((char* )GSM_RX_Buffer);

        sendAT("AT+HTTPTERM\r\n", "OK");
    }
    return "";
}

The full code can be found in this repository.

Why am I suddenly getting this behavior?

Note that the system didn't restart, but skipped the behavior of sending the json, without even sending the AT command attempt messages to the GSM.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ In gsm-send-http-post() you malloc some memory. Where do you free it? Could it be you run out of heap? You shouldn’t really be using malloc on a small embedded system anyway. \$\endgroup\$ Commented Aug 14, 2024 at 6:28
  • 2
    \$\begingroup\$ GSM modules usually draw a lot more current when doing the radio communication. Maybe your HW isn't designed properly and the GSM's current draw causes the voltage to drop.. \$\endgroup\$ Commented Aug 14, 2024 at 10:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.