Giter Site home page Giter Site logo

iothub-webclient's Introduction

IoTHub WebClient

Web application to connect to Azure IoT Hub from the browser (no server code required), written completely in JavaScript ES6

JavaScript Style Guide

MQTT in the browser

This app uses the Eclipse Paho JavaScript Client to communicate to Azure IoT Hub as described in Communicate with your IoT hub using the MQTT protocol

Sample code

requires paho to be added to the page using <script>

import { AzIoTHubClient, ackPayload } from './AzIoTHubClient.js'

const client = new AzIoTHubClient(host, deviceId, deviceKey, modelId)

client.setDirectMehodCallback((method, payload, rid) => {
  const response = JSON.stringify({ customResponse: 'cmdResponsePayload' })
  client.commandResponse(method, response, rid, 200)
})

client.setDesiredPropertyCallback((desired) => {
  const dco = JSON.parse(desired)
  const payload = ackPayload(dco, status, dco.$version)
  const updateResult = await client.updateTwin(JSON.stringify(payload))
})

await client.connect()
const twin = await client.getTwin()
await client.updateTwin('{}')

Authentication

Azure IoT Hub uses an HMAC signature to produce a SaS token used to authenticate the MQTT client. This client uses the HMAC primitives avaiable on modern browsers.

Features

  • Connect using the PnP Convention (announce model-id) with SasKeys
  • Read Device Twin reported and desired properties (D2C)
  • Update reported properties (D2C)
  • Receive desired properties updates (C2D)
  • ACK desired properties updates following the PnP convention (D2C)
  • Receive command request (C2D)
  • Reply commands with custom responses (D2C)
  • .d.ts typings

Roadmap

  • DPS client over MQTT
  • DPS with master keys
  • Suggest payloads from PnP models
  • Create ES6 modules for paho js client

iothub-webclient's People

Contributors

dependabot[bot] avatar kartben avatar msftgits avatar rido-min avatar ridomin avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

iothub-webclient's Issues

License(s)?

Hi! I noticed this repo doesn't have a LICENSE file.
Under which license(s) is this offered (if any)?

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.