wubbl0rz / FiatChamp

FIAT (uconnect) Home Assistant Addon πŸš—
https://github.com/wubbl0rz/FiatChamp
MIT License
103 stars 25 forks source link

No success on new install #25

Closed cgraf closed 1 year ago

cgraf commented 1 year ago

Hello,

This looks really cool, but I'm not able to get a successful response. Not sure if there is a way to tell if the problem is on my end or somewhere else. Logging in to Uconnect works fine with my credentials.

[09:38:49 INF] Now fetching new data...
[09:38:49 INF] Mqtt connection successful
[09:38:50 DBG] {
  "CallId": "<removed>",
  "ErrorCode": 0,
  "ErrorDetails": null,
  "ErrorMessage": null,
  "ApiVersion": 2,
  "StatusCode": 200,
  "StatusReason": "OK",
  "Time": "2022-12-02T15:38:50.432+00:00"
}
[09:38:50 DBG] {
  "UID": "<removed>",
  "SessionInfo": {
    "login_token": "<removed>"
  },
  "CallId": "<removed>",
  "ErrorCode": 0,
  "ErrorDetails": null,
  "ErrorMessage": null,
  "ApiVersion": 2,
  "StatusCode": 200,
  "StatusReason": "OK",
  "Time": "2022-12-02T15:38:50.88+00:00"
}
[09:38:51 DBG] {
  "id_token": "<removed>,
  "CallId": "<removed>",
  "ErrorCode": 0,
  "ErrorDetails": null,
  "ErrorMessage": null,
  "ApiVersion": 2,
  "StatusCode": 200,
  "StatusReason": "OK",
  "Time": "2022-12-02T15:38:51.003+00:00"
}
[09:38:51 DBG] {
  "IdentityId": "<removed>",
  "Token": "<removed>"
}
[09:38:52 WRN] Error connecting to the FIAT API. 
This can happen from time to time. Retrying in 15 minutes.
[09:38:52 DBG] Response could not be deserialized to JSON: GET https://channels.sdpr-02.fcagcv.com/v4/accounts/<removed>/vehicles?stage=ALL
[09:38:52 INF] Fetching COMPLETED. Next update in 15 minutes.
wubbl0rz commented 1 year ago

what car and which vendor and what region ?

can you control your car with one of the following sites ?

Fiat: https://myuconnect.fiat.com/ Jeep: https://myuconnect.jeep.com/ Ram: https://connect.ramtrucks.com/ Dodge: https://connect.dodge.com/ AlfaRomeo: https://myalfaconnect.alfaromeo.com/

cgraf commented 1 year ago

Jeep Grand Cherokee 4xe.

Yes with the Jeep site, although flow of hitting https://myuconnect.jeep.com/ goes to https://connect.jeep.com/ -> North America -> US and finally to https://connect.jeep.com/us/en/dashboard. Works there though.

I would be interested to see what response could not be deserialized to JSON from the API request. Usually that is some kind of higher level HTTP error like 401 or 503 prior to the api isn't it?

Hitting https://channels.sdpr-02.fcagcv.com/v4/accounts/<removed>/vehicles?stage=ALL actually produces a "FORBIDDEN" JSON response, because I don't have a session token in a normal browser session, but it looks like the API is up.

Happy to do some external testing in Postman if you could point me to some API documentation.

wubbl0rz commented 1 year ago

Happy to do some external testing in Postman if you could point me to some API documentation.

@cgraf πŸ˜† unfortunately they do not have any docs. im using some internal undocumented apis that have been reverse engineered from the app and website. if you want to dig deeper you can use the browser dev tools and inspect the requests on the uconnect site or the android app with proxy in the middle. for this case browser tools should be sufficient. you cannot use postman because they use a extremely complicated login mechanism with different urls, tokens and even amazon aws identity service is involed. you should see all in the browser dev tools including a request for listing vehicles.

last week there was a issue with jeep in brazil https://github.com/wubbl0rz/FiatChamp/issues/17 maybe they use a different aws region or url for north america. for better debugging i could extend the error message in debug mode with the actual response. let me know what you find out πŸ˜„

edit: it would be great if we can make this work together because i dont have any other car than my fiat 500e (europe). so its difficult for me to test anything else.

cgraf commented 1 year ago

if we can make this work together

Sure. I'm committed to trying whatever I can and feeding back anything I find.

inspect the requests on the uconnect site

I'm not sure I'll have time to do a deep dive into reverse engineering this weekend, but might have a look through some of your Cs to figure out what I can. :)

for better debugging i could extend the error message in debug mode with the actual response

That would be a great next step. Let me know when that is ready. Are you going to commit that to main and distribute through normal update, or will I need to do some local hijinks?

wubbl0rz commented 1 year ago

yes next update. i think its useful for all πŸ˜„ should be easy and only active when debug logging is enabled.

cgraf commented 1 year ago

Cool. I'll be watching for it. Maybe also in the debug show the request URL and method if possible.

lozzamatron commented 1 year ago

I'm having the same issue with my Jeep in North America. Same credentials work on the uconnect site, but not via FiatChamp. I am seeing the same API error in the log

cgraf commented 1 year ago

I did go ahead and get through the first four steps in Postman. I got everything working up to the Congnito part. Now I understand what the existing debug means, and why the whole thing can't be done in Postman. On Saturday I'll put it in code with some Cognito support and see how much further I get. I did notice in another FIat API project, they were using the real AWS region names in Cognito, like appear in the beginning it IdentityId in the tokenURL response, such as eu-west-1, rather than EUWest1, but I don't know enough about CS to even know what the name is doing there. My IdentityID starts with us-east-1. Probably nothing. I'll play with it some more in a few hours.

wubbl0rz commented 1 year ago

3.0.4 now has more debug logs. should now log error message, status code and response body. i suspect that jeep send back "bugged" json thats different from fiat. if you get a json response in the error message pls post it here anonymized :smile:

cgraf commented 1 year ago

Just a quick result while I go through it. Response is 200 and JSON is valid. Error persists. It's in this order:


[09:34:53 DBG] {
  "IdentityId": "<removed>",
  "Token": "<removed>"
}
[09:34:54 WRN] Error connecting to the FIAT API. 
This can happen from time to time. Retrying in 15 minutes.
[09:34:54 INF] ERROR: Response could not be deserialized to JSON: GET https://channels.sdpr-02.fcagcv.com/v4/accounts/<removed>/vehicles?stage=ALL
[09:34:54 INF] STATUS: 200
[09:34:54 INF] RESPONSE: <validated JSON>
[09:34:54 INF] Fetching COMPLETED. Next update in 15 minutes.
cgraf commented 1 year ago

Ah. The "could not be deserialized" error looks like a Flurl error. Like maybe it is trying to convert something in the response or treating something like an array that is actually a string or vice versa. Appears the comms are fine. Let me compare code and output.

cgraf commented 1 year ago

Looks to be something with VehicleResponse, but the only thing you seem to be doing with that is getting the VIN.

vehicleResponse.Vehicles.First().Vin

(object)->vehicles[0]->vin is present in the output, so nothing glaring there except for them being all lowercase in the JSON, but I don't think that matters in Microsoft land.

I think I got the more sensitive bits (UserID and VIN) out of this output, but I may have to come back and edit if I missed something. You should be able to run this through the Flurl parser manually and see where it is complaining.


