资源简介
我已经成功把MQTT移植到MT2503上。同样的在其他MCU上是可以移植的
资源包含了MQTT源码,移植及测试的详细步骤
代码片段和文件信息
/*******************************************************************************
* Copyright (c) 2014 IBM Corp.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Ian Craggs - initial API and implementation and/or initial documentation
*******************************************************************************/
#include “MQTTPacket.h“
#include “StackTrace.h“
#include
/**
* Determines the length of the MQTT connect packet that would be produced using the supplied connect options.
* @param options the options to be used to build the connect packet
* @return the length of buffer needed to contain the serialized version of the packet
*/
int MQTTSerialize_connectLength(MQTTPacket_connectData* options)
{
int len = 0;
FUNC_ENTRY;
if (options->MQTTVersion == 3)
len = 12; /* variable depending on MQTT or MQIsdp */
else if (options->MQTTVersion == 4)
len = 10;
len += MQTTstrlen(options->clientID)+2;
if (options->willFlag)
len += MQTTstrlen(options->will.topicName)+2 + MQTTstrlen(options->will.message)+2;
if (options->username.cstring || options->username.lenstring.data)
len += MQTTstrlen(options->username)+2;
if (options->password.cstring || options->password.lenstring.data)
len += MQTTstrlen(options->password)+2;
FUNC_EXIT_RC(len);
return len;
}
/**
* Serializes the connect options into the buffer.
* @param buf the buffer into which the packet will be serialized
* @param len the length in bytes of the supplied buffer
* @param options the options to be used to build the connect packet
* @return serialized length or error if 0
*/
int MQTTSerialize_connect(unsigned char* buf int buflen MQTTPacket_connectData* options)
{
unsigned char *ptr = buf;
MQTTHeader header = {0};
MQTTConnectFlags flags = {0};
int len = 0;
int rc = -1;
FUNC_ENTRY;
if (MQTTPacket_len(len = MQTTSerialize_connectLength(options)) > buflen)
{
rc = MQTTPACKET_BUFFER_TOO_SHORT;
goto exit;
}
header.byte = 0;
header.bits.type = CONNECT;
writeChar(&ptr header.byte); /* write header */
ptr += MQTTPacket_encode(ptr len); /* write remaining length */
if (options->MQTTVersion == 4)
{
writeCString(&ptr “MQTT“);
writeChar(&ptr (char) 4);
}
else
{
writeCString(&ptr “MQIsdp“);
writeChar(&ptr (char) 3);
}
flags.all = 0;
flags.bits.cleansession = options->cleansession;
flags.bits.will = (options->willFlag) ? 1 : 0;
if (flags.bits.will)
{
flags.bits.willQoS = options->will.qos;
flags.bits.willRetain = options->will.retained;
}
if (options->username.cstring || options->username.lenstring.dat
相关资源
- 基于STM32单片机的门禁控制系统-软件
- stm32 hart通信程序
- STM32F107模块化入门指导书
- stm32f407读写SD卡
- HC-SR04超声波测距 STM32 keil
- 基于STM32环境智能监测、报警系统
- MiniBalance上位机所有资料
- 2018电赛FDC2214STM32 程序+PCB板工程文件
- DS1302程序开发运用在STM32F103
- STM32与HTU21的I2C通讯源码
- 基于STM32的遥控小车程序NRF24l01
- 基于STM32的机器人控制
- 基于STM32车牌识别程序_带管理计费.
- UWB测距源码
- 基于STM32的风力摆程序
- stm32读取SD卡中图片,并在TFT中显示
- STM32F1控制HC-SR04超声波测距
- 基于stm32f103的蓝牙通信模块
- stm32f103RCT6-USB->UART
- stm32的gps定位及labview上位机.zip
- stm32f103双串口收发.zip
- SPI主从通讯最终版Demo2019_3_24
- 基于STM32程序的车牌识别
- STM32作从机实现简单的Modbus RTU协议
- STM32 3d打印机源码 IAR 工程
- stm32f207 ADC测试程序
- STM32F407 定时器触发ADC-DMA采集
- stm32f4xx挂载SD卡程序,可以正常读写
- 两路DMA_DAC_stm32f103rct6.zip
- stm32矩阵键盘按键扫描程序亲测可用
评论
共有 条评论