Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silly question about sensor value update #49

Open
UniversalMailer opened this issue Aug 2, 2015 · 2 comments
Open

Silly question about sensor value update #49

UniversalMailer opened this issue Aug 2, 2015 · 2 comments

Comments

@UniversalMailer
Copy link

Hi,
I'm trying to create a simple temperature sensor with your Homekit HAP but I'm not sure I fully understood the architecture: looking at Accessory.cpp it's pretty straightforward that the callback 'valueChangeFunctionCall' is invoked when the controller sets a new value for the characteristics but it's not clear (at least to me) what is the sibling 'read' callback.

The question is: is there a callback that is called whenever the controller asks for the current state? In the temperature example, I would like to return the current temperature (based on a call to an http server or whatever) but I wasn't able to do so.
I tried extending an intCharacteristics to my custom characteristics that override the constructor, value() and setValue() methods, to no avail: 'value()' is never changed...

Any hint on this?

Thanks!

@etwmc
Copy link
Owner

etwmc commented Aug 11, 2015

Since HomeKit is a framework for apps, there might be cases where the value of the characteristic being read rapidly, especially when there's multiple devices involved. In that case, you will perform lots of sensor reading, which could block the system and increase the latency, and potentially cause iOS to say the accessory is broken as the connection is dropped.
While I think you could just run a thread in the background that periodically update the value (which is the simplest solution), I think you can also just subclass the value() as subclass, although you will lost the notification feature.

@UniversalMailer
Copy link
Author

That was my first idea, so I wired a value to test it: the problem is that only the first 'setValue()' (the one called after the object is instantiated) gets called and there will be no update. If, for example, I set say 12 with setValue, then override value() to return '13' (wired), I always get 12 on iOS. If I however omit the first setValue(), the client will always display '0', no matter what I return from my overridden value()...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants