Skip to content
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

callback functions mqtt #527

Closed
ghost opened this issue Jul 3, 2015 · 3 comments
Closed

callback functions mqtt #527

ghost opened this issue Jul 3, 2015 · 3 comments

Comments

@ghost
Copy link

ghost commented Jul 3, 2015

When doing some subscribes consecutive, callback is always done from the last subscribe.

m:subscribe("test/test_1",0,function con() print("Subscribe 1") end)
m:subscribe("test/test_2",0,function con() print("Subscribe 2") end)
m:subscribe("test/test_3",0,function con() print("Subscribe 3") end)   

Output:
Subscribe 3
Subscribe 3
Subscribe 3

The same if consecutive publish's.

Text at API mqtt.client:subscribe() seems to be wrong:

Parameters
topic: a string topic to subscribe to
qos: qos subscription level, default 0
function(client, topic, message): callback fired when message received.

Parameters for callback function doesn't exist.

@benrussell
Copy link

Looks like C internals only support one callback function per client instance.

Data structure created here:
https://github.com/nodemcu/nodemcu-firmware/blob/master/app/modules/mqtt.c#L1038

Callback function stored here:
https://github.com/nodemcu/nodemcu-firmware/blob/master/app/modules/mqtt.c#L1114

Callback restored and called here:
https://github.com/nodemcu/nodemcu-firmware/blob/master/app/modules/mqtt.c#L277

Also appears that the instance of m is pushed as an argument to your function.

Example code here appears to be correct:
http://www.nodemcu.com/docs/mqtt-module/

API reference here appears to be wrong:
http://www.nodemcu.com/docs/mqtt-client-module/

@marcelstoer
Copy link
Member

Pity this wasn't fixed with #774. So, it's still wrong at http://nodemcu.readthedocs.org/en/dev/en/modules/mqtt/#mqttclientsubscribe

devsaurus added a commit to devsaurus/nodemcu-firmware that referenced this issue Jan 28, 2016
@devsaurus
Copy link
Member

ad 1.
You need to nest the calls to subscribe(). Firmware will execute the callback function that happens to be active at the time where subscription succeeds. This can be any of the three functions in your example.

ad 2.
API doc at http://nodemcu.readthedocs.org/en/dev/en/modules/mqtt/#mqttclientsubscribe is updated now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants