资源简介
基于freertos实时操作系统实现EC20 MQTT通讯订阅、发布;此代码的使用场景为一秒一次发布GGA数据到远程服务器,同时订阅服务器下发的参数。
代码片段和文件信息
#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
- 上一篇:C语言基础教程.pdf56620
- 下一篇:C语言编译器的设计与实现.doc
相关资源
- stm32f103 can驱动
- STM32三菱PLC源码原理图
- Wemos D1 mini阿里云MQTT例程
- MQTT协议
- 基于STM32智能家居的无线网关设计与实
- 基于stm32的交通信号灯代码
- DHT11驱动程序基于STM32
- 基于STEM32的倒车记录仪智能报警系统
- STM32_GY25Z计步器
- C语言实现的红外发送STM32F10x单片机应
- stm32L系列F系列 加密库Cryptographic lib
- 心率传感器算法-stm32-实测可用
- 工程使用的STM32版FX2N源码和原理图
- 基于stm32f1的频率计
- stm32F103zet6开串口通信2 C语言
- ADC电压采集程序
- CEC2017测试函数C++源码、和文献介绍
- STM32 电子密码锁设计,LCD12864显示C语
- 利用OV7725照相机与STM32F1识别车牌
- 基于STM32的小车红外黑线寻迹代码
- stm32图像采集+QT上位机源码
- STM32,5110液晶显示声纳探鱼器200KHz,
- stm32iap+bootloader+app+mfc上位机
- BMP180气压计STM32例程+51例程+数据手册
- STM32实现俄罗斯方块游戏C语言
- keil基于stm32的模拟交通灯项目源码+文
- STM32F4超声波测距
- HDC1080驱动 温湿度 STM32 IIC I2C
- 语音识别STM_C语言代码
- STC15单片机ESP8266开发试验程序含原理
评论
共有 条评论