gboudreau / nissan-connect-php

Use the Nissan Connect (was Carwings) API using a simple PHP class.
GNU General Public License v3.0
38 stars 17 forks source link

Issue with new API -- No battery info? #20

Closed jeremyakers closed 6 years ago

jeremyakers commented 6 years ago

I don't think this is an issue with the nissan-connect-php class, but I wanted to raise it just in case.

I'm no longer getting updated battery info after the switch to the new API (Was working fine until May 27 when the old API shut down) It also updates fine on the Nissan Owners Portal, so this issue is specific to the new API:

php test.php 
[2018-05-31 09:43:31] [NissanConnect] Request: POST https://icm.infinitiusa.com/NissanLeafProd/rest/auth/authenticationForAAS {"authenticate":{"userid":"myemail@gmail.com","password":"MyPassword","brand-s":"N","language-s":"en","country":"US"}}
[2018-05-31 09:43:41] [NissanConnect] Response: {"vehicles":[{"uvi":"<MyVIN>","brands":"N","modelcode":"17216","modelname":"LEAF","modelyear":"2016","extcolor":"PEARL WHITE","nickname":"2016 Leaf","pinAndPassword":null,"batteryRecords":null,"interiorTempRecords":null,"subcriptionList":null,"genType":null,"deviceId":null,"svlStatus":null,"accountId":null,"contactId":null,"subscriberType":null,"subscriptionId":null,"firstName":null,"lastName":null,"rdlRequestId":null,"rdulRequestId":null,"accountStatus":null,"productSpecificationCode":null,"remoteStartReqId":null,"remoteStopReqId":null,"enrollmentCompleted":true}],"authenticationInfo":{"pinConfigured":false,"securityQuestions":null},"displayMessage":"BatteryStatusRecords not available for the user","displayNoTemperatureMessage":"InteriorTemperature Records are  not available for the VIN","accountID":"<accountID>","authToken":"<authToken>","status":200}
[2018-05-31 09:43:41] [NissanConnect] Saving authToken, VIN and accountID into local file /tmp/.nissan-connect-storage-<redacted>.json
[2018-05-31 09:43:41] [NissanConnect] Request: POST https://icm.infinitiusa.com/NissanLeafProd/rest/battery/vehicles/<MyVIN>/getChargingStatusRequest []
An error occurred: Non-JSON response received for request to 'battery/vehicles/<MyVIN>/getChargingStatusRequest'. Response received: ""

I checked the app itself with mitmproxy, and the official Nissan App has the same issue. I just have never noticed because I never use the official app anymore.

Any thoughts on how to resolve this? Everything else in the new API seems to work. HVAC start/stop, driving and electricity records, etc. Everything is fine except for battery status updates.

gboudreau commented 6 years ago

Works fine for me now. You?

jeremyakers commented 6 years ago

Nope, now I'm getting:

[2018-06-03 11:32:09] [NissanConnect] Using authToken, VIN and accountID found in local file /tmp/.nissan-connect-storage-67e2ade14f55bbcb1b4c6a2288e8986a.json
[2018-06-03 11:32:09] [NissanConnect] Request: POST https://icm.infinitiusa.com/NissanLeafProd/rest/battery/vehicles/<VIN>/getChargingStatusRequest []
An error occurred: Request for 'battery/vehicles/<VIN>/getChargingStatusRequest' failed. Response received: "<html><head><title>JBoss Web\/7.4.10.Final-redhat-1 - JBWEB000064: Error report<\/title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--><\/style> <\/head><body><h1>JBWEB000065: HTTP Status 405 - <\/h1><HR size=\"1\" noshade=\"noshade\"><p><b>JBWEB000309: type<\/b> JBWEB000067: Status report<\/p><p><b>JBWEB000068: message<\/b> <u><\/u><\/p><p><b>JBWEB000069: description<\/b> <u>JBWEB000125: The specified HTTP method is not allowed for the requested resource.<\/u><\/p><HR size=\"1\" noshade=\"noshade\"><h3>JBoss Web\/7.4.10.Final-redhat-1<\/h3><\/body><\/html>"

I think because "getChargingStatusRequest" should be accessed via GET rather than POST based on my looking at the mitmproxy data from the official app.

However: The official app is still not returning battery data either. It's returning "No content" instead of the expected JSON. I'm starting to think I may need to call Nissan.

gboudreau commented 6 years ago

getChargingStatusRequest is sent via a GET, not a POST; it's just the log that incorrectly logs "POST". Try the latest version of the class; it will fix the log, and will also retry to log in, when it receives a 405.

gboudreau commented 6 years ago

I went back to the old API, but with an updated base URL, which seems to work just fine. I kept the work I did for the new api in the new-api branch, in case we need it in the future, but for now, the new base URL should fix the issues we were having when Nissan deprecated the old URL.