Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QoS 1/2 doesn't work #2

Closed
Amblego opened this issue Apr 17, 2014 · 8 comments
Closed

QoS 1/2 doesn't work #2

Amblego opened this issue Apr 17, 2014 · 8 comments

Comments

@Amblego
Copy link

Amblego commented Apr 17, 2014

Sskaje, thank you for quick actions!

Problem with uncaught exception was fixed, but it seems QoS 1/2 doesn't work.

For example: I start the subscribe script, after subscribe (with QoS=1 or 2) action I kill the script. After that I run publish script - it send some messages with QoS=1 or 2 and I kill it.

After that I run the same subscribe script (with QoS=1 or 2 and the same client_id) and there are no messages...

Where is my mistake?

@sskaje
Copy link
Owner

sskaje commented Apr 17, 2014

@Amblego , was QoS 1/2 working for you before my last commit?

@Amblego
Copy link
Author

Amblego commented Apr 17, 2014

@sskaje, before your last commit in my case (start_sub_with_client_id + subscribe + kill_without_unsubscribe, start_pub + publish, start_sub_with_the_same_client_id_as_before + subscribe - as described above) script fallen down on second subscription stage..

@sskaje
Copy link
Owner

sskaje commented Apr 19, 2014

@Amblego did you try to use mosquitto_pub/mosquitto_sub? how are these two performing like?

@Amblego
Copy link
Author

Amblego commented Apr 19, 2014

@sskaje , in console utils everything is OK:

brabantia@debian:$ mosquitto_sub -c -i id_2 -q 1 -u gamble0 -P 123123 -t amblego/test/#
^C
brabantia@debian:
$ mosquitto_pub -i pub_2 -q 1 -u gamble0 -P 123123 -t "amblego/test/QoS_1" -m "test message 1"
brabantia@debian:$ mosquitto_pub -i pub_2 -q 2 -u gamble0 -P 123123 -t "amblego/test/QoS_2" -m "test message 2"
brabantia@debian:
$ mosquitto_pub -i pub_2 -q 0 -u gamble0 -P 123123 -t "amblego/test/QoS_0" -m "test message 3"
brabantia@debian:~$ mosquitto_sub -c -i id_2 -q 1 -u gamble0 -P 123123 -t amblego/test/#
test message 1
test message 2

@Amblego
Copy link
Author

Amblego commented Apr 19, 2014

And in debug mode:

brabantia@debian:$ mosquitto_sub -c -i id_3 -q 1 -u gamble0 -P 123123 -t amblego/test/# -d
Client id_3 sending CONNECT
Client id_3 received CONNACK
Client id_3 sending SUBSCRIBE (Mid: 1, Topic: amblego/test/#, QoS: 1)
Client id_3 received SUBACK
Subscribed (mid: 1): 1
^C
brabantia@debian:
$ mosquitto_pub -i pub_2 -q 1 -u gamble0 -P 123123 -t "amblego/test/QoS_1" -m "test message 1" -d
Client pub_2 sending CONNECT
Client pub_2 received CONNACK
Client pub_2 sending PUBLISH (d0, q1, r0, m1, 'amblego/test/QoS_1', ... (14 bytes))
Client pub_2 received PUBACK (Mid: 1)
Client pub_2 sending DISCONNECT
brabantia@debian:$ mosquitto_pub -i pub_2 -q 2 -u gamble0 -P 123123 -t "amblego/test/QoS_2" -m "test message 2" -d
Client pub_2 sending CONNECT
Client pub_2 received CONNACK
Client pub_2 sending PUBLISH (d0, q2, r0, m1, 'amblego/test/QoS_2', ... (14 bytes))
Client pub_2 received PUBREC (Mid: 1)
Client pub_2 sending PUBREL (Mid: 1)
Client pub_2 received PUBCOMP (Mid: 1)
Client pub_2 sending DISCONNECT
brabantia@debian:
$ mosquitto_pub -i pub_2 -q 0 -u gamble0 -P 123123 -t "amblego/test/QoS_0" -m "test message 3" -d
Client pub_2 sending CONNECT
Client pub_2 received CONNACK
Client pub_2 sending PUBLISH (d0, q0, r0, m1, 'amblego/test/QoS_0', ... (14 bytes))
Client pub_2 sending DISCONNECT
brabantia@debian:$ mosquitto_sub -c -i id_3 -q 1 -u gamble0 -P 123123 -t amblego/test/# -d
Client id_3 sending CONNECT
Client id_3 received CONNACK
Client id_3 sending SUBSCRIBE (Mid: 1, Topic: amblego/test/#, QoS: 1)
Client id_3 received PUBLISH (d0, q1, r0, m1, 'amblego/test/QoS_1', ... (14 bytes))
Client id_3 sending PUBACK (Mid: 1)
test message 1
Client id_3 received PUBLISH (d0, q1, r0, m2, 'amblego/test/QoS_2', ... (14 bytes))
Client id_3 sending PUBACK (Mid: 2)
test message 2
Client id_3 received SUBACK
Subscribed (mid: 1): 1
^C
brabantia@debian:
$

@sskaje
Copy link
Owner

sskaje commented Apr 21, 2014

I tried

 $mqtt->setConnectClean(false);

in subscriber, something is wrong.
I'll fix it.

@sskaje
Copy link
Owner

sskaje commented Apr 21, 2014

@Amblego
In my examples/subscribe.php, I wrote like new, connect, ping, subscribe, loop
but the ping() does not have a 'correct' response(dont know why)
I removed the ping() and $mqtt->setConnectClean(false); then it works as examples you gave me.

code:
publish.php

<?php
require(__DIR__ . '/../../spMQTT.class.php');

$clientid = substr(md5('QOS111_01'), 0, 20);

$mqtt = new spMQTT('tcp://192.168.76.142:1883/', $clientid);

spMQTTDebug::Enable();

//$mqtt->setAuth('sskaje', '123123');
$connected = $mqtt->connect();
if (!$connected) {
    die("Not connected\n");
}

$mqtt->ping();

$msg = str_repeat('1234567890', 1);

# mosquitto_sub -t 'sskaje/#'  -q 1 -h test.mosquitto.org
$mqtt->publish('sskaje/test/qos0', $msg, 0, 0, 0, 1);

# mosquitto_sub -t 'sskaje/#'  -q 1 -h test.mosquitto.org
$mqtt->publish('sskaje/test/qos1', $msg, 0, 1, 0, 2);

# mosquitto_sub -t 'sskaje/#'  -q 1 -h test.mosquitto.org
$mqtt->publish('sskaje/test/qos2', $msg, 0, 2, 0, 3);

subscribe.php

<?php

require(__DIR__ . '/../../spMQTT.class.php');

$clientid = substr(md5('QOS111_02'), 0, 20);

$mqtt = new spMQTT('tcp://192.168.76.142:1883/', $clientid);

spMQTTDebug::Enable();
$mqtt->setConnectClean(false);


$mqtt->setKeepalive(3600);
$connected = $mqtt->connect();
if (!$connected) {
    die("Not connected\n");
}

//$mqtt->ping();


$topics['sskaje/test/#'] = 1;

$mqtt->subscribe($topics);


$mqtt->loop('default_subscribe_callback');


/**
 * @param spMQTT $mqtt
 * @param string $topic
 * @param string $message
 */
function default_subscribe_callback($mqtt, $topic, $message) {
    printf("Message received: Topic=%s, Message=%s\n", $topic, $message);
}

Can you try if this works you there?

sskaje added a commit that referenced this issue Apr 21, 2014
@Amblego
Copy link
Author

Amblego commented Apr 21, 2014

@sskaje,
It's awesome! Everything's OK now.
Thank you!

@Amblego Amblego closed this as completed Apr 21, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants