flobz / psa_car_controller

Control psa car with connected_car v4 API.
GNU General Public License v3.0
427 stars 225 forks source link

Error on Sever startup, VIN was detected and login works though. Just no data #29

Closed dreimer1986 closed 3 years ago

dreimer1986 commented 3 years ago

Describe the bug Did everything according to readme aka downloaded the APK, installed the requirements via text and decrypted. It shows my valid VIN. All seemed fine, but when the server is started I get "No data to show" on main page and the http://localhost:5000/get_vehicleinfo/--- shows a "Internal Server Error"

To Reproduce Steps to reproduce the behavior:

  1. what solution did you use (solution 1 or 2): There is only one left when I see right?
  2. C:\Users---\AppData\Local\Programs\Python\Python39\python.exe server.py -f test.json -c charge_config1.json -r (Work path is correctly set to where I loaded the GIT to)
  3. when the bug append ? On startup

Config file { "client_id": "---", "client_secret": "---", "customer_id": "---", "proxies": { "http": "", "https": "" }, "realm": "clientsB2CPeugeot", "refresh_token": "---", "remote_refresh_token": "---", "weather_api": "---" }

Environment (please complete the following information):

Additional context Add any other context about the problem here.

2021-02-24 00:40:06,210 :: INFO :: server start
mypeugeot email: ---
mypeugeot password: ---
2021-02-24 00:40:19,729 :: INFO :: {'---': {'id': '---'}}
2021-02-24 00:40:20,170 :: INFO :: update_data
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
2021-02-24 00:40:20,346 :: ERROR :: can't refresh_remote_token: {'error': 'invalid_grant', 'error_description': 'grant is invalid'}
 Create a new one
2021-02-24 00:40:23,234 :: INFO :: ask state to ---
2021-02-24 00:40:23,373 :: INFO :: Connected with result code {'session present': 0}
2021-02-24 00:40:23,374 :: INFO :: subscribe to psa/RemoteServices/to/cid/---/#
2021-02-24 00:40:23,375 :: INFO :: subscribe to psa/RemoteServices/events/MPHRTServices/---
2021-02-24 00:40:23,794 :: INFO :: {"access_token": "---", "customer_id": "---", "correlation_id": "---", "req_date": "2021-02-23T23:40:23Z", "vin": "---", "req_parameters": {"action": "state"}}
2021-02-24 00:40:24,371 :: ERROR :: Traceback (most recent call last):
  File "C:\psa_car_controller\ChargeControl.py", line 53, in start
    res = self.psacc.get_vehicle_info(self.vin)
  File "C:\psa_car_controller\MyPSACC.py", line 197, in get_vehicle_info
    self.record_info(vin, res)
  File "C:\psa_car_controller\MyPSACC.py", line 472, in record_info
    longitude = status.last_position.geometry.coordinates[0]
AttributeError: 'NoneType' object has no attribute 'geometry'

2021-02-24 00:40:24,375 :: INFO :: save config change
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
2021-02-24 00:40:24,542 :: INFO :: mqtt msg psa/RemoteServices/to/cid/AP-ACNT---/VehicleState/ProcessManagement b'{"process_date":"2021-02-23T23:40:25Z","vin":"---","correlation_id":"---","process_code":"900","process_message":"Your request has been accepted and is being processed"}'
2021-02-24 00:40:24,685 :: INFO :: mqtt msg psa/RemoteServices/to/cid/AP-ACNT---/VehicleState b'{"resp_date":"2021-02-23T23:40:25Z","vin":"---","correlation_id":"---","return_code":"0","resp_data":{"date":"2021-02-23T22:28:41Z","etat_res_elec":0,"precond_state":{"available":1,"programs":{"program1":{"hour":0,"minute":0,"on":0,"day":[0,0,0,0,0,0,0]},"program2":{"hour":0,"minute":0,"on":0,"day":[0,0,0,0,0,0,0]},"program3":{"hour":0,"minute":0,"on":0,"day":[0,0,0,0,0,0,0]},"program4":{"hour":0,"minute":0,"on":0,"day":[0,0,0,0,0,0,0]}},"asap":0,"status":0,"aff":1},"charging_state":{"program":{"hour":0,"minute":0},"available":1,"remaining_time":0,"rate":0,"cable_detected":0,"soc_batt":85,"autonomy_zev":316,"type":0,"aff":1,"hmi_state":1,"mode":0},"vin":"---","reason":4,"signal_quality":1,"sev_stop_date":"2021-02-23T22:28:04Z","fds":["NBM01","NCG01","NAO01","NAS01"],"sev_state":0,"obj_counter":17,"privacy_customer":0,"privacy_applicable":0,"privacy_applicable_max":2,"superlock_state":0}}'
127.0.0.1 - - [24/Feb/2021 00:40:50] "←[37mGET / HTTP/1.1←[0m" 200 -
127.0.0.1 - - [24/Feb/2021 00:40:50] "←[37mGET /_dash-layout HTTP/1.1←[0m" 200 -
127.0.0.1 - - [24/Feb/2021 00:40:51] "←[37mGET /_dash-dependencies HTTP/1.1←[0m" 200 -
127.0.0.1 - - [24/Feb/2021 00:40:51] "←[37mGET /_favicon.ico?v=1.19.0 HTTP/1.1←[0m" 200 -
B4jusz commented 3 years ago

