Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

Node client duplicate messages
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

Node client duplicate messages

by txjmb on Mon Dec 28, 2015 10:59 pm

I've been trying out the Node client on a PI and testing some of the examples in the adafruit-io-basics package.

I've been seeing some unusual behavior with duplicate and unexpected messages. Maybe I am just doing something wrong. Here is what I ran as a test:

Code: Select all | TOGGLE FULL SIZE
var AIO = require('adafruit-io');


// replace xxxxxxxxxxx with your Adafruit IO key
var AIO_KEY = 'key',
    AIO_USERNAME = 'username';

// aio init
var aio = AIO(AIO_USERNAME, AIO_KEY);

aio.feeds('myfeed').on('data', function(record){
   
   log('received: ' + record);
   
});

setTimeout(function() {
   log('sending: OFF') ;
   aio.feeds('myfeed').write('OFF');
}, 10000);

setTimeout(function() {
   log('sending: ON') ;
   aio.feeds('myfeed').write('ON');
}, 30000);

setTimeout(function() {
   log('sending: OFF') ;
   aio.feeds('myfeed').write('OFF');
}, 50000);

function log (message)
{   
   console.log((new Date).toISOString().slice(11,-5) + ' -- ' + message);
}



The code basically just sets up a subscription and then sends three messages with a healthy delay between each message. I didn't set it up as a pipe as in the examples because I wasn't writing to another stream. When the 'on' event is first set up, I get at least one message that is often duplicated. Except for the duplication, this makes sense, as it is the last message sent to the feed, regardless of when it was sent and this behavior is part of the subscription setup. However, after this, when the code sends each of the new messages, it often receives a bunch of duplicates and some extra messages. When a new message is sent to the broker, the broker (or more likely the client) returns the last value the new message. That doesn't seem to be expected behavior and isn't what happens with the Python client. Those messages can be duplicated. Then it returns the new message and it is also usually duplicated. I was not able to get the duplication to happen with a Python client, so these behaviors may be something unique to the Node.js client. Here are some examples of output showing the rather non-deterministic results:

Code: Select all | TOGGLE FULL SIZE
02:40:09 -- received: OFF
02:40:18 -- sending: OFF
02:40:23 -- received: OFF
02:40:23 -- received: OFF
02:40:38 -- sending: ON
02:40:42 -- received: OFF
02:40:42 -- received: OFF
02:40:42 -- received: ON
02:40:58 -- sending: OFF
02:41:02 -- received: ON
02:41:02 -- received: ON
02:41:02 -- received: ON
02:41:02 -- received: OFF
02:41:02 -- received: OFF


Code: Select all | TOGGLE FULL SIZE
02:47:02 -- received: OFF
02:47:07 -- sending: OFF
02:47:09 -- received: OFF
02:47:09 -- received: OFF
02:47:09 -- received: OFF
02:47:27 -- sending: ON
02:47:30 -- received: OFF
02:47:30 -- received: ON
02:47:30 -- received: ON
02:47:47 -- sending: OFF
02:47:51 -- received: ON
02:47:51 -- received: ON
02:47:51 -- received: OFF


Code: Select all | TOGGLE FULL SIZE
02:55:43 -- received: OFF
02:55:53 -- sending: OFF
02:55:57 -- received: OFF
02:55:57 -- received: OFF
02:56:13 -- sending: ON
02:56:18 -- received: OFF
02:56:18 -- received: OFF
02:56:18 -- received: ON
02:56:18 -- received: ON
02:56:33 -- sending: OFF
02:56:36 -- received: ON
02:56:36 -- received: ON
02:56:36 -- received: OFF
02:56:36 -- received: OFF
02:56:36 -- received: OFF


I would appreciate any help you might be able to provide.

txjmb
 
Posts: 3
Joined: Sun Dec 27, 2015 12:20 am

Please be positive and constructive with your questions and comments.