Comments (5)
Yes! That's just what I needed. Thanks for your help. Great library by the way!
from arduinomqtt.
Hi @rapasal
What broker do you use?
Please provide a full debug log. See #define MQTT_LOG_ENABLED 1
I didn't notice anything very wrong from the first look. Need to debug.
Try to add more logs to void deliverMessage(MQTTString& topic, Message& message) {}
method.
It looks like the client can't match the topic value with the value used on subscribe.
You use clean session
, so the broker should not send messages until you subscribe and set the handler...
Verify the topic value is sent by the broker
Try to reproduce the same using public MQTT
broker like Mosquitto and on x86
platform. See example
It could be easier to debug on PC.
from arduinomqtt.
I reformatted to bring the code listed above out of the MqttWrapper
class and it works fine! For some reason wrapping it up introduces this behavior. I will do some experimenting today with some logic wrapped and some just in setup()
and loop()
to see if I can spot what breaks it. I'll add some extra logs like you suggest too.
from arduinomqtt.
OK, so I have been playing around and found that the problem is when calling mqtt->subscribe(...)
. In my example above I had a hard coded topic. I got myself in a muddle before posting and was actually calling this with a char array instead of a hard coded string when I got the error.
char subTopic[64];
functionToPopulateSubTopic(subTopic);
mqttWrapper.mqtt->subscribe(subTopic, MqttClient::QOS0, subCallback);
When I hard code as per my initial example it actually works! When I pass the char array in I get the error described. Having the code in a wrapper has no effect. I can confirm that running the ConnectEsp8266WiFiClient
example in Arduino IDE also shows the same error when using a char array as the subscription topic.
When I pass a char array to mqtt->publish(...)
it works fine. I noticed that the topic argument for both subscribe
and publish
are converted into a MQTTString
differently, and tried to use the implementation from publish
in the subscribe
method but no luck.
I added the following line to deliverMessage(...)
inside the for loop:
MQTT_LOG_PRINTFLN("Incoming topic: %s", (char*)(mMessageHandlers.get()[i].topic));
This threw up something strange... When I hard code the subscription address this prints the correct topic. When I pass the subscription address as a char array it prints the publish topic! I know that the char array I pass definitely contains the subscription topic as I print it right before calling subscribe(...)
.
I'm not sure what the solution here is. Hard coding isn't really an option as I want to be able to store the topics in arrays so that they can be edited at run time.
from arduinomqtt.
@rapasal
I think your problem with a string
allocated on stack
.
When you use this library or the original Paho
library you have to assume that nothing is copied by default.
You have full memory control. That is good for embedded systems.
The topic is stored by reference in default implementation.
Look at
I guess this is exactly what you need to avoid hardcoded topics.
If you know the maximum topic length I would suggest using MessageHandlersStaticImpl
I see no problem with the default MessageHandlers
implementation if you guaranty the topic
pointer is valid
until you unsubscribe.
You can organize own topic storage or write custom MessageHandlers
implementation if you wish
The library is flexible enough to provide everything externally with no need for library modification.
from arduinomqtt.
Related Issues (20)
- Cannot Subscribes new topic after setup MQTT done HOT 6
- Got error Exception(28) when lost power in modem. HOT 5
- Stack overflow due to recursive callback call HOT 7
- Curly Braces HOT 8
- Does this support ssl/tls on arduino mega? HOT 4
- Make NET_MAX_TM_MS and NET_MIN_TM_MS configurable HOT 11
- Correct use of mqtt->yield HOT 5
- Reduce the `yield` execution time HOT 4
- Got Disconnect when sent 3 messages in once using SSL HOT 9
- PubSub Example message.payloadLen HOT 1
- Username and Key HOT 2
- Using with Sloeber HOT 2
- Arduino MKR usage HOT 2
- How to get topic name in message callback function? HOT 6
- ESP32 Task-WDT make reboot in special situation [solved] HOT 4
- Client freases out. HOT 2
- Connection Error HOT 1
- MqttClient::Network implementation HOT 2
- Not a real issue - uninitialized variable
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 arduinomqtt.