I experience the same issue. The URL http://localhost:5000/get_vehicleinfo/--- works, if I don't add the "-r", when starting server.py. It returns some info related to "energy", but it shows "last_position": null. Which might explain the error:

AttributeError: 'NoneType' object has no attribute 'geometry'

But the activity log do show some GPS data:

2021-02-24 14:36:39,351 :: INFO :: mqtt msg psa/RemoteServices/to/cid/------------/VehicleState b'{"resp_date":"2021-02-24T13:36:42Z","vin":"------","correlation_id":"-------------","return_code":"0","location":{"dop":{"h":99.989998,"p":99.989998,"v":99.989998,"valid_h":false,"valid_p":false,"valid_v":false},"dr":{"heading":148.052292,"latitude":47.4------,"longitude":19.0------,"speed":0,"valid_hdg":true,"valid_lat":true,"valid_lng":true,"valid_spd":true},"gnss":{"altitude":0,"error_altitude":-1,"error_h_position":0,"error_v_speed":-1,"fix_status":0,"heading":0,"latitude":0,"longitude":0,"speed":0,"timestamp":"2016-01-01T00:00:00Z","valid_alt":false,"valid_err_alt":false,"valid_err_hps":false,"valid_err_spd":false,"valid_hdg":false,"valid_lat":false,"valid_lng":false,"valid_spd":false},"satellites":{"tracked":0,"used":0,"valid_trk":false,"valid_usd":false,"valid_vis":false,"visible":33}},"resp_data":{"date":"2021-02-24T08:25:59Z","etat_res_elec":1,"precond_state":{"available":1,"programs":{"program1":{"hour":9,"minute":30,"on":1,"day":[0,0,0,0,0,1,0]},"program2":{"hour":34,"minute":7,"on":0,"day":[0,0,0,0,0,0,0]},"program3":{"hour":34,"minute":7,"on":0,"day":[0,0,0,0,0,0,0]},"program4":{"hour":34,"minute":7,"on":0,"day":[0,0,0,0,0,0,0]}},"asap":0,"status":0,"aff":1},"charging_state":{"program":{"hour":6,"minute":30},"available":1,"remaining_time":635,"rate":0,"cable_detected":1,"soc_batt":60,"autonomy_zev":96,"type":0,"aff":1,"hmi_state":0,"mode":2},"vin":"-------------","reason":4,"signal_quality":2,"sev_stop_date":"2021-02-23T12:05:33Z","fds":["NBM01","NCG01","NAO01","NAS01"],"sev_state":0,"timestamp_gnss":1613758241,"obj_counter":3,"privacy_customer":0,"privacy_applicable":0,"privacy_applicable_max":2,"superlock_state":0}}'

My car is an e-208 with 10" screen, built in December 2019. I have subscription to E-remote, Real Time Traffic and Speedcam. The My Peugeot app and the car's Sat Nav works properly.

dreimer1986 commented 3 years ago

