STS_E2/Air_Quality_LORAWAN_WINEXT_.../User/user_mqtt.c

59 lines
1.4 KiB
C

/**
******************************************************************************
* @file : user_mqtt.c
* @author : zsq
* @version : V1.0
* @date : 2020-01-15
* @brief : mqtt ²âÊÔ
******************************************************************************
* @attention
*
* Copyright (c) 2019 YUNHORN(Shenzhen YunHorn Technology Co., Ltd
* All rights reserved.
*
******************************************************************************
*/
//-- Includes -----------------------------------------------------------------
#include "main.h"
#include "user_mqtt.h"
#include "mqtt_wrapper.h"
void mqtt_demo(void)
{
int count = 1;
int sock_id = 0;
uint8_t read_data[40];
int read_len;
char topic[30];
char buffer[32];
mqtt_con_opt_t con_opt;
con_opt.keep_alive_interval = 2000;
con_opt.cleansession = 1;
con_opt.username = MQTT_USR_NAME;
con_opt.password = MQTT_PASSWORD;
con_opt.client_id = MQTT_CLIENT_ID;
mqtt_pub_opt_t pub_opt;
pub_opt.dup = 0;
pub_opt.qos = 0;
pub_opt.retained = 0;
pub_opt.id = 0;
pub_opt.topic = MQTT_PUBLISH_TOPIC;
mqtt_sub_opt_t sub_opt;
sub_opt.count = 1;
sub_opt.dup = 0;
sub_opt.id = 1;
sub_opt.req_qos = 0;
sub_opt.topic = MQTT_SUBSCRIBE_TOPIC;
sock_id = tos_mqtt_connect(MQTT_SERVER_IP, MQTT_SERVER_PORT, &con_opt);
if (tos_mqtt_subscribe(sock_id, &sub_opt) != 0) {
printf("subscribe failed!!!\n");
}
}