thin-edge / thin-edge.io

The open edge framework for lightweight IoT devices
https://thin-edge.io
Apache License 2.0
221 stars 54 forks source link

Custom MQTT port is not respected when connecting using tedge connect c8y #2787

Closed reubenmiller closed 5 months ago

reubenmiller commented 7 months ago

Describe the bug

The tedge connect c8y does not use the port given via the c8y.mqtt configuration setting (feature introduced in https://github.com/thin-edge/thin-edge.io/issues/1931).

This affects cases where Cumulocity IoT is configured to use a non-default port of 8883.

The code currently incorrectly uses a static value of 8883 (see below):

let mut mqtt_options = MqttOptions::new(bridge_config.remote_clientid.clone(), host[0], 8883);

However it must be noted that the c8y-bridge.conf uses the configured c8y.mqtt host/port.

To Reproduce

The easiest way to check this is to set an incorrect port which should cause thin-edge.io not to connect (due to the misconfigured port).

  1. Set the c8y.url

    tedge config c8y.url thin-edge-io.eu-latest.cumulocity.com
  2. Set a custom c8y.mqtt value which uses an invalid port 1234

    tedge config set c8y.mqtt thin-edge-io.eu-latest.cumulocity.com:1234
  3. It is expected that the tedge connect c8y should fail (due to the incorrect port)

    tedge connect c8y

Expected behavior

When the user specifies a custom MQTT port using the c8y.mqtt configuration.

Screenshots

Environment (please complete the following information):

Additional context

gligorisaev commented 6 months ago

QA has thoroughly checked the bug and here are the results: