There is no option for setting the path in the ConnectTo property of the MQTT_Client component.

Post here to discuss any new features, components, chips, etc, that you would like to see in Flowcode.
niedian
Posts: 85
http://meble-kuchenne.info.pl
Joined: Thu Jan 07, 2021 11:28 am
Has thanked: 3 times
Been thanked: 4 times

Re: There is no option for setting the path in the ConnectTo property of the MQTT_Client component.

Post by niedian »

Can't connect to EMQX. Please help me, thank you! Here is my flowcode file.
Attachments
Snipaste_2024-01-04_23-11-29.png
Snipaste_2024-01-04_23-11-29.png (16.73 KiB) Viewed 1602 times
MQTT.fcfx
(20.93 KiB) Downloaded 143 times

niedian
Posts: 85
Joined: Thu Jan 07, 2021 11:28 am
Has thanked: 3 times
Been thanked: 4 times

Re: There is no option for setting the path in the ConnectTo property of the MQTT_Client component.

Post by niedian »

Still unable to connect to EMQX, please take a look for me, thank you! This is my workflow code file.Regards!
Attachments
MQTT-2.fcfx
(21.96 KiB) Downloaded 144 times

Steve-Matrix
Matrix Staff
Posts: 1253
Joined: Sat Dec 05, 2020 10:32 am
Has thanked: 167 times
Been thanked: 277 times

Re: There is no option for setting the path in the ConnectTo property of the MQTT_Client component.

Post by Steve-Matrix »

I have managed to use your credentials to successfully connect and send/receive MQTT messages using Flowcode Web Developer. The project is attached. So there are no issues with the authentication, etc, so the properties you are using in your embedded project are correct.

IMPORTANT: As the attached is a Web Developer project, it uses WebSockets and so I changed the port to 8084. Your embedded project should use the MQTT protocol directly on port 8883.

Looking at your embedded project, you are calling "MQTT_Client1::Connect()" outside the "While 1" loop and then calling it again inside that loop. This second call will return false (assuming the first connects ok), meaning your project is always responding to a connection error. So the logic appears to be wrong.

A better approach would be to use a variable (e.g. "bConnected") to remember the connection status within the loop. Something like this:

Code: Select all

bConnected = false
while (1)
  if (bConnected)
    //connected, so you can publish messages
    //and also check for any received messages that have been subscribed to
  else
    bConnected = MQTT_Client1::Connect()   //attempt to connect
    if (bConnected)
      //subscribe to any messages
    else
      //report an error
    end if
  end if
end while
Attachments
mqtt example3a - niedian.fcsx
(40.2 KiB) Downloaded 132 times

niedian
Posts: 85
Joined: Thu Jan 07, 2021 11:28 am
Has thanked: 3 times
Been thanked: 4 times

Re: There is no option for setting the path in the ConnectTo property of the MQTT_Client component.

Post by niedian »

Hello, thank you very much for your example code. I tested it and the connection is working fine. The subscribe and publish functions are also working properly. It's great! However, unfortunately, after modifying the program for ESP32-S3 and flashing it onto the ESP32, the ESP32-S3 still cannot connect to EMQX. Can you please take a look and help me make some changes to the ".fcfx" file? Thank you!!!Regards!
Attachments
MQTT-5.fcfx
(22.07 KiB) Downloaded 145 times

niedian
Posts: 85
Joined: Thu Jan 07, 2021 11:28 am
Has thanked: 3 times
Been thanked: 4 times

Flowcode v10 Re: There is no option for setting the path in the ConnectTo property of the MQTT_Client component.

Post by niedian »

Hello, thank you very much for your example code. I tested it and the connection is working fine. The subscribe and publish functions are also working properly. It's great! However, unfortunately, after modifying the program for ESP32-S3 and flashing it onto the ESP32, the ESP32-S3 still cannot connect to EMQX. Can you please take a look and help me make some changes to the ".fcfx" file? Thank you!!!Regards!
Attachments
MQTT6.fcfx
(15.35 KiB) Downloaded 134 times

Steve-Matrix
Matrix Staff
Posts: 1253
Joined: Sat Dec 05, 2020 10:32 am
Has thanked: 167 times
Been thanked: 277 times

Re: There is no option for setting the path in the ConnectTo property of the MQTT_Client component.

Post by Steve-Matrix »

Please see and try following my previous suggested pseudocode logic. Your project has multiple problems. For example, you need to remove the "connect" outside the loop and don't replace your "connected" bool with the return from "publish".

niedian
Posts: 85
Joined: Thu Jan 07, 2021 11:28 am
Has thanked: 3 times
Been thanked: 4 times

Re: There is no option for setting the path in the ConnectTo property of the MQTT_Client component.

Post by niedian »

Hello, in the past few days, I have been reading a lot of materials about MQTT. I made several modifications and tests to the Flowcode program for ESP32, and even replaced the ESP32 hardware board. However, unfortunately, the ESP32 hardware still cannot connect to EMQX. Can you please help me? Thank you so much!!! Regards!

niedian
Posts: 85
Joined: Thu Jan 07, 2021 11:28 am
Has thanked: 3 times
Been thanked: 4 times

Re: There is no option for setting the path in the ConnectTo property of the MQTT_Client component.

Post by niedian »

Can you provide me with an example code for ESP32 accessing EMQX? Greetings.

niedian
Posts: 85
Joined: Thu Jan 07, 2021 11:28 am
Has thanked: 3 times
Been thanked: 4 times

Re: There is no option for setting the path in the ConnectTo property of the MQTT_Client component.

Post by niedian »

Hello, I finally did it! EMQX server, ESP32 terminal, PC terminal, mobile terminal, web terminal, and DingTalk terminal are all working perfectly. Flowcode is amazing! Thank you for your guidance. Greetings!

Post Reply