.watch delay between messages
marabesi opened this issue · comments
I was wondering if there is any options that we can pass in to the .watch
method to delay the messages by a given time. Something like the following:
listener.watch({
delay: 500
});
Can you give a bit more detail? Delaying messages would create a backlog of messages and your application would work with outdated information?
Or do you want to be the watch method to be less chatty and send less measurements?
The second option is what I am looking, I would like to have the watch method to be less chatty. Right now I have a MQTT serve that I send all the measurements, but I just realize that there is no need to send the data in the same velocity that the sensor works.
I ended up with a 'workaround' which is just to control the time by hand using the Date object. So I push to the queue every 2 seconds.
let currentMoment = Date.now();
let desired = now + 2000;
if (currentMoment >= desired) {
console.log('published ', Date.now());
client.publish(topic, JSON.stringify(tpv));
now = Date.now();
}
This module is not the right place to solve this IMO. According to the gpsd
documentation most GPS devices emit their location once every second. In your case the device sends more readings? Maybe you can configure this in your device.
From my point of view this should be either fixed in the device or in the software that uses this module as this module targets to be just the bindings between gpsd
and a nodejs program and nothing more.
I see your point of view but it is weird though, what I am asking is not to change the lib focus, instead I am asking for a configurable option in which to decide the delay of the information given by the module.
I don't want the information in less than 1 second, actually I want it to be 3 seconds. I just wrote a snippet of what I was looking for delay: 500
means nothing, just an example.
Thank you for your time in answer this issue.
But you can perfectly do this from the your own code right?
I think adding logic to the binding does change the focus of the lib. Currently all options are passed to gpsd
allowing you to use the options of the gpsd
protocol:
/* Start the watching mode: see ?WATCH command */
Listener.prototype.watch = function(options) {
var watch = { class: 'WATCH', json: true, nmea: false };
if (options) watch = options;
this.serviceSocket.write('?WATCH=' + JSON.stringify(watch));
};
From my point of view it would be more logical to ask the gpsd folks to add the option to their protocol.
Thank you for contributing with your question. I appreciate the discussion.