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

How to coalesce multiple requests to a device? #1455

Closed
FrankC2000 opened this issue Aug 24, 2017 · 5 comments
Closed

How to coalesce multiple requests to a device? #1455

FrankC2000 opened this issue Aug 24, 2017 · 5 comments
Labels

Comments

@FrankC2000
Copy link

FrankC2000 commented Aug 24, 2017

Hi there!

I am writing a platform to control a single phisical device with 48 individuals light bulbs (declared as distinct accessories inside the platform). I started from homebridge-samplePlatform.

Everything work as expected when I turn the lights individually by the Home app. But when I activate a scene with more than 10 lights, it hangs the Home app with "no response" statuses. The plugin sends several individual requests (one for each light) at the same time, flooding the device.

Here's part of the log:

EventedHTTPServer [::ffff:192.168.11.19] HTTP request: /characteristics +5s
  HAPServer [CC:22:3D:E3:CE:31] HAP Request: PUT /characteristics +0ms
  Accessory [Homebridge Mac] Processing characteristic set: [{"aid":10,"iid":9,"value":false},{"aid":11,"iid":9,"value":false},{"aid":3,"iid":9,"value":1},{"aid":2,"iid":9,"value":1},{"aid":12,"iid":9,"value":1},{"aid":14,"iid":9,"value":1},{"aid":13,"iid":9,"value":1},{"aid":9,"iid":9,"value":1},{"aid":8,"iid":9,"value":false},{"aid":7,"iid":9,"value":1},{"aid":4,"iid":9,"value":1},{"aid":5,"iid":9,"value":false},{"aid":6,"iid":9,"value":1},{"aid":15,"iid":9,"value":1}] +2ms

It shows that homebridge receive just one request from HAPServer but split in several individual requests to the device (not in the log).

I guess it should coalesce all these separated requests into a single request to the device but I have no idea how to do that, I mean, which events to implement. Can anybody help me? Examples will be welcome.

Thanks in advance!

@ebaauw
Copy link
Contributor

ebaauw commented Aug 28, 2017

I ran into, and solved, the very same problem in my homebridge-hue plugin for Philips Hue. HomeKit sends the characteristics from a scene in one message to homebridge, but homebridge cuts this up into multiple 'set' events to the plugin, one for each characteristic. When translating each event in a separate API request to the Hue bridge, it would report errors and drop requests when recalling a HomeKit scene, see ebaauw/homebridge-hue#15.

The Hue API allows me to combine multiple settings for the same light (on/off, brightness, hue, saturation) into one request, but requires a separate request for each light. So I took the following measures:

@FrankC2000
Copy link
Author

Thanks, it worked!

@aboulfad
Copy link

Hoi @ebaauw , I quickly reached the limits of "kludge" in my issue and I am trying to learn your solution. Not easy as I am learning many things and to simply my challenge I decided to stay with HAPnode.js not switching to Homebridge.

I'd appreciate if you can provide some guidance to a noob dev:

  1. I use an _acc.js in HAPnode, can I implement an equivalent solution in that file ? or do I have to modify some files in HAPnode itself ?
  2. Is your solution "portable" to HAPnode or does it depend on any functions/classes in Homebridge ?
  3. I assume the core of the solution is at function ?

Dank u well, Tot ziens ;-)

@ebaauw
Copy link
Contributor

ebaauw commented Dec 19, 2017

1, 2: I really don't know - I've only ever used homebridge, never native HAP-NodeJS. I do think the Service and Characteristic stuff is HAP-NodeJS, though.

3: My solution consists of the following:

@stale
Copy link

stale bot commented Jun 17, 2018

This issue has been automatically marked as stale because it has not had recent activity, and will be closed if no further activity occurs. If this issue was overlooked, forgotten, or should remain open for any other reason, please reply here to call attention to it and remove the stale status. Thank you for your contributions.

@stale stale bot added the stale label Jun 17, 2018
@stale stale bot closed this as completed Jul 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants