Nissan Leaf Plugin

Posted on
Sat Apr 02, 2016 2:57 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Nissan Leaf Plugin

Ah, I've restarted the plugin and I now get loads of the following (with XXXX's in various places to hide what might be confidential):

Code: Select all
2016-04-02 09:48:58.026   Nissan Leaf Debug   request and update status
2016-04-02 09:48:58.026   Nissan Leaf   requesting status for
2016-04-02 09:48:58.026   Nissan Leaf   not yet logged in; doing that first
2016-04-02 09:48:58.027   Nissan Leaf Debug   logging in to carwings
2016-04-02 09:48:58.027   Nissan Leaf Debug   invoking carwings API: https://gdcportalgw.its-mo.com/gworchest_0307C/gdc/InitialApp.php
2016-04-02 09:48:58.028   Nissan Leaf Debug   params: {
   "RegionCode": "NE",
   "custom_sessionid": "",
   "initial_app_strings": "geORNtsXXXXXXXG9GZiA",
   "lg": "en-US"
}
2016-04-02 09:49:00.002   Nissan Leaf Debug   Response HTTP Status Code: 200
2016-04-02 09:49:00.002   Nissan Leaf Debug   Response HTTP Response Body: {"status":200,"message":"success","baseprm":"uyI5DjXXXXXXRUbr3g"}
2016-04-02 09:49:00.006   Nissan Leaf Debug   invoking carwings API: https://gdcportalgw.its-mo.com/gworchest_0307C/gdc/UserLoginRequest.php
2016-04-02 09:49:00.007   Nissan Leaf Debug   params: {
   "Password": "IFfQXXXXXX2m33Q==",
   "RegionCode": "NE",
   "UserId": "XXXXXXX",
   "custom_sessionid": "",
   "initial_app_strings": "geORNtXXXXXXjG9GZiA"
}
2016-04-02 09:49:08.095   Nissan Leaf Debug   Response HTTP Status Code: 200
2016-04-02 09:49:08.095   Nissan Leaf Debug   Response HTTP Response Body: {"status":200,"message":"success","vehicleInfo":[{"vin":"SJNFAXXXXX","nickname":"Leafy","charger20066":"true","telematicsEnabled":"true","custom_sessionid":"B\/mDV\/7JGwFymXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXQiEb0U8w=="}],"vehicle":{"profile":{"vin":"SJNFAAX","gdcUserId":"XXXXXX","gdcPassword":"XXXXXX","encAuthToken":"60EB9512XXXXXXXXXXXXXXXXXXXXXXF00CC680CB6B06F6247","dcmId":"201XXXXX41","status":"true","statusDate":"2016\/03\/15 23:00","nickname":"Leafy"}},"EncAuthToken":"6EAF081A0517XXXXXXXXXXXXXXXXXXXXXXXxAC06E100B1EB2439","CustomerInfo":{"UserId":"XXXXXXXXX","Language":"en_GB","Timezone":"Europe\/Paris","RegionCode":"NE","OwnerId":"30XXXXX0","EMailAddress":"XXX@XXXXXX.co.uk","Nickname":"Leafy","Country":"GB","VehicleImage":"\/content\/language\/default\/images\/img\/ph_car.jpg","UserVehicleBoundDurationSec":"946771200","VehicleInfo":{"VIN":"SJXXXXXX","DCMID":"201XXXX","SIMID":"89460XXXXX991","NAVIID":"10XXXXX98","EncryptedNAVIID":"479470XXXXXXX5E2","MSN":"46XXXX799","LastVehicleLoginTime":"","UserVehicleBoundTime":"2016-03-16T16:33:27Z","LastDCMUseTime":"2016\/04\/01 17:04"}},"UserInfoRevisionNo":"1"}
2016-04-02 09:49:08.099   Nissan Leaf Error   Error in plugin execution runConcurrentThread:

Traceback (most recent call last):
  File "plugin.py", line 136, in runConcurrentThread
  File "/Library/Application Support/Perceptive Automation/Indigo 6/Plugins/Nissan Leaf.indigoPlugin/Contents/Server Plugin/indigo_leaf.py", line 113, in request_and_update_status
  File "/Library/Application Support/Perceptive Automation/Indigo 6/Plugins/Nissan Leaf.indigoPlugin/Contents/Server Plugin/indigo_leaf.py", line 132, in request_status
  File "/Library/Application Support/Perceptive Automation/Indigo 6/Plugins/Nissan Leaf.indigoPlugin/Contents/Server Plugin/indigo_leaf.py", line 51, in login
  File "/Library/Application Support/Perceptive Automation/Indigo 6/Plugins/Nissan Leaf.indigoPlugin/Contents/Server Plugin/pycarwings2/pycarwings2.py", line 150, in connect
