cancel
Showing results for 
Search instead for 
Did you mean: 

System crashing HTTP execution with GSM module

MatheusMarkies
Associate III

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.

Capturasdfasdfasd8ar.PNG

 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.

Capturasdfasdfasdar.PNG

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\",\"http://ec2-54-212-246-25.us-west-2.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: https://gist.github.com/MatheusMarkies/caa02e8f6832da12cd972be54f09f3bf

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.

 

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

0 REPLIES 0