Introvertuous / react-native-mqtt

Mqtt client for react native.
MIT License
156 stars 31 forks source link

onMessageArrived not triggered #24

Closed johnnyBira closed 5 years ago

johnnyBira commented 5 years ago

I'm having problem receiving the messages which are published to my broker.

I'm connecting to a MQTT service locally over webSockets, running on node using Mosca.

When publishing messages to the service through the test site (http://www.hivemq.com/demos/websocket-client/) I can see all the messages arriving to the broker just fine.

As far as I can tell I'm also able to connect to the service in my React Native app using recat_native_mqtt, i.e. the onConnect event is trigger when I start the app.

Everything up to this point seams to be working as expected, my problem is that the onMessageArrival handler isn't triggered, even though the messages are clearly reaching the MQTT broker. Just i case I should also mention that I've set the useSSL-flag to false since my localhost is not on SSL.

johnnyBira commented 5 years ago

Okey, so the missing piece in my case was that I hadn't explicitly subscribed to a given topic, /World in the case of the example. As it stands atm, the example in the README dosen't work without it.

This pice was missing in the README, and it isn't super clear what module is employed under the hood. After a bit of digging I found that it was the module called paho.mqtt.js that was being referenced, and from that I could figure out what was missing. The link to the original Eclipse implantation threw me off for a second.

I'll submit a PR with a suggestion to update the README later.

johnnyBira commented 5 years ago

Complemented README with missing information.