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

[MQTT] Topic returning topic filter, not message topic #81

Closed
fiLLLip opened this issue May 8, 2020 · 1 comment
Closed

[MQTT] Topic returning topic filter, not message topic #81

fiLLLip opened this issue May 8, 2020 · 1 comment

Comments

@fiLLLip
Copy link

fiLLLip commented May 8, 2020

When trying out the sample, and listening to MQTT on a wildcard topic, the topic set in the on_publish is set to the filter, not the actual topic that the message appeared on. How to deal with this, and get the actual topic?

E.g. '$aws/things/+/shadow/update/accepted' should give topic '$aws/things/my_test_device/shadow/update/accepted'

connection.subscribe('/test/me/senpai', mqtt.QoS.AtLeastOnce, (topic, payload) => {

I posted the same issue in aws/aws-iot-device-sdk-js-v2#40 but I think this is the right place for it

@fiLLLip
Copy link
Author

fiLLLip commented May 8, 2020

Changed my code to subscribe without callback, and then add a .on('message') event handler instead. This gives me the topic :)

            await connection.subscribe('$aws/things/+/shadow/update/accepted', mqtt.QoS.AtLeastOnce);
            await connection.on('message', async (topic, payload) => {
                if (payload === undefined) {
                    reject("Undefined payload");
                }
                const payload_str = decoder.decode(payload);
                const message = JSON.parse(payload_str);
                const id = topic.split('/')[2];
                await pubsub.publish(id.split('_')[0], {event: {id: id, data: message.state.reported}});
                resolve(true);
            });

@fiLLLip fiLLLip closed this as completed May 8, 2020
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

1 participant