Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: APP can not connect mqtt as native, not Dapr #230

Open
1 task done
ley901017 opened this issue Mar 18, 2024 · 1 comment
Open
1 task done

[Bug]: APP can not connect mqtt as native, not Dapr #230

ley901017 opened this issue Mar 18, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@ley901017
Copy link

Severity

Critical

What release version, tag or commit-hash did you use?

v0.1.1

Current Behavior

When I run velocita app directly without dapr, the below error message has been appeared.

Exception ignored in: <function Client.__del__ at 0x7f2f7c87c670>
Traceback (most recent call last):
  File "/home/vscode/.local/lib/python3.10/site-packages/paho/mqtt/client.py", line 874, in __del__
    self._reset_sockets()
  File "/home/vscode/.local/lib/python3.10/site-packages/paho/mqtt/client.py", line 1133, in _reset_sockets
    self._sock_close()
  File "/home/vscode/.local/lib/python3.10/site-packages/paho/mqtt/client.py", line 1119, in _sock_close
    if not self._sock:
AttributeError: 'Client' object has no attribute '_sock'
Traceback (most recent call last):
  File "/workspaces/vehicle-app-python-template/app/src/main.py", line 25, in <module>
    from vehicle import Vehicle, vehicle  # type: ignore
  File "/home/vscode/.local/lib/python3.10/site-packages/vehicle/__init__.py", line 8, in <module>
    from velocitas_sdk.model import (
  File "/home/vscode/.local/lib/python3.10/site-packages/velocitas_sdk/model.py", line 24, in <module>
    from velocitas_sdk import config
  File "/home/vscode/.local/lib/python3.10/site-packages/velocitas_sdk/config.py", line 49, in <module>
    _config = Config(__middleware_type)
  File "/home/vscode/.local/lib/python3.10/site-packages/velocitas_sdk/config.py", line 36, in __init__
    self.middleware: Middleware = self.__create_middleware(__middleware)
  File "/home/vscode/.local/lib/python3.10/site-packages/velocitas_sdk/config.py", line 41, in __create_middleware
    _middleware = NativeMiddleware()
  File "/home/vscode/.local/lib/python3.10/site-packages/velocitas_sdk/native/middleware.py", line 34, in __init__
    self.pubsub_client = MqttClient(_port, _hostname)
  File "/home/vscode/.local/lib/python3.10/site-packages/velocitas_sdk/native/mqtt.py", line 42, in __init__
    self._pub_client = mqtt.Client()
TypeError: Client.__init__() missing 1 required positional argument: 'callback_api_version'

Steps to Reproduce

  1. In Dev Container, run task Local Runtime - Up
  2. execute python3 /workspaces/vehicle-app-python-template/app/src/main.py in terminal
  3. then you will see the error message

Expected Behavior

The app can run normally without dapr.

Possible Solution

No response

Additional Information

In velocitas_sdk, the below code may have some bugs, the path is velocitas_sdk/native/mqtt.py the function init of MqttClient, I cannot see any parameters on line 42 when call mqtt,Client()

lass MqttClient(PubSubClient):
    """This class is a wrapper for the on_message callback of the MQTT broker."""

    def __init__(self, port: Optional[int] = None, hostname: Optional[str] = None):
        self._port = port
        self._hostname = hostname
        self._topics_to_subscribe: list[MqttTopicSubscription] = []

        self._pub_client = mqtt.Client()
        self._sub_client = mqtt.Client()
        self._sub_client.on_connect = self.on_connect
        self._sub_client.on_disconnect = self.on_disconnect

        self._sub_client.connect(self._hostname, self._port)
        self._pub_client.connect(self._hostname, self._port)

Code of Conduct

  • I agree to follow this project's "Code of Conduct".
@ley901017 ley901017 added the bug Something isn't working label Mar 18, 2024
@dennismeister93
Copy link
Contributor

dennismeister93 commented Mar 20, 2024

Hi @ley901017

  1. Option:
    If you want to stay at tag v0.1.1:

git checkout v0.1.1

velocitas.json:

{
    "packages": [
        {
            "name": "devenv-runtimes",
            "version": "v2.2.6"
        },
        {
            "name": "devenv-github-workflows",
            "version": "v4.1.3"
        },
        {
            "name": "devenv-github-templates",
            "version": "v1.0.3"
        },
        {
            "name": "devenv-devcontainer-setup",
            "version": "v1.4.7"
        }
    ],
    "variables": {
        "language": "python",
        "repoType": "app",
        "appManifestPath": "app/AppManifest.json",
        "githubRepoId": "eclipse-velocitas/vehicle-app-python-template",
        "generatedModelPath": "./gen/vehicle_model"
    },
    "cliVersion": "v0.6.3"
}
velocitas --version 
velocitas-cli/0.6.3 linux-arm64 node-v18.5.0

Steps:

start dev container -> wait for installation / setup

export SDV_MIDDLEWARE_TYPE=native
export SDV_MQTT_ADDRESS=mqtt://localhost:1883
export SDV_VEHICLEDATABROKER_ADDRESS=grpc://localhost:55555

Change app/requirements-velocitas.txt content to (We fixed the bug there where your problem originates from eclipse-velocitas/vehicle-app-python-sdk#119 fixed with https://github.com/eclipse-velocitas/vehicle-app-python-sdk/releases/tag/v0.13.1):

velocitas-sdk==0.13.1

velocitas exec sdk-installer install-deps
velocitas exec sdk-installer run

Press F1 and run Task: Local Runtime - Up

Afterwards:
python3 /workspaces/vehicle-app-python-template/app/src/main.py

  1. Option (preferred one because that is using all the latest changes out of the box):

git checkout main

velocitas.json:

{
    "packages": [
        {
            "name": "devenv-runtimes",
            "version": "v2.2.6"
        },
        {
            "name": "devenv-github-workflows",
            "version": "v4.1.4"
        },
        {
            "name": "devenv-github-templates",
            "version": "v1.0.3"
        },
        {
            "name": "devenv-devcontainer-setup",
            "version": "v1.5.1"
        }
    ],
    "variables": {
        "language": "python",
        "repoType": "app",
        "appManifestPath": "app/AppManifest.json",
        "githubRepoId": "eclipse-velocitas/vehicle-app-python-template",
        "generatedModelPath": "./gen/vehicle_model"
    },
    "cliVersion": "v0.7.0"
}
velocitas --version
velocitas-cli/0.7.0 linux-arm64 node-v18.5.0

start dev container -> wait for installation / setup

export SDV_MIDDLEWARE_TYPE=native
export SDV_MQTT_ADDRESS=mqtt://localhost:1883
export SDV_VEHICLEDATABROKER_ADDRESS=grpc://localhost:55555

Press F1 and run Task: Local Runtime - Up

Afterwards:
python3 /workspaces/vehicle-app-python-template/app/src/main.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: 🏗 In progress
Development

No branches or pull requests

2 participants