Confirmed that without -r it does show information on http://localhost:5000/get_vehicleinfo/--- BUUUT my informaton are all NULL or 0 which is quite.... strange? Last sync date is yesterday when I first tried out the server. App works fine and had last sync today morning when I arrived at work. all eControl etc Services are registered. Needed firmware updates in the car are installed. Maybe I need to wait a lil longer? Got the car just yesterday. Checked without PIN as I was not sure if I really had one at all but my PIN was correct as without it just burns down in vain. Working or not, the car is worth it :P

flobz commented 3 years ago

http://localhost:5000/get_vehicleinfo/--- works, if I don't add the "-r", when starting server.py. It returns some info related to "energy", but it shows "last_position": null. Which might explain the error:

You probably right. If this endpoint don't give the position of your vehicle the problem come from PSA.

flobz commented 3 years ago

If it doesn't work in few day tell me.

B4jusz commented 3 years ago

What is "dr"? It seems it gives the position of the vehicle.

dreimer1986 commented 3 years ago

OK, this looks way better.

2021-02-26 00:06:45,488 :: INFO :: server start
2021-02-26 00:06:46,769 :: INFO :: {'*VID*': {'id': '*ID*'}}
2021-02-26 00:06:47,689 :: INFO :: ask state to *VID*
2021-02-26 00:06:47,832 :: INFO :: Connected with result code {'session present': 0}
2021-02-26 00:06:47,833 :: INFO :: subscribe to psa/RemoteServices/to/cid/*CID*/#
2021-02-26 00:06:47,833 :: INFO :: subscribe to psa/RemoteServices/events/MPHRTServices/*VID*
2021-02-26 00:06:48,013 :: INFO :: {"access_token": "*TOKEN*", "customer_id": "*CID*", "correlation_id": "*CorrID*", "req_date": "2021-02-25T23:06:48Z", "vin": "*VID*", "req_parameters": {"action": "state"}}
2021-02-26 00:06:48,317 :: INFO :: mqtt msg psa/RemoteServices/to/cid/*CID*/VehicleState/ProcessManagement b'{"process_date":"2021-02-25T23:06:49Z","vin":"*VID*","correlation_id":"*CorrID*","process_code":"900","process_message":"Your request has been accepted and is being processed"}'
2021-02-26 00:06:48,351 :: INFO :: mqtt msg psa/RemoteServices/to/cid/*CID*/VehicleState b'{"resp_date":"2021-02-25T23:06:49Z","vin":"*VID*","correlation_id":"*CorrID*","return_code":"0","resp_data":{"date":"2021-02-25T22:41:20Z","etat_res_elec":0,"precond_state":{"available":1,"programs":{"program1":{"hour":0,"minute":0,"on":0,"day":[0,0,0,0,0,0,0]},"program2":{"hour":0,"minute":0,"on":0,"day":[0,0,0,0,0,0,0]},"program3":{"hour":0,"minute":0,"on":0,"day":[0,0,0,0,0,0,0]},"program4":{"hour":0,"minute":0,"on":0,"day":[0,0,0,0,0,0,0]}},"asap":0,"status":0,"aff":1},"charging_state":{"program":{"hour":0,"minute":0},"available":1,"remaining_time":0,"rate":0,"cable_detected":0,"soc_batt":89,"autonomy_zev":334,"type":0,"aff":1,"hmi_state":1,"mode":0},"vin":"*VID*","reason":4,"signal_quality":1,"sev_stop_date":"2021-02-25T18:22:37Z","fds":["NDR01","NBM01","NCG01","NAO01","NAS01"],"sev_state":0,"obj_counter":2,"privacy_customer":0,"privacy_applicable":0,"privacy_applicable_max":2,"superlock_state":0}}'
2021-02-26 00:06:48,456 :: INFO :: new position recorded for *VID*
2021-02-26 00:06:48,459 :: INFO :: charging status of *VID* is Disconnected, battery level: 95.0
2021-02-26 00:06:48,460 :: INFO :: save config change
2021-02-26 00:06:49,359 :: INFO :: update_data
 * Running on http://192.168.181.50:5000/ (Press CTRL+C to quit)
