-
-
Notifications
You must be signed in to change notification settings - Fork 19
Implemented a very simple server to pipe the DJI USB to WiFi. #10
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
Open
MythicLionMan
wants to merge
1
commit into
fpvout:main
Choose a base branch
from
MythicLionMan:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| #!/usr/bin/python3 | ||
| # | ||
| # A server that waits for connections and pipes the output of fpv-c to the | ||
| # remote client. The client will be an h264 stream (without an MP4 wrapper) | ||
| # so clients will need to act accordingly. To view the stream in VLC open | ||
| # a url: tcp/h264://fpvout.local:8081 | ||
| # | ||
| # This service can be used to create a simple device that will clients such | ||
| # as iOS to connect to DJI FPV goggles. I haven't tested yet, but I suspect | ||
| # even a Pi Zero could handle it since it's just redirecting USB to Wifi and | ||
| # not even decoding the video. That said my Pi 4 has horrible latency, so this | ||
| # may not work. | ||
|
|
||
| import socket | ||
| import subprocess | ||
| import sys | ||
|
|
||
| # Create a TCP/IP socket | ||
| sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
|
|
||
| # Bind the socket to the port | ||
| server_address = ('', 8081) | ||
| print('starting up on %s port %s' % server_address, file=sys.stderr) | ||
| sock.bind(server_address) | ||
|
|
||
| # Listen for incoming connections | ||
| sock.listen(1) | ||
|
|
||
| while True: | ||
| # Wait for a connection | ||
| print('waiting for a connection', file=sys.stderr) | ||
| connection, client_address = sock.accept() | ||
|
|
||
| try: | ||
| print('connection from %s port %s' % client_address, file=sys.stderr) | ||
|
|
||
| socket_input = connection.makefile('wb',0) | ||
| proc = subprocess.run(['/home/fpvout/Scripts/fpv-c/fpv-video-out'], stdout=socket_input) | ||
| finally: | ||
| # Clean up the connection | ||
| print('closed connection from %s port %s' % client_address, file=sys.stderr) | ||
| connection.close() | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar with python - but does this script need to be called from somewhere to start?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this a very basic server. It waits for a connection and when it gets one it pipes the data from the goggles to the remote client on line 38. It can only handle 1 client at a time because the client takes over the connection to the goggles.
Originally I had wanted to implement this as an inetd service (and the script wouldn't have been required) but inetd isn't installed anymore. I think that the mechanism used to launch fpv-video-out when the USB connection to the goggles is made would be able to launch on an incoming connection, but I wasn't familiar with that, and this was a quick proof of concept.
I thought that I did set up something to launch this automatically, but I don't remember what it is, and it doesn't look like I comitted it. I'll have to check my image to see exactly what I did.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use inetd, it's all about systems for many years now.
Also pipelining video to a webserver might be faster if threaded and called via go or node maybe, or somehow wrap lighttpd or other super small and fast server into the mix.
Sadly I lack time to really write a good doc on this, but if you dig hard, at least find ways to multithread it in python, etc.
I want to see this done, but I'd likely bodge out a crap c++ implementation, and then do it in rust (that's my daily driver language) but I'm so backlogged now. :(