Closed Amblego closed 10 years ago
@Amblego , was QoS 1/2 working for you before my last commit?
@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..
@Amblego did you try to use mosquitto_pub/mosquitto_sub? how are these two performing like?
@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
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:~$
I tried
$mqtt->setConnectClean(false);
in subscriber, something is wrong. I'll fix it.
@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, It's awesome! Everything's OK now. Thank you!
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?