mqtt client release v1.1.0 ...
This commit is contained in:
@@ -19,15 +19,14 @@
|
||||
static void tos_topic_handler(void* client, message_data_t* msg)
|
||||
{
|
||||
(void) client;
|
||||
LOG_I("-----------------------------------------------------------------------------------");
|
||||
LOG_I("%s:%d %s()...\ntopic: %s, qos: %d. \nmessage:\n\t%s\n", __FILE__, __LINE__, __FUNCTION__,
|
||||
MQTT_LOG_I("-----------------------------------------------------------------------------------");
|
||||
MQTT_LOG_I("%s:%d %s()...\ntopic: %s, qos: %d. \nmessage:\n\t%s\n", __FILE__, __LINE__, __FUNCTION__,
|
||||
msg->topic_name, msg->message->qos, (char*)msg->message->payload);
|
||||
LOG_I("-----------------------------------------------------------------------------------\n");
|
||||
MQTT_LOG_I("-----------------------------------------------------------------------------------\n");
|
||||
}
|
||||
|
||||
|
||||
mqtt_client_t client;
|
||||
client_init_params_t init_params;
|
||||
|
||||
extern void TCPIP_Init(void);
|
||||
|
||||
@@ -36,39 +35,41 @@ void application_entry(void *arg)
|
||||
int error;
|
||||
char buf[80] = { 0 };
|
||||
mqtt_message_t msg;
|
||||
mqtt_client_t *client = NULL;
|
||||
memset(&msg, 0, sizeof(msg));
|
||||
|
||||
sprintf(buf, "welcome to mqttclient, this is a publish test...");
|
||||
printf("\nwelcome to mqttclient test...\n");
|
||||
|
||||
TCPIP_Init();
|
||||
|
||||
init_params.read_buf_size = 1024;
|
||||
init_params.write_buf_size = 1024;
|
||||
init_params.connect_params.network_params.addr = "iotcloud-mqtt.gz.tencentdevices.com";
|
||||
init_params.connect_params.network_params.port = "1883";
|
||||
init_params.connect_params.user_name = "7ABAKP6KNCtest1;12010126;KGRDH;1618120908";
|
||||
init_params.connect_params.password = "35c065988c4beeb32d8a2f1f283a7a1535e79295f4b6368f2ec61ee7b1b8c271;hmacsha256";
|
||||
init_params.connect_params.client_id = "7ABAKP6KNCtest1";
|
||||
init_params.connect_params.clean_session = 1;
|
||||
mqtt_log_init();
|
||||
|
||||
log_init();
|
||||
client = mqtt_lease();
|
||||
|
||||
mqtt_init(&client, &init_params);
|
||||
mqtt_set_port(client, "1883");
|
||||
|
||||
error = mqtt_connect(&client);
|
||||
mqtt_set_host(client, "iotcloud-mqtt.gz.tencentdevices.com");
|
||||
mqtt_set_client_id(client, "7ABAKP6KNCtest1");
|
||||
mqtt_set_user_name(client, "7ABAKP6KNCtest1;12010126;KGRDH;1618120908");
|
||||
mqtt_set_password(client, "35c065988c4beeb32d8a2f1f283a7a1535e79295f4b6368f2ec61ee7b1b8c271;hmacsha256");
|
||||
mqtt_set_clean_session(client, 1);
|
||||
|
||||
LOG_D("mqtt connect error is %#x", error);
|
||||
error = mqtt_connect(client);
|
||||
|
||||
mqtt_subscribe(&client, "7ABAKP6KNC/test1/data", QOS0, tos_topic_handler);
|
||||
MQTT_LOG_D("mqtt connect error is %#x", error);
|
||||
|
||||
mqtt_subscribe(client, "7ABAKP6KNC/test1/data", QOS0, tos_topic_handler);
|
||||
|
||||
memset(&msg, 0, sizeof(msg));
|
||||
|
||||
sprintf(buf, "welcome to mqttclient, this is a publish test...");
|
||||
|
||||
for (;;) {
|
||||
|
||||
msg.qos = QOS0;
|
||||
msg.payload = (void *) buf;
|
||||
|
||||
mqtt_publish(&client, "7ABAKP6KNC/test1/data", &msg);
|
||||
mqtt_publish(client, "7ABAKP6KNC/test1/data", &msg);
|
||||
|
||||
tos_task_delay(4000);
|
||||
}
|
||||
|
Reference in New Issue
Block a user