implemented downstream topic subscribe and receive

This commit is contained in:
strawmanbobi
2022-03-19 15:53:39 +08:00
parent 74e9328092
commit 0ef02dcf4b
4 changed files with 47 additions and 25 deletions

View File

@@ -148,7 +148,7 @@ int AliyunIoTSDK::mqttCheckConnect() {
return mqttStatus;
}
void AliyunIoTSDK::begin(Client &espClient,
int AliyunIoTSDK::begin(Client &espClient,
const char *_productKey,
const char *_deviceName,
const char *_deviceSecret,
@@ -189,7 +189,7 @@ void AliyunIoTSDK::begin(Client &espClient,
client->setCallback(callback);
#endif
mqttCheckConnect();
return mqttCheckConnect();
}
int AliyunIoTSDK::loop() {
@@ -236,6 +236,10 @@ void AliyunIoTSDK::sendCustomData(const char *topic, const uint8_t *data, int le
Serial.println(d);
}
boolean AliyunIoTSDK::subscribe(const char* topic, int qos) {
return client->subscribe(topic, qos);
}
void AliyunIoTSDK::registerCustomCallback(MQTT_CALLBACK_SIGNATURE) {
client->setCallback(callback);
}

View File

@@ -64,11 +64,11 @@ public:
* @param _deviceSecret : AliyunIoT device secret
* @param _region : AliyunIoT region
*/
static void begin(Client &espClient,
const char *_productKey,
const char *_deviceName,
const char *_deviceSecret,
const char *_region);
static int begin(Client &espClient,
const char *_productKey,
const char *_deviceName,
const char *_deviceSecret,
const char *_region);
/**
* Send data
@@ -134,9 +134,18 @@ public:
*/
static void sendCustomData(const char *topic, const uint8_t *data, int length);
/**
* Subscribe MQTT topic for Aliot
*
* @param topic : topic in string
* @param qos : MQTT qos param
* @return if succeeded
*/
static boolean subscribe(const char* topic, int qos);
/**
* Register customized MQTT message callback
*
*
* @param callback : callback pointer
*/
static void registerCustomCallback(MQTT_CALLBACK_SIGNATURE);