Skip to content

Commit

Permalink
wol packages are sent as a broadcast additionally
Browse files Browse the repository at this point in the history
(many devices can't be awakened otherwise)
- send wol packages 5 times in a row
- max number of ping retires set to 25, and they are now not shown in the UI explicitly
  • Loading branch information
herzhenr committed Jun 18, 2023
1 parent 8831933 commit 1db26b1
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/services/network.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,22 @@ Stream<Message> sendWolPackage({required NetworkDevice device}) async* {
// if no error occurred: try to send wol package
yield Message(text: "Provided ip and mac address are both valid");
yield Message(text: "Trying to send WOL Packages");

IPv4Address ipv4Address = IPv4Address(ip);
MACAddress macAddress = MACAddress(mac);

// sometimes only a broadcast works to wake a device so a broadcast is sent additionally

final subnet = ip.substring(0, ip.lastIndexOf("."));
final broadcast = "$subnet.255";
IPv4Address ipv4Broadcast = IPv4Address(broadcast);

try {
WakeOnLAN wol = WakeOnLAN(ipv4Address, macAddress, port: port!);
await wol.wake(repeat: 10);
await wol.wake(repeat: 5);
await Future.delayed(const Duration(seconds: 1));
WakeOnLAN wolBroadcast = WakeOnLAN(ipv4Broadcast, macAddress, port: port);
await wolBroadcast.wake(repeat: 5);
yield Message(
text: "Successfully send WOL packages to $ip", type: MsgType.check);
} catch (e) {
Expand All @@ -108,10 +119,10 @@ Stream<Message> sendWolPackage({required NetworkDevice device}) async* {
yield Message(text: "Trying to ping device until it is online...");
bool online = false;
int tries = 0;
const maxPings = 20;
const maxPings = 25;
while (!online && tries < maxPings) {
tries++;
yield Message(text: "Sending ping $tries/$maxPings", type: MsgType.ping);
yield Message(text: "Sending ping #$tries", type: MsgType.ping);

final ping = Ping(ip, count: 1, timeout: 5);

Expand Down

0 comments on commit 1db26b1

Please sign in to comment.