{
  "userid": "12345678901234567890123456789012",
  "version": 1667772713470,
  "vehicles": [
    {
      "regStatus": "COMPLETED_STAGE_3",
      "color": "BALTIC GREY",
      "tsoBodyCode": "",
      "year": 2022,
      "isCompanyCar": "",
      "navEnabledHU": false,
      "language": "",
      "customerRegStatus": "Y",
      "radio": "",
      "activationSource": "DEALER",
      "nickname": "",
      "company": "FCA",
      "model": "WLXT74",
      "vin": "12345678901234567",
      "tcuType": "2",
      "make": "Jeep",
      "brandCode": "57",
      "soldRegion": "NAFTA",
      "svla": {
        "status": "INACTIVE",
        "timestamp": 0
      },
      "tc": {
        "activation": {
          "version": "v1.23",
          "status": "Accepted"
        },
        "registration": {
          "version": "1.0.0",
          "status": "Accepted"
        }
      },
      "market": "US",
      "modelDescription": "Grand Cherokee 4xe",
      "fuelType": "H",
      "tsoModelYear": "",
      "sdp": "IGNITE",
      "regTimestamp": 1666471789686,
      "services": [
        {
          "vehicleCapable": true,
          "service": "SVLAAPP",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "SVLA",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": false,
          "service": "ROC",
          "serviceEnabled": false
        },
        {
          "vehicleCapable": true,
          "service": "RDU",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "RDL",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "HUC",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "AOTAC",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "BCALL",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "SOS",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "ASSIST",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "ECALL",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "HBLF",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "ASOS",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "DTC",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "NAV_OB_FUEL_FINDER",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "NAV_OB_PARKING_FINDER",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "NAV_OB_ROUTE_DRM",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "NAV_OB_SEARCH",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "NAV_OB_SPEED_CAMERA",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "NAV_OB_TRAFFIC",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "NAV_OB_WEATHER",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "PARENT",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "REOFF",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "REON",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "SDV",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": false,
          "service": "SQDF",
          "serviceEnabled": false
        },
        {
          "vehicleCapable": true,
          "service": "TA",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "VF",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "VHSG",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "VRC",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "WIFIHOTSPOT",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": false,
          "service": "FTD",
          "serviceEnabled": false
        },
        {
          "vehicleCapable": true,
          "service": "IVA",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "IVM",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": false,
          "service": "PHEV",
          "serviceEnabled": false
        },
        {
          "vehicleCapable": true,
          "service": "ALEXAVA",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "WIFIP",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "VHS",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "CNOW",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "CSL",
          "serviceEnabled": false
        },
        {
          "vehicleCapable": true,
          "service": "CP",
          "serviceEnabled": false
        },
        {
          "vehicleCapable": true,
          "service": "EVNOT",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "ELECPAGES",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "ORP",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": false,
          "service": "GSKILLL",
          "serviceEnabled": false
        },
        {
          "vehicleCapable": true,
          "service": "LASTMILE",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "AOTACI",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "ROAD",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "CARE",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "ROCRANKINHIBITON",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "ROCRANKINHIBITOFF",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "TA_SUP",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": false,
          "service": "DRIVEMODES",
          "serviceEnabled": false
        },
        {
          "vehicleCapable": false,
          "service": "RACEOPTIONS",
          "serviceEnabled": false
        },
        {
          "vehicleCapable": true,
          "service": "NAV_OB_MOTA_CELL",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "NAV_OB_MOTA_WIFI",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "NAV_OB_MOTA_WIFI_CELL",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "BRAND",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "DUMMY",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "DEEPREFRESH",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": false,
          "service": "FRONTSEAT",
          "serviceEnabled": false
        },
        {
          "vehicleCapable": true,
          "service": "MACMEDIAAPP",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": false,
          "service": "L2DATALOG",
          "serviceEnabled": false
        },
        {
          "vehicleCapable": false,
          "service": "L2MAPSGEO",
          "serviceEnabled": false
        },
        {
          "vehicleCapable": false,
          "service": "L2GPSCORRECTION",
          "serviceEnabled": false
        },
        {
          "vehicleCapable": true,
          "service": "TUTORIALS",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "ORPPLUS",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "ADA_TBM",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "NAV_TOMTOM",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "ROCLRPERSDATA",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "ROC2",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "ADA_UBI",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": true,
          "service": "CPCHRG2",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": false,
          "service": "CPA",
          "serviceEnabled": false
        },
        {
          "vehicleCapable": true,
          "service": "CSEV",
          "serviceEnabled": true
        },
        {
          "vehicleCapable": false,
          "service": "TRAILERTP",
          "serviceEnabled": false
        },
        {
          "vehicleCapable": false,
          "service": "KNGLNKOUT",
          "serviceEnabled": false
        },
        {
          "vehicleCapable": false,
          "service": "DUMMY_EVAS",
          "serviceEnabled": false
        },
        {
          "vehicleCapable": false,
          "service": "DUMMY_ENHDCAM",
          "serviceEnabled": false
        },
        {
          "vehicleCapable": false,
          "service": "DUMMY_TECHFEE",
          "serviceEnabled": false
        },
        {
          "vehicleCapable": false,
          "service": "DUMMY_WIRECAM",
          "serviceEnabled": false
        },
        {
          "vehicleCapable": false,
          "service": "DUMMY_TRAILERTP",
          "serviceEnabled": false
        }
      ],
      "privacyMode": "INACTIVE",
      "cslProvider": "TOMTOM",
      "subMake": "Jeep",
      "pp": {
        "activation": {
          "version": "1.0.0",
          "status": "Accepted"
        }
      },
      "enrollmentStatus": "COMPLETE",
      "channelFeatures": [
        {
          "featureCode": "100",
          "channels": [
            "CWP",
            "GMA"
          ]
        },
        {
          "featureCode": "f_0097_N",
          "channels": [
            "CWP",
            "GMA"
          ]
        }
      ]
    }
  ]
}
wubbl0rz commented 1 year ago

