flobz / psa_car_controller

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

5000 not reachable after adding car (DS Brand) #635

Closed giteki closed 8 months ago

giteki commented 9 months ago

Describe the bug Using the lastest docker container image, after adding a car (through OTP process) , unable to reach the configured port (TCP/5000). Crash message seen in logs

Traceback (most recent call last):
  File "/usr/local/bin/psa-car-controller", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.9/dist-packages/psa_car_controller/__main__.py", line 20, in main
    app.load_app()
  File "/usr/local/lib/python3.9/dist-packages/psa_car_controller/psacc/application/car_controller.py", line 108, in load_app
    self.start_remote_control()
  File "/usr/local/lib/python3.9/dist-packages/psa_car_controller/psacc/application/car_controller.py", line 63, in start_remote_control
    self.myp.remote_client.start()
  File "/usr/local/lib/python3.9/dist-packages/psa_car_controller/psa/RemoteClient.py", line 113, in start
    self.mqtt_client.connect(MQTT_SERVER, 8885, 60)
  File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 941, in connect
    return self.reconnect()
  File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 1075, in reconnect
    sock = self._create_socket_connection()
  File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 3546, in _create_socket_connection
    return socket.create_connection(addr, source_address=source, timeout=self._keepalive)
  File "/usr/lib/python3.9/socket.py", line 843, in create_connection
    raise err
  File "/usr/lib/python3.9/socket.py", line 831, in create_connection
    sock.connect(sa)
socket.timeout: timed out

To Reproduce Steps to reproduce the behavior:

  1. download and install last container image in docker
  2. register a car through the web interface (tcp/5000) : works
  3. interface not reachable anymore after adding the car (e.g. http://server_address:port/config)
  4. restarting container does not help.
  5. deleting configuration folder et registering again lead to the same result

Config file Give the anonymize content of the config file

Environment (please complete the following information):

Additional context logs

Containerised psa_car_controller loading...
2023-10-17 09:26:30,110 :: INFO :: ["{'vin': '*****', 'vehicle_id': '********', 'label': 'DS4 E-Tense', 'brand': 'DS', 'abrp_name': None, 'battery_power': 12.4, 'fuel_capacity': 40, 'max_elec_consumption': 70, 'max_fuel_consumption': 30}"]
2023-10-17 09:26:30,647 :: INFO :: save config change
Traceback (most recent call last):
  File "/usr/local/bin/psa-car-controller", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.9/dist-packages/psa_car_controller/__main__.py", line 20, in main
    app.load_app()
  File "/usr/local/lib/python3.9/dist-packages/psa_car_controller/psacc/application/car_controller.py", line 108, in load_app
    self.start_remote_control()
  File "/usr/local/lib/python3.9/dist-packages/psa_car_controller/psacc/application/car_controller.py", line 63, in start_remote_control
    self.myp.remote_client.start()
  File "/usr/local/lib/python3.9/dist-packages/psa_car_controller/psa/RemoteClient.py", line 113, in start
    self.mqtt_client.connect(MQTT_SERVER, 8885, 60)
  File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 941, in connect
    return self.reconnect()
  File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 1075, in reconnect
    sock = self._create_socket_connection()
  File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 3546, in _create_socket_connection
    return socket.create_connection(addr, source_address=source, timeout=self._keepalive)
  File "/usr/lib/python3.9/socket.py", line 843, in create_connection
    raise err
  File "/usr/lib/python3.9/socket.py", line 831, in create_connection
    sock.connect(sa)
socket.timeout: timed out
Containerised psa_car_controller loading...
2023-10-17 09:30:35,558 :: INFO :: ["{'vin': '*****', 'vehicle_id': '********', 'label': 'DS4 E-Tense', 'brand': 'DS', 'abrp_name': None, 'battery_power': 12.4, 'fuel_capacity': 40, 'max_elec_consumption': 70, 'max_fuel_consumption': 30}"]
2023-10-17 09:30:36,300 :: INFO :: save config change

Analysis

$ netstat 
tcp        0      1 1.2.3.4:11111   194.2.56.96:8885        SYN_SENT    113959/python3

Seems that mqtt psa server not reachable (or client id blacklisted due to over requests by psacarctrl ? not sure)

Solution :

Provide a way to change/refresh the information (mqtt destination server) Avoid web ui crash when psa mqtt servers are not reachable. Provide a way to change refresh rate

giteki commented 9 months ago

After checking : IP was blacklisted. Doing good by changing the source IP.

The bug can be sum up : when mqtt psa servers are not reachable , the local psacarctrl web ui is not reachable.

Solution (improvment) : should just raise an error message on the web interface.

(can be reproduced by blocking through netfilter for example).