50 lines
1.6 KiB
C
50 lines
1.6 KiB
C
/* ESP drivers */
|
|
#include "esp_log.h"
|
|
#include "esp_system.h"
|
|
#include "esp_tls.h"
|
|
|
|
/* Cert bundle */
|
|
#include "esp_crt_bundle.h"
|
|
|
|
/* MQTT client */
|
|
#include "mqtt_client.h"
|
|
|
|
extern const char mqtt_client_cert_start[] asm("_binary_client_crt_start");
|
|
extern const char mqtt_client_cert_end[] asm("_binary_client_crt_end");
|
|
extern const char mqtt_client_key_start[] asm("_binary_client_key_start");
|
|
extern const char mqtt_client_key_end[] asm("_binary_client_key_end");
|
|
|
|
static void app_mqtt_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data);
|
|
static void app_mqtt_task(void *pvParameters);
|
|
|
|
esp_err_t app_mqtt_init(void) {
|
|
if (xTaskCreate(app_mqtt_task, "MQ_TASK", 2048, NULL, 2U, NULL) != pdPASS) {
|
|
return ESP_FAIL;
|
|
}
|
|
|
|
return ESP_OK;
|
|
}
|
|
|
|
static void app_mqtt_task(void *pvParameters) {
|
|
const esp_mqtt_client_config_t mqtt_cfg = {
|
|
.uri = CONFIG_APP_MQTT_BROKER_ADDR,
|
|
.client_cert_pem = mqtt_client_cert_start,
|
|
.client_key_pem = mqtt_client_key_start,
|
|
.clientkey_password = CONFIG_APP_MQTT_TLS_CLIENT_PASSPHRASE,
|
|
.clientkey_password_len = strlen(CONFIG_APP_MQTT_TLS_CLIENT_PASSPHRASE),
|
|
.crt_bundle_attach = esp_crt_bundle_attach,
|
|
};
|
|
|
|
esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt_cfg);
|
|
esp_mqtt_client_register_event(client, ESP_EVENT_ANY_ID, app_mqtt_event_handler, NULL);
|
|
|
|
esp_mqtt_client_start(client);
|
|
|
|
for (;;) {
|
|
vTaskSuspend(NULL);
|
|
}
|
|
}
|
|
|
|
static void app_mqtt_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data) {
|
|
/**/
|
|
} |