mmitch / fritz

Perl module for AVM FRITZ!Box interaction via TR-064

Home Page:https://metacpan.org/release/Net-Fritz

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Get all WLAN devices (provided sample code)

estegewr opened this issue · comments

I try to identify devices connected to WLAN using the sample code provided by distribution:

my $services = $d->find_service_names('Configuration:');
$services->errorcheck;
for my $serviceType (@{$services->data}) {
my $service = $d->get_service($serviceType);
$services->errorcheck;
my $response = $services->call('GetTotalAssociations');
$response->errorcheck;
# ...
}

Unfortunately script fails at cmd $services->call('GetTotalAssociations'); with error msg Can't locate object method "call" via package "Net::Fritz::Data"

There was a mixup in the example code, see the latest checkin (referenced above), it should fix it.
As I still don't have an active WLAN with any clients, the comment

# now do a loop and read device by device - my WLAN is off, so I can't test here :-)

still applies.

Thank you. Now it works!

If you want you can add the loop to your sample code ...

	# now do a loop and read device by device
	for my $host ( 0 .. $response->data->{NewTotalAssociations} - 1) {
		$response = $service->call('GetGenericAssociatedDeviceInfo', 'NewAssociatedDeviceIndex' => $host);
		$response->errorcheck;
		my $d = $response->data;

		printf("%15s   %-20s   %-15d   %-7d   %d\n",
			   $d->{"NewAssociatedDeviceIPAddress"},
			   $d->{"NewAssociatedDeviceMACAddress"},
			   $d->{"NewX_AVM-DE_SignalStrength"},
			   $d->{"NewX_AVM-DE_Speed"},
			   $d->{"NewAssociatedDeviceAuthState"},
			);
	}

Thanks!

I applied your code (with a slight change for clarity: don't silently overwrite $response, use a new $hostresponse inside the loop)