Giter Site home page Giter Site logo

servercharlie / iot-gateway-mqtt-http Goto Github PK

View Code? Open in Web Editor NEW

This project forked from azure-samples/iot-gateway-mqtt-http

0.0 0.0 0.0 11 KB

MQTT and HTTP endpoints for Azure IoT Gateway in node.js using Mosca

License: Other

JavaScript 100.00%

iot-gateway-mqtt-http's Introduction

services platforms author
iothub
node
marcschier

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments

Sample MQTT and HTTP Gateway modules

This project provides two Gateway modules that expose IoTHub-style MQTT and HTTPS endpoints for telemetry upload and in the case of MQTT module also C2D messaging:

Mqtt broker module

The Mqtt broker module utilizes Mosca, version 2.0.2.
Mosca supports TLS with mutual authentication, however only Server authentication is provided as part of the sample. Client certificate validation can be added to improve security by changing the authenticate prototype function.

The Mqtt module can be configured to listen on a specified interface using the LocalAddress property. Set this property in the module args of the gateway's config.json to the IP address of the interface the server should listen on. By default the server listens on all interfaces (= null).

HTTP/s server module

The HTTP/s webserver module uses the built in node.js HTTPS server functionality. It currently only supports POST messages, and no GET polling.

The server can be configured to listen on a specified interface using the LocalAddress property. Like in the case of Mqtt, set this property in the module's args section of the gateway's config.json. By default the server listens on all interfaces (= null).

Building and running the Gateway

Azure IoT Gateway SDK compatibility

The current version of the modules are targeted at the Azure IoT Gateway SDK at commit '287beed07490d98a24a4e9ddd33ec7127fc3acbf'.

Use the following command line to clone the compatible version Azure IoT Gateway SDK, then follow the build instructions included:

git clone --recursive https://github.com/Azure/azure-iot-gateway-sdk.git
git checkout 287beed07490d98a24a4e9ddd33ec7127fc3acbf

Building

Ensure you have the following tools installed on your development machine:

  • npm
  • Openssl or equivalent tool (to generate certificates)

Build the Gateway using the Azure IoT Gateway SDK build script. Enable the node.js binding by passing the --enable-node-binding command line option. then run

npm install iot-gateway-mqtt-http --save`

Generating TLS certs for testing

Generate a self signed certificate and private key to identify the GW and enable TLS/SSL. This can be done with openssl, e.g. open a command shell in this folder and run: openssl genrsa -out tls-key.pem 2048 openssl req -new -sha256 -key tls-key.pem -out tls-csr.pem openssl x509 -req -in tls-csr.pem -signkey tls-key.pem -out tls-cert.pem Hint: Sometimes it is necessary to set the OPENSSL_CONF ENV variable to the location of the openssl.cnf file.

> IMPORTANT: Ensure that you correctly enter the name of your gw host machine as the server when creating the certificate.  Clients
will validate the server name in the GW provided certificate against the host name they connect to.  If names do not match, the 
connection is sometimes refused before your code can validate the certificate.

Configure the gateway

Add the following to the modules section of your gateway JSON configuration file:

{
    "modules": [
        {
        "name": "mqtt",
            "loader": {
                "name": "node",
                "entrypoint": {
                    "main.path": ".\node_modules\iot-gateway-mqtt-http\mqtt.js"
                }
            },
            "args": {
                "LocalAddress": null
            }
        },
        {
        "name": "https",
            "loader": {
                "name": "node",
                "entrypoint": {
                    "main.path": ".\node_modules\iot-gateway-mqtt-http\https.js"
                }
            },
            "args": {
                "LocalAddress": null
            }
        },
        ...

Then in the links section, patch the module into the message flow:

    ],
    "links": [
        {"source": "iothub", "sink": "mqtt"},
        {"source": "mqtt", "sink": "iothub"},
        {"source": "https", "sink": "iothub"},
        ...
    ]
}

License

This project is licensed under the MIT License.

iot-gateway-mqtt-http's People

Contributors

marcschier avatar

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.