Skip to content

Commit

Permalink
Address Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
npentrel committed Sep 23, 2023
1 parent 534d883 commit 59ac856
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 36 deletions.
5 changes: 3 additions & 2 deletions docs/program/connectivity.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ tags:
["client", "sdk", "viam-server", "networking", "apis", "robot api", "session"]
---

A [client session](/program/apis/sessions/) uses the most efficient route to connect to your robot either through local LAN or WAN or the internet.
When connecting to a robot using the connection code from the [code sample tab](/program/#hello-world-the-code-sample-tab), a [client session](/program/apis/sessions/) automatically uses the most efficient route to connect to your robot either through local LAN or WAN or the internet.

When a robot loses its connection to the internet but is still connected to a LAN or WAN:

- Client sessions connected through the internet will timeout and end.
- Client sessions connected through the same LAN or WAN will function normally.
- Client sessions connected through the internet will timeout and end.
If the client is on the same LAN or WAN, the client will automatically disconnect and then reconnect over LAN.
- [Cloud Sync](/services/data/#cloud-sync) for Data Management will pause until the internet connection is re-established since the robot will be unable to connect to the [Viam app](https://app.viam.com).

When a robot loses its connection to LAN or WAN, all client sessions will timeout and end by default.
Expand Down
50 changes: 16 additions & 34 deletions docs/program/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,40 +69,22 @@ flutter run <DART_FILE>

This is useful because as long as that computer is able to establish a network connection with the robot's computer, your control logic will be executed on the robot.

## Run Code On-Robot
### Authentication

{{< alert title="Info" color="info" >}}
This method of running code locally is only implemented on the Viam Python SDK.
{{< /alert >}}

In case your robots have intermittent internet connectivity, you can ensure this does not interfere with the code's execution.
If you need to run [PID control loops](https://en.wikipedia.org/wiki/PID_controller) or other on-robot code, you can run control code on the same board that is running `viam-server`.

In the `connect()` method of your control code, make the following changes:

1. Set `disable_webrtc=True` to disable {{< glossary_tooltip term_id="webrtc" >}}.
2. Set `auth_entity` to your robot's [configured](/manage/configuration/) `name`.
3. Replace the remote address in `RobotClient.at_address` with `localhost:8080`

Your SDK code should now look like:

```python {class="line-numbers linkable-line-numbers"}
async def connect():
creds = Credentials(type='robot-location-secret',
payload=YOUR_LOCATION_SECRET)
opts = RobotClient.Options(
refresh_interval=0,
dial_options=DialOptions(
credentials=creds,
disable_webrtc=True,
auth_entity="<YOUR_ROBOT_NAME>"
)
)
return await RobotClient.at_address('localhost:8080', opts)
```
You must authenticate yourself to the robot using the robot's location secret.
However, the app hides the robot location secret from the sample by default for your security.

To copy the robot location secret, select **Include Secret** on the **Code sample** tab of your robot's page on the [Viam app](https://app.viam.com).
Paste it into your environment variables or directly into your code.

You must also include the robot's remote address, like `12345.somerobot-main.viam.cloud`, as an external or public address to connect to your robot.
The code sample should include this address at default.
You can find it at the top of the robot's **Control** tab.

{{% snippet "secret-share.md" %}}

## Run Code On-Robot

Your localhost can now make a secure connection to `viam-server` locally.
SSL will check the server hostname against the `auth_entity` required by {{< glossary_tooltip term_id="grpc" >}} from the `auth_entity` `DialOptions`.
In case you run [PID control loops](https://en.wikipedia.org/wiki/PID_controller) or your robots have intermittent network connectivity, you can ensure this does not interfere with the code's execution, by running the the control code on the same board that is running `viam-server`.

This ensures that you can send commands to the robot through localhost without internet connectivity.
Note that all commands will be sent using {{< glossary_tooltip term_id="grpc" >}} only without {{< glossary_tooltip term_id="webrtc" >}}.
When connecting to a robot using the connection code from the [code sample tab](/program/#hello-world-the-code-sample-tab), a [client session](/program/apis/sessions/) automatically uses the [most efficient route](/program/connectivity/) to connect to your robot, which means the favored route for commands will be over localhost.

0 comments on commit 59ac856

Please sign in to comment.