Even wat gespeeld met het ocean connect platform…
Hier is een voorbeeldje middels een klein script om de Oceanconnect te bevragen…
Mede dank an @waltert !
gevoelige informatie heb ik in een los shell script gestopt:
# Ocean connect settings
APPKEY=*************************************
SECRET=*************************************
SSLKEY=`find $PWD -name outgoing.CertwithKey.key`
SSLCERT=`find $PWD -name outgoing.CertwithKey.crt`
export APPKEY SECRET SSLKEY SSLCERT
die je bv. vervolgens zo aan je environment kunt toevoegen:
. ~/.settings
#!/usr/bin/perl -w
# This file is part of NB-iot-perl.
#
# NB-iot-perl is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# (c) 2017 Henk Vergonet
use strict;
use LWP::UserAgent;
use JSON;
use MIME::Base64;
use Data::Dumper;
# Disable certificate check
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0;
# Do nut mess with underscores in the header fields
$HTTP::Headers::TRANSLATE_UNDERSCORE = 0;
# For Northbound interfaces we will need these environment variables:
#
# APPKEY => Get it from https://devreg.iot.t-mobile.nl/login key parameter
# SECRET => Get it from https://devreg.iot.t-mobile.nl/login Secret parameter
# SSLKEY => Location of the SSL key file
# SSLCERT => Location of the SSL certificate file
my %conf = (
# Ocean Connect Northbound Interface
host => 'https://160.44.201.248:8743',
appid => ($ENV{APPKEY} || die "Define environment variable APPKEY"),
secret => ($ENV{SECRET} || die "Define environment variable SECRET"),
sslcert => ($ENV{SSLCERT} || die "Define envvronment SSLCERT for ssl certificate file"),
sslkey => ($ENV{SSLKEY} || die "Define envvronment SSLCERT for ssl key file"),
);
my $res;
my $ua = LWP::UserAgent->new(
ssl_opts => {
SSL_verify_mode => 0,
SSL_ca_path => '/etc/ssl/certs',
SSL_cert_file => $conf{sslcert},
SSL_key_file => $conf{sslkey},
});
################################################################################
# Login
$res = $ua->post($conf{host}.'/iocm/app/sec/v1.1.0/login',
{ appId => $conf{appid}, Secret => $conf{secret}});
my $token = from_json($res->content());
print Dumper($token);
################################################################################
# Get All My Devices
{
my $page = 0;
my $ret;
do {
$res = $ua->get($conf{host}.'/iocm/app/dm/v1.1.0/devices?pageNo='.$page,
'app_key' => $conf{appid},
'authorization' => "Bearer $token->{accessToken}",
'cache-control' => 'no-cache',
'content-type' => 'application/json',
);
$ret = from_json($res->content());
print Dumper($ret->{devices});
last unless $ret->{totalCount} && $ret->{pageSize};
$page += $ret->{pageSize};
} while($page < $ret->{totalCount});
}