waggle-sensor / pywaggle

Python SDK for integrating plugins with Waggle.
Other
6 stars 8 forks source link

pywaggle cannot reach microphones from inside a containerized environment #29

Closed dariodematties closed 2 years ago

dariodematties commented 2 years ago

Hi there, here I am trying to run birdnet-lite using pywaggle from inside one of the waggle nodes. This is my repository From the Dockerfile I am bootstrapping FROM nvcr.io/nvidia/l4t-tensorflow:r32.4.4-tf2.3-py3 as you are able to see here

From inside the node I do sudo docker run --rm -it --entrypoint bash birdnet-lite

And inside the containerized env I do

root@9a725f5a879a:/# python3
Python 3.6.9 (default, Oct  8 2020, 12:12:24) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from waggle.plugin import Plugin
>>> from waggle.data.audio import Microphone
using backwards compatible implementation of time_ns
>>> with Plugin() as plugin:
...  microphone = Microphone(samplerate=48000)
... 

And receive the following error

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/usr/local/lib/python3.6/dist-packages/waggle/data/audio.py", line 35, in __init__
    import soundcard
  File "/usr/local/lib/python3.6/dist-packages/soundcard/__init__.py", line 4, in <module>
    from soundcard.pulseaudio import *
  File "/usr/local/lib/python3.6/dist-packages/soundcard/pulseaudio.py", line 261, in <module>
    _pulse = _PulseAudio()
  File "/usr/local/lib/python3.6/dist-packages/soundcard/pulseaudio.py", line 72, in __init__
    assert self._pa_context_get_state(self.context)==_pa.PA_CONTEXT_READY
AssertionError
>>> 

I would really appreciate to work directly from the node in a containerized env before pushing the final version of the repo to ECR.

Unfortunately this is an impediment since I cannot run my code as it is from the node

Any help, suggestions etc?

Thanks!

gemblerz commented 2 years ago

Hello Dario, Thanks for the report.

First of all, all code running that requires the access to sensors we manage you must use pluginctl because Waggle sets up the environment for you to access to the microphone. We are documenting instructions on how to use pluginctl. We will get back to you once the document is ready.

For the in-node code development, we are happy to announce that pluginctl exec (>= 0.8.3) supports debugging codes inside a container (see New features. However, I am hesitant to support local Docker building and saving changes in to a built Docker image because it does not keep track of changes easily so when you push your app to ECR your Dockerfile may not have all you need. For this reason, it would be much better for you to launch a bootstrapping container using pluginctl, resolve dependencies and debug your code inside the container, update your Dockerfile based on what you changed in that container, and push that Dockerfile to ECR. I think this is much better to ensure the Dockerfile has all the debugging you did with the dev container. Does this sound reasonable?

seanshahkarami commented 2 years ago

Closing for now: The expectation is that the container will be run within the Waggle Edge Stack environment, not a bare Docker container. Microphone access should work in that setting.