2025-01-23 11:13:58 +08:00
|
|
|
#ifndef MQTTCLIENT_H
|
|
|
|
|
#define MQTTCLIENT_H
|
|
|
|
|
|
|
|
|
|
#include "common/common_func.hpp"
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
#include "mosquitto.h"
|
|
|
|
|
|
|
|
|
|
struct userdata {
|
|
|
|
|
char **topics;
|
|
|
|
|
int topic_count;
|
|
|
|
|
int topic_qos;
|
|
|
|
|
char **filter_outs;
|
|
|
|
|
int filter_out_count;
|
|
|
|
|
char *username;
|
|
|
|
|
char *password;
|
|
|
|
|
char *resp_topic;
|
|
|
|
|
char *gwid;
|
|
|
|
|
char *dataUrl;
|
|
|
|
|
char *fsUrl;
|
|
|
|
|
int verbose;
|
|
|
|
|
bool quiet;
|
|
|
|
|
bool no_retain;
|
|
|
|
|
bool eol;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef struct mqttsinfo {
|
|
|
|
|
char domain[100];
|
|
|
|
|
char devicekey[36];
|
|
|
|
|
char gwid[21];
|
|
|
|
|
int port;
|
|
|
|
|
char username[100];
|
|
|
|
|
char password[100];
|
|
|
|
|
char dataUrl[100];
|
|
|
|
|
char fsUrl[100];
|
|
|
|
|
char salt[100];
|
|
|
|
|
int ssl;
|
|
|
|
|
int qos;
|
|
|
|
|
int encrypt;
|
|
|
|
|
} mqttsdata_t;
|
|
|
|
|
|
|
|
|
|
extern struct userdata ud;
|
|
|
|
|
typedef void (*connect_callback)(struct mosquitto *mosq, void *obj, int result);
|
|
|
|
|
typedef void (*disconnect_callback)(struct mosquitto *mosq, void *obj, int result);
|
|
|
|
|
typedef void (*message_callback)(struct mosquitto *mosq, void *obj, const struct mosquitto_message *message);
|
|
|
|
|
typedef void (*subscribe_callback)(struct mosquitto *mosq, void *obj, int mid, int qos_count, const int *granted_qos);
|
|
|
|
|
typedef void (*log_callback)(struct mosquitto *mosq, void *obj, int level, const char *str);
|
|
|
|
|
typedef void (*publish_callback)(struct mosquitto *mosq, void *obj, int mid);
|
|
|
|
|
|
|
|
|
|
// mqtt注册
|
|
|
|
|
void register_collback(connect_callback connect_c, message_callback message_c, subscribe_callback subscribe_c, log_callback log_c, disconnect_callback disconnect_c, publish_callback publish_c);
|
|
|
|
|
int data_publish(const char *str, const char *topic);
|
|
|
|
|
int disconnect();
|
|
|
|
|
int reconnect();
|
|
|
|
|
int subscribe(const char *topic, int qos);
|
|
|
|
|
int unsubscribe(const char *topic);
|
|
|
|
|
int start_client(const char *boardname, const char *gwid, const char *gwip, const char *gwver, const char *gwcode, std::string &salt);
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|