thx for the json output. i think the error is at line 566 when the http client tried to deserialize the response ( https://github.com/wubbl0rz/FiatChamp/blob/master/FiatChampAddon/FiatClient/FiatClient.cs#L566 )

should not be that hard to figure out. i will try to deserialize it by hand as VehicleResponse and see what the actual error from the serializer is.

wubbl0rz commented 1 year ago

thats the problem

Error converting value "WLXT74" to type 'System.Int64'. Path 'vehicles[0].model',                           

fiat model is always a number :smile: sould be easy to fix ... switch from int to string should not break anything.

wubbl0rz commented 1 year ago

should work now. pls try 3.0.5.

lozzamatron commented 1 year ago

Just updated to 3.05 and it's working for me. Really appreciate the work to fix this. Thank you! :) FYI I am west coast USA and have 2022 Jeep Grand Cherokee L

cgraf commented 1 year ago

Hmm. Not for me I don't think. Got further but still erroring. Looking...

cgraf commented 1 year ago

Something related to location it seems. I changed my actual long/lat below, but fairly close

[10:43:24 WRN] Error connecting to the FIAT API. 
This can happen from time to time. Retrying in 15 minutes.
[10:43:24 DBG] ERROR: Response could not be deserialized to JSON: GET https://channels.sdpr-02.fcagcv.com/v1/accounts/<removed>/vehicles/<removed>/location/lastknown
[10:43:24 DBG] STATUS: 200
[10:43:24 DBG] RESPONSE: {"timeStamp":1670076291636,"longitude":-95.707932,"latitude"32.536167:,"altitude":null,"bearing":null,"isLocationApprox":false}
[10:43:24 INF] Fetching COMPLETED. Next update in 15 minutes.
cgraf commented 1 year ago

Maybe not expecting NULL for altitude and bearing?

cgraf commented 1 year ago

I do have refresh location configured off. Retrying.

wubbl0rz commented 1 year ago

let me check. but good you find all this bugs :grin:

wubbl0rz commented 1 year ago

altitude is a double so null might be a problem ... i dont want to know how many workarounds they have implemented in their app to get all this working :smile: refresh location off does not matter its only for automatic querying new location from the car every N minutes.

cgraf commented 1 year ago

No change when location refresh configured ON. Error persists. Altitude and bearing are still NULL.

wubbl0rz commented 1 year ago

pls try with 3.0.6

cgraf commented 1 year ago

Yuck. I don't have PIN configured in the add-on.

[11:22:13 ERR] Command: DEEPREFRESH ERROR. Maybe wrong pin?
[11:22:13 DBG] Flurl.Http.FlurlHttpException: Call failed with status code 403 (Forbidden): POST https://mfa.fcl-01.fcagcv.com/v1/accounts/<removed>/ignite/pin/authenticate
   at Flurl.Http.FlurlRequest.HandleExceptionAsync(FlurlCall call, Exception ex, CancellationToken token)
   at Flurl.Http.FlurlRequest.SendAsync(HttpMethod verb, HttpContent content, CancellationToken cancellationToken, HttpCompletionOption completionOption)
   at Flurl.Http.FlurlRequest.SendAsync(HttpMethod verb, HttpContent content, CancellationToken cancellationToken, HttpCompletionOption completionOption)
   at Flurl.Http.ResponseExtensions.ReceiveJson[T](Task`1 response)
   at FiatChamp.FiatClient.SendCommand(String vin, String command, String pin, String action) in /home/runner/work/FiatChamp/FiatChamp/FiatChampAddon/FiatClient/FiatClient.cs:line 529
   at Program.<>c__DisplayClass0_0.<<<Main>$>g__TrySendCommand|1>d.MoveNext() in /home/runner/work/FiatChamp/FiatChamp/FiatChampAddon/FiatClient/Program.cs:line 259
[11:22:13 INF] SEND COMMAND VF: 
[11:22:13 ERR] Command: VF ERROR. Maybe wrong pin?
[11:22:13 DBG] Flurl.Http.FlurlHttpException: Call failed with status code 403 (Forbidden): POST https://mfa.fcl-01.fcagcv.com/v1/accounts/<removed>/ignite/pin/authenticate
   at Flurl.Http.FlurlRequest.HandleExceptionAsync(FlurlCall call, Exception ex, CancellationToken token)
   at Flurl.Http.FlurlRequest.SendAsync(HttpMethod verb, HttpContent content, CancellationToken cancellationToken, HttpCompletionOption completionOption)
   at Flurl.Http.FlurlRequest.SendAsync(HttpMethod verb, HttpContent content, CancellationToken cancellationToken, HttpCompletionOption completionOption)
   at Flurl.Http.ResponseExtensions.ReceiveJson[T](Task`1 response)
   at FiatChamp.FiatClient.SendCommand(String vin, String command, String pin, String action) in /home/runner/work/FiatChamp/FiatChamp/FiatChampAddon/FiatClient/FiatClient.cs:line 529
   at Program.<>c__DisplayClass0_0.<<<Main>$>g__TrySendCommand|1>d.MoveNext() in /home/runner/work/FiatChamp/FiatChamp/FiatChampAddon/FiatClient/Program.cs:line 259
wubbl0rz commented 1 year ago

disable "refresh battery status" and "refresh location"

cgraf commented 1 year ago

I have data for the first time! Location and battery have data in HA, so I'm not sure what those refresh settings do, or why changing them fixed the issue.

Documentation says PIN is only needed for write ops.

It looks like HA still creates switches for write ops, but I dare not click them.

wubbl0rz commented 1 year ago

nice :+1: i should rename "refresh battery status" and "refresh location" to "FORCE refresh" or something like that. it will actively request new values from the car and consume more battery power. thats why it needs the pin. fiat calls this "commands". if you leave them disabled new data will arrive when the car thinks its a good time to update :smile:

if you like we can make commands work ? thats the only thing i cannot lookup myself without owning a car. because one need to send a command to a real car to see which url and api key is used. all can be seen in browser dev tools i can post a screenshot where to look at.

PS: if no pin is set a "PIN NOT SET" exception should be raised but it looks like thats not the case. i will fix this with next update.

cgraf commented 1 year ago

I'll probably mess around with commands.

I think it is cool as a developer to understand user's use-cases, I will tell you that I sought out this add-on because I wanted HA to send a reminder when the EV is at home, battery is not full, and EV is not plugged in. Sometimes we forget to plug it in. Seems like a fairly common use case for people that make it this far in their life instrumentation and automation journey. Strangely it seems like the reminder portion is not yet a commercial feature, at least not for the Stellantis group.

I think it is ok to close this bug, as long as you want me to open new ones for other stuff I find.

wubbl0rz commented 1 year ago

alright nice that t works πŸ‘ if you want to lookup command urls and api keys in the browser tools let me know πŸš€