MicroOcpp icon indicating copy to clipboard operation
MicroOcpp copied to clipboard

If GetDiagnostics failed again, charger didn't send DiagnosticsStatusNotification

Open JungHeum-Park opened this issue 1 year ago • 1 comments

Hi @matth-x . I'm using v1.2.0. I'm working with FirmwareUpdate/Diagnostics.

After Diagnostics upload failed, if I request GetDiagnostic again, charger didn't send DiagnosticsStatusNotification.

Here's log

[MO] Recv: [2,"81ce6fca-6967-48ff-8391-1255116ca892","GetDiagnostics",{"location":"ftp://127.0.0.1:21/files/failedLocation"}]
[MO] info (DiagnosticsService.cpp:173): Scheduled Diagnostics upload!
                  location = ftp://127.0.0.1:21/files/failedLocation/diagnostics.log
                  retries = 1, retryInterval = 20                  startTime = 1970-01-01T00:00:00Z
                  stopTime = 2026-01-24T05:13:41Z
[MO] debug (DiagnosticsService.cpp:185): Initial try at 2025-01-24T05:13:47Z
[MO] verbose (RequestQueue.cpp:74): front 1 len 0
[MO] Send: [3,"81ce6fca-6967-48ff-8391-1255116ca892",{"fileName":"diagnostics.log"}]
[MO] debug (DiagnosticsService.cpp:66): Call onUpload
[MO] debug (DiagnosticsService.cpp:379): discovered 3 files
[MO] debug (FtpMbedTLS.cpp:504): init upload ftp://127.0.0.1:21/files/failedLocation/diagnostics.log
[MO] debug (FtpMbedTLS.cpp:829): parsed dir: /files/failedLocation; fname: diagnostics.log
[MO] debug (FtpMbedTLS.cpp:854): parsed user: ; pass: -***
[MO] debug (FtpMbedTLS.cpp:871): parsed host: 127.0.0.1; port: 21
[MO] ERROR (FtpMbedTLS.cpp:276): mbedtls_net_connect: 1
[MO] ERROR (FtpMbedTLS.cpp:302): connect: 1
[MO] ERROR (FtpMbedTLS.cpp:522): could not establish connection to FTP server: 1
[MO] info (DiagnosticsService.cpp:469): FTP upload failure (2)
[MO] warning (DiagnosticsService.cpp:99): Upload timeout or failed
[MO] debug (DiagnosticsService.cpp:112): end upload routine (no more retry)
[MO] verbose (RequestQueue.cpp:74): front 3 len 0
[MO] Send: [2,"b177a108-92fa-e60a-66bc-639534ecf5d3","DiagnosticsStatusNotification",{"status":"UploadFailed"}]
[MO] Recv: [3,"b177a108-92fa-e60a-66bc-639534ecf5d3",{}]
[MO] Recv: WS pong
[MO] Recv: WS pong
[MO] Recv: WS pong
[MO] Recv: WS pong
[MO] Recv: WS pong
[MO] Recv: [2,"36c364c0-aa10-4aaf-9b68-7203256f0dbe","GetDiagnostics",{"location":"ftp://127.0.0.1:21/files/failedLocation"}]
[MO] info (DiagnosticsService.cpp:173): Scheduled Diagnostics upload!
                  location = ftp://127.0.0.1:21/files/failedLocation/diagnostics.log
                  retries = 1, retryInterval = 20                  startTime = 1970-01-01T00:00:00Z
                  stopTime = 2026-01-24T05:14:51Z
[MO] debug (DiagnosticsService.cpp:185): Initial try at 2025-01-24T05:14:56Z
[MO] verbose (RequestQueue.cpp:74): front 2 len 0
[MO] Send: [3,"36c364c0-aa10-4aaf-9b68-7203256f0dbe",{"fileName":"diagnostics.log"}]
[MO] debug (DiagnosticsService.cpp:66): Call onUpload
[MO] debug (DiagnosticsService.cpp:379): discovered 3 files
[MO] debug (FtpMbedTLS.cpp:504): init upload ftp://127.0.0.1:21/files/failedLocation/diagnostics.log
[MO] debug (FtpMbedTLS.cpp:829): parsed dir: /files/failedLocation; fname: diagnostics.log
[MO] debug (FtpMbedTLS.cpp:854): parsed user: ; pass: -***
[MO] debug (FtpMbedTLS.cpp:871): parsed host: 127.0.0.1; port: 21
[MO] ERROR (FtpMbedTLS.cpp:276): mbedtls_net_connect: 1
[MO] ERROR (FtpMbedTLS.cpp:302): connect: 1
[MO] ERROR (FtpMbedTLS.cpp:522): could not establish connection to FTP server: 1
[MO] info (DiagnosticsService.cpp:469): FTP upload failure (2)
[MO] warning (DiagnosticsService.cpp:99): Upload timeout or failed
[MO] debug (DiagnosticsService.cpp:112): end upload routine (no more retry)
[MO] Recv: WS pong
[MO] Recv: WS pong
[MO] Recv: WS pong

I think the cause of this is that lastReportedStatus has not changed, but I need to check the exact details more.

std::unique_ptr<Request> DiagnosticsService::getDiagnosticsStatusNotification() {
     
    if (getDiagnosticsStatus() != lastReportedStatus) {
        lastReportedStatus = getDiagnosticsStatus();

        if (lastReportedStatus != DiagnosticsStatus::Idle) {
            Operation *diagNotificationMsg = new Ocpp16::DiagnosticsStatusNotification(lastReportedStatus);
            auto diagNotification = makeRequest(diagNotificationMsg);
            return diagNotification;
        }
    }

    return nullptr;
}

JungHeum-Park avatar Jan 24 '25 05:01 JungHeum-Park

I add uploadFailure = false; In Model/DiagnosticsService requestDiagnosticsUpload() and It looks working for now.

//timestamps before year 2021 will be treated as "undefined"
MicroOcpp::String DiagnosticsService::requestDiagnosticsUpload(const char *location, unsigned int retries, unsigned int retryInterval, Timestamp startTime, Timestamp stopTime) {
    if (onUpload == nullptr) {
        return makeString(getMemoryTag());
    }

    String fileName;
    if (refreshFilename) {
        fileName = refreshFilename().c_str();
    } else {
        fileName = "diagnostics.log";
    }

    this->location.reserve(strlen(location) + 1 + fileName.size());

    this->location = location;

    if (!this->location.empty() && this->location.back() != '/') {
        this->location.append("/");
    }
    this->location.append(fileName.c_str());

    this->retries = retries;
    this->retryInterval = retryInterval;
    this->startTime = startTime;
    
    Timestamp stopMin = Timestamp(2021,0,0,0,0,0);
    if (stopTime >= stopMin) {
        this->stopTime = stopTime;
    } else {
        auto newStop = context.getModel().getClock().now();
        newStop += 3600 * 24 * 365; //set new stop time one year in future
        this->stopTime = newStop;
    }
    
#if MO_DBG_LEVEL >= MO_DL_INFO
    {
        char dbuf [JSONDATE_LENGTH + 1] = {'\0'};
        char dbuf2 [JSONDATE_LENGTH + 1] = {'\0'};
        this->startTime.toJsonString(dbuf, JSONDATE_LENGTH + 1);
        this->stopTime.toJsonString(dbuf2, JSONDATE_LENGTH + 1);

        MO_DBG_INFO("Scheduled Diagnostics upload!\n" \
                        "                  location = %s\n" \
                        "                  retries = %i" \
                        ", retryInterval = %u" \
                        "                  startTime = %s\n" \
                        "                  stopTime = %s",
                this->location.c_str(),
                this->retries,
                this->retryInterval,
                dbuf,
                dbuf2);
    }
#endif

    nextTry = context.getModel().getClock().now();
    nextTry += 5; //wait for 5s before upload
    uploadIssued = false;
    uploadFailure = false; //THIS IS ADDED ONE
#if MO_DBG_LEVEL >= MO_DL_DEBUG
    {
        char dbuf [JSONDATE_LENGTH + 1] = {'\0'};
        nextTry.toJsonString(dbuf, JSONDATE_LENGTH + 1);
        MO_DBG_DEBUG("Initial try at %s", dbuf);
    }
#endif

    return fileName;
}

JungHeum-Park avatar Jan 24 '25 06:01 JungHeum-Park