gboudreau/nissan-connect-php

这是一个简单的库,允许您使用尼桑Connect(曾是Carwings)API检查您的尼桑LEAF,启动/停止气候控制或开始充电。

2.2.2 2019-01-10 22:14 UTC

This package is auto-updated.

Last update: 2024-09-18 14:53:46 UTC


README

使用简单的PHP类通过Nissan Connect(曾是Carwings)API。

安装

您可以直接下载NissanConnect.class.php并require/include它,或者使用composer

require "gboudreau/nissan-connect-php": "dev-master"

如果您在北美,您可能需要使用new-api分支,而不是master

require "gboudreau/nissan-connect-php": "dev-new-api"

使用方法

require_once 'NissanConnect.class.php';

// All parameters except the first two (username & password) are optional; the default values are shown here
// If you can't use the openssl_encrypt() function (very unlikely), you can use a web-service to encrypt your password. Simply change the last parameter to NissanConnect::ENCRYPTION_OPTION_WEBSERVICE
$nissanConnect = new NissanConnect('you@something.com', 'your_password_here', 'America/New_York', NissanConnect::COUNTRY_US, NissanConnect::ENCRYPTION_OPTION_OPENSSL);

// Change to TRUE to log debugging information into your PHP error log
$nissanConnect->debug = FALSE;

// How long (in seconds) should we wait for the result before giving up. Only used when $waitForResult = TRUE
$nissanConnect->maxWaitTime = 290;

try {
    $result = $nissanConnect->getStatus();
    var_dump($result);
    
    // Start charging
    $nissanConnect->startCharge();
    
    // Should we wait until the command result is known, before returning? Enabling this will wait until the car executed the command, and returned the response, which can sometimes take a few minutes.
    $waitForResult = FALSE; 
    
    // Start Climate Control
    $nissanConnect->startClimateControl($waitForResult);
    
    // Stop Climate Control
    $nissanConnect->stopClimateControl($waitForResult);
} catch (Exception $ex) {
    echo "An error occurred: " . $ex->getMessage();
}

示例输出(《getStatus调用的结果)

object(stdClass)#9 (18) {
  ["LastUpdated"]=>
  string(16) "2016-02-21 15:24"
  ["PluggedIn"]=>
  bool(true)
  ["Charging"]=>
  bool(false)
  ["ChargingMode"]=>
  string(12) "NOT_CHARGING"
  ["BatteryCapacity"]=>
  int(12)
  ["BatteryRemainingAmount"]=>
  int(9)
  ["BatteryRemainingAmountWH"]=>
  NULL
  ["BatteryRemainingAmountkWH"]=>
  NULL
  ["TimeRequiredToFull"]=>
  NULL
  ["TimeRequiredToFull200"]=>
  NULL
  ["TimeRequiredToFull200_6kW"]=>
  NULL
  ["CruisingRangeAcOn"]=>
  float(90.4)
  ["CruisingRangeAcOff"]=>
  float(115.712)
  ["CruisingRangeUnit"]=>
  string(2) "km"
  ["RemoteACRunning"]=>
  bool(false)
  ["RemoteACLastChanged"]=>
  string(16) "2016-02-21 15:24"
  ["ACStartStopURL"]=>
  NULL
  ["ACDurationBatterySec"]=>
  int(900)
  ["ACDurationPluggedSec"]=>
  int(7200)
}

致谢

感谢Joshua Perry为他提供的Carwings协议参考,我将其作为重构我的一键访问LEAF的参考,创建了此类。

主要使用以下免费开源许可证开发:
PHPStorm
JetBrains友好提供。谢谢大家!