|
|
@@ -1,5 +1,5 @@
|
|
|
##############################################################################
|
|
|
-# $Id: 32_withings.pm 17334 2018-09-12 21:29:19Z moises $
|
|
|
+# $Id: 32_withings.pm 17341 2018-09-13 22:23:46Z moises $
|
|
|
#
|
|
|
# 32_withings.pm
|
|
|
#
|
|
|
@@ -10,7 +10,7 @@
|
|
|
#
|
|
|
#
|
|
|
##############################################################################
|
|
|
-# Release 05 / 2018-03-01
|
|
|
+# Release 06 / 2018-09-13
|
|
|
|
|
|
package main;
|
|
|
|
|
|
@@ -50,7 +50,7 @@ my %device_models = ( 1 => { 1 => "Smart Scale", 2 => "Wireless Scale", 3 => "S
|
|
|
2 => { 21 => "Smart Baby Monitor", 22 => "Home", 22 => "Home v2", },
|
|
|
4 => { 41 => "iOS Blood Pressure Monitor", 42 => "Wireless Blood Pressure Monitor", 43 => "BPM", 44 => "BPM+", },
|
|
|
16 => { 51 => "Pulse Ox", 52 => "Activite", 53 => "Activite v2", 54 => "Go", 55 => "Steel HR", },
|
|
|
- 32 => { 60 => "Aura", 61 => "Sleep Sensor", 62 => "Sleep Mat", },
|
|
|
+ 32 => { 60 => "Aura", 61 => "Sleep Sensor", 62 => "Sleep Mat", 63 => "Sleep", },
|
|
|
64 => { 70 => "Thermo", }, );
|
|
|
|
|
|
#Firmware files: cdnfw_withings_net
|
|
|
@@ -507,6 +507,7 @@ sub withings_getToken($) {
|
|
|
Log3 "withings", 2, "withings: json evaluation error on getToken ".$@;
|
|
|
return undef;
|
|
|
}
|
|
|
+ Log3 "withings", 1, "withings: getToken json error ".$json->{error} if(defined($json->{error}));
|
|
|
|
|
|
my $once = $json->{body}{once};
|
|
|
$hash->{Once} = $once;
|
|
|
@@ -637,6 +638,7 @@ sub withings_getSessionKey($) {
|
|
|
Log3 $name, 2, "$name: json evaluation error on getSessionKey ".$@;
|
|
|
return undef;
|
|
|
}
|
|
|
+ Log3 $name, 1, "withings: getSessionKey json error ".$json->{error} if(defined($json->{error}));
|
|
|
|
|
|
foreach my $account (@{$json->{body}{account}}) {
|
|
|
next if( !defined($account->{id}) );
|
|
|
@@ -873,13 +875,13 @@ sub withings_initDevice($) {
|
|
|
$hash->{lastweighindate} = $device->{lastweighindate} if( defined($device->{lastweighindate}) );
|
|
|
|
|
|
|
|
|
- if((defined($hash->{typeID}) && $hash->{typeID} == 16) or (defined($hash->{modelID}) && $hash->{modelID} == 61))
|
|
|
+ if((defined($hash->{typeID}) && $hash->{typeID} == 16) or (defined($hash->{typeID}) && $hash->{typeID} == 32 && defined($hash->{modelID}) && $hash->{modelID} != 60))
|
|
|
{
|
|
|
my $devicelink = withings_getDeviceLink( $hash );
|
|
|
- if(defined($devicelink->{userid}))
|
|
|
+ if(defined($devicelink) && defined($devicelink->{linkuserid}))
|
|
|
{
|
|
|
- $hash->{User} = $devicelink->{userid};
|
|
|
- $hash->{UserDevice} = $modules{$hash->{TYPE}}{defptr}{"U".$devicelink->{userid}} if defined($modules{$hash->{TYPE}}{defptr}{"U".$devicelink->{userid}});
|
|
|
+ $hash->{User} = $devicelink->{linkuserid};
|
|
|
+ $hash->{UserDevice} = $modules{$hash->{TYPE}}{defptr}{"U".$devicelink->{linkuserid}} if defined($modules{$hash->{TYPE}}{defptr}{"U".$devicelink->{linkuserid}});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -958,6 +960,7 @@ sub withings_getUsers($) {
|
|
|
Log3 $name, 2, "$name: json evaluation error on getUsers ".$@;
|
|
|
return undef;
|
|
|
}
|
|
|
+ Log3 $name, 1, "withings: getUsers json error ".$json->{error} if(defined($json->{error}));
|
|
|
|
|
|
my @users = ();
|
|
|
foreach my $user (@{$json->{body}{users}}) {
|
|
|
@@ -979,7 +982,7 @@ sub withings_getDevices($) {
|
|
|
withings_getSessionKey($hash);
|
|
|
|
|
|
my ($err,$data) = HttpUtils_BlockingGet({
|
|
|
- url => $hash->{'.https'}."://scalews.health.nokia.com/index/service/association",
|
|
|
+ url => $hash->{'.https'}."://scalews.withings.com/cgi-bin/association",
|
|
|
timeout => 10,
|
|
|
noshutdown => 1,
|
|
|
data => {sessionid => $hash->{SessionKey}, accountid => $hash->{AccountID} , type => '-1', enrich => 't' , appname => 'my2', appliver=> $hash->{helper}{appliver}, apppfm => 'web', action => 'getbyaccountid'},
|
|
|
@@ -998,6 +1001,7 @@ sub withings_getDevices($) {
|
|
|
Log3 $name, 2, "$name: json evaluation error on getDevices ".$@;
|
|
|
return undef;
|
|
|
}
|
|
|
+ Log3 $name, 1, "withings: getDevices json error ".$json->{error} if(defined($json->{error}));
|
|
|
Log3 "withings", 5, "$name: getdevices ".Dumper($json);
|
|
|
|
|
|
my @devices = ();
|
|
|
@@ -1035,6 +1039,7 @@ sub withings_getDeviceDetail($) {
|
|
|
Log3 $name, 2, "$name: json evaluation error on getDeviceDetail ".$@;
|
|
|
return undef;
|
|
|
}
|
|
|
+ Log3 $name, 1, "withings: getDeviceDetail json error ".$json->{error} if(defined($json->{error}));
|
|
|
|
|
|
if($json)
|
|
|
{
|
|
|
@@ -1067,10 +1072,10 @@ sub withings_getDeviceLink($) {
|
|
|
withings_getSessionKey( $hash->{IODev} );
|
|
|
|
|
|
my ($err,$data) = HttpUtils_BlockingGet({
|
|
|
- url => $hash->{'.https'}."://scalews.health.nokia.com/index/service/v2/link",
|
|
|
+ url => $hash->{'.https'}."://scalews.health.nokia.com/cgi-bin/association",
|
|
|
timeout => 10,
|
|
|
noshutdown => 1,
|
|
|
- data => {sessionid => $hash->{IODev}->{SessionKey}, deviceid => $hash->{Device} , appname => 'my2', appliver=> $hash->{IODev}->{helper}{appliver}, apppfm => 'web', action => 'get'},
|
|
|
+ data => {sessionid => $hash->{IODev}->{SessionKey}, appname => 'hmw', appliver=> $hash->{IODev}->{helper}{appliver}, enrich => 't', action => 'getbyaccountid'},
|
|
|
});
|
|
|
|
|
|
#my $ua = LWP::UserAgent->new;
|
|
|
@@ -1086,8 +1091,15 @@ sub withings_getDeviceLink($) {
|
|
|
Log3 $name, 2, "$name: json evaluation error on getDeviceLink ".$@;
|
|
|
return undef;
|
|
|
}
|
|
|
+ Log3 $name, 1, "withings: getDeviceLink json error ".$json->{error} if(defined($json->{error}));
|
|
|
|
|
|
- return $json->{body};
|
|
|
+ foreach my $association (@{$json->{body}{associations}}) {
|
|
|
+ next if( !defined($association->{deviceid}) );
|
|
|
+ next if( $association->{deviceid} ne $hash->{Device} );
|
|
|
+ return $association->{deviceproperties};
|
|
|
+ }
|
|
|
+
|
|
|
+ return undef;
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -1141,7 +1153,7 @@ sub withings_getDeviceReadingsScale($) {
|
|
|
$enddate = $now if ($enddate > $now);
|
|
|
|
|
|
HttpUtils_NonblockingGet({
|
|
|
- url => "https://scalews.health.nokia.com/index/service/v2/measure",
|
|
|
+ url => "https://scalews.health.nokia.com/cgi-bin/v2/measure",
|
|
|
timeout => 30,
|
|
|
noshutdown => 1,
|
|
|
data => {sessionid => $hash->{IODev}->{SessionKey}, deviceid=> $hash->{Device}, meastype => '12,35', startdate => int($lastupdate), enddate => int($enddate), devicetype => '16', appname => 'my2', appliver => $hash->{IODev}->{helper}{appliver}, apppfm => 'web', action => 'getmeashf'},
|
|
|
@@ -1176,7 +1188,7 @@ sub withings_getDeviceReadingsBedside($) {
|
|
|
$enddate = $now if ($enddate > $now);
|
|
|
|
|
|
HttpUtils_NonblockingGet({
|
|
|
- url => "https://scalews.health.nokia.com/index/service/v2/measure",
|
|
|
+ url => "https://scalews.health.nokia.com/cgi-bin/v2/measure",
|
|
|
timeout => 30,
|
|
|
noshutdown => 1,
|
|
|
data => {sessionid => $hash->{IODev}->{SessionKey}, deviceid=> $hash->{Device}, meastype => '12,13,14,15,56', startdate => int($lastupdate), enddate => int($enddate), devicetype => '16', appname => 'my2', appliver => $hash->{IODev}->{helper}{appliver}, apppfm => 'web', action => 'getmeashf'},
|
|
|
@@ -1211,7 +1223,7 @@ sub withings_getDeviceReadingsHome($) {
|
|
|
$enddate = $now if ($enddate > $now);
|
|
|
|
|
|
HttpUtils_NonblockingGet({
|
|
|
- url => "https://scalews.health.nokia.com/index/service/v2/measure",
|
|
|
+ url => "https://scalews.health.nokia.com/cgi-bin/v2/measure",
|
|
|
timeout => 30,
|
|
|
noshutdown => 1,
|
|
|
data => {sessionid => $hash->{IODev}->{SessionKey}, deviceid=> $hash->{Device}, meastype => '12,13,14,15,58', startdate => int($lastupdate), enddate => int($enddate), devicetype => '16', appname => 'my2', appliver => $hash->{IODev}->{helper}{appliver}, apppfm => 'web', action => 'getmeashf'},
|
|
|
@@ -1353,6 +1365,7 @@ sub withings_getVideoLink($) {
|
|
|
Log3 $name, 2, "$name: json evaluation error on getVideoLink ".$@;
|
|
|
return undef;
|
|
|
}
|
|
|
+ Log3 $name, 1, "withings: getVideoLink json error ".$json->{error} if(defined($json->{error}));
|
|
|
|
|
|
if(defined($json->{body}{device}))
|
|
|
{
|
|
|
@@ -1389,6 +1402,7 @@ sub withings_getS3Credentials($) {
|
|
|
Log3 $name, 2, "$name: json evaluation error on getS3Credentials ".$@;
|
|
|
return undef;
|
|
|
}
|
|
|
+ Log3 $name, 1, "withings: getS3Credentials json error ".$json->{error} if(defined($json->{error}));
|
|
|
|
|
|
if(defined($json->{body}{sts}))
|
|
|
{
|
|
|
@@ -1450,6 +1464,7 @@ sub withings_getUserDetail($) {
|
|
|
Log3 $name, 2, "$name: json evaluation error on getUserDetail ".$@;
|
|
|
return undef;
|
|
|
}
|
|
|
+ Log3 $name, 1, "withings: getUserDetail json error ".$json->{error} if(defined($json->{error}));
|
|
|
|
|
|
return $json->{body}{users}[0];
|
|
|
}
|
|
|
@@ -1512,7 +1527,7 @@ sub withings_poll($;$) {
|
|
|
withings_getDeviceProperties($hash) if($force > 1 || $lastProperties <= ($now - $intervalProperties));
|
|
|
withings_getDeviceReadingsBedside($hash) if($force || $lastData <= ($now - $intervalData));
|
|
|
}
|
|
|
- elsif(defined($hash->{modelID}) && $hash->{modelID} eq '61') {
|
|
|
+ elsif(defined($hash->{modelID}) && ($hash->{modelID} eq '61' || $hash->{modelID} eq '62' || $hash->{modelID} eq '63')) {
|
|
|
withings_getDeviceProperties($hash) if($force > 1 || $lastProperties <= ($now - $intervalProperties));
|
|
|
withings_getUserReadingsSleep($hash) if($force || $lastData <= ($now - $intervalData));
|
|
|
withings_getUserReadingsSleepDebug($hash) if($force || $lastDebug <= ($now - $intervalDebug));
|
|
|
@@ -1562,7 +1577,7 @@ sub withings_getUserReadingsDaily($) {
|
|
|
my $enddateymd = strftime("%Y-%m-%d", localtime($enddate));
|
|
|
|
|
|
HttpUtils_NonblockingGet({
|
|
|
- url => "https://scalews.health.nokia.com/index/service/v2/aggregate",
|
|
|
+ url => "https://scalews.health.nokia.com/cgi-bin/v2/aggregate",
|
|
|
timeout => 60,
|
|
|
noshutdown => 1,
|
|
|
data => {sessionid => $hash->{IODev}->{SessionKey}, userid=> $hash->{User}, range => '1', meastype => '36,37,38,40,41,49,50,51,52,53,87', startdateymd => $startdateymd, enddateymd => $enddateymd, appname => 'my2', appliver => $hash->{IODev}->{helper}{appliver}, apppfm => 'web', action => 'getbyuserid'},
|
|
|
@@ -1580,7 +1595,7 @@ sub withings_getUserReadingsDaily($) {
|
|
|
$enddateymd = strftime("%Y-%m-%d", localtime($enddate));
|
|
|
|
|
|
HttpUtils_NonblockingGet({
|
|
|
- url => "https://scalews.health.nokia.com/index/service/v2/activity",
|
|
|
+ url => "https://scalews.health.nokia.com/cgi-bin/v2/activity",
|
|
|
timeout => 60,
|
|
|
noshutdown => 1,
|
|
|
data => {sessionid => $hash->{IODev}->{SessionKey}, userid=> $hash->{User}, subcategory => '37', startdateymd => $startdateymd, enddateymd => $enddateymd, appname => 'my2', appliver => $hash->{IODev}->{helper}{appliver}, apppfm => 'web', action => 'getbyuserid'},
|
|
|
@@ -1664,7 +1679,7 @@ sub withings_getUserReadingsSleep($) {
|
|
|
# data => {sessionid => $hash->{IODev}->{SessionKey}, userid=> $hash->{User}, meastype => '43,44,11,57,59,60,61,62,63,64,65,66,67,68,69,70', startdate => int($lastupdate), enddate => int($enddate), devicetype => '32', appname => 'my2', appliver => $hash->{IODev}->{helper}{appliver}, apppfm => 'web', action => 'getvasistas'},
|
|
|
|
|
|
HttpUtils_NonblockingGet({
|
|
|
- url => "https://scalews.health.nokia.com/index/service/v2/measure",
|
|
|
+ url => "https://scalews.health.nokia.com/cgi-bin/v2/measure",
|
|
|
timeout => 60,
|
|
|
noshutdown => 1,
|
|
|
data => {sessionid => $hash->{IODev}->{SessionKey}, userid=> $hash->{User}, meastype => '11,39,41,43,44,57,59,87', startdate => int($lastupdate), enddate => int($enddate), devicetype => '32', appname => 'my2', appliver => $hash->{IODev}->{helper}{appliver}, apppfm => 'web', action => 'getvasistas'},
|
|
|
@@ -1698,7 +1713,7 @@ sub withings_getUserReadingsSleepDebug($) {
|
|
|
$enddate = $now if ($enddate > $now);
|
|
|
|
|
|
HttpUtils_NonblockingGet({
|
|
|
- url => "https://scalews.health.nokia.com/index/service/v2/measure",
|
|
|
+ url => "https://scalews.health.nokia.com/cgi-bin/v2/measure",
|
|
|
timeout => 60,
|
|
|
noshutdown => 1,
|
|
|
data => {sessionid => $hash->{IODev}->{SessionKey}, userid=> $hash->{User}, meastype => '60,61,62,63,64,65,66,67,68,69,70', startdate => int($lastupdate), enddate => int($enddate), devicetype => '32', appname => 'my2', appliver => $hash->{IODev}->{helper}{appliver}, apppfm => 'web', action => 'getvasistas'},
|
|
|
@@ -1736,7 +1751,7 @@ sub withings_getUserReadingsActivity($) {
|
|
|
Log3 "withings", 5, "$name: getactivityreadings ".$lastupdate." to ".$enddate;
|
|
|
|
|
|
HttpUtils_NonblockingGet({
|
|
|
- url => "https://scalews.health.nokia.com/index/service/v2/measure",
|
|
|
+ url => "https://scalews.health.nokia.com/cgi-bin/v2/measure",
|
|
|
timeout => 60,
|
|
|
noshutdown => 1,
|
|
|
data => {sessionid => $hash->{IODev}->{SessionKey}, userid=> $hash->{User}, meastype => '36,37,38,39,40,41,42,43,44,59,70,87,90', startdate => int($lastupdate), enddate => int($enddate), devicetype => '16', appname => 'my2', appliver => $hash->{IODev}->{helper}{appliver}, apppfm => 'web', action => 'getvasistas'},
|
|
|
@@ -1842,7 +1857,7 @@ sub withings_parseMeasureGroups($$) {
|
|
|
|
|
|
|
|
|
delete $hash->{CHANGETIME};
|
|
|
- Log3 $name, 4, "$name: got ".$i.' entries from MeasureGroups (latest: '.FmtDateTime($newlastupdate).')';
|
|
|
+ Log3 $name, 3, "$name: got ".$i.' entries from MeasureGroups (latest: '.FmtDateTime($newlastupdate).')';
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -1852,7 +1867,7 @@ sub withings_parseMeasurements($$) {
|
|
|
my ($hash, $json) = @_;
|
|
|
my $name = $hash->{NAME};
|
|
|
#parse
|
|
|
- Log3 "withings", 5, "$name: parsemeasurements";
|
|
|
+ Log3 "withings", 4, "$name: parsemeasurements";
|
|
|
my ($now) = time;
|
|
|
my $lastupdate = ReadingsVal( $name, ".lastData", ($now-21*24*60*60) );
|
|
|
my $newlastupdate = $lastupdate;
|
|
|
@@ -1924,7 +1939,7 @@ sub withings_parseMeasurements($$) {
|
|
|
|
|
|
|
|
|
delete $hash->{CHANGETIME};
|
|
|
- Log3 $name, 4, "$name: got ".$i.' entries from Measurements (latest: '.FmtDateTime($newlastupdate).')';
|
|
|
+ Log3 $name, 3, "$name: got ".$i.' entries from Measurements (latest: '.FmtDateTime($newlastupdate).')';
|
|
|
|
|
|
|
|
|
}
|
|
|
@@ -2192,7 +2207,7 @@ sub withings_parseVasistas($$;$) {
|
|
|
my @readingsvalue = (@{$values[$j++]});
|
|
|
if($readingsdate <= $lastupdate)
|
|
|
{
|
|
|
- Log3 $name, 4, "$name: old vasistas skipped: ".FmtDateTime($readingsdate);
|
|
|
+ Log3 $name, 5, "$name: old vasistas skipped: ".FmtDateTime($readingsdate);
|
|
|
next;
|
|
|
}
|
|
|
|
|
|
@@ -3155,8 +3170,9 @@ sub withings_Dispatch($$$) {
|
|
|
Log3 $name, 2, "$name: json evaluation error on dispatch type ".$param->{type}." ".$@;
|
|
|
return undef;
|
|
|
}
|
|
|
+ Log3 $name, 1, "withings: Dispatch ".$param->{type}." json error ".$json->{error} if(defined($json->{error}));
|
|
|
|
|
|
- Log3 $name, 4, "$name: json returned: ".Dumper($json);
|
|
|
+ Log3 $name, 5, "$name: json returned: ".Dumper($json);
|
|
|
|
|
|
if(defined($param->{enddate}))
|
|
|
{
|