<type 'exceptions.AttributeError'>: CarwingsLoginResponse instance has no attribute 'custom_sessionid'

2016-04-02 09:49:08.100   Nissan Leaf Error   plugin runConcurrentThread function returned or failed (will attempt again in 10 seconds)


I do note that the object they return still contains my password in plaintext which is ridiculous!!!

Peter

Posted on
Sat Apr 02, 2016 2:27 pm
dustysparkle offline
Posts: 54
Joined: Dec 14, 2015

Re: Nissan Leaf Plugin

howartp,

Yep, for some reason, the carwings server has two slightly different JSON response data structures for a login request. I had altered the login code for the data structure that I get back, but I didn't know exactly what the 'other' response structure would look like in order to fix that one, too.

With your log snippet, though, I think I was able to fix the code so it will work with either response type. Version 0.1.1 is available on github.

Posted on
Sat Apr 02, 2016 3:23 pm
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Nissan Leaf Plugin

Code: Select all
2016-04-02 22:22:34.716   Nissan Leaf Error   Error in plugin execution runConcurrentThread:

Traceback (most recent call last):
  File "plugin.py", line 136, in runConcurrentThread
  File "/Library/Application Support/Perceptive Automation/Indigo 6/Plugins/Nissan Leaf.indigoPlugin/Contents/Server Plugin/indigo_leaf.py", line 113, in request_and_update_status
  File "/Library/Application Support/Perceptive Automation/Indigo 6/Plugins/Nissan Leaf.indigoPlugin/Contents/Server Plugin/indigo_leaf.py", line 132, in request_status
  File "/Library/Application Support/Perceptive Automation/Indigo 6/Plugins/Nissan Leaf.indigoPlugin/Contents/Server Plugin/indigo_leaf.py", line 51, in login
  File "/Library/Application Support/Perceptive Automation/Indigo 6/Plugins/Nissan Leaf.indigoPlugin/Contents/Server Plugin/pycarwings2/pycarwings2.py", line 160, in connect
  File "/Library/Application Support/Perceptive Automation/Indigo 6/Plugins/Nissan Leaf.indigoPlugin/Contents/Server Plugin/pycarwings2/responses.py", line 141, in __init__
<type 'exceptions.TypeError'>: list indices must be integers, not str

2016-04-02 22:22:34.718   Nissan Leaf Error   plugin runConcurrentThread function returned or failed (will attempt again in 10 seconds)

Posted on
Sat Apr 02, 2016 3:44 pm
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Nissan Leaf Plugin

I've completely removed the plugin and prefs file, and deleted my Leaf device.

Now I've re-enabled and entered details etc again and made new device, I can't get the plugin to do anything, fail or succeed...

It's created an indigoleaf session (pycarwings2.blah) and done an object init() but not much else.

I'll look again in the morning.

Peter

Posted on
Sat Apr 02, 2016 4:30 pm
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Nissan Leaf Plugin

Aha!

Sorted it.

In your responses.py on lines 141 and 142, you need to change them to:

Code: Select all
         self.nickname = response["vehicleInfo"][0]["nickname"]
         self.custom_sessionid = response["vehicleInfo"][0]["custom_sessionid"]


Peter

Posted on
Sat Apr 02, 2016 8:37 pm
dustysparkle offline
Posts: 54
Joined: Dec 14, 2015

Re: Nissan Leaf Plugin

Great, thanks! Yep, I missed that array bracket in the JSON. I'll update the plugin on Github with your fix.

Posted on
Sun Apr 03, 2016 1:46 am
Gusten offline
Posts: 171
Joined: Dec 30, 2015
Location: Sweden, Gothenburg

Re: Nissan Leaf Plugin

Everything is working for me :) AWESOME !!!!!


Skickat från min iPhone med Tapatalk

Posted on
Sun Apr 03, 2016 12:33 pm
Gusten offline
Posts: 171
Joined: Dec 30, 2015
Location: Sweden, Gothenburg

Re: Nissan Leaf Plugin

Hi

Its working for a couple of hours, then i get an error, if i restart the plugin it starts to work for another couple of hours.

Nissan Leaf requesting status for XXXXXXXXXXXXXX
Nissan Leaf Error Error in plugin execution runConcurrentThread:

Traceback (most recent call last):
File "plugin.py", line 136, in runConcurrentThread
File "/Library/Application Support/Perceptive Automation/Indigo 6/Plugins/Nissan Leaf.indigoPlugin/Contents/Server Plugin/indigo_leaf.py", line 113, in request_and_update_status
File "/Library/Application Support/Perceptive Automation/Indigo 6/Plugins/Nissan Leaf.indigoPlugin/Contents/Server Plugin/indigo_leaf.py", line 134, in request_status
File "/Library/Application Support/Perceptive Automation/Indigo 6/Plugins/Nissan Leaf.indigoPlugin/Contents/Server Plugin/pycarwings2/pycarwings2.py", line 206, in request_update
File "/Library/Application Support/Perceptive Automation/Indigo 6/Plugins/Nissan Leaf.indigoPlugin/Contents/Server Plugin/pycarwings2/pycarwings2.py", line 104, in _request_with_retry
<type 'exceptions.NameError'>: global name 'j' is not defined

Nissan Leaf Error plugin runConcurrentThread function returned or failed (will attempt again in 10 seconds)


//Gusten

Posted on
Sun Apr 03, 2016 1:07 pm
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Nissan Leaf Plugin

Correct, j is not defined at that point in the script.

:-)

That's a new function to detect 404 errors that he's copied from somewhere else but not redefined j when he did so.

Basically Indigo is getting 'page not found' from Nissan at those times.


Sent from my iPhone using Tapatalk

Posted on
Sun Apr 03, 2016 6:03 pm
dustysparkle offline
Posts: 54
Joined: Dec 14, 2015

Re: Nissan Leaf Plugin

Yep, the new secure API seems to get the NO_MACH_VIN/404 error relatively frequently, so I had to polish up the retry logic that I had last really used in the XML-based plugin long ago, and I missed a variable name.

Hotfix pushed to github; thanks howartp and Gusten (and sorry for the continued issues).

Posted on
Mon Apr 04, 2016 12:36 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Nissan Leaf Plugin

Don't worry - you've got the new version for supporting Nissan's changes out remarkably quickly so there's inevitably going to be some issues.

If you were taking days to fix them, THEN we'd be moaning! :-)


Sent from my iPhone using Tapatalk

Posted on
Wed Dec 28, 2016 12:51 pm
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Nissan Leaf Plugin

Dusty, what's the status of this plugin?

I've been running a it since April ok, with one tweak for Indigo 7 (need new crypto modules reinstalling for Python 2.7).

My CarWings packed up last month and I've only just sorted that - but the plugin is now giving errors which suggests the API has changed at Nissan.

Are you still maintaining the plugin, or shall I locate these errors and publish a fix?


Sent from my iPhone using Tapatalk

Posted on
Thu Dec 29, 2016 11:10 am
dustysparkle offline
Posts: 54
Joined: Dec 14, 2015

Re: Nissan Leaf Plugin

Hi howartp,

I ran into some issues a few weeks ago where I was receiving "NO MACH VIN" errors, but things have been working ok since then. I assume it had something to do with the upcoming shutdown of 2G in the USA. I think I had to log back in to Carwings on my laptop after getting my 3G telematics unit replaced, but I unfortunately don't remember for sure.

So I guess I don't know of any problems with it at the moment. If you can isolate an error to illustrate that would be helpful, sure.

Posted on
Thu Dec 29, 2016 1:45 pm
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Nissan Leaf Plugin

Hi Dusty.

I tracked down the problem last night.

In CarwingsLatestClimateControlStatusResponse() you are accessing status["RemoteACRecords"].

This property didn't exist in the response from Nissan until I'd sent an AC Start command from the Nissan App - after that, the property appeared in the response, and continued to appear after I'd sent AC Stop.

I suspect when a user first registers for CarWings, or re-activates their CarWings account in the car (Settings > Security Details > Edit Password > Save > Activate (or something like that) that this property doesn't exist until remote AC has been used.

I simply added an if (status["RemoteACRecords"]) line to the code and it started working.

Peter

Posted on
Thu Dec 29, 2016 5:25 pm
dustysparkle offline
Posts: 54
Joined: Dec 14, 2015

Re: Nissan Leaf Plugin

Interesting. Thanks for tracking that down.

I'll commit and release a bug fix version after the holiday celebrations mercifully end.

Who is online

Users browsing this forum: No registered users and 5 guests