Skip to content

Commit

Permalink
add setting to enable UDP broadcast
Browse files Browse the repository at this point in the history
  • Loading branch information
glynhudson committed Feb 12, 2019
1 parent 66affc2 commit e2b2e87
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions device_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e2b2e87

Please sign in to comment.