balena-labs-projects / balena-cam

Network Camera with Raspberry Pi and WebRTC. Tutorial:
https://balena.io/blog/build-a-raspberry-pi-based-network-camera/
MIT License
175 stars 78 forks source link

Feed stops after some short time (frames) #56

Closed robot-army closed 4 years ago

robot-army commented 4 years ago

After fixing the setup by issuing the command modprobe bcm2835-v4l2 in a terminal, I was able to get a camera feed, but only for a short time.

After that, the browser screen goes blank, and I eventually get a sad smiley with some 'sorry' error message.

I tried changing a line to await asyncio.sleep(5) from I think 0.2? to slow things down, thinking it might be too much data for the pi zero to handle.

It didn't actually slow the framerate down from what I could tell...

Some logs follow.


16.12.19 22:59:17 (-0800) <balena-cam> 
16.12.19 22:59:17 (-0800) <balena-cam> #############################################################
16.12.19 22:59:17 (-0800) <balena-cam> Authorization is disabled.
16.12.19 22:59:17 (-0800) <balena-cam> Anyone can access your balenaCam, using the device's URL!
16.12.19 22:59:17 (-0800) <balena-cam> Set the username and password environment variables 
16.12.19 22:59:17 (-0800) <balena-cam> to enable authorization.
16.12.19 22:59:17 (-0800) <balena-cam> For more info visit: 
16.12.19 22:59:17 (-0800) <balena-cam> https://github.com/balena-io-playground/balena-cam
16.12.19 22:59:17 (-0800) <balena-cam> #############################################################
16.12.19 22:59:17 (-0800) <balena-cam> 
16.12.19 22:59:17 (-0800) <balena-cam> ======== Running on http://0.0.0.0:80 ========
16.12.19 22:59:17 (-0800) <balena-cam> (Press CTRL+C to quit)
16.12.19 23:01:09 (-0800) <balena-cam> Exception in callback Transaction.__retry()
16.12.19 23:01:09 (-0800) <balena-cam> handle: <TimerHandle when=326.478631283 Transaction.__retry()>
16.12.19 23:01:09 (-0800) <balena-cam> Traceback (most recent call last):
16.12.19 23:01:09 (-0800) <balena-cam>   File "/usr/lib/python3.5/asyncio/events.py", line 126, in _run
16.12.19 23:01:09 (-0800) <balena-cam>     self._callback(*self._args)
16.12.19 23:01:09 (-0800) <balena-cam>   File "/usr/local/lib/python3.5/dist-packages/aioice/stun.py", line 272, in __retry
16.12.19 23:01:09 (-0800) <balena-cam>     self.__future.set_exception(exceptions.TransactionTimeout())
16.12.19 23:01:09 (-0800) <balena-cam>   File "/usr/lib/python3.5/asyncio/futures.py", line 360, in set_exception
16.12.19 23:01:09 (-0800) <balena-cam>     raise InvalidStateError('{}: {!r}'.format(self._state, self))
16.12.19 23:01:09 (-0800) <balena-cam> asyncio.futures.InvalidStateError: FINISHED: <Future finished result=(Message(messa...\tN\xcfF\x10'), ('192.168.0.26', 58055))>``` 
robot-army commented 4 years ago
16.12.19 22:23:45 (-0800) <balena-cam> Exception in callback _SelectorTransport._call_connection_lost(None)
16.12.19 22:23:45 (-0800) <balena-cam> handle: <Handle _SelectorTransport._call_connection_lost(None)>
16.12.19 22:23:45 (-0800) <balena-cam> Traceback (most recent call last):
16.12.19 22:23:45 (-0800) <balena-cam>   File "/usr/lib/python3.5/asyncio/events.py", line 126, in _run
16.12.19 22:23:45 (-0800) <balena-cam>     self._callback(*self._args)
16.12.19 22:23:45 (-0800) <balena-cam>   File "/usr/lib/python3.5/asyncio/selector_events.py", line 662, in _call_connection_lost
16.12.19 22:23:45 (-0800) <balena-cam>     self._protocol.connection_lost(exc)
16.12.19 22:23:45 (-0800) <balena-cam>   File "/usr/local/lib/python3.5/dist-packages/aioice/ice.py", line 161, in connection_lost
16.12.19 22:23:45 (-0800) <balena-cam>     self.receiver.data_received(None, self.local_candidate.component)
16.12.19 22:23:45 (-0800) <balena-cam> AttributeError: 'NoneType' object has no attribute 'component'
16.12.19 22:23:45 (-0800) <balena-cam> Exception in callback _SelectorTransport._call_connection_lost(None)
16.12.19 22:23:45 (-0800) <balena-cam> handle: <Handle _SelectorTransport._call_connection_lost(None)>
16.12.19 22:23:45 (-0800) <balena-cam> Traceback (most recent call last):
16.12.19 22:23:45 (-0800) <balena-cam>   File "/usr/lib/python3.5/asyncio/events.py", line 126, in _run
16.12.19 22:23:45 (-0800) <balena-cam>     self._callback(*self._args)
16.12.19 22:23:45 (-0800) <balena-cam>   File "/usr/lib/python3.5/asyncio/selector_events.py", line 662, in _call_connection_lost
16.12.19 22:23:45 (-0800) <balena-cam>     self._protocol.connection_lost(exc)
16.12.19 22:23:45 (-0800) <balena-cam>   File "/usr/local/lib/python3.5/dist-packages/aioice/ice.py", line 161, in connection_lost
16.12.19 22:23:45 (-0800) <balena-cam>     self.receiver.data_received(None, self.local_candidate.component)
16.12.19 22:23:45 (-0800) <balena-cam> AttributeError: 'NoneType' object has no attribute 'component'
robot-army commented 4 years ago

Output from top seems like kswapd0 takes over CPU usage right when the thing fails. I've tried changing the GPU memory settings, let's see how that goes.

robot-army commented 4 years ago

Yep, by far the longest run I've had yet (and it's still running as I post this comment) has come by overriding device configuration BALENA_HOST_CONFIG_gpu_mem_512 value from 256 to 128 (from here: https://www.balena.io/docs/learn/develop/hardware/i2c-and-spi/#raspberry-pi-camera-module )

robot-army commented 4 years ago

Some noise in the logs and a broken feed that seemed to work on refresh:

17.12.19 01:55:47 (-0800) <balena-cam> handle: <TimerHandle when=1585.787987345 Transaction.__retry()>
17.12.19 01:55:47 (-0800) <balena-cam> Traceback (most recent call last):
17.12.19 01:55:47 (-0800) <balena-cam>   File "/usr/lib/python3.5/asyncio/events.py", line 126, in _run
17.12.19 01:55:47 (-0800) <balena-cam>     self._callback(*self._args)
17.12.19 01:55:47 (-0800) <balena-cam>   File "/usr/local/lib/python3.5/dist-packages/aioice/stun.py", line 272, in __retry
17.12.19 01:55:47 (-0800) <balena-cam>     self.__future.set_exception(exceptions.TransactionTimeout())
17.12.19 01:55:47 (-0800) <balena-cam>   File "/usr/lib/python3.5/asyncio/futures.py", line 360, in set_exception
17.12.19 01:55:47 (-0800) <balena-cam>     raise InvalidStateError('{}: {!r}'.format(self._state, self))
17.12.19 01:55:47 (-0800) <balena-cam> asyncio.futures.InvalidStateError: FINISHED: <Future finished result=(Message(messa...\x97"ZM\x1f]'), ('192.168.0.26', 58452))>
17.12.19 01:57:15 (-0800) <balena-cam> Exception in callback Transaction.__retry()
17.12.19 01:57:15 (-0800) <balena-cam> handle: <TimerHandle when=1675.406446503 Transaction.__retry()>
17.12.19 01:57:15 (-0800) <balena-cam> Traceback (most recent call last):
17.12.19 01:57:15 (-0800) <balena-cam>   File "/usr/lib/python3.5/asyncio/events.py", line 126, in _run
17.12.19 01:57:15 (-0800) <balena-cam>     self._callback(*self._args)
17.12.19 01:57:15 (-0800) <balena-cam>   File "/usr/local/lib/python3.5/dist-packages/aioice/stun.py", line 272, in __retry
17.12.19 01:57:15 (-0800) <balena-cam>     self.__future.set_exception(exceptions.TransactionTimeout())
17.12.19 01:57:15 (-0800) <balena-cam>   File "/usr/lib/python3.5/asyncio/futures.py", line 360, in set_exception
17.12.19 01:57:15 (-0800) <balena-cam>     raise InvalidStateError('{}: {!r}'.format(self._state, self))
17.12.19 01:57:15 (-0800) <balena-cam> asyncio.futures.InvalidStateError: FINISHED: <Future finished exception=TransactionFailed(Message(message_method=Method.BINDING, message_class=Class.ERROR, transaction_id=b'\x9a\xe6\xa6\xc3\xfd\xf3\xd8j\x86\xd7OE'),)>
17.12.19 01:57:15 (-0800) <balena-cam> Exception in callback Transaction.__retry()
17.12.19 01:57:15 (-0800) <balena-cam> handle: <TimerHandle when=1676.390663887 Transaction.__retry()>
17.12.19 01:57:15 (-0800) <balena-cam> Traceback (most recent call last):
17.12.19 01:57:15 (-0800) <balena-cam>   File "/usr/lib/python3.5/asyncio/events.py", line 126, in _run
17.12.19 01:57:15 (-0800) <balena-cam>     self._callback(*self._args)
17.12.19 01:57:15 (-0800) <balena-cam>   File "/usr/local/lib/python3.5/dist-packages/aioice/stun.py", line 272, in __retry
17.12.19 01:57:15 (-0800) <balena-cam>     self.__future.set_exception(exceptions.TransactionTimeout())
17.12.19 01:57:15 (-0800) <balena-cam>   File "/usr/lib/python3.5/asyncio/futures.py", line 360, in set_exception
17.12.19 01:57:15 (-0800) <balena-cam>     raise InvalidStateError('{}: {!r}'.format(self._state, self))
17.12.19 01:57:15 (-0800) <balena-cam> asyncio.futures.InvalidStateError: FINISHED: <Future finished exception=TransactionFailed(Message(message_method=Method.BINDING, message_class=Class.ERROR, transaction_id=b'?\xf1`\x96;\xcb*\xb0(\xa4kG'),)>
17.12.19 01:57:15 (-0800) <balena-cam> Exception in callback Transaction.__retry()
17.12.19 01:57:15 (-0800) <balena-cam> handle: <TimerHandle when=1676.409545741 Transaction.__retry()>
17.12.19 01:57:15 (-0800) <balena-cam> Traceback (most recent call last):
17.12.19 01:57:15 (-0800) <balena-cam>   File "/usr/lib/python3.5/asyncio/events.py", line 126, in _run
17.12.19 01:57:15 (-0800) <balena-cam>     self._callback(*self._args)
17.12.19 01:57:15 (-0800) <balena-cam>   File "/usr/local/lib/python3.5/dist-packages/aioice/stun.py", line 272, in __retry
17.12.19 01:57:15 (-0800) <balena-cam>     self.__future.set_exception(exceptions.TransactionTimeout())
17.12.19 01:57:15 (-0800) <balena-cam>   File "/usr/lib/python3.5/asyncio/futures.py", line 360, in set_exception
17.12.19 01:57:15 (-0800) <balena-cam>     raise InvalidStateError('{}: {!r}'.format(self._state, self))
17.12.19 01:57:15 (-0800) <balena-cam> asyncio.futures.InvalidStateError: FINISHED: <Future finished exception=TransactionFailed(Message(message_method=Method.BINDING, message_class=Class.ERROR, transaction_id=b'\xc5\xec\xb5x\xe05\xe4\x8d\xde~\xc7r'),)>
17.12.19 02:00:38 (-0800) <balena-cam> Exception in callback Transaction.__retry()
17.12.19 02:00:38 (-0800) <balena-cam> handle: <TimerHandle when=1874.514632089 Transaction.__retry()>
17.12.19 02:00:38 (-0800) <balena-cam> Traceback (most recent call last):
17.12.19 02:00:38 (-0800) <balena-cam>   File "/usr/lib/python3.5/asyncio/events.py", line 126, in _run
17.12.19 02:00:38 (-0800) <balena-cam>     self._callback(*self._args)
17.12.19 02:00:38 (-0800) <balena-cam>   File "/usr/local/lib/python3.5/dist-packages/aioice/stun.py", line 272, in __retry
17.12.19 02:00:38 (-0800) <balena-cam>     self.__future.set_exception(exceptions.TransactionTimeout())
17.12.19 02:00:38 (-0800) <balena-cam>   File "/usr/lib/python3.5/asyncio/futures.py", line 360, in set_exception
17.12.19 02:00:38 (-0800) <balena-cam>     raise InvalidStateError('{}: {!r}'.format(self._state, self))
17.12.19 02:00:40 (-0800) <balena-cam> asyncio.futures.InvalidStateError: FINISHED: <Future finished result=(Message(messa...d1m\xb8\x12>'), ('192.168.0.26', 62341))>

Also, this is after uncommenting the line commented here

if __name__ == '__main__':
    #checkDeviceReadiness() 
mbalamat commented 4 years ago

@robot-army since you don't have this problem anymore do you mind closing this? Also I'd recommend always using the latest available version of balenaOS.

robot-army commented 4 years ago

I think this needs something for the README to fix the GPU memory sizes, but I'll try again with a new version if I get a moment and see if that fixes it. Thanks for your help!

mbalamat commented 4 years ago

@robot-army I am going to close this, if you still have the issue feel free to re-open it.