Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSDP Reply for Belkin/Phillips Hue Not working? #13

Closed
ikkysleepy opened this issue Jan 6, 2019 · 1 comment
Closed

SSDP Reply for Belkin/Phillips Hue Not working? #13

ikkysleepy opened this issue Jan 6, 2019 · 1 comment
Labels

Comments

@ikkysleepy
Copy link

I am trying to reply to a SSDP search request and it does reply but for some odd reason the other device doesn't do anything. I just want to make sure everything is working correctly with this php library:

/**
 * Be discoverable via SSDP as Phillips Hue
 */

use Clue\React\Multicast\Factory;

require_once __DIR__ . '/../vendor/autoload.php';

$address = '239.255.255.250:1900';
$loop = React\EventLoop\Factory::create();
$factory = new Factory($loop);
$socket = $factory->createReceiver($address);

$socket->on('message', function ($data, $remote) use ($socket) {

    $lines = explode("\n", $data);
    if (strpos($lines[0], 'M-SEARCH * HTTP/1.1') !== false) {

        foreach ($lines as $line) {
            $line_explode = explode(":", $line, 2);

            $ip = exec("/sbin/ifconfig enp0s8 | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'");

            if ($line_explode[0] === 'ST') {
                $response_message = "HTTP/1.1 200 OK\n";
                $response_message .= "NT: urn:schemas-upnp-org:device:basic:1\n";
                $response_message .= "SERVER: node.js/0.10.28 UPnP/1.1\n";
                $response_message .= "ST: urn:schemas-upnp-org:device:basic:1\n";
                $response_message .= "USN: uuid:Socket-1_0-221438K0100073::urn:Belkin:device:**\n";
                $response_message .= "LOCATION: http://" . $ip . ":80/description.xml\n";
                $response_message .= "HOST: 239.255.255.250:1900\n";
                $response_message .= "CACHE-CONTROL: max-age=1800\n";
                $response_message .= "EXT:\n";
                $response_message .= "DATE: " . gmdate('D, d M Y H:i:s T', time()) . "\n";
                $response_message .= "\n\n";
                $socket->send($response_message, $remote);
            }
        }
    }

});

$loop->run();

I have the code working fine in nodejs:

var ssdp = require("peer-ssdp");
var peer = ssdp.createPeer();

peer.on("search",function(headers, address){
    if (headers.ST && headers.MAN=='"ssdp:discover"') {
        peer.reply({
            NT: "urn:schemas-upnp-org:device:basic:1",
            SERVER: "node.js/0.10.28 UPnP/1.1",
            ST: "urn:schemas-upnp-org:device:basic:1",
            USN: "uuid:Socket-1_0-221438K0100073::urn:Belkin:device:**",
            LOCATION: "http://{{networkInterfaceAddress}}:80/description.xml",
        }, address);
    }
});

peer.start();

The replies from both seem to be identical:

HTTP/1.1 200 OK
NT: urn:schemas-upnp-org:device:basic:1
SERVER: node.js/0.10.28 UPnP/1.1
ST: urn:schemas-upnp-org:device:basic:1
USN: uuid:Socket-1_0-221438K0100073::urn:Belkin:device:**
LOCATION: http://192.168.10.145:80/description.xml
HOST: 239.255.255.250:1900
CACHE-CONTROL: max-age=1800
EXT: 
DATE: Sun, 06 Jan 2019 04:00:35 GMT


Received from 192.168.56.102:50772 (php)
HTTP/1.1 200 OK
NT: urn:schemas-upnp-org:device:basic:1
SERVER: node.js/0.10.28 UPnP/1.1
ST: urn:schemas-upnp-org:device:basic:1
USN: uuid:Socket-1_0-221438K0100073::urn:Belkin:device:**
LOCATION: http://192.168.56.102:80/description.xml
HOST: 239.255.255.250:1900
CACHE-CONTROL: max-age=1800
EXT: 
DATE: Sun, 06 Jan 2019 04:00:35 GMT

I just find it very odd that with the PHP code the other device (amazon alexa) does not query the xml location for php . Oddly enough the device does query it if I run nodejs. I can change the IP to match and still same issue. Any ideas or suggestions? Thanks.

@clue clue added the question label Jan 6, 2019
@clue
Copy link
Owner

clue commented Jan 6, 2019

@ikkysleepy Thank you for this excellent question!

SSDP builds on top of HTTP over UDP, so your reply message would have to adhere to HTTP semantics. In particular, HTTP header lines have to be terminated with CRLF (\r\n) instead of just LF (\n).

Other than that, I'm afraid your question is a bit out of scope for this project. As an alternative, there's also an open issue in clue/reactphp-ssdp#4 to eventually add this as part of said library. Perhaps you can help contributing there?

Again thank you and I hope this helps 👍

@clue clue closed this as completed Jan 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants