Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Functions to store and load MQTT config attributes to/from NVS storage. based on ESP-IDF.

License

Notifications You must be signed in to change notification settings

mdvorak-iot/esp-aws-iot-mqtt-config

Repository files navigation

aws_iot_mqtt_config component

platformio build

Component for ESP-IDF. Provides functions to store and load MQTT config attributes to/from NVS storage.

Following attributes are managed:

  • host
  • port
  • uri
  • cert_pem, cert_len
  • client_cert_pem, client_cert_len
  • client_key_pem, client_key_len
  • clientkey_password, clientkey_password_len

Usage

When used as IDF component, add it as a Git submodule

git submodule add https://github.com/mdvorak-iot/esp-aws-iot-mqtt-config.git components/aws_iot_mqtt_config

When used as platformio library, add it to platformio.ini:

[env]
lib_deps = https://github.com/mdvorak-iot/esp-aws-iot-mqtt-config.git

Code

See example.

Note that when attributes are loaded into config, they are newly allocated and should be freed when not needed.

esp_mqtt_client_init() method creates copy of some attributes, but does not copy certificates and key. Those must not be freed as long as mqtt client exists.

esp_mqtt_client_config_t mqtt_cfg = {};
mqtt_cfg.cert_pem = AWS_IOT_ROOT_CA;
mqtt_cfg.cert_len = AWS_IOT_ROOT_CA_LEN;
ESP_ERROR_CHECK(aws_iot_mqtt_config_load(&mqtt_cfg));

esp_mqtt_client_handle_t mqtt_client = esp_mqtt_client_init(&mqtt_cfg);
// ...

aws_iot_mqtt_config_free_unused(&mqtt_cfg);
ESP_ERROR_CHECK(esp_mqtt_client_start(mqtt_client));

About

Functions to store and load MQTT config attributes to/from NVS storage. based on ESP-IDF.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published