#!/usr/bin/perl

use v5.10;

use warnings;
use strict;

use Readonly;
use IPC::Cmd qw/ run /;

# Get the MACs of all other homeplugs
run(command => "echo A038 | faifa -m",
    buffer => \my $out,
    # For some reason it takes about this long to get the data
    timeout => 3);
Readonly my @MACS => $out =~ /\n((?:\w{2}:){5}\w{2})/g;

for my $mac (@MACS) { 
    # Reboot other homeplugs one at a time
    run(command => "echo A01C | faifa -m -a $mac",
	timeout => 1);
}

# Then reboot this one
run(command => "echo A01C | faifa -m",
    timeout => 1);
