mqttjs / MQTT.js

The MQTT client for Node.js and the browser
Other
8.55k stars 1.42k forks source link

keepalive option #228

Closed alexislg2 closed 9 years ago

alexislg2 commented 9 years ago

Hey I'm testing different values for the keepalive option but I can't see any difference. I tried 60, 600 and 3600. I would expect to have a 60 times lower traffic with 3600 but it's still the same ~100 kB/hr which is a far too much for my 3G application Any idea?

mcollina commented 9 years ago

Are you sending data? Are you disconnecting the client?

Debugging these can be tricky. You definitely need to intercept what's going on using wireshark or similar.

Anyway, can you post me the code that shows the problem? Can you do a 'lab setup' without a 3G connection? Il sab 1 nov 2014 alle 08:01 ALEXIS LE GOFF notifications@github.com ha scritto:

Hey I'm testing different values for the keepalive option but I can't see any difference. I tried 60, 600 and 3600. I would expect to have a 60 times lower traffic with 3600 but it's still the same ~100 kB/hr which is a far too much for my 3G application Any idea?

— Reply to this email directly or view it on GitHub https://github.com/adamvr/MQTT.js/issues/228.

alexislg2 commented 9 years ago

I don't send any data, I'm just tryng to have a living connection 24/7 to see how much data it requires per month.

var mqtt = require('mqtt')
var client = mqtt.createClient(1883, 'my_mosquitto_broker_url',
    {
    protocolId: 'MQIsdp',
    protocolVersion: 3,
    clientId: 'my3Gdevice',
    keepalive: 60 // also tried 600, 3600
});

client.on('message', function (topic, message) {
    console.log('topic:', topic);
    console.log('message:', message);
    }
);

client.on('connect', function(){
    console.log('connected');
    reconnection(client);
});

client.on('close', function(){console.log('mqtt connection closed');});

function reconnection(client){
    client.unsubscribe('#', function(){
        client.subscribe('channel1/' + sn, {qos: 2});
        client.subscribe('channel2/' + sn, {qos: 2});
    });
}
alexislg2 commented 9 years ago

Wait... I just discovered I have other traffic on the connection. I have to make sure only mqtt use the line before making any precise measurement I keep you in touch

alexislg2 commented 9 years ago

It's working well I have now a less than 1kB/hr traffic with 3600 Sorry for my mistake You can close the issue Thanks again