|
@@ -39,6 +39,7 @@ uint8_t isQueueSendable = 1;
|
|
|
uint8_t counterLwsRestart = 0;;
|
|
|
uint8_t counterQueueSent = 0;
|
|
|
uint8_t counterConnect = 0;
|
|
|
+uint8_t counterPingSend = 0;
|
|
|
|
|
|
//=================================
|
|
|
// Common routine
|
|
@@ -253,10 +254,8 @@ static int OCPP20Callback(struct lws *wsi, enum lws_callback_reasons reason, voi
|
|
|
ConnectionEstablished=0;
|
|
|
break;
|
|
|
case LWS_CALLBACK_CLIENT_WRITEABLE://10
|
|
|
- if((0 < GetWebSocketPingInterval()) && (GetWebSocketPingInterval() <= getDiffSecNow(startTime.pingOn)) && (GetServerSign() == TRUE))
|
|
|
- {
|
|
|
+ if(isWebsocketSendable && (0 < GetWebSocketPingInterval()) && (GetWebSocketPingInterval() <= getDiffSecNow(startTime.pingOn)) && (GetServerSign() == TRUE))
|
|
|
SendPing(wsi);
|
|
|
- }
|
|
|
else
|
|
|
SendData(wsi);
|
|
|
break;
|
|
@@ -305,6 +304,8 @@ static int OCPP20Callback(struct lws *wsi, enum lws_callback_reasons reason, voi
|
|
|
DEBUG_INFO("LWS_CALLBACK_CLIENT_RECEIVE_PONG\n");
|
|
|
DEBUG_OCPPMESSAGE_INFO("<==== Get PONG packet.\n");
|
|
|
refreshStartTimer(&startTime.pingOn);
|
|
|
+ isWebsocketSendable = ON;
|
|
|
+ counterPingSend = 0;
|
|
|
break;
|
|
|
case LWS_CALLBACK_OPENSSL_PERFORM_SERVER_CERT_VERIFICATION:
|
|
|
DEBUG_INFO("LWS_CALLBACK_OPENSSL_PERFORM_SERVER_CERT_VERIFICATION\n");
|
|
@@ -977,23 +978,11 @@ void* processWatchdog()
|
|
|
system("pkill OcppBackend20");
|
|
|
}
|
|
|
|
|
|
- /*
|
|
|
- if(system("pidof -s Module_PhBackend > /dev/null") != 0)
|
|
|
- {
|
|
|
- DEBUG_INFO("Module_PhBackend not running, restart it.\r\n");
|
|
|
- system("/root/Module_PhBackend &");
|
|
|
- }*/
|
|
|
-
|
|
|
if((0 < GetWebSocketPingInterval()) && ((GetWebSocketPingInterval()+5) <= getDiffSecNow(startTime.pingOn)) && (wsi_client != NULL) && (GetServerSign() == TRUE))
|
|
|
{
|
|
|
DEBUG_WARN("Pong packet receive timeout.\n");
|
|
|
system("pkill OcppBackend20");
|
|
|
}
|
|
|
- else if((0 < GetWebSocketPingInterval()) && (GetWebSocketPingInterval() <= getDiffSecNow(startTime.pingOn)) && (wsi_client != NULL) && (GetServerSign() == TRUE))
|
|
|
- {
|
|
|
- lws_callback_on_writable(wsi_client);
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
usleep(500000);
|
|
|
}
|
|
@@ -1189,6 +1178,13 @@ int main(void)
|
|
|
// Check System Value
|
|
|
CheckSystemValue();
|
|
|
|
|
|
+ // PING packet
|
|
|
+ if(isWebsocketSendable && (0 < GetWebSocketPingInterval()) && ((GetWebSocketPingInterval()+counterPingSend) <= getDiffSecNow(startTime.pingOn)))
|
|
|
+ {
|
|
|
+ lws_callback_on_writable(wsi_client);
|
|
|
+ counterPingSend++;
|
|
|
+ }
|
|
|
+
|
|
|
if(GetHeartBeatWithNOResponse() >= 30)
|
|
|
{
|
|
|
lws_context_destroy(context);
|