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

use as Bridge #7

Closed
gerswin opened this issue Jan 20, 2018 · 8 comments
Closed

use as Bridge #7

gerswin opened this issue Jan 20, 2018 · 8 comments

Comments

@gerswin
Copy link

gerswin commented Jan 20, 2018

do you have an example for use as bridge?

@gerswin gerswin closed this as completed Jan 20, 2018
@ikalchev
Copy link
Owner

Hi!

Try the below. There is another example in main.py. If you have any more questions, please ask :)

Best,
Ivan

from pyhap.util import generate_mac
from pyhap.accessories.AM2302 import AM2302
from pyhap.accessories.ShutdownSwitch import ShutdownSwitch
from pyhap.accessory import Bridge
from pyhap.accessory_driver import AccessoryDriver

def create_bridge():
    bridge = Bridge(display_name="pyhap", mac=generate_mac(), pincode=b"203-23-999")
    am2302 = AM2302("DHT22")
    shutdown_switch = ShutdownSwitch("Halt")
    bridge.add_accessory(am2302)
    bridge.add_accessory(shutdown_switch)
    return bridge

def main():
    bridge = create_bridge()
    driver = AccessoryDriver(bridge, port=..., address=..., persist_file=...)
    # signal.signal(signal.SIGINT, driver.signal_handler) optional
    # signal.signal(signal.SIGTERM, driver.signal_handler) optional
    driver.start()

@gerswin
Copy link
Author

gerswin commented Jan 20, 2018

I can not make it work, i can see accessory mode in homekit but not bridge mode

@gerswin gerswin reopened this Jan 20, 2018
@ikalchev
Copy link
Owner

This is odd. What's in your code that starts the Bridge? Is it like the one above? Or if you are using main.py from HAP-python, did you delete the file accessory.pickle before changing from accessory to bridge? (this file contains a cached accessory: after a restart of HAP-python, it reads from it and does not create a new accessory object, i.e. you may have changed the code, but the old state from the file is being used)

@gerswin
Copy link
Author

gerswin commented Jan 20, 2018

i test it with main.py and the one above, y delete accessory.pickle too

@gerswin
Copy link
Author

gerswin commented Jan 20, 2018

i just test it with fresh install of respbian, still not working :(

@ikalchev
Copy link
Owner

I just got a clean copy of the project and I can see both Bridge and Accessory (I am using main.py), both from a mac OS and a Raspberry Pi.

Are you using a different mac address for the bridge (generate_mac() provides a random one, so if you are using this - yes)? Have you tried starting it more than once?

Do you still see ONLY the Accessory and not the Bridge?

@gerswin
Copy link
Author

gerswin commented Jan 20, 2018

in fresh install of raspberry pi i need this sudo apt-get install libavahi-compat-libdnssd-dev, now is working. i will keep testing and let you know

@ikalchev
Copy link
Owner

ikalchev commented Jan 20, 2018

Oh, avahi, for the mDNS, of course... I need to add this to the setup script. Thanks!

Yes, please let me know if you manage to run it properly (or if you don't) :)

@gerswin gerswin closed this as completed Jan 24, 2018
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