From rajeevsoni71 at gmail.com Tue Aug 2 09:08:22 2022 From: rajeevsoni71 at gmail.com (Rajeev Soni) Date: Tue, 2 Aug 2022 12:38:22 +0530 Subject: [Libwebsockets] Runtime Error in minimal-Mqtt-client example. Message-ID: Hi Team, I am trying to run Mqtt client from the below path.. Src Path : minimal-examples-lowlevel/mqtt-client/minimal-mqtt-client/minimal-mqtt-client.c Compiled Path : libwebsockets/build/bin/lws-minimal-mqtt-client When I am running this example binary without -s option it runs and able to receive the published message only once and it exits with below message ------------------ Without -s Option Logs-------------- [2022/08/02 12:28:43:2254] U: LWS minimal MQTT client unencrypted [-d][-s] [2022/08/02 12:28:43:2262] N: lws_create_context: LWS: 4.3.99-v4.3.0-258-ge3ed2ba6, NET CLI SRV H1 H2 WS MQTT SS-JSON-POL ConMon IPv6-absent [2022/08/02 12:28:43:2263] N: __lws_lc_tag: ++ [wsi|0|pipe] (1) [2022/08/02 12:28:43:2264] N: __lws_lc_tag: ++ [vh|0|netlink] (1) [2022/08/02 12:28:43:2265] N: __lws_lc_tag: ++ [vh|1|default||-1] (2) [2022/08/02 12:28:43:3274] N: lws_mqtt_generate_id: User space provided a client ID 'lwsMqttClient' [2022/08/02 12:28:43:3274] N: __lws_lc_tag: ++ [wsicli|0|MQTT/mqtt/default/localhost] (1) [2022/08/02 12:28:43:3310] N: [wsicli|0|MQTT/mqtt/default/localhost]: lws_client_connect_3_connect: trying 127.0.0.1 [2022/08/02 12:28:43:3323] N: __lws_lc_tag: ++ [mux|0|default|mqtt_sid1] (1) [2022/08/02 12:28:43:3323] N: _lws_mqtt_rx_parser: migrated nwsi [wsicli|0|MQTT/mqtt/default/localhost] to sid 1 [mux|0|default|mqtt_sid1] [2022/08/02 12:28:43:3324] U: callback_mqtt: MQTT_CLIENT_ESTABLISHED [2022/08/02 12:28:43:3324] U: callback_mqtt: WRITEABLE: Subscribing [2022/08/02 12:28:43:3326] U: callback_mqtt: MQTT_SUBSCRIBED [2022/08/02 12:28:43:3326] U: callback_mqtt: WRITEABLE: Publish [2022/08/02 12:28:43:3327] U: callback_mqtt: MQTT_CLIENT_RX [2022/08/02 12:28:43:3327] N: [2022/08/02 12:28:43:3327] N: 0000: 74 65 73 74 2F 74 6F 70 69 63 30 test/topic0 [2022/08/02 12:28:43:3327] N: [2022/08/02 12:28:43:3328] N: [2022/08/02 12:28:43:3328] N: 0000: E2 80 9C 68 65 6C 6C 6F E2 80 9D ...hello... [2022/08/02 12:28:43:3328] N: [2022/08/02 12:28:43:3328] U: callback_mqtt: WRITEABLE: Publish [2022/08/02 12:28:43:3329] U: callback_mqtt: WRITEABLE: Publish [2022/08/02 12:28:43:3329] U: callback_mqtt: WRITEABLE: Publish [2022/08/02 12:28:43:3330] U: callback_mqtt: WRITEABLE: Publish [2022/08/02 12:28:43:3330] U: callback_mqtt: MQTT_ACK [2022/08/02 12:28:43:3331] U: callback_mqtt: WRITEABLE: Publish [2022/08/02 12:28:43:3331] U: callback_mqtt: WRITEABLE: Publish [2022/08/02 12:28:43:3332] U: callback_mqtt: WRITEABLE: Publish [2022/08/02 12:28:43:3332] U: callback_mqtt: WRITEABLE: Publish [2022/08/02 12:28:43:3333] U: callback_mqtt: WRITEABLE: Publish [2022/08/02 12:28:43:3334] U: callback_mqtt: MQTT_ACK [2022/08/02 12:28:43:3334] U: Completed: OK [2022/08/02 12:28:43:3335] N: __lws_lc_untag: -- [wsi|0|pipe] (0) 107.145ms [2022/08/02 12:28:43:3335] U: callback_mqtt: CLIENT_CLOSED [2022/08/02 12:28:43:3335] N: __lws_lc_untag: -- [mux|0|default|mqtt_sid1] (0) 1.189ms [2022/08/02 12:28:43:3336] N: __lws_lc_untag: -- [vh|1|default||-1] (1) 107.020ms [2022/08/02 12:28:43:3336] N: __lws_lc_untag: -- [wsicli|0|MQTT/mqtt/default/localhost] (0) 6.166ms [2022/08/02 12:28:43:3336] N: __lws_lc_untag: -- [vh|0|netlink] (0) 107.232ms --------------------------------------------------------------- but as per the code it should wait for a new publish message,,, And also I tried to execute it with -s option so that it will use a different port number ex (8883). but at runtime it throws the below error. ------------------WIth -s Option Logs ------------------ [2022/08/02 12:31:56:7527] U: LWS minimal MQTT client tls enabled [-d][-s] [2022/08/02 12:31:56:7536] N: lws_create_context: LWS: 4.3.99-v4.3.0-258-ge3ed2ba6, NET CLI SRV H1 H2 WS MQTT SS-JSON-POL ConMon IPv6-absent [2022/08/02 12:31:56:7537] N: __lws_lc_tag: ++ [wsi|0|pipe] (1) [2022/08/02 12:31:56:7538] N: __lws_lc_tag: ++ [vh|0|netlink] (1) [2022/08/02 12:31:56:7582] N: __lws_lc_tag: ++ [vh|1|default||-1] (2) [2022/08/02 12:31:56:8591] N: lws_mqtt_generate_id: User space provided a client ID 'lwsMqttClient' [2022/08/02 12:31:56:8592] N: __lws_lc_tag: ++ [wsicli|0|MQTT/mqtt/default/localhost] (1) [2022/08/02 12:31:56:8636] N: [wsicli|0|MQTT/mqtt/default/localhost]: lws_client_connect_3_connect: trying 127.0.0.1 [2022/08/02 12:31:56:8651] E: callback_mqtt: CLIENT_CONNECTION_ERROR: connect SYSCALL 104 [2022/08/02 12:31:56:8653] N: __lws_lc_untag: -- [wsicli|0|MQTT/mqtt/default/localhost] (0) 6.106ms [2022/08/02 12:31:56:8653] U: Completed: failed [2022/08/02 12:31:56:8653] N: __lws_lc_untag: -- [wsi|0|pipe] (0) 111.575ms [2022/08/02 12:31:56:8654] N: __lws_lc_untag: -- [vh|0|netlink] (1) 111.534ms [2022/08/02 12:31:56:8654] N: __lws_lc_untag: -- [vh|1|default||-1] (0) 107.250ms --------------------------------------------------------------- --------------------Mosquitto broker Logs while using -s option in client and -p 8883 option in broker------------- 1659423849: mosquitto version 2.0.14 starting 1659423849: Using default config. 1659423849: Starting in local only mode. Connections will only be possible from clients running on this machine. 1659423849: Create a configuration file which defines a listener to allow remote access. 1659423849: For more details see https://mosquitto.org/documentation/authentication-methods/ 1659423849: Opening ipv4 listen socket on port 8883. 1659423849: Opening ipv6 listen socket on port 8883. 1659423849: mosquitto version 2.0.14 running 1659423855: New connection from 127.0.0.1:35960 on port 8883. 1659423855: Client disconnected due to malformed packet. --------------------------------------------------------------------------------------------------------------------------------------------- Could you please help me to understand the runtime error and also execute this code successfully. Note: I am running the mosquitto broker with the option below while using -s option on the client side. $mosquitto -p 8883 For libwebsockets i have followed below step to compile it with MQTT enable feature 1. Download LibWebsockets: $ git clone https://github.com/warmcat/libwebsockets.git 2. Building: 2.1. Install CMake 2.8 or greater: http://cmake.org/cmake/resources/software.html (Most Unix distributions comes with a packaged version also) 2.2. Install OpenSSL. 3 To enable the mqtt support. $ cd libwebscokets $ vim CMakeLists.txt Turn On : option(LWS_ROLE_MQTT "Build with support for MQTT client" ON) Default: option(LWS_ROLE_MQTT "Build with support for MQTT client" OFF) 4. Generate the build files (default is Make files): ``` $ cd /path/to/src $ mkdir build $ cd build $ cmake .. ``` 5. Finally you can build using the generated Makefile: ``` $ make && sudo make install Thanks and regards Rajeev Soni -------------- next part -------------- An HTML attachment was scrubbed... URL: