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

zeroconf.NonUniqueNameException #186

Open
sderuiter opened this issue Feb 24, 2019 · 2 comments
Open

zeroconf.NonUniqueNameException #186

sderuiter opened this issue Feb 24, 2019 · 2 comments

Comments

@sderuiter
Copy link

sderuiter commented Feb 24, 2019

Hi,

My setup:
1 Pi Zero W with camera module running Homebridge
1 Pi Zero W with camera module running HAP-python

The homebridge instance works perfectly, but now I want to add another Homekit instance using HAP-python.

HAP-python runs fine (on the second Pi) using python busy-home.py.

However, doing python camera-main.py yields (after pairing):

`[accessory_driver] Paired with bfe57bae-cd06-4a0a-ba31-e3f86fa89396.
[zeroconf] Unknown error, possibly benign: KeyError('camera._hap._tcp.local.',)
Traceback (most recent call last):
  File "/home/pi/berryconda3/lib/python3.6/site-packages/zeroconf.py", line 1871, in unregister_service
    del self.services[info.name.lower()]
KeyError: 'camera._hap._tcp.local.'
----------------------------------------
Exception happened during processing of request from ('192.168.178.46', 65309)
Traceback (most recent call last):
  File "/home/pi/berryconda3/lib/python3.6/socketserver.py", line 639, in process_request_thread
    self.finish_request(request, client_address)
  File "/home/pi/.local/lib/python3.6/site-packages/pyhap/hap_server.py", line 853, in finish_request
    self, self.accessory_handler)
  File "/home/pi/.local/lib/python3.6/site-packages/pyhap/hap_server.py", line 143, in __init__
    super(HAPServerHandler, self).__init__(sock, client_addr, server)
  File "/home/pi/berryconda3/lib/python3.6/socketserver.py", line 696, in __init__
    self.handle()
  File "/home/pi/berryconda3/lib/python3.6/http/server.py", line 420, in handle
    self.handle_one_request()
  File "/home/pi/berryconda3/lib/python3.6/http/server.py", line 406, in handle_one_request
    method()
  File "/home/pi/.local/lib/python3.6/site-packages/pyhap/hap_server.py", line 204, in dispatch
    getattr(self, self.HANDLERS[self.command][path])()
  File "/home/pi/.local/lib/python3.6/site-packages/pyhap/hap_server.py", line 539, in handle_pairings
    self._handle_add_pairing(tlv_objects)
  File "/home/pi/.local/lib/python3.6/site-packages/pyhap/hap_server.py", line 552, in _handle_add_pairing
    client_uuid, client_public)
  File "/home/pi/.local/lib/python3.6/site-packages/pyhap/accessory_driver.py", line 500, in pair
    self.update_advertisement()
  File "/home/pi/.local/lib/python3.6/site-packages/pyhap/accessory_driver.py", line 464, in update_advertisement
    self.advertiser.register_service(self.mdns_service_info)
  File "/home/pi/berryconda3/lib/python3.6/site-packages/zeroconf.py", line 1836, in register_service
    self.check_service(info, allow_name_change)
  File "/home/pi/berryconda3/lib/python3.6/site-packages/zeroconf.py", line 1952, in check_service
    raise NonUniqueNameException
zeroconf.NonUniqueNameException
----------------------------------------`

Somehow there seems to be a conflict with the other camera registered through homebridge?

Anyone seen this before?

Edit: after some googling, I found this issue in Home-assistant, which reports the same error.

Edit 2: dug slightly deeper. After patching accessory_driver.py at line 186 to change self.safe_mode = False to self.safe_mode = True, the error disappears. However, the stream does start and another error occurs.

...
camera] [df5875a9-2798-49aa-aa18-51654b39ea76] Started stream process - PID 7322
[camera] [df5875a9-2798-49aa-aa18-51654b39ea76] Stopping stream.
[hap_server] 192.168.178.20 - "PUT /characteristics HTTP/1.1" 204 -
[base_events] Task exception was never retrieved
future: <Task finished coro=<Camera._stop_stream() done, defined at /home/pi/.local/lib/python3.6/site-packages/pyhap/camera.py:549> exception=ProcessLookupError()>
Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.6/site-packages/pyhap/camera.py", line 567, in _stop_stream
    await self.stop_stream(session_info)
  File "/home/pi/.local/lib/python3.6/site-packages/pyhap/camera.py", line 806, in stop_stream
    ffmpeg_process.terminate()
  File "/home/pi/berryconda3/lib/python3.6/asyncio/subprocess.py", line 135, in terminate
    self._transport.terminate()
  File "/home/pi/berryconda3/lib/python3.6/asyncio/base_subprocess.py", line 155, in terminate
    self._check_proc()
  File "/home/pi/berryconda3/lib/python3.6/asyncio/base_subprocess.py", line 148, in _check_proc
    raise ProcessLookupError()
