資源簡介
基于freertos實時操作系統(tǒng)實現(xiàn)EC20 MQTT通訊訂閱、發(fā)布;此代碼的使用場景為一秒一次發(fā)布GGA數(shù)據(jù)到遠(yuǎn)程服務(wù)器,同時訂閱服務(wù)器下發(fā)的參數(shù)。
代碼片段和文件信息
#include?“main.h“
#include?“mqtt.h“
/**
??******************************************************************************
??*?@file???????????:?mqtt.c
??*?@brief??????????:?implement?for?mqtt.c?file.
??*???????????????????This?file?contains?the?common?implement?of?the?application.
??*?@author :?xiaozhi
??*?@attention
??*
??* Copyright?(c)?2019?Technology?Co.?Ltd.
??*
??*******************************************************************************
??*/
/*
?*?globla?variable
?*/
osThreadId_t?xy_mqtt_publish_handle???=?NULL;
osThreadId_t?xy_mqtt_subscribe_handle?=?NULL;
extern?uint8_t?rx_flag;
extern?char?send_buf[UART3_TX_QUEUE_LEN];
extern?int?num;
extern?int?head;
/*
?*?function?declaration
?*/
unsigned?char?xy_mqtt_task_init(void);
void?xy_mqtt_publish_task(void?*?argument);
void?xy_mqtt_subscribe_task(void?*?parameter);
static?unsigned?char?xy_mqtt_send_receive(const?char?*?at_instruction?const?char?*?instruction_exec_status);
static?unsigned?char?xy_mqtt_receive_again(char?*?response);
static?unsigned?char?xy_mqtt_cfg_version(void);
static?unsigned?char?xy_mqtt_cfg_will(void);
static?unsigned?char?xy_mqtt_cfg_timeout(void);
static?unsigned?char?xy_mqtt_cfg_session(void);
static?unsigned?char?xy_mqtt_cfg_keepalive(void);
static?unsigned?char?xy_mqtt_cfg_ssl(void);
static?unsigned?char?xy_mqtt_cfg_recv_mode(void);
/**
?*?xy_mqtt_task_init?-?mqtt?task?init.
?*?@none
?*/
unsigned?char?xy_mqtt_task_init(void)
{
/*?publish?attributes?*/
const?osThreadAttr_t?mqtt_publish_task_attributes?=?{
.name?=?“mqtt_publish“
.priority?=?(osPriority_t)?osPriorityNormal2
.stack_size?=?1024?*?12
};
/*?subscribe?attributes?*/
const?osThreadAttr_t?mqtt_subscribe_task_attributes?=?{
.name?=?“mqtt_subscribe“
.priority?=?(osPriority_t)?osPriorityNormal1
.stack_size?=?1024?*?12
};
/*?create?publish?task?*/
xy_mqtt_publish_handle?=?osThreadNew(xy_mqtt_publish_task?NULL?&mqtt_publish_task_attributes);
if?(NULL?==?xy_mqtt_publish_handle)?{
ac_traces(“[[?error?:?mqtt?publish?task?fail.?]]\r\n“);
return?0xff;
}
#if?1
/*?create?subscribe?task?*/
xy_mqtt_subscribe_handle?=?osThreadNew(xy_mqtt_subscribe_task?NULL?&mqtt_subscribe_task_attributes);
if?(NULL?==?xy_mqtt_subscribe_handle)?{
ac_traces(“[[?error?:?mqtt?subscribe?task?fail.?]]\r\n“);
return?0xff;
}
#endif
return?0;
}
/**
?*?xy_mqtt_send_receive?-?mqtt?at?instructions?send?and?receive.
?*?@at_instruction :?at?instruction
?*?@instruction_exec_status?:?comparison?value
?*/
static?unsigned?char?xy_mqtt_send_receive(const?char?*?at_instruction?const?char?*?instruction_exec_status)
{
char?receive_buffer[MQTT_BUFFER_LEN]?=?{?0?};
/*?uart?interrupt?invoke?*/
memset(send_buf?0?UART3_TX_QUEUE_LEN);
head?=?0;
num?=?0;
__exhibit(at_instruction);
/*?at?instruction?send?*/
SEND_AT_INSTRUCTION(at_instruction);
/*?receive?instruction?return?value?*/
if?((xQu
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????19263??2019-12-05?09:54??mqtt-ec20\mqtt.c
?????文件??????17719??2019-12-05?10:00??mqtt-ec20\mqtt.h
?????文件???????5777??2019-12-05?09:54??mqtt-ec20\mqtt_run.c
?????文件????????948??2019-12-05?09:55??mqtt-ec20\mqtt_run.h
?????目錄??????????0??2019-12-05?09:49??mqtt-ec20
-----------?---------??----------?-----??----
????????????????43707????????????????????5
評論
共有 條評論