miio 0.3.0

  • Readme
  • Changelog
  • Example
  • Installing
  • new49

MIIO #

Dart implementation for MIIO LAN protocol.

The protocol an encrypted, binary protocol based on UDP (port 54321), which is used to configure & control smart home devices made by Xiaomi Ecosystem.

CLI #

The package contains a simple CLI program that built on top of miio.

Example #

miio discover --ip 192.168.1.255

miio send --ip 192.168.1.100 --token ffffffffffffffffffffffffffffffff --payload '{\"id\": 1, \"method\": \"miIO.info\", \"params\": []}'

Protocol #

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Magic Number = 0x2131         | Packet Length (incl. header)  |
|-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-|
| Unknown                                                       |
|-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-|
| Device ID ("did")                                             |
|-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-|
| Stamp                                                         |
|-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-|
| MD5 Checksum                                                  |
| ... or Device Token in response to the "Hello" packet         |
|-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-|
| Optional variable-sized payload (encrypted)                   |
|...............................................................|


Packet Length: 16 bits unsigned int
    Length in bytes of the whole packet, including header(0x20 bytes).

Unknown: 32 bits
    This value is always 0.
    0xFFFFFFFF in "Hello" packet.

Device ID: 32 bits
    Unique number. Possibly derived from the MAC address.
    0xFFFFFFFF in "Hello" packet.

Stamp: 32 bit unsigned int
    Continously increasing counter.

MD5 Checksum:
    Calculated for the whole packet including the MD5 field itself,
    which must be initialized with token.

    In "Hello" packet,
    this field contains the 128-bit 0xFF.

    In the response to the first "Hello" packet,
    this field contains the 128-bit device token.

Optional variable-sized payload:
    Payload encrypted with AES-128-CBC (PKCS#7 padding).

        Key = MD5(Token)
        IV  = MD5(MD5(Key) + Token)

[0.3.0] - 25/Jun./2020 #

  • Add send & hello to Miio.
  • Add send to CLI.

[0.2.0] - 24/Jun./2020 #

  • Add example package.
  • Fix Dart analyzer error.

[0.1.0] - 23/Jun./2020 #

  • MIIO packet.
  • Discovery.
  • Basic CLI.

example/lib/main.dart

import 'package:miio/miio.dart';

void main(List<String> args) {
  // Discover MIIO devices and print.
  Miio.discover('192.168.1.255', print);
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  miio: ^0.3.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:miio/miio.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
96
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
49
Learn more about scoring.

We analyzed this package on Jul 6, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13

Analysis suggestions

Package not compatible with runtime flutter-web on web

Because of the import of dart:io via the import chain package:miio/miio.dartdart:io

Package not compatible with runtime web

Because of the import of dart:io via the import chain package:miio/miio.dartdart:io

Health suggestions

Fix lib/packet.dart. (-2.96 points)

Analysis of lib/packet.dart reported 6 hints, including:

line 136 col 49: DO use curly braces for all flow control structures.

line 140 col 51: DO use curly braces for all flow control structures.

line 144 col 49: DO use curly braces for all flow control structures.

line 154 col 7: DO use curly braces for all flow control structures.

line 154 col 38: DO use curly braces for all flow control structures.

Fix lib/miio.dart. (-0.50 points)

Analysis of lib/miio.dart reported 1 hint:

line 75 col 9: DO use curly braces for all flow control structures.

Fix lib/utils.dart. (-0.50 points)

Analysis of lib/utils.dart reported 1 hint:

line 28 col 7: DO use curly braces for all flow control structures.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
args ^1.6.0 1.6.0
crypto ^2.1.5 2.1.5
encrypt ^4.0.2 4.0.2
tuple ^1.0.3 1.0.3
Transitive dependencies
asn1lib 0.6.5
charcode 1.1.3
clock 1.0.1
collection 1.14.13
convert 2.1.1
matcher 0.12.8
meta 1.2.1
path 1.7.0
pointycastle 1.0.2
quiver 2.1.3
stack_trace 1.9.5
typed_data 1.2.0