Giter Site home page Giter Site logo

Automatic connect function about wolfmqtt HOT 9 OPEN

wolfssl avatar wolfssl commented on July 17, 2024
Automatic connect function

from wolfmqtt.

Comments (9)

dgarske avatar dgarske commented on July 17, 2024

Hi skyformat99,

Thanks for the excellent suggestion! The "Add automatic re-connect" is already on our feature request list, but I will give it a bump up on the list. I expect this feature to be added by the end of this 2017. How urgent is the automatic reconnect requirement for using wolfMQTT?

Thanks,
David Garske, wolfSSL

from wolfmqtt.

skyformat99 avatar skyformat99 commented on July 17, 2024

@dgarske
Thank you for your reply!

This feature should be a very useful feature. For example, in 4G network communication, there are often network failures, and if there are automatic reconnect functions (including automatic pub and sub), it will be much more convenient.

from wolfmqtt.

skyformat99 avatar skyformat99 commented on July 17, 2024

Have any progress about it?

from wolfmqtt.

BeIllegalBeagle avatar BeIllegalBeagle commented on July 17, 2024

I'm in need of the same feature, I tried to see if I could loop the rc = client->net->write(client->net->context, buf, buf_len, timeout_ms);
function in mqtt_socket.c until a successful connection to the broker occurs but the program simply stalls when a broker is not detected, making the 'rc' variable a bit useless(unless I'm doing it wrong)

from wolfmqtt.

dgarske avatar dgarske commented on July 17, 2024

This feature is being added and should be available next week. I will post an update here when its ready. Thanks, David Garske

from wolfmqtt.

dgarske avatar dgarske commented on July 17, 2024

Hi All,

I've pushed a basic disconnect callback to a pull request here:
#69

The callbacks are issued from the mqtt_packet layer and the original error code is then sent up the stack. The idea is for you to set this disconnect callback in your application and then have it trigger some some type of reconnect action. I don't think its a good idea to do the reconnect in the callback, but instead set a state or context variable that triggers this in your main thread.

I would like to see an automatic reconnect feature as the next step for this. Let me know your thoughts.

Thanks,
David Garske, wolfSSL

from wolfmqtt.

BeIllegalBeagle avatar BeIllegalBeagle commented on July 17, 2024

Hi @dgarske I'm trying to do the following

  1. Have a reconnection if the broker is not live
  2. Have a reconnection if connection is lost

How would I use this callback you added currently? Within the netwrite thread my program stalls at the 'connect' or 'write' function.

This is the function - static int NetWrite(void *context, const byte* buf, int buf_len, int timeout_ms) inside of mqttnet.c

and this is the line
rc = (int)SOCK_SEND(sock->fd, buf, buf_len, 0);
I don't even get any value of the rc if there is an error here, it just stops here if the broker is not running so I can't do anything further up like you mentioned. What would you suggest?

I will also try to see if I get a better result when I try closing the broker once a connection has been established to the client.

from wolfmqtt.

milamber-ls avatar milamber-ls commented on July 17, 2024

any update on the automatic reconnect? is there a way to implement it ourselves?

from wolfmqtt.

dgarske avatar dgarske commented on July 17, 2024

Hi All,

The actual socket handling for connect is handled via callbacks, which the consumer of the library is responsible for setting up. If you are waiting for a message MqttClient_WaitMessage and MQTT_CODE_ERROR_TIMEOUT then you might consider doing a "keep-alive" much like our example here: https://github.com/wolfSSL/wolfMQTT/blob/master/examples/mqttclient/mqttclient.c#L508

If you get a response code that is not MQTT_CODE_SUCCESS or MQTT_CODE_CONTINUE (for non-blocking) then you would have received a socket error and you would need to reconnect the socket and call MqttClient_Connect again.

We added a disconnect callback that you can register via MqttClient_SetDisconnectCallback, which will tell you when a network error occurred. This allows you to set a flag indicating your client needs to reconnect. The actual socket reconnect cannot occur in this callback.

Let me know if you have any questions or issues.

Thanks,
David Garske, wolfSSL

from wolfmqtt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.