qvest-digital / go-nuki Goto Github PK
View Code? Open in Web Editor NEWA go library to control nuki devices - such as Smart Locks - via bluetooth.
License: MIT License
A go library to control nuki devices - such as Smart Locks - via bluetooth.
License: MIT License
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?
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.