Skip to content
forked from mcollina/ponte

The M2M/IoT Bridge for REST developers

Notifications You must be signed in to change notification settings

liucy2007975/ponte

 
 

Repository files navigation

Ponte

Build Status

Ponte is a multi-transport Internet of Things / Machine to Machine broker. As the current state it supports MQTT and REST APIs.

Ponte Architecture

Ponte is under active development, but it should work :). If you plan to use Ponte in production let us know, we'll be more than happy to help you getting started and solve any issue you'll find out.

Installation

Ponte is a node.js application, so it needs node.js to run.

$ npm install ponte bunyan -g
$ ponte -v | bunyan

Then you can connect to it with your preferred MQTT, CoAP or HTTP client.

Command Line Options

$ ./bin/ponte --help

  Usage: ponte [options]

  Options:

    -h, --help           output usage information
    -V, --version        output the version number
    -m, --mqtt-port <n>  the mqtt port to listen to
    -p, --http-port <n>  the http port to listen to
    -a, --coap-port <n>  the coap port to listen to
    -d, --db <path>      the path were to store the database
    -c, --config <c>     the config file to use (override every other
     option)
    -v, --verbose        set the bunyan log to INFO
    --very-verbose       set the bunyan log to DEBUG

Usage Example

Start ponte:

$ ponte -v | bunyan

Publishing from HTTP to MQTT

Publish from HTTP:

$ curl -X PUT -d 'world' http://localhost:3000/resources/hello

The messages from HTTP are retained, which means that are sent to every new subscriber.

Subscribe using mosquitto_sub (mosquitto):

$ mosquitto_sub -t "hello" -v
hello world

Publishing from MQTT to HTTP

In order to publish a message that can be read from HTTP, a MQTT client needs to set the retain flag. This is how it is done using mosquitto_pub:

$ mosquitto_pub -t hello-from-mqtt -m "world" -r

Reading the published value is an HTTP GET away:

$ curl http://localhost:3000/resources/hello-from-mqtt
world

Publishing from CoAP to MQTT

You can send CoAP messages from the command line using coap-cli In the following example we do a CoAP PUT to a resource:

$ echo -n 'world' | coap put coap://localhost/r/hello

Subscribe using mosquitto_sub (mosquitto):

$ mosquitto_sub -t "hello" -v
hello world

Publishing MQTT to CoAP

In order to publish a message that can be read from CoAP, a MQTT client needs to set the retain flag. This is how it is done using mosquitto_pub:

$ mosquitto_pub -t hello-from-mqtt -m "world" -r

In order to receive the live updates with CoAP, we need to use the observe switch:

$ coap -o coap://localhost/r/hello-from-mqtt

Embedding

Ponte can be run in embbedded mode, by listening to specific events:

var ponte = require("ponte");
var opts = {
  logger: {
    level: 'info'
  },
  http: {
    port: 3000 // tcp
  },
  mqtt: {
    port: 3001 // tcp
  },
  coap: {
    port: 3000 // udp
  },
  persistence: {
    type: 'level',
    path: './db'
  }
};
var server = ponte(opts);

server.on("updated", function(resource, buffer) {
  console.log("Resource Updated", resource, buffer);
});

// Stop the server after 1 minute
setTimeout(function() {
  server.close(function() {
    console.log("server stopped");
  });
}, 60 * 1000);

Configuration

TO BE DONE!

Pub/Sub Brokers

Ponte is based on Ascoltatori, so it supports the same backends:

  • RabbitMQ and all implementations of the AMQP protocol.
  • Redis, the fabulous key/value store by @antirez.
  • Mosquitto and all implementations of the MQTT protocol.
  • MongoDB, the documental NoSQL that is revolutioning how web apps are built.
  • ZeroMQ without a central broker, so Ascoltatori can also be used in a P2P fashion.

Persistence

Ponte requires a persistent storage for HTTP syndication and MQTT support. At the current state, it uses Mosca persistence layer. Thus, it offers several persitence options:

All of them can be configured from the configuration file, under the persistence key. The only exception is LevelUp, which can be specified by using the --db option from the command line.

To do

These are the new features you should expect in the coming months:

  • Better bootstrap sequence.
  • Allow and document embedding inside other Node apps.
  • Add Web Hooks support.
  • Document configuration options.
  • Add WebSocket and Server-Sent Events support.
  • Add a Web App for reading and writing.
  • Add CoAP support.
  • Standalone persistence layer.

Any help is very welcome, so feel free to submit a pull-request.

Eclipse, QEST and Ponte

Ponte is a proposal at Eclipse, and this is a pure-JS rewrite of QEST in Javascript and on top of Mosca. You can find the Eclipse Project Proposal here: http://eclipse.org/proposals/technology.ponte/

Contributing to Ponte

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
  • Fork the project
  • Start a feature/bugfix branch
  • Commit and push until you are happy with your contribution
  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
  • Please try not to mess with the Makefile and package.json. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

LICENSE - "New BSD License"

Copyright (c) 2013, Matteo Collina http://matteocollina.com All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

About

The M2M/IoT Bridge for REST developers

Resources

Stars

Watchers

Forks

Packages

No packages published