thin-edge / thin-edge.io

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

Socket error on client tedge-mapper-c8y #972

Closed mbie-sag closed 2 years ago

mbie-sag commented 2 years ago

Describe the bug Seems like tedge c8y mapper cannot connect to local broker properly. See error messages below. tedge was installed on a fresh Ubuntu 18.04 with the latest installation script. Doing the same thing in a fresh 20.04 does work properly. Mosquitto is running. The configs look good. All tedge components are running.

To Reproduce Install tedge with installation script on a Ubuntu 18.04 LTS.

`ubuntu@swell-grouper:/etc/tedge$ sudo tedge connect c8y The system config file '/etc/tedge/system.toml' doesn't exist. Use '/bin/systemctl' as a service manager.

Checking if systemd is available.

Checking if configuration for requested bridge already exists.

Validating the bridge certificates.

Creating the device in Cumulocity cloud.

Saving configuration for requested bridge.

Restarting mosquitto service.

Awaiting mosquitto to start. This may take up to 5 seconds.

Enabling mosquitto service on reboots.

Successfully created bridge connection!

Sending packets to check connection. This may take up to 2 seconds.

ERROR: Io(Os { code: 111, kind: ConnectionRefused, message: "Connection refused" })

Make sure mosquitto is running. Warning: Bridge has been configured, but Cumulocity connection check failed.

Checking if tedge-mapper is installed.

Starting tedge-mapper-c8y service.

Persisting tedge-mapper-c8y on reboot.

tedge-mapper-c8y service successfully started and enabled!

ERROR: Io(Os { code: 111, kind: ConnectionRefused, message: "Connection refused" })

Make sure mosquitto is running. Failed to get the connected tenant URL from Cumulocity.

Enabling software management.

Checking if tedge-agent is installed.

Starting tedge-agent service.

Persisting tedge-agent on reboot.

tedge-agent service successfully started and enabled!

ubuntu@swell-grouper:/etc/tedge$ sudo tedge mqtt pub tedge/measurements '{ "temperature": 25 }' ERROR: the message has not been published Error: failed to publish the message "{ "temperature": 25 }" on the topic "tedge/measurements" with QoS "AtMostOnce".

Caused by: MQTT connection error: I/O: Connection refused (os error 111)

Hint: Is MQTT server running?

ubuntu@swell-grouper:/etc/tedge$ sudo cat /var/log/mosquitto/mosquitto.log 1646257951: mosquitto version 1.4.15 (build date Tue, 18 Jun 2019 11:42:22 -0300) starting 1646257951: Config loaded from /etc/mosquitto/mosquitto.conf. 1646257951: Opening ipv4 listen socket on port 1883. 1646257951: Opening ipv6 listen socket on port 1883. 1646257955: New connection from 127.0.0.1 on port 1883. 1646257955: New client connected from 127.0.0.1 as tedge-mapper-c8y (c0, k60). 1646257955: Socket error on client tedge-mapper-c8y, disconnecting. 1646257957: New connection from 127.0.0.1 on port 1883. 1646257957: New client connected from 127.0.0.1 as tedge_agent (c0, k60). 1646257957: Socket error on client tedge_agent, disconnecting. 1646258015: mosquitto version 1.4.15 terminating`

Environment (please complete the following information):

PradeepKiruvale commented 2 years ago

@mbie-sag could you please share your /etc/tedge/mosquitto-conf/tedge-mosquitto.conf and also output of sudo tedge config list.

mbie-sag commented 2 years ago

ubuntu@swell-grouper:~$ sudo cat /etc/tedge/mosquitto-conf/tedge-mosquitto.conf per_listener_settings true connection_messages true log_type error log_type warning log_type notice log_type information log_type subscribe log_type unsubscribe message_size_limit 268435455 listener 1883 127.0.0.1 allow_anonymous true require_certificate false

ubuntu@swell-grouper:~$ sudo tedge config list device.id=Ubuntu1804 device.type=thin-edge.io device.key.path=/etc/tedge/device-certs/tedge-private-key.pem device.cert.path=/etc/tedge/device-certs/tedge-certificate.pem c8y.url=XXX.eu-latest.cumulocity.com c8y.root.cert.path=/etc/ssl/certs az.root.cert.path=/etc/ssl/certs az.mapper.timestamp=true mqtt.bind_address=127.0.0.1 mqtt.port=1883 tmp.path=/tmp

PradeepKiruvale commented 2 years ago

I do not see any issues with the configs. Could you please check if the mosquitto is running?

mbie-sag commented 2 years ago

Just did a manual installation. Mosquitto is up and running until 'tedge connect c8y'. Afterwards its active(exited) and won't restart (see below). It seems as there have been some issues with mosquitto and ubuntu packaging, but I do not know, if this stands in relation with this issue. Within Ubuntu 20.04 everything works fine.

mosquitto.service - LSB: mosquitto MQTT v3.1 message broker Loaded: loaded (/etc/init.d/mosquitto; generated) Active: active (exited) since Wed 2022-03-09 12:07:26 CET; 2min 11s ago Docs: man:systemd-sysv-generator(8) Tasks: 0 (limit: 1151) CGroup: /system.slice/mosquitto.service

PradeepKiruvale commented 2 years ago

Could you please try using the mosquitto 2.0 version?

mbie-sag commented 2 years ago

Issue is related to the used mosquitto version provided in the Ubuntu 18.04 repos and was fixed by using the latest mosquitto version instead. Thanks @PradeepKiruvale