2018-02-17 11:42:41 +07:00
|
|
|
/*
|
|
|
|
|
* This file is subject to the terms and conditions defined in
|
|
|
|
|
* file 'LICENSE', which is part of this source code package.
|
|
|
|
|
* Tuan PM <tuanpm at live dot com>
|
|
|
|
|
*/
|
|
|
|
|
|
2018-02-16 02:40:16 +07:00
|
|
|
#ifndef _MQTT_CLIENT_H_
|
|
|
|
|
#define _MQTT_CLIENT_H_
|
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
#include <string.h>
|
2018-03-26 16:07:20 +08:00
|
|
|
#include "esp_err.h"
|
2018-02-16 02:40:16 +07:00
|
|
|
|
|
|
|
|
#include "mqtt_config.h"
|
|
|
|
|
|
2018-05-27 04:50:31 +03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-02-16 02:40:16 +07:00
|
|
|
typedef struct esp_mqtt_client* esp_mqtt_client_handle_t;
|
|
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
|
MQTT_EVENT_ERROR = 0,
|
|
|
|
|
MQTT_EVENT_CONNECTED,
|
|
|
|
|
MQTT_EVENT_DISCONNECTED,
|
|
|
|
|
MQTT_EVENT_SUBSCRIBED,
|
|
|
|
|
MQTT_EVENT_UNSUBSCRIBED,
|
|
|
|
|
MQTT_EVENT_PUBLISHED,
|
|
|
|
|
MQTT_EVENT_DATA,
|
|
|
|
|
} esp_mqtt_event_id_t;
|
|
|
|
|
|
2018-02-22 10:07:57 +07:00
|
|
|
typedef enum {
|
|
|
|
|
MQTT_TRANSPORT_UNKNOWN = 0x0,
|
|
|
|
|
MQTT_TRANSPORT_OVER_TCP,
|
|
|
|
|
MQTT_TRANSPORT_OVER_SSL,
|
|
|
|
|
MQTT_TRANSPORT_OVER_WS,
|
|
|
|
|
MQTT_TRANSPORT_OVER_WSS
|
|
|
|
|
} esp_mqtt_transport_t;
|
|
|
|
|
|
2018-02-16 02:40:16 +07:00
|
|
|
typedef struct {
|
|
|
|
|
esp_mqtt_event_id_t event_id;
|
|
|
|
|
esp_mqtt_client_handle_t client;
|
|
|
|
|
void *user_context;
|
|
|
|
|
char *data;
|
|
|
|
|
int data_len;
|
2018-02-16 22:48:22 +07:00
|
|
|
int total_data_len;
|
|
|
|
|
int current_data_offset;
|
2018-02-16 02:40:16 +07:00
|
|
|
char *topic;
|
|
|
|
|
int topic_len;
|
|
|
|
|
int msg_id;
|
|
|
|
|
} esp_mqtt_event_t;
|
|
|
|
|
|
|
|
|
|
typedef esp_mqtt_event_t* esp_mqtt_event_handle_t;
|
|
|
|
|
|
|
|
|
|
typedef esp_err_t (* mqtt_event_callback_t)(esp_mqtt_event_handle_t event);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
mqtt_event_callback_t event_handle;
|
2018-05-03 21:50:24 +07:00
|
|
|
const char *host;
|
|
|
|
|
const char *uri;
|
2018-02-16 02:40:16 +07:00
|
|
|
uint32_t port;
|
2018-05-03 21:50:24 +07:00
|
|
|
const char *client_id;
|
|
|
|
|
const char *username;
|
|
|
|
|
const char *password;
|
|
|
|
|
const char *lwt_topic;
|
|
|
|
|
const char *lwt_msg;
|
2018-02-16 02:40:16 +07:00
|
|
|
int lwt_qos;
|
|
|
|
|
int lwt_retain;
|
2018-02-22 13:16:41 +01:00
|
|
|
int lwt_msg_len;
|
2018-02-16 18:46:13 +07:00
|
|
|
int disable_clean_session;
|
2018-02-16 02:40:16 +07:00
|
|
|
int keepalive;
|
2018-02-16 18:46:13 +07:00
|
|
|
bool disable_auto_reconnect;
|
2018-02-16 02:40:16 +07:00
|
|
|
void *user_context;
|
|
|
|
|
int task_prio;
|
|
|
|
|
int task_stack;
|
|
|
|
|
int buffer_size;
|
2018-02-16 22:00:57 +07:00
|
|
|
const char *cert_pem;
|
2018-02-22 10:07:57 +07:00
|
|
|
esp_mqtt_transport_t transport;
|
2018-02-16 02:40:16 +07:00
|
|
|
} esp_mqtt_client_config_t;
|
|
|
|
|
|
|
|
|
|
esp_mqtt_client_handle_t esp_mqtt_client_init(const esp_mqtt_client_config_t *config);
|
|
|
|
|
esp_err_t esp_mqtt_client_set_uri(esp_mqtt_client_handle_t client, const char *uri);
|
|
|
|
|
esp_err_t esp_mqtt_client_start(esp_mqtt_client_handle_t client);
|
|
|
|
|
esp_err_t esp_mqtt_client_stop(esp_mqtt_client_handle_t client);
|
|
|
|
|
esp_err_t esp_mqtt_client_subscribe(esp_mqtt_client_handle_t client, const char *topic, int qos);
|
|
|
|
|
esp_err_t esp_mqtt_client_unsubscribe(esp_mqtt_client_handle_t client, const char *topic);
|
|
|
|
|
int esp_mqtt_client_publish(esp_mqtt_client_handle_t client, const char *topic, const char *data, int len, int qos, int retain);
|
|
|
|
|
esp_err_t esp_mqtt_client_destroy(esp_mqtt_client_handle_t client);
|
|
|
|
|
|
2018-05-27 04:50:31 +03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif //__cplusplus
|
|
|
|
|
|
2018-02-16 02:40:16 +07:00
|
|
|
#endif
|