Comments (7)
Hi,
the client library has a maximum packet size of 128 bytes - which your code is exceeding. This isn't a scenario the code guards against (it does for incoming messages, but not for outgoing).
The length value is written to the header and then that number of bytes are copied to the internal payload buffer. If length exceeds the internal buffer, it carries on writing beyond the end of the array, which could cause memory corruption.
I'll put a fix in that guards against this, but in the meantime, if you want to increase the max packet size, change MAX_PACKET_SIZE in PubSubClient.h - this will obviously increase the memory usage of the code.
Nick
from pubsubclient.
Thanks Nick. I'll change the length to 140 (you can guess why).
from pubsubclient.
Actually, looking at it after a cup of tea, the write method only supports a single byte of length - which limits you to a 128 byte message. So you cannot simply change the #define.
When I get a chance later today, I'll put a fix in that enables multi-byte length encoding.
Once that is in place you'll be able to increase the message size.
You'll need to allow for the message headers when determining your message size. The sum is:
1 byte fixed header
2 bytes length (for messages 128 < length <16383 )
2 bytes for the topic length
topic bytes
payload bytes
which gives you 5+topic+payload bytes.
This assumes a qos 0 message (which is all the arduino lib currently supports), otherwise you need another 2 bytes for message ID in there.
from pubsubclient.
I've found that forked copy of your library. I'll take a look at that.
from pubsubclient.
Which forked copy? I haven't kept track of the handful of forks others have done, but I'm not aware of anyone making these changes already.
from pubsubclient.
https://github.com/karlp/pubsubclient
Or I'll put my S/370 (aka zSeries now) Assembler knowledge back in the cupboard, sharpen my C/C++ coding pencil and hack at your code.
I've been doing messaging and queuing for 30 years (along with lots of DL/I and DB2 databases), This MQTT stuff is like a little IMS thing. It's lots of fun. Look me up in BluePages.
from pubsubclient.
Reviewing the open issues. The library now handles larger packets (when the MAX packet size constant is changed in the .h file). Nothing more to do here.
from pubsubclient.
Related Issues (20)
- Reconnects every 4 hours HOT 2
- Sometimes payload are mixed up with topic. HOT 1
- Callback is not called when i am pubishing audio data in bytes.
- Intermittent delay of minutes between ESP publish and receipt by mosquitto in a pi HOT 1
- Anomolous performing when using along with I2S
- Issue while setting keep alive zero. HOT 2
- Bug in PubSubClient::connected HOT 1
- Retain Flag not working HOT 1
- receiving arbitrarily large messages HOT 1
- Use hostname for the MQTT broker IP HOT 2
- Library when subscribing to third topic won't connect to ethernet
- Connecting and running smoothly on mobile hotspot while rc=-2 on fiber broadband wifi router
- Future of this module HOT 7
- Reconnect Problem. HOT 11
- Different error on Ubuntu arduino ide from windows arduino ide.
- #error "This library only supports boards with an AVR, SAM, SAMD, NRF52 or STM32F4 processor." HOT 1
- Client.connected() does not return false if MQTT Broker Pc disconnects from Internet or local network. HOT 1
- Can't Connect to mqtt broker after including SPI.h
- When callback is registered to topic that contains underscore, the underscore is replaced with space HOT 1
- pubsub library not thread safe.
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 pubsubclient.