官方例程, sample/mqtt-example.c
首先控制台订阅topic为data且属性为订阅和发布, 以实现自发自收的测试.
sub的消息到底时的代码如下
static void _demo_message_arrive(void *pcontext, void *pclient, iotx_mqtt_event_msg_pt msg)
{
iotx_mqtt_topic_info_pt ptopic_info = (iotx_mqtt_topic_info_pt) msg->msg;
// print topic name and topic message
EXAMPLE_TRACE("----");
EXAMPLE_TRACE("Topic(%d): '%.*s'", ptopic_info->topic_len, ptopic_info->topic_len, ptopic_info->ptopic);
EXAMPLE_TRACE("Payload(%d): '%.*s'", ptopic_info->payload_len, ptopic_info->payload_len, ptopic_info->payload);
EXAMPLE_TRACE("----");
}
小端模式下sub消息是OK的.
[dbg] iotx_mc_cycle(1568): PUBACK
event_handle|160 :: publish success, packet-id=2
[dbg] iotx_mc_cycle(1585): PUBLISH
[dbg] iotx_mc_handle_recv_PUBLISH(1420): msg.id = | 8570 |
[dbg] iotx_mc_handle_recv_PUBLISH(1421): topicName = | /WTbJ0ETJacK/device_01/data |
[dbg] iotx_mc_handle_recv_PUBLISH(1431): delivering msg ...
[dbg] iotx_mc_deliver_message(1158): topic be matched
_demo_message_arrive|191 :: ----
_demo_message_arrive|192 :: Topic(27): '/WTbJ0ETJacK/device_01/data'
_demo_message_arrive|193 :: Payload(45): '{"attr_name":"temperature", "attr_value":"1"}'
_demo_message_arrive|194 :: ----
mqtt_client|312 :: packet-id=3, publish topic msg={"attr_name":"temperature", "attr_value":"1"}
[dbg] iotx_mc_cycle(1568): PUBACK
event_handle|160 :: publish success, packet-id=3
[dbg] iotx_mc_cycle(1585): PUBLISH
[dbg] iotx_mc_handle_recv_PUBLISH(1420): msg.id = | 8614 |
[dbg] iotx_mc_handle_recv_PUBLISH(1421): topicName = | /WTbJ0ETJacK/device_01/data |
[dbg] iotx_mc_handle_recv_PUBLISH(1431): delivering msg ...
[dbg] iotx_mc_deliver_message(1158): topic be matched
_demo_message_arrive|191 :: ----
_demo_message_arrive|192 :: Topic(27): '/WTbJ0ETJacK/device_01/data'
_demo_message_arrive|193 :: Payload(45): '{"attr_name":"temperature", "attr_value":"1"}'
_demo_message_arrive|194 :: ----
但是大端模式下执行结果如下, 消息长度为0?
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。