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 a08d00c commit 9260e27
Show file tree
Hide file tree
Showing 2 changed files with 5 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
36 changes: 2 additions & 34 deletions docs/program/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,38 +71,6 @@ This is useful because as long as that computer is able to establish a network c

## Run Code On-Robot

{{< 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)
```

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 9260e27

Please sign in to comment.