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

Update outdated browserified version #16

Open
hunsalz opened this issue Sep 9, 2016 · 4 comments
Open

Update outdated browserified version #16

hunsalz opened this issue Sep 9, 2016 · 4 comments

Comments

@hunsalz
Copy link

hunsalz commented Sep 9, 2016

Current browserified version is outdated and leads to a continuous flapping with wss:// connections.

I tried to use <mqtt-elements> with cloudmqtt.com and couldn't establish a stable connection. Alternative I tried mqtt-client and could perfectly connect my setup. Unfortunately the code base seems not maintained anymore and mqttws31.js appears to me a minus to mqttjs. In addition I didn't find any other MQTT Polymer element that's up to date or ready to use.

That's why I retried <mqtt-elements> with various approaches again. With the mqtt CLI I noticed that I need --insecure as argument to subscribe to my topic. But rejectUnauthorized = false seems not to solve my problem programmatically, so that I finally started to implement the basics on my own. After browserify the current mqttjs trunk version and writing the basic JS myself everything worked perfectly in a few minutes.

I tried to use my browserified version with <mqtt-elements>, but the current version contains breaking changes, so that I was unable to use it out of the box.

Any plans to upgrade the <mqtt-elements> to the current MQTT.js version?

@sandro-k
Copy link
Contributor

I can install <mqtt-elements> via bower and use it without building anything. I will try with cloudmqtt.com and update mqtt.js

@sandro-k
Copy link
Contributor

@hunsalz I created an account at cloudmqtt.com and was able to connect, subscribe and publish. The following code can be used to publish to the topic foo/bar with the payload of Hello world!. The connection was flapping when I did not add the with-credentials flag, as mqtt-elements connects right away without waiting for a username or password to be set on the mqtt-connection element. Note that the url, username and password on the <mqtt-connection> have to be set to your credentials available on the Instance info page.

mkdir mqtt-elements-test
cd mqtt-elements-test
bower install --save mqtt-elements
touch index.html

index.html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>mqtt-elements</title>
  <script src="bower_components/webcomponentsjs/webcomponents.js"></script>
  <link rel="import" href="bower_components/mqtt-elements/mqtt-elements.html">
</head>
<body>
<template is="dom-bind">

  <div>[[lastMessage.parsedPayload]]</div>

  <mqtt-connection url="wss://m20.cloudmqtt.com:34207" username="CHANGE USERNAME" password="CHANGE PASSWORD" with-credentials auto>

    <mqtt-publish
        auto
        retained
        qos="1"
        topic="foo/bar"
        payload="Hello world!"></mqtt-publish>

    <mqtt-subscription
        topic="foo/bar"
        number-of-messages="Infinity"
        last-message="{{lastMessage}}"
        messages="{{messages}}"
        subscribed="{{subscribed}}"></mqtt-subscription>


  </mqtt-connection>

</template>
</body>
</html>

@hunsalz
Copy link
Author

hunsalz commented Sep 14, 2016

Thx @sandro-k for your quick response - I retried with you're code snippet and surprise everything worked like a charm.

I'm not sure what I missed out. I was sure that I tried with-credentials as one of various unsuccessful attempts. Therefore sorry, that I supposed a bug in the current version.

Nevertheless it might be a good idea to upgrade polymer dependency from 1.2.4 to latest 1.6.2. My current version is working fine with this version.

... and as mentioned earlier the dependency towards the browserfied MQTT.js version seems outdated to me. At least I wasn't unable to upgrade quickly myself without fixing all breaking changes.

Once again thank you for your advising help.

@sandro-k
Copy link
Contributor

I will update to polymer 1.6 and MQTT.js 1.X in the next weeks. I don't see that many breaking changes . The Update to MQTT.js 2.0 which is about to be released might need some work. if you use mqtt-elements in your project feel free to give as much feedback as possible.

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

2 participants