192.168.181.55 - - [26/Feb/2021 00:07:13] "←[37mGET /get_vehicleinfo/*VID* HTTP/1.1←[0m" 200 -
192.168.181.55 - - [26/Feb/2021 00:07:13] "←[37mGET /favicon.ico HTTP/1.1←[0m" 200 -
192.168.181.55 - - [26/Feb/2021 00:07:15] "←[37mGET / HTTP/1.1←[0m" 200 -
192.168.181.55 - - [26/Feb/2021 00:07:15] "←[37mGET /_dash-component-suites/dash_renderer/polyfill@7.v1_9_0m1611082192.8.7.min.js HTTP/1.1←[0m" 200 -
192.168.181.55 - - [26/Feb/2021 00:07:15] "←[37mGET /_dash-component-suites/dash_renderer/react@16.v1_9_0m1611082192.14.0.min.js HTTP/1.1←[0m" 200 -
192.168.181.55 - - [26/Feb/2021 00:07:16] "←[37mGET /_dash-component-suites/dash_renderer/react-dom@16.v1_9_0m1611082192.14.0.min.js HTTP/1.1←[0m" 200 -
192.168.181.55 - - [26/Feb/2021 00:07:16] "←[37mGET /_dash-component-suites/dash_table/bundle.v4_11_2m1611087174.js HTTP/1.1←[0m" 200 -
192.168.181.55 - - [26/Feb/2021 00:07:16] "←[37mGET /_dash-component-suites/dash_renderer/prop-types@15.v1_9_0m1611082192.7.2.min.js HTTP/1.1←[0m" 200 -
192.168.181.55 - - [26/Feb/2021 00:07:16] "←[37mGET /_dash-component-suites/dash_core_components/dash_core_components.v1_15_0m1611086582.min.js HTTP/1.1←[0m" 200 -
192.168.181.55 - - [26/Feb/2021 00:07:16] "←[37mGET /_dash-component-suites/dash_core_components/dash_core_components-shared.v1_15_0m1611086582.js HTTP/1.1←[0m" 200 -
192.168.181.55 - - [26/Feb/2021 00:07:16] "←[37mGET /_dash-component-suites/dash_bootstrap_components/_components/dash_bootstrap_components.v0_11_3m1614122433.min.js HTTP/1.1←[0m" 200 -
192.168.181.55 - - [26/Feb/2021 00:07:16] "←[37mGET /_dash-component-suites/dash_html_components/dash_html_components.v1_1_2m1611087126.min.js HTTP/1.1←[0m" 200 -
192.168.181.55 - - [26/Feb/2021 00:07:16] "←[37mGET /_dash-component-suites/dash_renderer/dash_renderer.v1_9_0m1611082209.min.js HTTP/1.1←[0m" 200 -
192.168.181.55 - - [26/Feb/2021 00:07:16] "←[37mGET /_dash-dependencies HTTP/1.1←[0m" 200 -
192.168.181.55 - - [26/Feb/2021 00:07:16] "←[37mGET /_dash-layout HTTP/1.1←[0m" 200 -
192.168.181.55 - - [26/Feb/2021 00:07:16] "←[37mGET /_favicon.ico?v=1.19.0 HTTP/1.1←[0m" 200 -
192.168.181.55 - - [26/Feb/2021 00:07:21] "←[37mGET /favicon.ico HTTP/1.1←[0m" 200 -

What I did? I waited a bit and now it seems to be quite happy on startup. Position tracking site still shows no data, but this might vanish now too. Just started it with -r and maybe have to wait a bit there too. So I guess I am happy now. Still need to find a way to parse all these information via restful, but that's another story and nothing for this report.

flobz commented 3 years ago

Yeah you need to have enough data so that stats work properly. What information do you want to retrieve? If callback doesn't exist please make a pull request.

dreimer1986 commented 3 years ago

No problem. Was quite a adventure to get all stuff I think I need (some variables i still don't know what they are meant for), but works now. Even a device tracker. https://community.home-assistant.io/t/peugeot-citroen-ds-cars-connected-car/202949 if anyone needs some reference. Sadly I need a bunch of rest sensors as I can't put all output in one sitting on root dictionary.