I modified the subcribe and publish code and edited sd Card section here is my code :
Code: Select all
#if defined(CONFIG_EXAMPLE_EMBEDDED_CERTS)
mqttInitParams.pRootCALocation = (const char *)aws_root_ca_pem_start;
mqttInitParams.pDeviceCertLocation = (const char *)certificate_pem_crt_start;
mqttInitParams.pDevicePrivateKeyLocation = (const char *)private_pem_key_start;
#elif defined(CONFIG_EXAMPLE_FILESYSTEM_CERTS)
mqttInitParams.pRootCALocation = ROOT_CA_PATH;
mqttInitParams.pDeviceCertLocation = DEVICE_CERTIFICATE_PATH;
mqttInitParams.pDevicePrivateKeyLocation = DEVICE_PRIVATE_KEY_PATH;
#endif
mqttInitParams.mqttCommandTimeout_ms = 20000;
mqttInitParams.tlsHandshakeTimeout_ms = 5000;
mqttInitParams.isSSLHostnameVerify = true;
mqttInitParams.disconnectHandler = disconnectCallbackHandler;
mqttInitParams.disconnectHandlerData = NULL;
#ifdef CONFIG_EXAMPLE_SDCARD_CERTS
ESP_LOGI(TAG, "Initializing SPIFFS");
esp_vfs_spiffs_conf_t conf = {
.base_path = "/spiffs",
.partition_label = NULL,
.max_files = 5,
.format_if_mount_failed = false
};
// Use settings defined above to initialize and mount SPIFFS filesystem.
// Note: esp_vfs_spiffs_register is an all-in-one convenience function.
esp_err_t ret = esp_vfs_spiffs_register(&conf);
if (ret != ESP_OK) {
if (ret == ESP_FAIL) {
ESP_LOGE(TAG, "Failed to mount or format filesystem");
} else if (ret == ESP_ERR_NOT_FOUND) {
ESP_LOGE(TAG, "Failed to find SPIFFS partition");
} else {
ESP_LOGE(TAG, "Failed to initialize SPIFFS (%d)", ret);
}
return;
}else
ESP_LOGW(TAG,"spiffs register Status: %d",ret);
size_t total = 0, used = 0;
ret = esp_spiffs_info(NULL, &total, &used);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "Failed to get SPIFFS partition information");
} else {
ESP_LOGW(TAG, "Partition size: total: %d, used: %d", total, used);
}
if( esp_spiffs_mounted(conf.partition_label))
{
ESP_LOGW(TAG,"SPIFFS Mounted.......");
}else
ESP_LOGW(TAG,"SPIFFS NOT Mounted.......");
// Check if destination file exists
struct stat st;
if (stat(ROOT_CA_PATH, &st) == 0) {
ESP_LOGI(TAG,"FILE EXIST")
}
if (stat(DEVICE_CERTIFICATE_PATH, &st) == 0) {
ESP_LOGI(TAG,"FILE EXIST")
}
if (stat(DEVICE_PRIVATE_KEY_PATH, &st) == 0) {
ESP_LOGI(TAG,"FILE EXIST")
}
#endif
rc = aws_iot_mqtt_init(&client, &mqttInitParams);
there is some problem that I face
my log
Code: Select all
I (276) subpub: AWS IoT SDK Version 2.2.1-
I (276) subpub: Initializing SPIFFS
W (296) subpub: spiffs register Status: 0
W (296) subpub: Partition size: total: 52961, used: 5773
W (296) subpub: SPIFFS Mounted.......
I (296) subpub: FILE EXIST
I (306) subpub: FILE EXIST
I (306) subpub: FILE EXIST
I (1606) wifi: n:11 0, o:1 0, ap:255 255, sta:11 0, prof:1
I (2596) wifi: state: init -> auth (b0)
I (3596) wifi: state: auth -> init (2)
I (3596) wifi: n:11 0, o:11 0, ap:255 255, sta:11 0, prof:1
I (3716) wifi: n:11 0, o:11 0, ap:255 255, sta:11 0, prof:1
I (3716) wifi: state: init -> auth (b0)
I (3716) wifi: state: auth -> assoc (0)
I (3726) wifi: state: assoc -> run (10)
I (3746) wifi: connected with UNICORN, channel 11
I (5106) event: sta ip: 192.168.43.197, mask: 255.255.255.0, gw: 192.168.43.1
I (5106) subpub: Connecting to AWS...
E (5106) aws_iot: failed! mbedtls_x509_crt_parse returned -0x3e00 while parsing root cert
E (5116) subpub: Error(-19) connecting to :8883
E (6116) aws_iot: failed! mbedtls_x509_crt_parse returned -0x3e00 while parsing root cert
E (6116) subpub: Error(-19) connecting to :8883