88 lines
960 B
C
88 lines
960 B
C
#ifndef MQTT_MANAGER_H
|
|
#define MQTT_MANAGER_H
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
/*
|
|
* MQTT状态
|
|
*/
|
|
typedef enum
|
|
{
|
|
MQTT_STATE_INIT = 0,
|
|
MQTT_STATE_CONNECTING,
|
|
MQTT_STATE_CONNECTED,
|
|
MQTT_STATE_DISCONNECTED,
|
|
MQTT_STATE_ERROR
|
|
|
|
} mqtt_state_t;
|
|
|
|
|
|
|
|
/*
|
|
* MQTT消息接收回调
|
|
*
|
|
* topic:
|
|
* 主题
|
|
*
|
|
* payload:
|
|
* 数据
|
|
*
|
|
* len:
|
|
* 长度
|
|
*/
|
|
typedef void (*mqtt_message_callback_t)//函数指针==指针==保存函数地址的指针
|
|
(
|
|
const char *topic,
|
|
const uint8_t *payload,
|
|
uint32_t len
|
|
);
|
|
|
|
|
|
|
|
/*
|
|
* MQTT初始化
|
|
*/
|
|
int mqtt_manager_init(void);
|
|
|
|
|
|
|
|
/*
|
|
* 启动MQTT任务
|
|
*/
|
|
int mqtt_manager_start(void);
|
|
|
|
|
|
|
|
/*
|
|
* 发布数据
|
|
*/
|
|
int mqtt_manager_publish
|
|
(
|
|
const char *topic,
|
|
const uint8_t *data,
|
|
uint32_t len
|
|
);
|
|
|
|
|
|
|
|
/*
|
|
* 设置接收回调
|
|
*/
|
|
void mqtt_manager_set_callback
|
|
(
|
|
mqtt_message_callback_t callback
|
|
);
|
|
|
|
|
|
|
|
/*
|
|
* 获取MQTT状态
|
|
*/
|
|
mqtt_state_t mqtt_manager_get_state(void);
|
|
|
|
|
|
|
|
#endif |