-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
about publishing more than 2 topic #182
Comments
same here. any news on that? |
Sorry not to have followed up on this. Without a lot more detail as to what you're trying to do and what behaviour you're seeing I cannot help. |
hi, after a callback i set a flag that a message needs to publish. if the esp receives more than one callback in a short time the esp hangs forever without any exception. it seems that when the esp is publishing something and at the same time is receiving a callback the esp will hang... i use an older version of the pubsubclient (1.99.1) but just tested with the current version and it seems to be the same... thanks for the awsome library anyway :) i use it on about 20 devices. |
Just for testing purpose, can you please try with my fork? https://github.com/suxsem/pubsubclient/ |
thank you. i will take a look and give you feedback |
@chrigu1981 any news? |
hi @Suxsem |
Hello, I have this same problem and @Suxsem 's fork isn't helping me... Please help... |
@BlackXDragon can you post your code? |
@chrigu1981 this is the code:
|
you are trying to subscribe to just one topic? what in detail is the problem? |
The problem is that the last line; i.e., |
try to call client.loop(); in while loop |
Ok, I'll try that... |
This is my new code, and the problem still persists:
|
Hey!! @chrigu1981 !! I rectified the problem!! Thanks for the help!!! |
nice :) can you share what you‘ve done? |
I used the TinyGPS++ library instead of using the raw bitstream from serial...
|
I'm currently having the same problem. I'm trying to publish 2 topics.
/**************
#define VARIABLE_LABEL "sensor" // Assing the variable label #define SENSOR 35 // Set the GPIO12 as SENSOR char mqttBroker[] = "things.ubidots.com"; /**************
void callback(char* topic, byte* payload, unsigned int length) { void reconnect() {
} /**************
{ Serial.println(); while (WiFi.status() != WL_CONNECTED) Serial.println(""); emon1.current(35, 2.5); // Current: input pin, calibration. void loop() double Irms = emon1.calcIrms(1480); // Calculate Irms only sprintf(topic, "%s%s", "/v1.6/devices/try", DEVICE_LABEL); float sensor = analogRead(SENSOR); /* 4 is mininum width, 2 is precision; float value is copied onto str_sensor*/ sprintf(payload, "%s {"value": %s", payload, str_sensor); // Adds the value
/**************
#define VARIABLE_LABEL "current" // Assing the variable label #define DEVICE_LABEL "esp32" // Assig the device label #define SENSOR 35 // Set the GPIO12 as SENSOR*/ char mqttBroker[] = "things.ubidots.com"; /**************
void callback(char* topic, byte* payload, unsigned int length) /* char p[length + 1]; void reconnect() {
} /**************
{ Serial.println(); while (WiFi.status() != WL_CONNECTED) Serial.println(""); client.setCallback(callback); emon1.current(33, 25.7); // Current: input pin, calibration. } } double Irms = emon1.calcIrms(1480); // Calculate Irms only sprintf(topic, "%s%s", "/v1.6/devices/try", DEVICE_LABEL); sprintf(topic2, "%s%s", "/v1.6/devices/try", DEVICE_LABEL); float current = emon1.Irms; /* 4 is mininum width, 2 is precision; float value is copied onto str_current*/ dtostrf(lat, 4, 2, str_lat); sprintf(payload, "%s {"value": %s", payload, str_current); // Adds the value sprintf(payload, "%s, "context":{"lat": %s, "lng": %s}", payload, str_lat, str_lng); // Adds coordinates sprintf(payload, "%s {"value": %s", payload, str_sensor); // Adds the value Serial.print("current2: "); client.publish(topic, payload); client.loop(); anyone knows how? |
@zihny Do you have fix it? I'm with same problem as you... |
I see couple of things wrong with @zihny code. First, the delay(1000); in loop() is bad practice. It blocks everything for a long time. Second, the char pointers 'payload' and 'topic' are used as both a global variable for publishing ánd in the mqtt callback. The globals should be given another name, since it is likely it gets partially overwritten. Then the length of the global topic and topic2 variables. 150 is way too much. Set it something that actually matches the max topic length. How are you checking if messages actually get published? I don't see any subscription in the sketch to trigger callback. Edit: sprintf is used wrong as well. When setting up the payload, it points to the start of char array and overwrites the previous sprintf statement. Plus, you should use escape character ( \ ) before the quote marks that should be added as a character to the character string. Otherwise, the character string is terminated prematurely. |
@thijsdebont I create a new issuem cause Ithink I'm with another problem |
this library is just owsum and amazing i must admit it, it works very smooth whenever only 1 or 2 topic is published, but unfortunately when i try to publish more than 2 topic it starts malfunctioning........after publishing it gets stop and sometime it publishes again and then stop ......and then nothing is publishing anymore! whats the fix i can do to overcome this pathetic problem ??
The text was updated successfully, but these errors were encountered: