npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

miio-api

v0.4.1

Published

Xiami miIO protocol implementaion

Downloads

43

Readme

miio-api

The main goal of the project is to implement basic protocol functions without any assumptions about specific device, because there are dozens of Xiaomi devices and support them all is very hard task.

Install

npm install miio-api

Usage

typescript

import * as miio from "miio-api";

type Power = "on" | "off";
type Props = "power" | "humidity";

(async (): Promise<void> => {
  let device;

  try {
    device = await miio.device({
      address: "192.168.1.31",
      token: "93db466137accd4c9c6204315c542f9c",
    });

    const info = await device.call<Props[], [Power, number]>("get_prop", [
      "power",
      "humidity",
    ]);
    console.log(info);
  } catch (err) {
    console.error("ERROR: " + err);
  } finally {
    await device?.destroy();
  }
})();

javascript

const miio = require("miio-api");

(async () => {
  let device;

  try {
    device = await miio.device({
      address: "192.168.86.31",
      token: "93db466137accd4c9c6204315c542f9c",
    });

    const info = await device.call("get_prop", ["power"]);
    console.log(info);
  } catch (err) {
    console.error("ERROR: " + err);
  } finally {
    if (device) {
      device.destroy();
    }
  }
})();

Debug

$ DEBUG=miio-api node get-power.js

  miio-api:device:p96skmm1 -> { id: 3779375844, method: 'get_prop', params: [ 'power' ] } +0ms
  miio-api:device:p96skmm1 ->
  miio-api:device:p96skmm1 0000    21 31 00 60 00 00 00 00 04 7d 43 e4 00 68 42 7b
  miio-api:device:p96skmm1 0010    30 66 14 1d dc bf d0 30 7d 7e cc 4b 3a f6 15 0c
  miio-api:device:p96skmm1 0020    7a 0c 82 eb c8 be 3a 35 6b 88 ac cc af fa 03 13
  miio-api:device:p96skmm1 0030    41 60 eb 1e 86 a9 84 1e a9 af c9 7e 89 9d 52 1e
  miio-api:device:p96skmm1 0040    fd 91 18 4a 7c 34 fc 0f 82 07 0d 56 d4 94 ff 48
  miio-api:device:p96skmm1 0050    e4 28 55 0e b4 fd 72 5e d8 c1 29 0c 73 2f 60 44  +5ms
  miio-api:device:p96skmm1 <-
  miio-api:device:p96skmm1 0000    21 31 00 50 00 00 00 00 04 7d 43 e4 00 68 42 7b
  miio-api:device:p96skmm1 0010    13 24 2f c8 34 e1 9d 71 0e b1 b4 d5 06 40 3a 95
  miio-api:device:p96skmm1 0020    b5 9b 12 90 fd 6a e0 41 6b aa b7 e4 7a c8 0a 23
  miio-api:device:p96skmm1 0030    99 71 af 10 2c 9e 1d 63 ef 42 37 c5 e7 36 6b b6
  miio-api:device:p96skmm1 0040    d1 e1 13 10 19 ec 1f 29 9c 2d d6 a7 64 2d 8a 4b  +6ms
  miio-api:device:p96skmm1 <- { result: [ 'off' ], id: 3779375844 } +0ms