You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[](https://gitter.im/rtcbot/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
Copy file name to clipboardExpand all lines: examples/mobile/README.md
+64-5Lines changed: 64 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,13 +10,13 @@ Rather than connecting to the robot, we will have two separate Python programs.
10
10
```
11
11
12
12
In a previous tutorial, we developed a connection that streamed video to the browser. This tutorial will implement exactly the same functionality,
13
-
but with a robot on a remote connection.
13
+
but with the robot on a remote connection.
14
14
15
15
The browser-side code will remain unchanged - all of the work here will be in Python.
16
16
17
17
## Server Code
18
18
19
-
Most of the server code is identical. The only difference is that we set up a listener at `/ws`, which will establish a websocket connection with the robot:
19
+
Most of the server code is unchanged. The only difference is that we set up a listener at `/ws`, which will establish a websocket connection with the robot:
20
20
21
21
```python
22
22
ws =None# Websocket connection to the robot
@@ -140,7 +140,7 @@ web.run_app(app)
140
140
141
141
## Remote Code
142
142
143
-
In this tutorial, we will just run both server and robot on the local machine. The same code will work over the internet simply by setting the right IP for the robot to connect to. The robot connects to the server with a websocket, and waits for the message that will allow it to initialize its WebRTC connection.
143
+
In this tutorial, we will just run both server and robot on the local machine. The robot connects to the server with a websocket, and waits for the message that will allow it to initialize its WebRTC connection.
144
144
145
145
```python
146
146
import asyncio
@@ -171,12 +171,71 @@ finally:
171
171
172
172
With these two pieces of code, you first start the server, then start the robot, and finally open `http://localhost:8080` in the browser to view a video stream coming directly from the robot, even if the robot has an unknown IP.
173
173
174
+
## If it doesn't work over 4G
175
+
176
+
The above example should work for most people. However, some mobile network operators perform routing that disallows creating a direct WebRTC connection to a mobile device over 4G. If this is your situation, you need to use what is called a TURN server, which will forward data between the browser and robot.
177
+
178
+
```eval_rst
179
+
.. note::
180
+
You can check if your mobile operator allows such connections by using your phone to create a wifi hotspot, to which you can connect your robot. If video streaming works with the code above, you can ignore this section!
181
+
```
182
+
183
+
```eval_rst
184
+
.. warning::
185
+
Because a TURN server essentially serves as a proxy through which an entire WebRTC connection is routed, it can send and receive quite a bit of data - make sure that you don't
186
+
exceed your download and upload limits!
187
+
```
188
+
189
+
While installing and configuring [coTURN](https://github.com/coturn/coturn) on linux is recommended for permanent setups,
190
+
for simplicity we will run the [Pion TURN server](https://github.com/pion/turn) on the same computer that is running our server code.
191
+
192
+
The Pion server is easy to set up on Windows,Mac and Linux - all you need to do is [download the executable](https://github.com/pion/turn/releases/tag/1.0.3), and run it from the command line as shown.
193
+
194
+
**Linux/Mac**:
195
+
```bash
196
+
chmod +x ./simple-turn # allow executing the downloaded file
197
+
export USERS='myusername=mypassword'
198
+
export REALM=my.server.ip
199
+
export UDP_PORT=3478
200
+
./simple-turn-linux-amd64 # simple-turn-darwin-amd64 if on Mac
201
+
```
202
+
203
+
**Windows**: You can run the following from powershell:
204
+
```powershell
205
+
$env:USERS = "myusername=mypassword"
206
+
$env:REALM = "my.server.ip"
207
+
$env:UDP_PORT = 3478
208
+
./simple-turn-windows-amd64.exe
209
+
```
210
+
211
+
With the server running, you will need to let both Python and Javascript know about it when creating your `RTCConnection`:
With the above code, you should be able to stream video to your browser using 4G, even if your mobile operator disallows direct connections.
231
+
232
+
174
233
## Summary
175
234
176
-
This tutorial split up the server and robot code into distinct pieces. Also introduced was rtcbot's websocket wrapper, allowing you to easily establish a data-only connection.
235
+
This tutorial split up the server and robot code into distinct pieces. Also introduced was rtcbot's websocket wrapper, allowing you to easily establish a data-only connection. Finally, TURN servers were introduced, and instructions were given on how to set one up if direct connections fail.
177
236
178
237
## Extra Notes
179
238
180
239
Be aware that throughout these tutorials, all error handling and robustness was left out in the interest of
181
-
clarity of the fundamental program flow. In reality, you will probably want to make sure that the connection
240
+
clarity in the fundamental program flow. In reality, you will probably want to make sure that the connection
182
241
did not have an error, and add the ability to connect and disconnect multiple times.
Copy file name to clipboardExpand all lines: examples/offloading/README.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ The second part of the tutorial adds a neural network into the mix, which tries
11
11
12
12
```eval_rst
13
13
.. note::
14
-
While with a weak SBC like the Raspberry Pi there might be a non-negligible delay between sending a video frame and getting back a command, this is not a limitation of the approach, since it is possible to stream `video games with barely-noticeable lag <https://arstechnica.com/gaming/2019/03/googles-multiyear-quest-to-overcome-ids-stadia-streaming-skepticism/>`_. In particular, rtcbot currently cannot take advantage of the Pi's hardware acceleration, meaning that all video encoding is done in software, which ends up adding to video delay.
14
+
While with a Raspberry Pi there might be a non-negligible delay between sending a video frame and getting back a command, this is not a limitation of the approach, since it is possible to stream `video games with barely-noticeable lag <https://arstechnica.com/gaming/2019/03/googles-multiyear-quest-to-overcome-ids-stadia-streaming-skepticism/>`_. In particular, rtcbot currently cannot take advantage of the Pi's hardware acceleration, meaning that all video encoding is done in software, which ends up adding to video delay.
15
15
```
16
16
17
17
## Python to Python Streaming
@@ -137,6 +137,6 @@ This portion of the tutorial focuses on modifying the desktop code from the prev
137
137
a neural network which is trained exploiting the computational power available on a desktop PC.
138
138
139
139
This is an _advanced_ topic, requiring a working knowledge of machine learning basics. It is also assumed
140
-
that you are using linux on your desktop, and that you have an nvidia graphics card compatible with [pytorch](https://pytorch.org). If you choose to attempt this part on a windows desktop or on a mac, be aware that you might run into some problems that might need a bit of googling skills to solve.
140
+
that you are using linux on your desktop, and that you have an nvidia graphics card compatible with [pytorch](https://pytorch.org). If you choose to attempt this part on a windows desktop or on a mac, be aware that you might run into some problems that might require some googling skills to solve.
0 commit comments