Listen for device + trigger HTTP request
-
Hi,
I'm wondering if it's possible to have my Hub listen for a device on my local network and when it is not available trigger a HTTP request? Any ideas are welcome
Claes
-
@Emil Ok, thanks!! I'll do some research
-
@claes-jacobsson No idea. I guess you could try to connect to some port maybe. I don't know anything about Apple TV's network usage unfortunately.
-
@Emil Thanks again! I got the scripts working but it doesn't seem to get me where I want. I seems the Apple TV doesn't actually turn off when I turn it "off" - it goes into sleep mode but is still active on the network. I wonder if there's some other way to identify when it goes into sleep mode from the Flic Hub...
-
@Emil Great, thanks a lot! I'll try it out a bit later
-
@claes-jacobsson We have mDNS functionality but it is in beta so it is not documented yet.
But you can refer to the following code samples in the meantime (monitoring Sonos devices):const mdns = require("mdns"); // Service browse: browseHandle = mdns.serviceBrowse(null /*or interface string*/, "_sonos._tcp", function(obj) {console.log(JSON.stringify(obj));}) Output: {"add":true,"interface":"eth0","serviceName":"Sonos-38420B7D0C12@Meeting Room","regtype":"_sonos._tcp.","replyDomain":"local."} {"add":true,"interface":"eth0","serviceName":"Sonos-C43875785444@Kitchen","regtype":"_sonos._tcp.","replyDomain":"local."} {"add":true,"interface":"eth0","serviceName":"Sonos-B8E937B9C4EC@Dev","regtype":"_sonos._tcp.","replyDomain":"local."} {"add":true,"interface":"eth0","serviceName":"Sonos-B8E937EE3C04@Dev","regtype":"_sonos._tcp.","replyDomain":"local."} {"add":true,"interface":"wlan1","serviceName":"Sonos-38420B7D0C12@Meeting Room","regtype":"_sonos._tcp.","replyDomain":"local."} {"add":true,"interface":"wlan1","serviceName":"Sonos-C43875785444@Kitchen","regtype":"_sonos._tcp.","replyDomain":"local."} {"add":true,"interface":"wlan1","serviceName":"Sonos-B8E937B9C4EC@Dev","regtype":"_sonos._tcp.","replyDomain":"local."} {"add":true,"interface":"wlan1","serviceName":"Sonos-B8E937EE3C04@Dev","regtype":"_sonos._tcp.","replyDomain":"local."} browseHandle.cancel(); // Stops the monitoring // Resolve a service instance resolveHandle = mdns.serviceResolve("eth0", "Sonos-38420B7D0C12@Meeting Room", "_sonos._tcp", function(obj) {console.log(JSON.stringify(obj));}); Output: {"interface":"eth0","fullname":"Sonos-38420B7D0C12@Meeting\\032Room._sonos._tcp.local.","hosttarget":"Sonos-38420B7D0C12.local.","port":1443,"txtEntries":{"bootseq":[56,54],"hhid":[83,111,110,111,115,95,76,68,99,69,97,107,111,56,74,56,52,121,102,99,114,54,75,49,89,69,109,48,104,57,99,111],"hhsslport":[49,56,52,51],"info":[47,97,112,105,47,118,49,47,112,108,97,121,101,114,115,47,82,73,78,67,79,78,95,51,56,52,50,48,66,55,68,48,67,49,50,48,49,52,48,48,47,105,110,102,111],"infohash":[52,71,105,56,85,107,108,80,100,68,76,73,112,118,65,99,53,111,75,108,112,87,76,53,102,101,97,110,118,74,106,57,74,73,102,54,95,84,81,109,98,102,103],"location":[104,116,116,112,58,47,47,49,57,50,46,49,54,56,46,51,46,57,58,49,52,48,48,47,120,109,108,47,100,101,118,105,99,101,95,100,101,115,99,114,105,112,116,105,111,110,46,120,109,108],"locationid":[108,99,95,102,57,99,98,52,100,99,54,51,52,55,97,52,53,53,102,56,52,56,97,48,51,101,99,55,52,51,100,52,52,48,98],"mdnssequence":[48],"mhhid":[83,111,110,111,115,95,76,68,99,69,97,107,111,56,74,56,52,121,102,99,114,54,75,49,89,69,109,48,104,57,99,111,46,89,77,77,122,112,67,49,49,72,89,51,79,57,95,110,74,98,70,97,49],"minApiVersion":[49,46,49,46,48],"protovers":[49,46,52,48,46,48],"sslport":[49,52,52,51],"uuid":[82,73,78,67,79,78,95,51,56,52,50,48,66,55,68,48,67,49,50,48,49,52,48,48],"variant":[49],"vers":[53],"wss":[47,119,101,98,115,111,99,107,101,116,47,97,112,105]}} resolveHandle.cancel(); // Stops the monitoring // Get IP address getaddrinfoHandle = mdns.getAddrInfo("eth0", "Sonos-38420B7D0C12.local.", /*IPv4*/true, /*IPv6*/false, function(obj) {console.log(JSON.stringify(obj));}); Output: {"add":true,"interface":"eth0","ip":"192.168.3.9"} getaddrinfoHandle.cancel(); // Stops the monitoring
When you see "add": false, that means the device's dns-sd entry has expired, i.e. the device has not renewed its entry before it expired. You can either monitor all devices of a certain type (serviceBrowse) or monitor a specific host (getAddrInfo).
-
@Emil Yes, it shows up in a couple of places.
-
@claes-jacobsson Maybe monitoring it via DNS-SD could be an option. If you use e.g. https://apps.apple.com/us/app/discovery-dns-sd-browser/id305441017, do you see your Apple TV there when you scan your local network?
-
@Emil I want to detect when my Apple TV is turned off. I was thinking if it's possible to listen for its IP address and take action with the HTTP request when it doesn't respond.
-
@claes-jacobsson What kind of device do you want to monitor? How you "listen to" it depends a lot of what kind of features it supports.
-
@Emil Thanks! Yes, I've found that and got started with the SDK. I was more looking for help with the code
-
@claes-jacobsson If you use the Flic Hub (1st gen) or Flic Hub LR, that is possible with the Hub SDK, but requires you to write custom javascript code. Please see https://flic.io/flic-hub-studio.