Skip to content

Commit

Permalink
Network connections now output more debug info
Browse files Browse the repository at this point in the history
  • Loading branch information
aholstenson committed Jan 25, 2018
1 parent 0348e74 commit 327c961
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 14 additions & 2 deletions lib/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,12 @@ class Network extends EventEmitter {

// Bind the socket and when it is ready mark it for broadcasting
this._socket.bind();
this._socket.on('listening', () => this._socket.setBroadcast(true));
this._socket.on('listening', () => {
this._socket.setBroadcast(true);

const address = this._socket.address();
this.debug('Network bound to port', address.port);
});

// On any incoming message, parse it, update the discovery
this._socket.on('message', (msg, rinfo) => {
Expand Down Expand Up @@ -252,6 +257,7 @@ class DeviceInfo {
}

set token(t) {
this.debug('Using manual token:', t.toString('hex'));
this.packet.token = t;
this.tokenChanged = true;
}
Expand Down Expand Up @@ -279,11 +285,17 @@ class DeviceInfo {
let promise;
if(! this.packet.token) {
// No automatic token found - see if we have a stored one
this.debug('Loading token from storage, device hides token and no token set via options');
this.autoToken = false;
promise = tokens.get(this.id)
.then(token => this.token = Buffer.from(token, 'hex'));
} else {
this.autoToken = this.tokenChanged ? false : true;
if(this.tokenChanged) {
this.autoToken = false;
} else {
this.autoToken = true;
this.debug('Using automatic token:', this.packet.token.toString('hex'));
}
promise = Promise.resolve();
}

Expand Down
2 changes: 1 addition & 1 deletion lib/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const dirs = new AppDirectory('miio');
const CHECK_TIME = 1000;
const MAX_STALE_TIME = 120000;

const debug = require('debug')('miio.tokens');
const debug = require('debug')('miio:tokens');

/**
* Shared storage for tokens of devices. Keeps a simple JSON file synced
Expand Down

0 comments on commit 327c961

Please sign in to comment.