ProcessLookupError

Edit 3: In the above output, there is a process PID 7322 that is created to start the stream process. This process however never exists.

ps -p 7322
  PID TTY          TIME CMD

So something is preventing this process to happen...

Output from logging at DEBUG level (with a different PID of course):

camera] [191b6d96-2ce1-45f7-8d9e-877c3ebfe38c] Starting stream with the following parameters: {'v_profile_id': b'\x02', 'v_level': b'\x02', 'width': 640, 'height': 360, 'fps': 30, 'v_ssrc': 1, 'v_payload_type': b'c', 'v_max_bitrate': 132, 'v_rtcp_interval': 0.5, 'v_max_mtu': b'b\x05', 'a_codec': b'\x02', 'a_comfort_noise': b'\x00', 'a_channel': 1, 'a_bitrate': False, 'a_sample_rate': 16, 'a_packet_time': 30, 'a_ssrc': b'\x01', 'a_payload_type': b'n', 'a_max_bitrate': 24, 'a_rtcp_interval': 5.0, 'a_comfort_payload_type': b'\r', 'id': UUID('191b6d96-2ce1-45f7-8d9e-877c3ebfe38c'), 'address': '192.168.178.20', 'v_port': 63706, 'v_srtp_key': 'pO0Jau/GlU/Z8oCdBRY5vvu7/88RZQlAnV2morl0', 'a_port': 52473, 'audio_srtp_key': 'tALco2OhIqkSsgGtavDNwjkqYok/tJWG8RwwHuHY'}
[hap_server] 192.168.178.20 - "PUT /characteristics HTTP/1.1" 204 -
[camera] Executing start stream command: "ffmpeg -re -f avfoundation -i 0:0 -threads 0 -vcodec libx264 -an -pix_fmt yuv420p -r 30 -f rawvideo -tune zerolatency -vf scale=640:360 -b:v 132k -bufsize 132k -payload_type 99 -ssrc 1 -f rtp -srtp_out_suite AES_CM_128_HMAC_SHA1_80 -srtp_out_params pO0Jau/GlU/Z8oCdBRY5vvu7/88RZQlAnV2morl0 srtp://192.168.178.20:63706?rtcpport=63706&localrtcpport=63706&pkt_size=1378"
[camera] [191b6d96-2ce1-45f7-8d9e-877c3ebfe38c] Started stream process - PID 8085
[hap_server] Request PUT from address '('192.168.178.20', 54279)' for path '/characteristics'.
[hap_server] Set characteristics content: {'characteristics': [{'aid': 1, 'iid': 15, 'value': 'ARUCAQABEBkbbZYs4UX3jZ6HfD6/44w='}]}
[characteristic] client_update_value: SelectedRTPStreamConfiguration to ARUCAQABEBkbbZYs4UX3jZ6HfD6/44w=
[camera] set_selected_stream_config - value - ARUCAQABEBkbbZYs4UX3jZ6HfD6/44w=
[camera] Set stream config request: 0
[hap_server] 192.168.178.20 - "PUT /characteristics HTTP/1.1" 204 -
[camera] [191b6d96-2ce1-45f7-8d9e-877c3ebfe38c] Stopping stream.
[base_events] Task exception was never retrieved
future: <Task finished coro=<Camera._stop_stream() done, defined at /home/pi/.local/lib/python3.6/site-packages/pyhap/camera.py:549> exception=ProcessLookupError()>
Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.6/site-packages/pyhap/camera.py", line 567, in _stop_stream
    await self.stop_stream(session_info)
  File "/home/pi/.local/lib/python3.6/site-packages/pyhap/camera.py", line 806, in stop_stream
    ffmpeg_process.terminate()
  File "/home/pi/berryconda3/lib/python3.6/asyncio/subprocess.py", line 135, in terminate
    self._transport.terminate()
  File "/home/pi/berryconda3/lib/python3.6/asyncio/base_subprocess.py", line 155, in terminate
    self._check_proc()
  File "/home/pi/berryconda3/lib/python3.6/asyncio/base_subprocess.py", line 148, in _check_proc
    raise ProcessLookupError()
ProcessLookupError

@sbilly
Copy link

sbilly commented Feb 7, 2020

I have meet the zeroconf.NonUniqueNameException issue (home-assistant/core#17181).

In my case it caused by name conflicts. I add cache-entries-max=0 to avahi-daemon.conf , and restart avahi-daemon, everything just work.

Please check this: avahi/avahi#117 (comment)

@golles
Copy link

golles commented Apr 8, 2021

Thank you so much @sbilly, this has fixed it for me!

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

3 participants