Giter VIP home page Giter VIP logo

miio.go's Introduction

miio.go

Go implementation for MiIO protocol. inpsired by miio.dart

Install

go get github.com/icepie/miio.go

Usage

for get device token and device id, you can try micloud

device := miio.New("192.168.1.12").
	SetToken("ffffffffffffffffffffffffffffffff").
	SetDid("did") // some device must use the true device id

// get device info
info, err := device.Info()
if err != nil {
	panic(err)
}

fmt.Printf("%s\n", info)

// for get siid and piid, see https://home.miot-spec.com/
// get properties
getProps, err := device.GetProps(miio.PropParam{
	Siid: 5,
	Piid: 1,
}, miio.PropParam{
	Siid: 5,
	Piid: 2,
})

if err != nil {
	panic(err)
}

fmt.Printf("%s\n", getProps)

// set properties
setPropsParams := []miio.PropParam{
	{
		Siid:  5,
		Piid:  1,
		Value: true,
	},
	{
		Siid:  5,
		Piid:  2,
		Value: 0,
	},
}

setProps, err := device.SetProps(setPropsParams...)
if err != nil {
	panic(err)
}

// Do action
action, err := device.DoAction(miio.ActionParam{
	Siid: 2,
	Aiid: 1,
	// In:   []any{0, "test"}, if need to send extra data
})

if err != nil {
	panic(err)
}

fmt.Printf("%s\n", action)

// some old devices can not use the standard way to control...
// https://github.com/icepie/miio.go/issues/1
// you can try to send raw data, like:
getProps, err := device.Send("get_prop", []interface{}{"power", "mode", "fan_level", "ver_swing"})
setProps, err := device.Send("set_mode", []interface{}{"cool"})


// or you can try: https://github.com/icepie/micloud

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.
    Number of seconds since device startup.

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(Key + Token)

Link

miio.go's People

Contributors

icepie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

ayasechan tzxhy

miio.go's Issues

Method not found.

 // JSON data can be returned normally.
client.Info

// Result {"error":{"code":-32601,"message":"Method not found."},"id":2}
client.GetProperties
client.SetProperties
client.Action

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.