Giter Site home page Giter Site logo

mqtt-http-bridge's Introduction

mqtt-http-bridge.rb

This simple web application provides a bridge between HTTP and MQTT using a RESTish interface. It is possible to GET, POST, PUT and DELETE retained messages on a remote MQTT server.

Getting started

Install bundler:

sudo gem install bundler

Install the other gem dependencies:

bundle install

Run the local web server:

bundle exec rackup -p 1234

You can then open the bridge in your browser:

http://localhost:1234/

To connect to your own MQTT server:

Edit the first few lines of `mqtt-http-bridge.rb` to match your server.

If you want to use a different port than the default 1883, add `:remote_port => [PORT NUMBER],` under the line with the IP address. Do not put the port number in quotation marks.

Examples using curl

To get a retained value for a topic:

curl http://localhost:1234/test

To publish to a topic (retained):

curl -X PUT --data-binary "Hello World" http://localhost:1234/test

To publish to a topic (non-retained):

curl -X POST --data-binary "Hello World" http://localhost:1234/test

To delete the retained value for a topic:

curl -X DELETE http://localhost:1234/test

License

The ruby mqtt-http-bridge is licensed under the terms of the MIT license. See the file LICENSE for details.

Contact

mqtt-http-bridge's People

Contributors

njh avatar varkokonyi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mqtt-http-bridge's Issues

Externalise config

It's not very friendly to have to edit the broker name in the main Ruby code...

Occasional crash due to protocol error?

Suspect this is either network or ruby-mqtt related

$  rackup
>> Thin web server (v1.5.0 codename Knife)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:9292, CTRL+C to stop
127.0.0.1 - - [20/Jun/2013 16:46:33] "GET / HTTP/1.1" 200 12547 1.3553
127.0.0.1 - - [20/Jun/2013 16:46:35] "GET /favicon.ico HTTP/1.1" 404 25 1.2055

... after a short period

/Users/andyp/Development/github/mqtt-http-bridge/.bundle/gems/ruby/1.9.1/gems/mqtt-0.0.9/lib/mqtt/packet.rb:238:in `read_byte': MQTT::ProtocolException (MQTT::ProtocolException)
    from /Users/andyp/Development/github/mqtt-http-bridge/.bundle/gems/ruby/1.9.1/gems/mqtt-0.0.9/lib/mqtt/packet.rb:21:in `read'
    from /Users/andyp/Development/github/mqtt-http-bridge/.bundle/gems/ruby/1.9.1/gems/mqtt-0.0.9/lib/mqtt/client.rb:280:in `receive_packet'
    from /Users/andyp/Development/github/mqtt-http-bridge/.bundle/gems/ruby/1.9.1/gems/mqtt-0.0.9/lib/mqtt/client.rb:151:in `block (2 levels) in connect'
    from /Users/andyp/Development/github/mqtt-http-bridge/.bundle/gems/ruby/1.9.1/gems/mqtt-0.0.9/lib/mqtt/client.rb:151:in `loop'
    from /Users/andyp/Development/github/mqtt-http-bridge/.bundle/gems/ruby/1.9.1/gems/mqtt-0.0.9/lib/mqtt/client.rb:151:in `block in connect'

Seems to be non-deterministic and random. Seen both locally running on OS X, and also on cloud deployed bridge.

Responsive web design

Use e.g. Bootstrap or something to make the pages scale more nicely across devices

(pull request coming)

Only works on localhost

Hey. I'm trying to get this to work from anywhere, but it only works from localhost, otherwise, I get a "connection refused". What do I need to change?

Installing Error

When i tried to run ruby install i am getting the following error:

/usr/lib/ruby/1.9.1/rubygems/dependency.rb:247:in to_specs': Could not find bundler (>= 0) amongst [] (Gem::LoadError) from /usr/lib/ruby/1.9.1/rubygems/dependency.rb:256:into_spec'
from /usr/lib/ruby/1.9.1/rubygems.rb:1231:in gem' from /usr/local/bin/bundle:18:in

'

What is the problem?

not sure how to use this bridge

I installed this mqtt-http-bridge in accordance to the "Getting Started" write up and then continued to try out the examples using cURL. What I do not understand is that using curl, I'm directly publishing HTTP requests and when I open the localhost window, I see the general topics.

When I PUT posts to localhost:80/test, it shows up on the bundle exec rackup -p 80 command window as "PUT /test TTP/1.1" 200 1.251, which is just fine. But nothing changes in the /test file of my localhost:80.

My main question is how is this bridging from HTTP to MQTT and vice versa? How do I publish/subscribe from my mosquitto broker and use this bridge for HTTP requests?
I'm a newbie to the internet protocol area, and while it is fascinating, I find myself very confused. Please help me out!

Fails to handle broker outage (or wrong url)

If the configured MQTT broker cannot be reached (either it has been incorrectly specified host/port in the code, or it is down), then the web page returned by Ruby will print an inelegant error page.

Errno::ECONNREFUSED at /
Connection refused - connect(2)
file: client.rb location: initialize line: 127

This could be handled more gracefully.

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.