Browse Source

2021-12-08 / Jerry Wang
Actions:
1. Set the HeartbeatInterval with the Interval key value in BootNotificationRes.
2. Add function to record PeriodEnergy value for reporting DataTransfer[periodEnergy] to backend.

File:
1. EVSE/Modularization/ocpp20/MessageHandler.c -->Action: 1
2. EVSE/Modularization/ocppfiles/MessageHandler.c -->Action: 1,2
3. EVSE/Modularization/ocppfiles/Module_OcppBackend.c -->Action: 2
4. EVSE/Modularization/ocppph/MessageHandler.c -->Action: 1
5. EVSE/Modularization/ocppph/Module_OcppBackend.c -->Action: just add word';'

Image version: D0.00.XX.XXXX.XX
Image checksum: XXXXXXX

Hardware PWB P/N: XXXXXXX
Hardware Version: XXXXXXX

Jerry Wang 3 years ago
parent
commit
0a79ccc85c

+ 14 - 3
EVSE/Modularization/ocpp20/MessageHandler.c

@@ -3223,14 +3223,14 @@ int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg
 	if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
 	{
 		result = FAIL;
-		DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
+		DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
 	}
 
 	sprintf(sqlStr, "delete from ocpp20_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-2000) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
 	if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
 	{
 		result = FAIL;
-		DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
+		DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
 	}
 
 	return result;
@@ -17057,6 +17057,7 @@ int handleSetVariablesRequest(char *uuid, char *payload)
 								}
 								else
 									HeartBeatWaitTime = atoi((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value);
+
 							}
 
 							if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "SecurityCtrlr") != NULL) &&
@@ -17846,7 +17847,6 @@ void handleBootNotificationResponse(char *payload, int gun_index)
 
 	ShmOCPP20Data->BootNotification.Response_interval = intervalInt;
 	BootNotificationInterval = intervalInt;
-	HeartBeatWaitTime = intervalInt;
 
 	//write back to ShmOCPP20Data->BootNotification
 	strcpy((char *)ShmOCPP20Data->BootNotification.Response_currentTime, currentTimeStr);
@@ -17854,6 +17854,17 @@ void handleBootNotificationResponse(char *payload, int gun_index)
 
 	if((strcmp(statusStr, RegistrationStatusEnumTypeStr[RegistrationStatusEnumType_Accepted]) == 0 ))
 	{
+		if(intervalInt < (int)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.minLimit)
+		{
+			//Do nothing because the value is out of range.
+		}
+		else
+		{
+			sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value,"%d", HeartBeatWaitTime);
+			HeartBeatWaitTime = intervalInt;
+			DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
+		}
+
 		server_sign = TRUE;
 		server_pending =FALSE;
 		DB_updateBootType(BootReasonEnumType_PowerUp);

+ 214 - 182
EVSE/Modularization/ocppfiles/MessageHandler.c

@@ -1081,19 +1081,219 @@ int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg
 	if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
 	{
 		result = FAIL;
-		DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
+		DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
 	}
 
 	sprintf(sqlStr, "delete from ocpp_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-2000) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
 	if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
 	{
 		result = FAIL;
-		DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
+		DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
 	}
 
 	return result;
 }
 
