Page 2 of 2

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

Posted: Thu Jan 04, 2024 3:13 pm
by niedian
Can't connect to EMQX. Please help me, thank you! Here is my flowcode file.

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

Posted: Thu Jan 04, 2024 3:39 pm
by niedian
Still unable to connect to EMQX, please take a look for me, thank you! This is my workflow code file.Regards!

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

Posted: Fri Jan 05, 2024 9:54 am
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

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

Posted: Sat Jan 06, 2024 4:17 pm
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!

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

Posted: Sun Jan 07, 2024 4:01 pm
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!

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

Posted: Mon Jan 08, 2024 9:22 am
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".

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

Posted: Thu Jan 11, 2024 7:50 am
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!

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

Posted: Thu Jan 11, 2024 9:02 am
by niedian
Can you provide me with an example code for ESP32 accessing EMQX? Greetings.

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

Posted: Sun Jan 14, 2024 8:57 am
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!