Giter Club home page Giter Club logo

go-nuki's People

Contributors

memoos avatar rovo89 avatar sschum avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

sschum rovo89

go-nuki's Issues

PIN must be specified in hex?!?

ReadLogEntryStream() and other functions require the device PIN. I would have expected that a PIN like 9999 would be specified as integer 9999 or as string "9999". But the current implementation of NewPin() expects a hex string like "270F" instead. Is this intended?

How to implement callbacks?

I'm trying to implement a MQTT service based on this library so I can monitor and control my smart lock via ioBroker.

One key requirement for this is to get informed by the lock that the state has changed, so it would be worth to call ReadStates(). This can be checked via the advertisements (explanation). Based on this example, I was able to implement the following

func main() {
	...
	chkErr(ble.Scan(ctx, *dup, advHandler, advFilter))
}

var PREFIX, _ = hex.DecodeString("4C000215A92EE200550111E4916C0800200C9A66")
func advFilter(a ble.Advertisement) bool {
	return a.Connectable() && bytes.HasPrefix(a.ManufacturerData(), PREFIX)
}

func advHandler(a ble.Advertisement) {
	md := a.ManufacturerData()
	id := hex.EncodeToString(md[20:24])
	txPower := int8(md[len(md)-1])
	updated := txPower & 1 == 1
	fmt.Printf("%s [%s], id: %s, txPower: %d, updated %t\n", a.Addr(), a.LocalName(), id, txPower, updated)
}

Now the big question is: What could be a good way to add a new library function to subscribe to "state of device x has changed", i,e. updated has changed from false to true? It would involve setting up the scan and running it in the background, providing a callback function, the ability to cancel the scan (which might be necessary to connect, not sure?!?), and probably other things.

Any ideas where to start, which patterns or libraries to use? Keep in mind that waiting for an update shouldn't block the whole process, because at any time there could be an MQTT command to unlock the door.

By the way, this library currently assumes that you already know the device's MAC address. Maybe some functions to discover available devices (using code similar to the above) would be a nice addition.

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.