[bug] QOS 2
See original GitHub issueQOS 2
Hello, I’m going through a somewhat embarrassing situation, I disconnect the Client from the server, send new messages to the topic, but after the client connects, he does not receive the messages. is this normal in QOS 2? I read a very interesting topic: mqtt-essentials-part-6-mqtt-quality-of-service-levels - I’m testing QOS 2
SERVER:
require('dotenv').config();
const mongoose = require('mongoose');
const queryString = require('query-string');
const ClientIo = require('./client-io');
const boardSendRouter = require('./routes/board_send');
const boardRouter = require('./routes/board');
const appSendRouter = require('./routes/app_send');
const appRouter = new appSendRouter();
const url = require('url');
const aedes = require('aedes')();
const mqtt = require('mqtt');
const server = require('net').createServer(aedes.handle);
const port = 1883;
mongoose.connect(process.env.DATABASE_URL, {
useUnifiedTopology: true,
useNewUrlParser: true,
useFindAndModify: false,
});
server.listen(port, function() {
console.log('Aedes listening on port:', port)
})
aedes.subscribe('board/submit_action', function(packet, cb) {
try {
var element = JSON.parse(packet.payload.toString());
var topic = "board_" + element['id_board'];
aedes.publish({
topic: topic,
payload: packet.payload.toString()
})
cb();
} catch (e) {
// declarações para manipular quaisquer exceções
console.log(e); // passa o objeto de exceção para o manipulador de erro
}
});
CLIENT ARDUINO:
byte willQoS = 2;
const char* willTopic = "arduino/status";
const char* willMessage = "OFF_LINE";
boolean willRetain = true;
const char* username = "Placa_1";
const char* password = "legal";
boolean cleanSession = false;
if (clientMqtt.connect(id_board, username, password, willTopic, willQoS, willRetain, willMessage, cleanSession) {
clientMqtt.subscribe("board_5ffcf3e5c18f457afa091c19");
}
API:
router.get('/', async (req, res, next) => {
var result = {};
var result = {
success: false,
message: "Invalido"
};
// var object = req.body;
var object = req.query
if (mongoose.Types.ObjectId.isValid(object.id_board)) {
if (object.cod != '' && object.cod != '?' && object.cod != undefined) {
const app_send = new AppSend({
id_board: object.id_board,
message: object.cod,
});
var save = await app_send.save();
topic = "board/submit_action";
var client = mqtt.connect('MYSERVER/mqtt', {
username: 'Placa_1',
password: 'legal',
clientId: 'client_api',
});
client.on('connect', () => {
client.publish(topic, JSON.stringify(save));
// client.publish("arduino/status", "testekkk");
client.end();
});
client.on('disconnect', () => {
console.log('disconnect eita');
});
client.on('offline', () => {
console.log('offline eita');
});
// client.end();
// console.log("chegou na acao");
result['success'] = true;
result['message'] = "Ação enviada!";
res.json(result);
return;
}
var promise = await BoardSend.findOne({
id_board: object.id_board
}).sort({
_id: -1
}).limit(1);
result = promise ? JSON.parse(promise.message) : {};
res.json(result);
return;
} else {
res.send(404);
return;
// var json = require('./teste-offline.json'); //with path
}
});
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
CSCun56276 - %ETH-QOS-2 ... - Cisco Bug
Bug information is viewable for customers and partners who have a service contract. Registered users can view up to 200 bugs per month...
Read more >Mosquitto QoS2 bug - or subtle spec interpretation?
As I see no way to argue that my missing RX3 is not "QoS 1 and QoS 2 messages pending transmission to the...
Read more >Bug: MQTT QOS 2 duplicated messages (IDFGH-7558) · Issue ...
I have experienced that when sending more than one message in quick succession that I sometimes receive duplicate messages in my server. Does ......
Read more >[mosquitto-dev] MQTT QoS 2 protocol problem - Eclipse
I just want to verify whether this indeed is a protocol error of the client or not. This MQTT client is sending messages...
Read more >MQTT - AWS IoT Core
The MQTT protocol defines a third level of QoS, level 2 , but AWS IoT does ... You can debug or process error...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I will do the test and give feedback #
What you are looking for is the retain flag (on published messages) or the clean flag (on connect). I suggest you to avoid using the clean flag as in most cases retain flag is enough. So set the option
retain: true
to the messages you send and when the client connects it will receive the last message sent to each topicDaniel