MicroOcpp icon indicating copy to clipboard operation
MicroOcpp copied to clipboard

ESP gets rebooted when getDiagnostics was called from CMS

Open VjSargunam opened this issue 2 years ago • 7 comments

Hi Matt,

I tried to get the getdiagnostics.log file from the OCPP client. I initiated the GetDiagnostics request from CMS as below. [2,"815b4363-d702-4931-971d-e557bf2e38ea","GetDiagnostics",{"location":"ftp://<username>:<password>@rrthost.myftp.org","retries":1,"retryInterval":1,"startTime":"2023-10-09T09:25:23.000Z","stopTime":"2023-10-09T09:25:23.000Z"}]. But whenever I initiate this request the esp32 gets crashed and rebooted automatically. is this the correct way to initiate the request. please clarify.And this is my CMS requesting format for location ex:ftp://ftpusername:password@ftpserverIP/locationUrl/DiagnosticsFileName.gpg

Regards VJSargunam

VjSargunam avatar Oct 09 '23 09:10 VjSargunam

Hi @VjSargunam,

At the moment, there's no integrated logging / file upload mechanism. The OCPP specs also lack a description of what should be part of the diagnostics file and I believe that the vendor should decide it, so I left the diagnostics functionality very minimal but customizable.

To implement GetDiagnostics, the OCPP lib needs to be configured with a custom upload handler and an upload status input. When the server sends a GetDiagnostics request to the charger, then the OCPP lib executes the upload handler and forwards all parameters to it. The custom upload handler needs to implement the generation of the diagnostics data and the actual file upload. During the process, the OCPP lib polls the upload status input so that it can inform the server about the current progress via DiagnosticsStatusNotification messages.

As an example, the OpenEVSE platform uses the HTTP protocol to upload its event history to the server: https://github.com/OpenEVSE/openevse_esp32_firmware/blob/8c9a482c912005f4c5f0e2d82d2f596e665dd6eb/src/ocpp.cpp#L480-L595

Currently I'm evaluating an FTP client based on Mongoose which I published in the MicroOcppMongoose repository with very promising results. I'm planning to release an application reference very soon.

Btw. and thank you very much for the bug report. Of course the library shouldn't crash when there's no diagnostics handler. This is already fixed in the develop branch.

matth-x avatar Oct 10 '23 09:10 matth-x

Hi Matt, How to call the custom upload handler from main.cpp for the current version of OCPP library

VjSargunam avatar Oct 10 '23 11:10 VjSargunam

To configure the library with the custom upload handler in main.cpp, fetch the DiagnosticsService object and pass the upload handler to it like this:

// your upload handler
bool customUploadHandler(const std::string &location, ArduinoOcpp::Timestamp &startTime, ArduinoOcpp::Timestamp &stopTime) {
    //TODO collect your hardware data here

    //TODO upload the diagnostics file to `location`

    return true;
}

void setup() {
    // initialize the charger and MicroOcpp here

    // fetch the DiagnosticsService object and configure it
    MicroOcpp::DiagnosticsService *diagService = getDiagnosticsService();
    if (diagService) {
        // set the custom upload handler defned above which the library will call now as soon as a GetDiagnostic request comes in
        diagService->setOnUpload(customUploadHandler);
    }

}

Generally, the OpenEVSE reference integration of GetDiagnostics is still up to date with the master branch (apart from the project name change from ArduinoOcpp to MicroOcpp). Especially, it shows how collecting the diagnostics data and uploading it to the server can look like.

matth-x avatar Oct 14 '23 17:10 matth-x

Hi Matt, Thanks for your reply. Is this scenario being same for firmware update too? Or is there is any other approach to do the same?

VjSargunam avatar Oct 16 '23 05:10 VjSargunam

Yes, the approach is the same.

Again, the OpenEVSE integration is a reference for the custom FW update. On top of that, the OCPP lib also includes a very simple demo FW update handler (https://github.com/matth-x/MicroOcpp/blob/master/src/MicroOcpp/Model/FirmwareManagement/FirmwareService.cpp#L336-L369). It works for the ESP platforms if using the default links2004 WebSocket lib. Furthermore, the UpdateFirmware request needs to point to an http:// location.

matth-x avatar Oct 16 '23 10:10 matth-x

Hi Matt, As per your suggestion I included this piece of code MicroOcpp::DiagnosticsService *diagService = getDiagnosticsService(); in the setup() function to initialize getdiagnostic service but iam getting error likeidentifier "getDiagnosticsService();" is undefined while compile the code. I even added the header file #include <MicroOcpp/Model/Diagnostics/DiagnosticsService.h> in the main.cpp but still iam getting the above error. please clarify

VjSargunam avatar Oct 31 '23 09:10 VjSargunam

Oh this function is excluded by an #if preprocessor statement and needs to be enabled first (probably I will change it to enabled by default in a future version). Set the build flag MO_CUSTOM_DIAGNOSTICS (or MOCPP_CUSTOM_DIAGNOSTICS, depending on your version), in the platformio.ini and then it should be there.

matth-x avatar Oct 31 '23 11:10 matth-x