+int OCPP_updatePeriodEnergy(uint8_t gun_index)
+{
+	int isSuccess = TRUE;
+	int tempIndex;
+	json_object *EnergyDataTransfer = json_object_new_object();
+	json_object *periodEnergys = json_object_new_object();
+	char sql[1024];
+	char zErrMsg[200];
+
+	memset(sql, 0, ARRAY_SIZE(sql));
+	memset(zErrMsg, 0, ARRAY_SIZE(zErrMsg));
+
+	if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
+	{
+		if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
+		{
+			tempIndex = ((gun_index==2) ? 1: 0);
+		}
+		else
+		{
+			tempIndex = gun_index;
+		}
+
+		for (int index = 0; index < CHAdeMO_QUANTITY; index++)
+		{
+			if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
+			{
+				json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
+				for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
+				{
+					uint8_t period[3];
+					sprintf((char*)period, "%d", idxPeriod);
+
+					json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
+				}
+
+				json_object_object_add(EnergyDataTransfer, "periodEnergy", json_object_new_string(json_object_to_json_string_ext(periodEnergys, JSON_C_TO_STRING_PLAIN)));
+			} //end of the same index
+		}//end of for CHAdeMO_QUANTITY
+	}
+	else if(gunType[gun_index] == GUN_TYPE_CCS)
+	{
+		if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
+		{
+			tempIndex = ((gun_index==2) ? 1: 0);
+		}
+		else
+		{
+			tempIndex = gun_index;
+		}
+
+		for (int index = 0; index < CCS_QUANTITY; index++)
+		{
+			if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
+			{
+				json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
+				for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
+				{
+					uint8_t period[3];
+					sprintf((char*)period, "%d", idxPeriod);
+
+					json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
+				}
+
+				json_object_object_add(EnergyDataTransfer, "periodEnergy", json_object_new_string(json_object_to_json_string_ext(periodEnergys, JSON_C_TO_STRING_PLAIN)));
+			} //end of the same index
+		} // end of for CCS_QUANTITY
+	}
+	else if(gunType[gun_index] == GUN_TYPE_GBT)
+	{
+		if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
+		{
+			tempIndex = ((gun_index==2) ? 1: 0);
+		}
+		else
+		{
+			tempIndex = gun_index;
+		}
+
+		for (int index = 0; index < GB_QUANTITY; index++)
+		{
+			if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
+			{
+				json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
+				for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
+				{
+					uint8_t period[3];
+					sprintf((char*)period, "%d", idxPeriod);
+
+					json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
+				}
+
+				json_object_object_add(EnergyDataTransfer, "periodEnergy", json_object_new_string(json_object_to_json_string_ext(periodEnergys, JSON_C_TO_STRING_PLAIN)));
+			} //end of the same index
+		} // end of for GB_QUANTITY
+	}
+	else if(gunType[gun_index] == GUN_TYPE_DO)
+	{
+		tempIndex = gun_index;
+
+		for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
+		{
+			if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
+			{
+				json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
+
+				for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod);idxPeriod++)
+				{
+					uint8_t period[3];
+					sprintf((char*)period, "%d", idxPeriod);
+
+					json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod[idxPeriod]));
+				}
+
+				json_object_object_add(EnergyDataTransfer, "periodEnergy", json_object_new_string(json_object_to_json_string_ext(periodEnergys, JSON_C_TO_STRING_PLAIN)));
+			} //end of the same index
+		}
+	}
+	else
+	{
+		if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
+		{
+			tempIndex = 2;
+		}
+		else
+		{
+			tempIndex = gun_index;
+		}
+
+		for (int index = 0; index < AC_QUANTITY; index++)
+		{
+			if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
+			{
+				json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
+
+				for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
+				{
+					uint8_t period[3];
+					sprintf((char*)period, "%d", idxPeriod);
+
+					json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
+				}
+
+				json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
+			}//end of the same index
+		}//end of for AC_QUANTITY
+	}
+
+	sprintf(sql, "insert or replace into ocpp_period_energy (transactionId, connectorId, occurDatetime, periodEnergy) VALUES ('%d', '%d', CURRENT_TIMESTAMP, '%s');", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, (gun_index+1), json_object_to_json_string_ext(EnergyDataTransfer, JSON_C_TO_STRING_PLAIN));
+	json_object_put(EnergyDataTransfer);
+
+	//* Execute SQL statement */
+	if( sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg) != SQLITE_OK )
+	{
+		DEBUG_WARN("SQL error: %s\n", zErrMsg);
+		isSuccess = FALSE;
+	}
+
+	sprintf(sql, "delete from ocpp_period_energy where (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
+	if (sqlite3_exec(db, sql, 0, 0, (char **)&zErrMsg) != SQLITE_OK)
+	{
+		DEBUG_WARN( "delete period energy record error message: %s\n", zErrMsg);
+		isSuccess = FALSE;
+	}
+
+	return isSuccess;
+}
+
+int OCPP_getPeriodEnergyToDataTransfer(int32_t transactionId)
+{
+	int isSuccess = TRUE;
+	char sql[512];
+	char zErrMsg[200];
+	int rows, cols;
+	char **resultData;
+
+	sprintf(sql, "select * from ocpp_period_energy where transactionId=%d;", transactionId);
+
+	/* Execute SQL statement */
+	if( sqlite3_get_table(db, sql, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
+	{
+		DEBUG_WARN("SQL error: %s\n", zErrMsg);
+		isSuccess = FALSE;
+	}
+	else
+	{
+		if((rows > 0) && (atoi(resultData[4]) > 0))
+		{
+			sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, "%s", resultData[7]);
+		}
+		else
+		{
+			DEBUG_WARN("There is not match transaction data.\n");
+			isSuccess = FALSE;
+		}
+	}
+
+	return isSuccess;
+}
+
 //==========================================
 // Check time passed since today
 //==========================================
@@ -4302,6 +4502,7 @@ void CheckSystemValue(void)
 		{
 			ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
 			sendStopTransactionRequest(gun_index);
+			OCPP_updatePeriodEnergy(gun_index);
 			if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
 			refreshStartTimer(&clientTime.StopTransaction);
 			memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
@@ -10026,183 +10227,6 @@ void createFirmwareVersionByDataTransfer(void)
 	json_object_put(FirmwareDataTransfer);
 }
 
-int createPresetChargingedEnergyByDataTransfer(uint8_t gun_index, int transactionId)
-{
-	int result = FAIL;
-	int tempIndex;
-	json_object *EnergyDataTransfer = json_object_new_object();
-	json_object *periodEnergys = json_object_new_object();
-
-	if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
-	{
-		if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
-		{
-			tempIndex = ((gun_index==2) ? 1: 0);
-		}
-		else
-		{
-			tempIndex = gun_index;
-		}
-
-		for (int index = 0; index < CHAdeMO_QUANTITY; index++)
-		{
-			if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
-			{
-				if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionId)
-				{
-					json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(transactionId));
-
-					for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
-					{
-						uint8_t period[3];
-						sprintf((char*)period, "%d", idxPeriod);
-
-						json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
-					}
-
-					json_object_object_add(EnergyDataTransfer, "periodEnergy", json_object_new_string(json_object_to_json_string_ext(periodEnergys, JSON_C_TO_STRING_PLAIN)));
-
-					result = PASS;
-				}
-			} //end of the same index
-		}//end of for CHAdeMO_QUANTITY
-	}
-	else if(gunType[gun_index] == GUN_TYPE_CCS)
-	{
-		if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
-		{
-			tempIndex = ((gun_index==2) ? 1: 0);
-		}
-		else
-		{
-			tempIndex = gun_index;
-		}
-
-		for (int index = 0; index < CCS_QUANTITY; index++)
-		{
-			if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
-			{
-				if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionId)
-				{
-					json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(transactionId));
-
-					for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
-					{
-						uint8_t period[3];
-						sprintf((char*)period, "%d", idxPeriod);
-
-						json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
-					}
-
-					json_object_object_add(EnergyDataTransfer, "periodEnergy", json_object_new_string(json_object_to_json_string_ext(periodEnergys, JSON_C_TO_STRING_PLAIN)));
-
-					result = PASS;
-				}
-			} //end of the same index
-		} // end of for CCS_QUANTITY
-	}
-	else if(gunType[gun_index] == GUN_TYPE_GBT)
-	{
-		if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
-		{
-			tempIndex = ((gun_index==2) ? 1: 0);
-		}
-		else
-		{
-			tempIndex = gun_index;
-		}
-
-		for (int index = 0; index < GB_QUANTITY; index++)
-		{
-			if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
-			{
-				if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionId)
-				{
-					json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(transactionId));
-
-					for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
-					{
-						uint8_t period[3];
-						sprintf((char*)period, "%d", idxPeriod);
-
-						json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
-					}
-
-					json_object_object_add(EnergyDataTransfer, "periodEnergy", json_object_new_string(json_object_to_json_string_ext(periodEnergys, JSON_C_TO_STRING_PLAIN)));
-
-					result = PASS;
-				}
-			} //end of the same index
-		} // end of for GB_QUANTITY
-	}
-	else if(gunType[gun_index] == GUN_TYPE_DO)
-	{
-		tempIndex = gun_index;
-
-		for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
-		{
-			if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
-			{
-				if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionId)
-				{
-					json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(transactionId));
-
-					for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod);idxPeriod++)
-					{
-						uint8_t period[3];
-						sprintf((char*)period, "%d", idxPeriod);
-
-						json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod[idxPeriod]));
-					}
-
-					json_object_object_add(EnergyDataTransfer, "periodEnergy", json_object_new_string(json_object_to_json_string_ext(periodEnergys, JSON_C_TO_STRING_PLAIN)));
-
-					result = PASS;
-				}
-			} //end of the same index
-		}
-	}
-	else
-	{
-		if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
-		{
-			tempIndex = 2;
-		}
-		else
-		{
-			tempIndex = gun_index;
-		}
-
-		for (int index = 0; index < AC_QUANTITY; index++)
-		{
-			if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
-			{
-				if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionId)
-				{
-					json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(transactionId));
-
-					for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
-					{
-						uint8_t period[3];
-						sprintf((char*)period, "%d", idxPeriod);
-
-						json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
-					}
-
-					json_object_object_add(EnergyDataTransfer, "periodEnergy", json_object_new_string(json_object_to_json_string_ext(periodEnergys, JSON_C_TO_STRING_PLAIN)));
-
-					result = PASS;
-				}
-			}//end of the same index
-		}//end of for AC_QUANTITY
-	}
-
-	sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(EnergyDataTransfer, JSON_C_TO_STRING_PLAIN));
-	json_object_put(EnergyDataTransfer);
-
-	return result;
-}
-
 int handleDataTransferRequest(char *uuid, char *payload)
 {
 	mtrace();
@@ -10747,7 +10771,7 @@ int handleDataTransferRequest(char *uuid, char *payload)
 			{
 				if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
 				{
-					if(createPresetChargingedEnergyByDataTransfer((json_object_get_int(json_object_object_get(data, "ConnectorId"))-1), json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
+					if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
 					{
 						json_object_object_add(response, "status", json_object_new_string("Accepted"));
 						json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
@@ -14818,7 +14842,6 @@ void handleBootNotificationResponse(char *payload, int gun_index)
 
 	ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
 	BootNotificationInterval = intervalInt;
-	HeartBeatWaitTime = intervalInt;
 
 	//write back to ShmOCPP16Data->BootNotification
 	strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
@@ -14827,9 +14850,16 @@ void handleBootNotificationResponse(char *payload, int gun_index)
 
 	if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
 	{
+
+		if((intervalInt == 0) || (intervalInt >= 10))
+		{
+			sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
+			HeartBeatWaitTime = intervalInt;
+			DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
+		}
+
 		server_sign = TRUE;
 		server_pending =FALSE;
-
 	}
 	else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
 	{
@@ -20228,6 +20258,8 @@ void storeTempStopTransaction(int gun_index)
 	fputs("\n", outfile);
 	fclose (outfile);
 	system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
+
+	OCPP_updatePeriodEnergy(gun_index);
 }
 
 void checkTempStopTransaction(int gun_index)

+ 17 - 1
EVSE/Modularization/ocppfiles/Module_OcppBackend.c

@@ -92,7 +92,12 @@ static char *sqlOcppAuthLocal = "create table if not exists ocpp_auth_local (idx
 static char *sqlTransaction = "create table if not exists ocpp_transaction_record (idx integer primary key,"
 						      "occurDatetime text,"
 							  "message_type text,"
-							  "message_content text)";
+							  "message_content text);";
+
+static char *sqlPeriodEnergy = "create table if not exists ocpp_period_energy ( transactionId integer primary key UNIQUE,"
+							   "connectorId integer,"
+							   "occurDatetime text,"
+							   "periodEnergy text);";
 
 //=================================
 // Common routine
@@ -1465,6 +1470,17 @@ int main(void)
 		DEBUG_INFO( "Opened ocpp_transaction_record table successfully\n");
 	}
 
+	// Create transaction period energy
+	if(sqlite3_exec(db, sqlPeriodEnergy, 0, 0, &errMsg) != SQLITE_OK)
+	{
+		DEBUG_INFO( "Create Table ocpp_period_energy error %s\n",errMsg);
+		return 0;
+	}
+	else
+	{
+		DEBUG_INFO( "Opened ocpp_period_energy table successfully\n");
+	}
+
 	if(initialConfigurationTable() != PASS)
 	{
 		DEBUG_WARN("OCPPConfiguration version mismatch, upgrade it.\n");

+ 9 - 3
EVSE/Modularization/ocppph/MessageHandler.c

@@ -788,14 +788,14 @@ int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg
 	if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
 	{
 		result = FAIL;
-		DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
+		DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
 	}
 
 	sprintf(sqlStr, "delete from ocpp_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-2000) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
 	if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
 	{
 		result = FAIL;
-		DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
+		DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
 	}
 
 	return result;
@@ -14352,9 +14352,15 @@ void handleBootNotificationResponse(char *payload, int gun_index)
 
 	if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
 	{
+		if((intervalInt == 0) || (intervalInt >= 10))
+		{
+			sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
+			HeartBeatWaitTime = intervalInt;
+			DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
+		}
+
 		server_sign = TRUE;
 		server_pending =FALSE;
-
 	}
 	else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
 	{

+ 1 - 1
EVSE/Modularization/ocppph/Module_OcppBackend.c

@@ -92,7 +92,7 @@ static char *sqlOcppAuthLocal = "create table if not exists ocpp_auth_local (idx
 static char *sqlTransaction = "create table if not exists ocpp_transaction_record (idx integer primary key,"
 						      "occurDatetime text,"
 							  "message_type text,"
-							  "message_content text)";
+							  "message_content text);";
 
 //=================================
 // Common routine