资源简介
在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协议实验过程及代
- 4G通过MQTT协议ONENET
- MT2503/6261等平台MQTT实现代码
- mqttws31.js文件和MQTT.js-master
- MT2503D资料
- MT2503开发资料包
- 有人MQTT透传云二次开发软件通讯协议
- 15.Aliyun.rar
- ESP8266_NONOS_SDK-2.2.0
- LWIP_MQTT_Succeed.7z
- EC20基于STM32F407 MQTT协议上传数据到
- MQTT_Client源码.rar
- 基于qt的mqtt实现,源代码
- Delphi MQTT客户端
- GPRS模块GA6和STM32F103C8T6单片机上移植
- MT2503移植MQTT协议.zip
- 博世xdkMQTT传输协议
- MQTT 协议文档
- 阿里云IoT物联网平台-ESP8266 MQTT 1路开
- ESP8266 MQTT SSL/TLS 阿里物联网套件 百度
- MQTT协议源码
- MQTT 最新版协议说明中文版
- MQTT需要的dll
- 通信猫(COMNET)可以进行网络调试,
- windows mqtt 客户端
- apache-apollo-1.7.1-windows-distro
- mqtt-ec20-freertos.rar
- 移远GSM模块MQTT开发应用手册
- MQTT-3.1.1-CN 中文版通讯协议
- 使用org.eclipse.paho.client.mqttv3实现mqtt
评论
共有 条评论