Device-Neurio
view release on metacpan or search on metacpan
lib/Device/Neurio.pm view on Meta::CPAN
undef $self->{'Appliances_url'};
undef $self->{'Appliances_Specs_url'};
undef $self->{'Appliances_Stats_url'};
undef $self->{'Appliances_Status_url'};
undef $self->{'Appliances_Events_url'};
undef $self->{'Users_url'};
undef $self->{'Cycles_url'};
undef $self->{'Cycles_Full_url'};
undef $self->{'Cycles_Groups_url'};
undef $self->{'Edges_url'};
undef $self->{'Sensors_url'};
undef $self->{'Analytics_url'};
undef $self->{'last_code'};
undef $self->{'last_reason'};
undef $self->{'last_exec_time'};
undef $self->{'rateLimitRemaining'};
undef $self->{'rateLimitReset'};
undef $self->{'rateLimitLimit'};
undef $self->{'contentLength'};
}
###################################################################################################
=head2 connect - open a secure connection to the Neurio server
Opens a secure connection via HTTPS to the Neurio server which provides
access to a set of API commands to access the sensor data.
An optional location ID can be given. This is only required if calls
will be made to the 'Appliance' methods. Calls to the 'Samples'
methods do not require that a location ID be set. If a location_id is not
specified at connection, then it must be specified when using the 'Appliance'
methods.
A location ID can be acquired from the Neurio developpers web site
$Neurio->connect($location_id);
This method accepts the following parameter:
- $location_id : unique location id - Optional
Returns 1 on success
Returns 0 on failure
=cut
sub connect {
my ($self,$location_id) = @_;
my $access_token = '';
if (defined $location_id) {
$self->{'location_id'} = $location_id;
} else {
$self->{'location_id'} = '';
}
# Submit request for authentiaction token.
my $response = $self->{'ua'}->post($self->{'base_url'}.'/oauth2/token',
{ basic_authentication => $self->{'base64'},
Content_Type => 'application/x-www-form-urlencoded',
grant_type => 'client_credentials',
client_id => $self->{'key'},
client_secret => $self->{'secret'},
}
);
if($response->is_success) {
my $return = $response->content;
$return =~ /\"access_token\":\"(.*)\"\,\"token_type\"/;
$self->{'access_token'} = $1;
return 1;
} else {
$self->printLOG("\nDevice::Neurio->connect(): Failed to connect.\n");
if ($self->{'debug'}) {$self->printLOG($response->content."\n\n");}
$self->{'last_code'} = '0';
$self->{'last_reason'} = 'Neurio->new(): Device::Neurio->connect(): Failed to connect';
return 0;
}
}
###################################################################################################
=head2 debug - Configure debug settings for a Neurio object
Enables debug printouts and an optional file handle can be supplied
where printouts will be re-directed.
$my_Neurio = Device::Neurio->new($key,$secret,$sensor_id);
$my_Neurio->connect($location_id);
$my_Neurio->debug($debug,$fileHandle);
This method accepts at least one of the following parameters:
- $debug : turn on debug messages - Optional
- $fileHandle : filehandle for logging debug messages - Optional
Returns nothing.
=cut
sub debug {
my ($self,$debug,$fileHandle) = @_;
if (defined $debug) {
$self->{'debug'} = $debug;
}
if (defined $fileHandle) {
$self->{'$fileHandle'} = $fileHandle;
}
}
###################################################################################################
=head2 fetch_Samples_Recent_Live - Fetch recent sensor samples
Get recent samples, one sample per second for up to the last 2 minutes.
The values represent the sum of all phases.
$Neurio->fetch_Samples_Recent_Live($last);
This method accepts the following parameters:
$last - time of last sample received specified using ISO8601
format (yyyy-mm-ddThh:mm:ssZ) - Optional
( run in 1.034 second using v1.01-cache-2.11-cpan-140bd7fdf52 )