flobz / psa_car_controller

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

Error 500 / Division by Zero on get_vehicleinfo #472

Closed marc6901 closed 1 year ago

marc6901 commented 1 year ago

Describe the bug 500 error while trying to get data. In logfile:

    File "/usr/local/lib/python3.9/dist-packages/psa_car_controller/psacc/application/battery_charge_curve.py", line 26, in dto_to_battery_curve
    km_by_kw = 0.8 * battery_curves_dto[-1].autonomy / battery_capacity
    ZeroDivisionError: float division by zero

See also issue: #437. The issue is not solved with the new version.

To Reproduce

  1. http://192.168.xxx.xxx:5000/get_vehicleinfo/
  2. when the bug append ? After a few hours
  3. Does it persist after restarting the program? Yes
  4. Does it persist after recreate config by going to http://server_address:port/config? Yes

Environment (please complete the following information):

marc6901 commented 1 year ago

There is an update on this issue. After some investigation from my side I found out this:

The Docker container contains a config file /data/cars.json. That file looks like this:

{ "abrp_name": null, "battery_power": 0, "brand": "Peugeot", "fuel_capacity": 53, "label": "SUV 3008", "max_elec_consumption": 70, "max_fuel_consumption": 30, "vehicle_id": "xxxxxxxxxxxxxxxxx", "vin": "VF3M4DGZUNS000000" }

When I change the "battery power" to 13 instead of 0 and restart the docker container the data starts flowing to the dashboard. So technically the issue is still there in the software but it seems to be caused by wrong car parameters. I don't know what is the source for these parameters but I think that should help?

Ilpo55 commented 1 year ago

Thanks! The only problem for me was how to edit the file in the Docker, but now battery power is 13. :-)

Philippehaz commented 1 year ago

Hi, I believe that the issue happens with Hybrid cars, that often have battery empty. This leads to battery_capacity being zero, and as there is no test for that before being used for division, this then gives the error. I assume that pure electric cars don't usually empty the battery so will not have this issue.

Ilpo55 commented 1 year ago

Hi, I think that it is not the current battery capasity which can be zero. I think that the problem is that PSA Car controller does not get the total battery capasity "battery_power" with hybrid Peugeot 3008 cars. "battery_power": in file cars.json is the total capasity of the battery. ( I have set it to 12.2 which gives quite correct values for "average consumtions".)

The solution would be the posibility to set thet value in the configuration with UI, now the the file has to be edited in a complex way.

This is how I did it:

Disable protection mode in SSH & Web Terminal Find the name of the PSA Car Controller docker container. docker ps I got "addon_b9f22d83_psacc". Run "docker exec ..." command to use the container (It is like ssh to that Docker) docker exec -t -i addon_b9f22d83_psacc /bin/bash Install editor in to the container apt-get update apt-get -y install nano Edit the cars.json file, change 0 to 12.2 in line "battery_power": cd /data nano cars.json Exit docker and restart PSA Car Controller. After about 1 minute I got correct "average consumtions" values in Trips.