Giter VIP home page Giter VIP logo

Comments (16)

njh avatar njh commented on July 17, 2024
  • Which MQTT server are you using?
  • What error message do you see in ruby?
  • Do you see any error message in the MQTT server's log?

from ruby-mqtt.

beraybentesen avatar beraybentesen commented on July 17, 2024

Broker: EMQX
Error: if I add tcp:// -> getaddrinfo: nodename nor servname provided, or not known (SocketError)
without tcp:// -> Connection refused: bad user name or password (MQTT::ProtocolException)

However, authentication information is correct. Works well with Go, Nodejs, C etc.

Broker log: I haven't checked yet, but I will tomorrow.

from ruby-mqtt.

njh avatar njh commented on July 17, 2024

tcp:// URIs are not supported. But MQTT URIs are:
https://github.com/mqtt/mqtt.github.io/wiki/URI-Scheme

from ruby-mqtt.

beraybentesen avatar beraybentesen commented on July 17, 2024

@njh Thanks for quick response. Is it possible to add support easily or is it another kind of process ?

from ruby-mqtt.

njh avatar njh commented on July 17, 2024

Sorry, I don't understand the question?

Is this not working for you?

MQTT::Client.connect(
  :host => '192.168.1.100',
  :username => 'abc',
  :password => 'abc',
  :ssl => false,
  :port => 1883
)

from ruby-mqtt.

beraybentesen avatar beraybentesen commented on July 17, 2024

Unfortunately, I receive : Connection refused: bad user name or password (MQTT::ProtocolException)

We were able to connect only if we provide tcp:// at the beginning for any mqtt client library.

from ruby-mqtt.

beraybentesen avatar beraybentesen commented on July 17, 2024

Also verified that broker requires that the client library should parse tcp:// endpoint.

from ruby-mqtt.

njh avatar njh commented on July 17, 2024

Sorry, I am still very confused about what you are trying to do and what isn't working.
I am going to install EMQX and see what is required to get it working.

Also verified that broker requires that the client library should parse tcp:// endpoint.

I don't think that can be true. tcp:// is not part of any MQTT specification.

from ruby-mqtt.

beraybentesen avatar beraybentesen commented on July 17, 2024

The Ruby client should parse the tcp://.. schema to a IP addr and Port.

Their response was that.

I am trying to send data to the broker. mqtt://ipaddress:port or ipaddress:port not working. Other libraries support tcp://ipaddress:port URI schema.

Thank you for support,

from ruby-mqtt.

njh avatar njh commented on July 17, 2024

Do you have a list of libraries you have tried that use the tcp: URI scheme?
It would be good to try and get everyone to move over to using the mqtt: URI scheme.

from ruby-mqtt.

njh avatar njh commented on July 17, 2024

I have given EMQX a go on my local machine. I have outlined all the steps I have gone through to get to a working test.

Out of the box emqx seems to allow anonymous connections and ignores the username and password if provided.

To turn on authentication, I edited etc/emqx.conf:

allow_anonymous = false

I then setup a username and password in etc/plugins/emqx_auth_username.conf:

auth.user.1.username = abc
auth.user.1.password = abc

And changed:

auth.user.password_hash = plain

Then I started emqx on the console:

./bin/emqx console

And in a separate window enabled the username authentication plugin:

./bin/emqx_ctl plugins load emqx_auth_username

I then first tested publishing using the mosquitto command line tools.

Example subscribe using CLI:

mosquitto_sub -t '#' -v -d -u abc -P abc

Then in a separate window, publish using CLI:

mosquitto_pub -h '127.0.0.1' -t 'test' -m 'hello' -u abc -P abc

Verified that authentication is working with no username / password:

$ mosquitto_sub -t '#' -v -d
Client mosq/cnoLLBEkE9hdlnMgKC sending CONNECT
Client mosq/cnoLLBEkE9hdlnMgKC received CONNACK (5)
Connection Refused: not authorised.
Client mosq/cnoLLBEkE9hdlnMgKC sending DISCONNECT

Example ruby publish:

MQTT::Client.connect(
  :host => '127.0.0.1',
  :username => 'abc',
  :password => 'abc',
) do |client|
  client.publish('test', "The time is: #{Time.now}")
end

Example ruby subscribe:

MQTT::Client.connect(
  :host => '127.0.0.1',
  :username => 'abc',
  :password => 'abc',
) do |client|
  client.get('#') do |topic,message|
    puts "#{topic}: #{message}"
  end
end

So I am unable to reproduce your authentication problems with EMQX + Ruby MQTT.

from ruby-mqtt.

beraybentesen avatar beraybentesen commented on July 17, 2024

Libraries we are currently using are :

For the EQMX Authentication, we use HTTP Authentication plugin with our internal APIs. (https://github.com/emqx/emqx-auth-http). I can send an email ip / username / password if that would be helpful to produce the scenario.

from ruby-mqtt.

beraybentesen avatar beraybentesen commented on July 17, 2024

Update: Arduino mqtt library managed to connect with just IP address. However I had to use setId method.

Update 2: It seems library auto generate id :

clientid=MjkyMzc4NTQ5MDg5NTQ2Mjg4ODIxNDY4NjE0NjQ5NDQ2NDA
&username=84520378-1a48-4462-b216-ee38b1543018
&password=wpJSpGTYnvphoKwIgfAa

I manually printed from our endpoints to understand.

:client_id => "id", fixed the connection problem.

from ruby-mqtt.

beraybentesen avatar beraybentesen commented on July 17, 2024

@njh Happy to confirm that finally managed to get it working. After settings all default settings, connection worked pretty well. Thank you for spending time on emqx and support.

MQTT::Client.connect(
:host => "ip",
:port => 1883,
:client_id => "abc",
:username => "abc",
:password => "abc",
:keep_alive => 15,
:clean_session => false,
:ack_timeout => 15,
:will_topic =>"abc",
:will_payload => '{"one":1,"two":2}',
:will_qos => 0,
:will_retain => false,
:ssl => false

from ruby-mqtt.

njh avatar njh commented on July 17, 2024

I am glad you got it working.

You shouldn't need to pass in all the default options - maybe try deleting them one by one and work out which ones are important for you?

from ruby-mqtt.

beraybentesen avatar beraybentesen commented on July 17, 2024

It turns out only ack timeout was necessary. But it was a good experiment to play with other options.

from ruby-mqtt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.