Skip to content
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

Updating websockets example and readme #231

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions examples/websocket-service/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Websocket Service

## Setup

```shell
script/setup --websockets
```

## Quick Start

In one terminal, run the following

```shell
script/run_websockets --uri 'tcp://0.0.0.0:10701' --websocket-host '0.0.0.0'
```

This will spawn a Wyoming server that listens to and then subsequently publishes events to the provided websocket host and port

```shell
script/run --name 'my satellite' --uri 'tcp://0.0.0.0:10700' --mic-command 'arecord -r 16000 -c 1 -f S16_LE -t raw' --snd-command 'aplay -r 22050 -c 1 -f S16_LE -t raw' --event-uri 'tcp://0.0.0.0:10701'
```

In another terminal, run the above. This will start the actual satellite and publish events to the Wyoming server in Terminal 1.

If you open the `timers.html` file in a browser, in the Network tab of the Dev Tools, you should see it connect to the websocket.

Alternatively, if you have another app that uses websockets, you should be able to connect to that as well now
4 changes: 2 additions & 2 deletions examples/websocket-service/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ def __init__(
self.queue = queue

async def handle_event(self, event: Event) -> bool:
_LOGGER.debug(event)
self.queue.put_nowait(event)
_LOGGER.info(event)
await self.queue.put(event)

return True

Expand Down
12 changes: 12 additions & 0 deletions script/run_websockets
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env python3
import sys
import subprocess
import venv
from pathlib import Path

_DIR = Path(__file__).parent
_PROGRAM_DIR = _DIR.parent
_VENV_DIR = _PROGRAM_DIR / ".venv"

context = venv.EnvBuilder().ensure_directories(_VENV_DIR)
subprocess.check_call([context.env_exe, "examples/websocket-service/server.py"] + sys.argv[1:])
7 changes: 7 additions & 0 deletions script/setup
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ _VENV_DIR = _PROGRAM_DIR / ".venv"

parser = argparse.ArgumentParser()
parser.add_argument("--dev", action="store_true", help="Install dev requirements")
parser.add_argument("--websockets", action="store_true", help="Install websocket requirements")
args = parser.parse_args()

# Create virtual environment
Expand Down Expand Up @@ -41,3 +42,9 @@ if args.dev:
subprocess.check_call(
pip + ["install", "-r", str(_PROGRAM_DIR / "requirements_dev.txt")]
)

if args.websockets:
# Install websocket requirements
subprocess.check_call(
pip + ["install", "-r", str(_PROGRAM_DIR / "requirements_websockets.txt")]
)
Loading