Comments (9)
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.
@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.
Have any progress about it?
from wolfmqtt.
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.
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.
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.
Hi @dgarske I'm trying to do the following
- Have a reconnection if the broker is not live
- 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.
any update on the automatic reconnect? is there a way to implement it ourselves?
from wolfmqtt.
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)
- MHC3 PIC32MZ - Client stops handling incoming messages if it stops publishing HOT 3
- WMQTT_NET_GLUE Error: Skt Timeout, occurred in func: WMQTT_NETGlue_DoRead, line: 522 HOT 5
- Multiple errors when including WolfSSl/ssl.h VS HOT 1
- HAVE_SNI define in wolfssl HOT 18
- wolfMQTT callbacks HOT 1
- Reconnect problem: MqttSocket_Connect relies on incorrect client->flags status value
- Dynamic property stack for v5 HOT 1
- Update AWS example to demonstrate MQTT v5 client
- Simple Publish & Subscribe Code to Test (Without TLS) HOT 5
- publish and subscribe at the same time in the same client HOT 13
- Refresh broker certs before release
- wolfMQTT Espressif ESP32 Managed Component Support HOT 1
- wolfMQTT unexpectedly attempts single-use Espressif hardware lock
- Use wolfMQTT without sockets HOT 2
- MQTT-SN Gateway that supports DTLS 1.3 HOT 2
- Broken wolfMQTT Cube Pack link HOT 3
- As a future TODO... when comparing this with `MqttClient_WaitType` there are some fixes that need brought over.
- showng header file error like no such dictionary HOT 30
- MqttClient_WaitType 死锁的问题 HOT 9
- Memory leakage issue in version 1.18.0 HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wolfmqtt.