Skip to content

Commit

Permalink
Discovery now sends several broadcasts
Browse files Browse the repository at this point in the history
  • Loading branch information
aholstenson committed Apr 12, 2017
1 parent d624ef2 commit 51f4338
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 29 deletions.
29 changes: 0 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,35 +128,6 @@ needs. Devices announce themselves via `_miio._udp` and should work for most
devices, in certain cases you might need to restart your device to make it
announce itself.

Here is an example on how to find devices with `tinkerhub-mdns`;

```javascript
const browser = require('tinkerhub-mdns')
.browser({
type: 'miio',
protocol: 'udp'
});

browser.on('available', reg => {
// Use infoFromHostname to figure out model and id of device
const info = miio.infoFromHostname(reg.name);
if(! info) return;

// Set the address and port from the found registration
info.address = reg.addresses[0];
info.port = reg.port;

const device = miio.createDevice(info);

// Do something with the device here
});

browser.on('unavailable', reg => {
const device = ...;
device.destroy();
});
```

## Devices types

The intent of this library is to encompass all miIO-compatible devices and to
Expand Down
7 changes: 7 additions & 0 deletions lib/discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ class Browser {
this._packet.handshake();
const data = this._packet.raw;
this._socket.send(data, 0, data.length, PORT, '255.255.255.255');

if(this.cacheTime / 3 > 500) {
// Broadcast an extra time in 500 milliseconds in case the first brodcast misses a few devices
setTimeout(() => {
this._socket.send(data, 0, data.length, PORT, '255.255.255.255');
}, 500);
}
}

_addService(service) {
Expand Down

0 comments on commit 51f4338

Please sign in to comment.