Performing a UPNP scan is not returning the Philips Hue Bridge
Asked Answered
E

2

10

I am trying to implement my own UpNP scan, it is mostly working, and to prove that it's not me I have a windows program that allows you to send packets and see what response comes back.

I am sending a packet to 239.255.255.250 on port 1900 and I am sending the following data:

M-SEARCH * HTTP/1.1
Host: 239.255.255.250:1900
Man: "ssdp:discover"
MX: 10
ST: ssdp:all

Just for further info, in my Java code (Android) I have the following but I get the same response as the packet tester application:

try
        {
            byte[] sendData = new byte[1024];
            //byte[] receiveData = new byte[1024];
            byte[] receiveData;
            String mSearch = "M-SEARCH * HTTP/1.1\r\nHost: 239.255.255.250:1900\r\nMan: \"ssdp:discover\"\r\nMX: 10\r\nST: ssdp:all\r\n\r\n";
            sendData = mSearch.getBytes();

            DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, InetAddress.getByName("239.255.255.250"), 1900);

            DatagramSocket clientSocket = new DatagramSocket();
            clientSocket.send(sendPacket);

            while (keepGoing)
            {
                receiveData = new byte[1024];
                receivePacket = new DatagramPacket(receiveData, receiveData.length);
                clientSocket.receive(receivePacket);

                String response = new String(receivePacket.getData());

                if (response == null || response.length() == 0)
                {
                    keepGoing = false;
                }
                else
                {
                    iupnpScan.updateText(response);
                }

            }
            iupnpScan.complete(true);
            return true;
        }
        catch (UnknownHostException ex)
        {
            Log.e("MainActivity", "Unknown Host Exception: " + ex.toString());
        }
        catch (SocketException ex)
        {
            Log.e("MainActivity", "Socket Exception: " + ex.toString());
        }
        catch (IOException ex)
        {
            Log.e("MainActivity", "IO Exception: " + ex.toString());
        }
        iupnpScan.complete(false);
        return false;

I am getting some devices come back, such as my smart TV, router and NAS but the Philips Hue bridge is never returned in the reply.

Does the Philips Hue Bridge implement UpNP differently? All I can see is what response they send back now anything about what is needed to find it.

Edmanda answered 2/5, 2016 at 20:15 Comment(7)
You're using quite a large MX value. 10 seconds is valid for UPnP 1.0 but v1.1 recommends a value in the range [1..5] - you could try reducing your MX value to 5 seconds to rule out the Philips device rejecting your MSEARCH as malformed. Also be aware that some UPnP devices ignore MSEARCH, instead relying on sending out frequent multicast ALIVE announcements. You could try listening for multicast announcements as well as unicast MSEARCH responses and see whether that helps.Bertine
Thanks I've tried changing the MX Value to 5 but no difference. Interestingly I have a UPNP Inspector for Windows from coherence.beebits.net/wiki/… and the Bridge doesn't come up on that eitherEdmanda
When I was working with upnp I found that most native packages/libraries are quite inconsistent in responding to discovery requests. If you can run a small test, try using cyberlink library or cybergarage if your embedded device still does not respond to discovery requests, there may be some problem with your device.Publicist
Also just to debug, what I did most of the times was extensively use wireshark to analyse the flow of upnp packets on the PC.Publicist
Thanks, I've been using wireshark and multiple different pieces of software that sends packets and does specific UPNP searches and they all behave in the same way as my own code. From Wireshark I can see my Philips Hue Bridge constantly responding with NOTIFY packets but never in response to a UPNP scan. It looks to me that Philips Hue Bridge doesn't correctly support the UPNP spec.Edmanda
where is the bounty? only for curiosity...Genipap
Check out the documentation developers.meethue.com/documentation/hue-bridge-discoveryEvonneevonymus
G
2

Although Philips site notes it supports UPnP, I do not know if it is true or not.

I would try scanning the entire network and testing IP by IP. Yes, I know, this is not which the standard says, but reality is insane sometimes.

This discovery is already implemented out there this way.

I programmed a network search in the past (looking for a Raspberry PI) and the best method I can use was matching MAC addresses with my known address start. Luckily, Philips publish their MAC addresses range.

Genipap answered 11/5, 2016 at 14:35 Comment(0)
H
1

I was also struggling with this behavior. After some trial and error, I realized that the Hue Bridge does not seem to understand the " around the ssdp:discover value. These quotation marks are also not present in the IETF draft: https://datatracker.ietf.org/doc/html/draft-cai-ssdp-v1-03

Following request was successful for me:

M-SEARCH * HTTP/1.1
ST: ssdp:all
MX: 3
MAN: ssdp:discover
HOST: 239.255.255.250:1900

This is the response I got:

HTTP/1.1 200 OK
HOST: 239.255.255.250:1900
EXT:CACHE-CONTROL: max-age=100
LOCATION: http://192.168.xxx.xxx:80/description.xml
SERVER: Linux/3.14.0 UPnP/1.0 IpBridge/1.16.0
hue-bridgeid: 001788FFFE29D301
ST: urn:schemas-upnp-org:device:basic:1
USN: uuid:2f402f80-da50-11e1-9b23-00178829d301
Hunger answered 22/12, 2016 at 19:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.