shuichan_new/STM32F103_App1/HardWare/WIFI/mqtt_client.h

29 lines
1.3 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef MQTT_CLIENT_H
#define MQTT_CLIENT_H
#include <stdint.h>
/* 精简版 MQTT 3.1.1 客户端:跑在 ESP-01S TCP 透传之上。
* 参考工程《4路继电器控制带WIFI和4G V3.4 WIFI无回弹》HARDWARE/ML302/mqtt.c
* 的报文拼接逻辑重写,去掉 6KB 环形缓冲RAM 紧张),
* 发送用单缓冲(主循环串行发布),接收直接从共享 U2_CopyBuff 切帧。 */
#define MQTT_KEEPALIVE_S 60 /* CONNECT 报文中的 keepalive */
/* PINGREQ 发出后置1收到 PINGRESP 清0net_wifi 据此判断链路存活 */
extern volatile uint8_t g_mqttc_ping_outstanding;
void mqttc_init(const char *client_id, const char *user, const char *pass);
int mqttc_connect(void); /* 发 CONNECT 等 CONNACK, 0=成功 */
int mqttc_subscribe(const char *topic); /* 发 SUBSCRIBE(QoS0) 等 SUBACK, 0=成功 */
int mqttc_publish(const char *topic, const char *payload); /* QoS0 发布, 0=成功 */
int mqttc_publish_qos1(const char *topic, const char *payload, uint16_t pkt_id); /* QoS1 发布(带报文标识符), 0=成功 */
int mqttc_wait_puback(uint16_t pkt_id, int timeout_ms); /* 等 PUBACK(调用方不得持有 net_at 锁), 0=收到 */ /* QoS0 发布, 0=成功 */
void mqttc_ping(void); /* 发 PINGREQ */
/* 从共享接收缓冲解析一条完整 MQTT 报文(粘包/半包安全)。
* 返回 1=处理了一条(可再调), 0=暂无完整报文, -1=链路断开(收到 CLOSED) */
int mqttc_process(void);
#endif /* MQTT_CLIENT_H */