Giter Site home page Giter Site logo

Comments (6)

scaprile avatar scaprile commented on July 28, 2024

A published message's QoS is the highest among the receiver's and the sender's; if you subscribe with 2 and publish with 0, it will be sent to you as 0. It should arrive anyway because it is TCP, but it would be nice from you to also describe where are you publishing to (the broker) and how are you sure that is not the problem. Unless there is a capture file showing the broker received a proper message and attempted to deliver to either the library or the client, I wouldn't bother to look at the code for possible errors. Even though, you might be having connection problems and your session be not persistent... (a clean one). Need to see the traffic.
What are you using ?... the library ?, the client ?
If you are using the library (MQTTPacket), please describe how.
If you are using the client (C or C++ ?) I can't help, wait for someone else. However, I suggest you do the Wireshark stuff.

from paho.mqtt.embedded-c.

hardikharpal avatar hardikharpal commented on July 28, 2024

@scaprile
Test broker "iot.eclipse.org" port1883
I am using MQTT C client. topic_A/hardik subscribed with qos2 running on ubuntu in virtual box.

And publishing message from MQTTlens on topic topic_A/hardik with qos2 also subscribed with same topic with qos2 . MQTTlens works fine with pubsub so no u=issue on broker side.

As per your suggestion wireshark logs are attached to this comment. My client is not sending PUBCOMP message.After looking at MQTT C client code, it does not processing PUBREL message and not sending PUBCOMP message back to broker. `int cycle(MQTTClient* c, Timer* timer)
{
// read the socket, see what work is due
unsigned short packet_type = readPacket(c, timer);
if (packet_type == 0)
return FAILURE; // no more data to read, unrecoverable

int len = 0,
    rc = SUCCESS;

switch (packet_type)
{
    case CONNACK:
    case PUBACK:
    case SUBACK:
        break;
    case PUBLISH:
    {
        MQTTString topicName;
        MQTTMessage msg;
        int intQoS;
        if (MQTTDeserialize_publish(&msg.dup, &intQoS, &msg.retained, &msg.id, &topicName,
           (unsigned char**)&msg.payload, (int*)&msg.payloadlen, c->readbuf, c->readbuf_size) != 1)
            goto exit;
        msg.qos = (enum QoS)intQoS;
        deliverMessage(c, &topicName, &msg);
        if (msg.qos != QOS0)
        {
            if (msg.qos == QOS1)
                len = MQTTSerialize_ack(c->buf, c->buf_size, PUBACK, 0, msg.id);
            else if (msg.qos == QOS2)
                len = MQTTSerialize_ack(c->buf, c->buf_size, PUBREC, 0, msg.id);
            if (len <= 0)
                rc = FAILURE;
            else
                rc = sendPacket(c, len, timer);
            if (rc == FAILURE)
                goto exit; // there was a problem
        }
        break;
    }
    case PUBREC:
    {
        unsigned short mypacketid;
        unsigned char dup, type;
        if (MQTTDeserialize_ack(&type, &dup, &mypacketid, c->readbuf, c->readbuf_size) != 1)
            rc = FAILURE;
        else if ((len = MQTTSerialize_ack(c->buf, c->buf_size, PUBREL, 0, mypacketid)) <= 0)
            rc = FAILURE;
        else if ((rc = sendPacket(c, len, timer)) != SUCCESS) // send the PUBREL packet
            rc = FAILURE; // there was a problem
        if (rc == FAILURE)
            goto exit; // there was a problem
        break;
    }
    case PUBCOMP:
        break;
    case PINGRESP:
        c->ping_outstanding = 0;
        break;
}
keepalive(c);

exit:
if (rc == SUCCESS && packet_type != FAILURE)
rc = packet_type;
return rc;
}`
screenshot 2

from paho.mqtt.embedded-c.

monstrenyatko avatar monstrenyatko commented on July 28, 2024

@hardikharpal

In Paho MQTT C-Client cycle I don't see the switch-case to process PUBREL message. It can't reply with PUBCOMP.

If your build environment has c++ compiler with some C++11 support you can try to use my forked and reworked version of Paho C++ MQTT Client (see processPacket method).

My project is targeted for Arduino environment but all resources including time are external so should not be a problem to use with any other environment.

from paho.mqtt.embedded-c.

RomNexus6 avatar RomNexus6 commented on July 28, 2024

same problem for me with c++.
with QOS2 it fails.

I solved making a little modification at MQTTClient.h, line 840.
from this:

#elif MQTTCLIENT_QOS2

to this:

#endif
#if MQTTCLIENT_QOS2

let me know if this solves your issue

from paho.mqtt.embedded-c.

eden-wang avatar eden-wang commented on July 28, 2024

I also opened an issue for qos2 problem specially #89

from paho.mqtt.embedded-c.

icraggs avatar icraggs commented on July 28, 2024

I've fixed the PUBREL case, sending of PUBCOMP, and the preprocessor definitions. For both the C and C++ clients, the Travis test using all QoSs, including QoS2, now works. Thanks.

from paho.mqtt.embedded-c.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.