2021-09-18 13:45:24 +08:00
|
|
|
#ifndef MQTTCLIENT_H
|
|
|
|
#define MQTTCLIENT_H
|
|
|
|
|
|
|
|
#include "../common/SH_CommonFunc.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注册
|
|
|
|
extern 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);
|
|
|
|
extern int data_publish(const char *str, const char* topic);
|
|
|
|
extern int data_publish_wave(WAVE_CONTAIN *str, const char *topic);
|
|
|
|
extern int disconnect();
|
2024-07-09 09:49:42 +08:00
|
|
|
extern int reconnect();
|
2021-09-18 13:45:24 +08:00
|
|
|
extern int subscribe(const char* topic, int qos);
|
|
|
|
extern int unsubscribe(const char* topic);
|
|
|
|
extern 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
|