Using and changing Certificates with arduinoJSON

Hi everyone, I am trying to onboard a device on AWS IOT. The process is that you start with default certificates, you onboard and receive now ones, then you can use them. This is arduino on ESP32, but I struggle with the char arrays and copies...

So I need to:

  • store a string in a JSON document (a default certificate)
  • Save that JSON to file
    then later:
  • Load the string, and onboard my device which will then receive its final certificate
  • change the certificate string with that new value
  • Save to file again to keep the new certi hardcoded.

My first issue: saving the default certificate. In the code below I have tried different formats

char* AWS_CERT_CA = \                              
"-----BEGIN CERTIFICATE-----\n" \
"5MsI+yMRQ+h.....................K642M4UwtBV8ob2xJNDd2ZhwLnoQdeXeGADbkpy\n" \
"rqXRfboQnoZsG4q5WTP468SQvvG5\n" \
"-----END CERTIFICATE-----\n"; 

(and same for AWS_CERT_CRT and AWS_CERT_PRIVATE)

const int capacity = 100 + JSON_OBJECT_SIZE(3);
  StaticJsonDocument<capacity> doc;
  File file;
  //Save to file
  file =, "w+");  //Create file
 doc["AWS_CERT_CRT"] = (char*)AWS_CERT_CRT;
 if (serializeJson(doc, file) == 0) {
   Serial.println(F("Failed to write to file"));
 } else Serial.println("file written");

When I print the resulting file, it gives that result:

10:06:18.031 -> Load certificates from file

How can I write the certificate correctly?

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.