Comments (4)
After a long thought, I'm almost sure that this is not bug. I've been further reading and it seems MQTT should deal correctly splitted MQTT messages (in several TCP packets).
Maybe one feature that would be really nice is to be able to specify the maximum payload you want to send out. Sometimes you are using a connection that has a maximum payload (for example NB-IoT) and you are forced to split the payload in serveral TCP packets. It would be nice to be able to tell the publish method the maximum payload of each client-write(). And if you set it to zero, it means "no limit" (for standard wifi connections).
from arduino-mqtt.
More findings: In Arduino (at least on ESP32) there's no way of knowing the size of the packages the stack tcp ip will send. No matter if you split the client->write() into multiple calls, it will send all together because it seems the ESP32 fills an output buffer instead of sending it instantly.
Nevertheless, the implementation change of splitting the payload in chunks turned out useful (at least with a SIMCOM) because some modems have a limited input buffer and you can't send unlimited data at once. Thus, in that case I changed you library to be able to configure the chunk size in the publish() function. Something like this (if you are interested, I can make a merge request in lwmqtt).
// send payload if available
if (msg.payload_len > 0) {
if(max_payload_chunk_size == 0) {
err = lwmqtt_write_to_network(client, msg.payload, msg.payload_len);
if (err != LWMQTT_SUCCESS) {
return err;
}
} else {
uint32_t sent = 0;
uint32_t chunk_size;
while(sent < msg.payload_len) {
if(msg.payload_len - sent >= max_payload_chunk_size) {
chunk_size = max_payload_chunk_size;
} else {
chunk_size = msg.payload_len - sent;
}
err = lwmqtt_write_to_network(client, msg.payload + sent, chunk_size);
if (err != LWMQTT_SUCCESS) {
return err;
}
sent += chunk_size;
}
}
}
from arduino-mqtt.
@gonzabrusco Thanks for the detailed report of your investigation!
However, I think that this should not be implemented in the scope of this library or the lwmqtt project. For both projects there is an elegant way to implement such custom networking behaviour. For arduino-mqtt you could simply implement your own Client class that performs the custom buffering. In lwmqtt, one would need to set a custom network write callback that implements the logic.
Also: If a modem silently drops data because its buffers are full and the network stack does not perform the proper TCP packet re-sending logic, you have a lot more problems to worry about.
from arduino-mqtt.
You are completely right. I will keep this implemented in my own fork.
from arduino-mqtt.
Related Issues (20)
- MQTT reconnection when not disconnected. ESP8266 HOT 6
- Unreliable behaviour with reconnections HOT 3
- MQTT HOT 1
- Websockets support HOT 3
- MQTT SSL connection issue with QoS1 and QoS2 messages HOT 1
- DCU: cannot connect to local MQTT broker HOT 1
- This library uses some posix functions that are not provided for Uno R4 HOT 3
- Subscribe query HOT 1
- Release version `v2.5.1` different of master version HOT 1
- 0
- Error connect MQTT SSL/TLS with module CBU use platform libretiny
- RP2040 seems to work fine HOT 2
- payload length / reconnect HOT 1
- Random error in MQTTClient::loop() function HOT 2
- Cosmetics only in MQTTClient.h / MQTTClient(...)
- Wrong version in README.md?
- ESP32 PSRAM for MQTT buffer?
- if available bytes on the network is available, close connection. HOT 1
- MQTT5 HOT 1
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 arduino-mqtt.