2022-11-12 22:21:23 +08:00
|
|
|
#include "_mqtt__MQTT.h"
|
2022-11-13 14:52:39 +08:00
|
|
|
#include "mqttclient.h"
|
2022-11-12 22:21:23 +08:00
|
|
|
|
|
|
|
void _mqtt__MQTT___init__(PikaObj* self,
|
|
|
|
char* ip,
|
|
|
|
int port,
|
|
|
|
char* clinetID,
|
|
|
|
char* username,
|
|
|
|
char* password,
|
|
|
|
char* version,
|
|
|
|
char* ca,
|
|
|
|
int keepalive) {
|
2022-11-13 15:16:08 +08:00
|
|
|
mqtt_client_t* _client = mqtt_lease();
|
|
|
|
obj_setPtr(self, "_client", _client);
|
|
|
|
/* port to str, and cache to object */
|
|
|
|
char port_str[10] = {0};
|
|
|
|
__platform_sprintf(port_str, "%d", port);
|
|
|
|
obj_setStr(self, "port", port_str);
|
|
|
|
mqtt_set_port(_client, port_str);
|
|
|
|
|
|
|
|
mqtt_set_ca(_client, ca);
|
|
|
|
mqtt_set_host(_client, ip);
|
|
|
|
mqtt_set_client_id(_client, clinetID);
|
|
|
|
mqtt_set_user_name(_client, username);
|
|
|
|
mqtt_set_password(_client, password);
|
|
|
|
mqtt_set_clean_session(_client, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _mqtt__MQTT___del__(PikaObj* self) {
|
|
|
|
mqtt_client_t* _client = obj_getPtr(self, "_client");
|
|
|
|
if (NULL != _client) {
|
|
|
|
mqtt_release_free(_client);
|
|
|
|
}
|
2022-11-12 23:28:55 +08:00
|
|
|
}
|