From e2b2e8772e02ebc2428c8edea5d4b888ddbb4766 Mon Sep 17 00:00:00 2001 From: TrystanLea Date: Tue, 12 Feb 2019 16:07:12 +0000 Subject: [PATCH] add setting to enable UDP broadcast --- device_controller.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/device_controller.php b/device_controller.php index c6d167a..3755d31 100644 --- a/device_controller.php +++ b/device_controller.php @@ -45,11 +45,13 @@ function device_controller() // 2. User checks for device waiting for authentication $result = $device->get_auth_request(); - $port = 5005; - $broadcast_string = "emonpi.local"; - $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); - socket_set_option($sock, SOL_SOCKET, SO_BROADCAST, 1); - socket_sendto($sock, $broadcast_string, strlen($broadcast_string), 0, '255.255.255.255', $port); + if (isset($enable_UDP_broadcast) && $enable_UDP_broadcast) { + $port = 5005; + $broadcast_string = "emonpi.local"; + $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); + socket_set_option($sock, SOL_SOCKET, SO_BROADCAST, 1); + socket_sendto($sock, $broadcast_string, strlen($broadcast_string), 0, '255.255.255.255', $port); + } } else if ($route->subaction=="allow" && $session['write']) { // 3. User allows device to receive authentication details