Last active
October 18, 2019 11:07
-
-
Save iahu/bce7baa459ef292cabac20c158ed7d6f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const dgram = require('dgram'); | |
const serverSocket = dgram.createSocket('udp4'); | |
const multicastAddress = '224.0.0.50'; | |
const multicastPort = 4321; | |
const serverPort = 9898; | |
var AqaraAccessoryFactory; | |
function startServer() { | |
// Show some message | |
serverSocket.on('listening', () => { | |
serverSocket.setMulticastTTL(128); | |
serverSocket.addMembership(multicastAddress); | |
}); | |
serverSocket.on('message', function(msg, rinfo) { | |
console.log(msg.toString(), rinfo); | |
}); | |
// Start server | |
serverSocket.bind(serverPort); | |
} | |
function search() { | |
var whoisCommand = '{"cmd": "whois"}'; | |
serverSocket.send(whoisCommand, 0, whoisCommand.length, multicastPort, multicastAddress); | |
// console.log("send %s to %s:%d", whoisCommand, multicastAddress, multicastPort); | |
} | |
startServer(); | |
setInterval(search, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment