资源简介
在MTK功能机平台实现mqtt协议,实现了connect ping subscribe public功能。实测可用。

代码片段和文件信息
#include “wwzlmqtt.h“
#include “aliyun_iot_common_md5.h“
#define MQTT_DUP_FLAG 1<<3
#define MQTT_QOS0_FLAG 0<<1
#define MQTT_QOS1_FLAG 1<<1
#define MQTT_QOS2_FLAG 2<<1
#define MQTT_RETAIN_FLAG 1
#define MQTT_CLEAN_SESSION 1<<1
#define MQTT_WILL_FLAG 1<<2
#define MQTT_WILL_RETAIN 1<<5
#define MQTT_USERNAME_FLAG 1<<7
#define MQTT_PASSWORD_FLAG 1<<6
extern int wwzl_mqtt_send_socket(void* socket_info const void* buf unsigned int count);
extern kal_int16 len_trans;
uint8_t mqtt_num_rem_len_bytes(const uint8_t* buf) {
uint8_t num_bytes = 1;
//printf(“mqtt_num_rem_len_bytes\n“);
if ((buf[1] & 0x80) == 0x80) {
num_bytes++;
if ((buf[2] & 0x80) == 0x80) {
num_bytes ++;
if ((buf[3] & 0x80) == 0x80) {
num_bytes ++;
}
}
}
return num_bytes;
}
uint16_t mqtt_parse_rem_len(const uint8_t* buf) {
uint16_t multiplier = 1;
uint16_t value = 0;
uint8_t digit;
//printf(“mqtt_parse_rem_len\n“);
buf++; // skip “flags“ byte in fixed header
do {
digit = *buf;
value += (digit & 127) * multiplier;
multiplier *= 128;
buf++;
} while ((digit & 128) != 0);
return value;
}
uint16_t mqtt_parse_msg_id(const uint8_t* buf) {
uint8_t type = MQTTParseMessageType(buf);
uint8_t qos = MQTTParseMessageQos(buf);
uint16_t id = 0;
//printf(“mqtt_parse_msg_id\n“);
if(type >= MQTT_MSG_PUBLISH && type <= MQTT_MSG_UNSUBACK) {
if(type == MQTT_MSG_PUBLISH) {
if(qos != 0) {
// fixed header length + Topic (UTF encoded)
// = 1 for “flags“ byte + rlb for length bytes + topic size
uint8_t rlb = mqtt_num_rem_len_bytes(buf);
uint8_t offset = *(buf+1+rlb)<<8; // topic UTF MSB
offset |= *(buf+1+rlb+1); // topic UTF LSB
offset += (1+rlb+2); // fixed header + topic size
id = *(buf+offset)<<8; // id MSB
id |= *(buf+offset+1); // id LSB
}
} else {
// fixed header length
// 1 for “flags“ byte + rlb for length bytes
uint8_t rlb = mqtt_num_rem_len_bytes(buf);
id = *(buf+1+rlb)<<8; // id MSB
id |= *(buf+1+rlb+1); // id LSB
}
}
return id;
}
uint16_t mqtt_parse_pub_topic(const uint8_t* buf uint8_t* topic) {
const uint8_t* ptr;
uint16_t topic_len = mqtt_parse_pub_topic_ptr(buf &ptr);
//printf(“mqtt_parse_pub_topic\n“);
if(topic_len != 0 && ptr != NULL) {
memcpy(topic ptr topic_len);
}
return topic_len;
}
uint16_t mqtt_parse_pub_topic_ptr(const uint8_t* buf const uint8_t **topic_ptr) {
uint16_t len = 0;
//printf(“mqtt_parse_pub_topic_ptr\n“);
if(MQTTParseMessageType(buf) == MQTT_MSG_PUBLISH) {
// fixed header length = 1 for “flags“ byte + rlb for length bytes
uint8_t rlb = mqtt_num_rem_len_bytes(buf);
len = *(buf+1+rlb)<<8; // MSB of topic UTF
len |= *(buf+1+rlb+1); // LSB of topic UTF
// start of topic = add 1 for “flags“ rlb for remaining length 2 for UTF
*topic_ptr = (buf + (1+rlb+2));
} else {
*topic_ptr = NULL;
}
return len;
}
uint16_t mqtt_parse_publish_msg(const uint8_t* buf uint8_t* msg) {
const uint
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 17772 2017-07-15 17:22 mtk 2503 mqtt\wwzlmqtt.c
文件 9187 2017-07-06 12:13 mtk 2503 mqtt\wwzlmqtt.h
文件 203895 2017-07-15 17:43 mtk 2503 mqtt\wwzl_w120ae_wx_tracker.c
文件 40698 2017-07-15 12:23 mtk 2503 mqtt\wwzl_w120ae_wx_tracker.h
目录 0 2017-07-24 10:44 mtk 2503 mqtt
----------- --------- ---------- ----- ----
271552 5
- 上一篇:挖掘鸡7.1~~非常不错的工具
- 下一篇:Fluent动网格和VOF详细设置教程
相关资源
- MQTT+串口(usart)透传
- MQTT推送Demo
- MQTT_3.1protocol_Specific中文版
- MQTTv3.1中文版
- mt7628 mqtt功能 放到packet下面就可以使
- MQTT-1.zip
- STM32F103C8T6与MQTT通信的源码
- ESP8266使用MQTT协议连接阿里云
- ESP8266程序加上MQTT调试工具
- STM32(TCP转MQTT).rar
- DHT11温湿度传感器项目代码.rar
- mqtt资料加源码stm32单片机+TCP
- ESP8266搭建MQTT客户端源码
- 智能家居 环境温湿度采集系统
- libmosquitto MQTT-Client
- MQTT即时通讯web
- STM32+FreeRTOS+W5500+MQTT
- 一个能用的mqtt库+测试窗体包括json解
- mqtt源码及文档
- MQTT 客户端调试工具V1.1
- air202 mqtt 测试程序
- STM32+SIM800C+MQTT连接阿里云物联网平台
- MTK2503工具FlashTool_v5.1640.00
- mosquitto 1.4.15 windows server服务器!!全
- Esp8266】百万条消息免费之乐鑫esp826
- 乐鑫 esp8266 源码分析 MQTT 实现过程,
- 基于NONOS_SDK动手做个8266毕设小案例,
- Esp8266进阶之路Windows系统搭建8266的本
- STM32+MQTT+SIM800使用AT指令实现
- esp8266创建MQTT任务,订阅接收和发布发
评论
共有 条评论