@uns-kit/cli 0.0.36 → 0.0.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +128 -128
- package/dist/index.js +11 -5
- package/package.json +8 -2
- package/templates/api/src/examples/api-example.ts +62 -62
- package/templates/azure-pipelines.yml +21 -21
- package/templates/codegen/codegen.ts +15 -15
- package/templates/codegen/src/uns/uns-tags.ts +1 -1
- package/templates/codegen/src/uns/uns-topics.ts +1 -1
- package/templates/config-files/config-docker.json +26 -26
- package/templates/config-files/config-localhost.json +26 -26
- package/templates/cron/src/examples/cron-example.ts +46 -46
- package/templates/default/README.md +32 -30
- package/templates/default/config.json +27 -27
- package/templates/default/gitignore +51 -51
- package/templates/default/package.json +38 -19
- package/templates/default/src/config/project.config.extension.example +23 -23
- package/templates/default/src/config/project.config.extension.ts +6 -6
- package/templates/default/src/examples/data-example.ts +68 -68
- package/templates/default/src/examples/load-test-data.ts +108 -108
- package/templates/default/src/examples/table-example.ts +66 -66
- package/templates/default/src/examples/uns-gateway-cli.ts +7 -7
- package/templates/default/src/index.ts +15 -15
- package/templates/default/src/uns/uns-tags.ts +2 -2
- package/templates/default/src/uns/uns-topics.ts +2 -2
- package/templates/default/tsconfig.json +29 -16
- package/templates/python/app/README.md +8 -8
- package/templates/python/examples/README.md +134 -134
- package/templates/python/examples/api_handler.py +28 -28
- package/templates/python/examples/data_publish.py +11 -11
- package/templates/python/examples/data_subscribe.py +8 -8
- package/templates/python/examples/data_transformer.py +17 -17
- package/templates/python/examples/table_transformer.py +15 -15
- package/templates/python/gateway/cli.py +75 -75
- package/templates/python/gateway/client.py +155 -155
- package/templates/python/gateway/manager.py +97 -97
- package/templates/python/proto/uns-gateway.proto +102 -102
- package/templates/python/pyproject.toml +4 -4
- package/templates/python/scripts/setup.sh +87 -87
- package/templates/temporal/src/examples/temporal-example.ts +35 -35
- package/templates/vscode/.vscode/launch.json +164 -164
- package/templates/vscode/.vscode/settings.json +9 -9
- package/templates/vscode/uns-kit.code-workspace +13 -13
- package/templates/python/gen/__init__.py +0 -1
- package/templates/python/gen/uns_gateway_pb2.py +0 -70
- package/templates/python/gen/uns_gateway_pb2_grpc.py +0 -312
|
@@ -1,134 +1,134 @@
|
|
|
1
|
-
# Python Examples for the UNS gRPC Gateway
|
|
2
|
-
|
|
3
|
-
These examples demonstrate how to use the Node-based UNS Gateway (MQTT + UNS infra) from Python via gRPC. They mirror the TypeScript examples for data, table, cron-like publishing, and API endpoints.
|
|
4
|
-
|
|
5
|
-
The gateway centralizes all UNS rules (packet format, sequenceId, interval, produced topics, handover). Python focuses on business logic and ML/ETL while calling the gateway.
|
|
6
|
-
|
|
7
|
-
## Prerequisites
|
|
8
|
-
|
|
9
|
-
- Build the Node project once: `npm run build`
|
|
10
|
-
- Generate Python stubs and venv: `cd python && ./scripts/setup.sh && source venv/bin/activate`
|
|
11
|
-
- Ensure `config.json` is present at repo root (Node gateway reads brokers and UNS options from it)
|
|
12
|
-
|
|
13
|
-
## Gateway Address
|
|
14
|
-
|
|
15
|
-
- If `--addr` is omitted, each script auto‑generates a unique address:
|
|
16
|
-
- Unix/macOS: `unix:/tmp/uns-gateway-<script>-<pid>.sock`
|
|
17
|
-
- Windows: `127.0.0.1:<ephemeral_port>`
|
|
18
|
-
- You can still pass an explicit `--addr` if you want a fixed address.
|
|
19
|
-
|
|
20
|
-
All examples accept `--addr` and `--auto`. With `--auto`, the example will spawn the gateway via `npm run gateway` and wait until it's ready.
|
|
21
|
-
|
|
22
|
-
Imports note: Examples add the generated stubs folder (`python/gen`) to `sys.path` so you can run them from the repo root or from the `python/` folder. Ensure you’ve run `./scripts/setup.sh` so `gen` exists.
|
|
23
|
-
|
|
24
|
-
Readiness: Examples call the gateway’s `Ready()` RPC to wait for the requested components (publisher/subscriber/API) to be active before publishing or subscribing. No manual sleeps are required.
|
|
25
|
-
|
|
26
|
-
## Common Flags
|
|
27
|
-
|
|
28
|
-
- `--addr`: Gateway address (`unix:/path.sock` or `host:port`)
|
|
29
|
-
- `--auto`: Auto-start the gateway if not running
|
|
30
|
-
|
|
31
|
-
## Scripts
|
|
32
|
-
### `data_transformer.py`
|
|
33
|
-
|
|
34
|
-
Transforms incoming sensor data and republishes it to a target topic.
|
|
35
|
-
|
|
36
|
-
- **Description:**
|
|
37
|
-
Subscribes to `sensors/temperature`, applies a transformation (e.g., scales the value), and republishes it as processed data.
|
|
38
|
-
|
|
39
|
-
- **Example:**
|
|
40
|
-
|
|
41
|
-
```bash
|
|
42
|
-
python python/examples/data_transformer.py
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
Transforms data from `sensors/temperature` and republishes to `sensors/temperature/room1` it with a modified value.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
---
|
|
49
|
-
|
|
50
|
-
### `data_subscribe.py`
|
|
51
|
-
|
|
52
|
-
Subscribes to topics via the gateway and prints received messages.
|
|
53
|
-
|
|
54
|
-
- **Description:**
|
|
55
|
-
Useful for monitoring live data updates.
|
|
56
|
-
|
|
57
|
-
- **Example:**
|
|
58
|
-
|
|
59
|
-
```bash
|
|
60
|
-
python python/examples/data_subscribe.py
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
Prints all messages received from `sensors/temperature`.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
---
|
|
67
|
-
|
|
68
|
-
### `data_publish.py`
|
|
69
|
-
|
|
70
|
-
Publishes a single data point to a UNS topic.
|
|
71
|
-
|
|
72
|
-
- **Description:**
|
|
73
|
-
Sends a single temperature measurement (e.g., 22.5 °C) to the gateway, waits 10 seconds, then exits.
|
|
74
|
-
|
|
75
|
-
- **Example:**
|
|
76
|
-
|
|
77
|
-
```bash
|
|
78
|
-
python python/examples/data_publish.py
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
Publishes one temperature value to `sensors/temperature/room1`.
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
---
|
|
85
|
-
|
|
86
|
-
### `table_transformer.py`
|
|
87
|
-
|
|
88
|
-
Publishes a structured table-like JSON object as UNS table data.
|
|
89
|
-
|
|
90
|
-
- **Description:**
|
|
91
|
-
Sends summarized or grouped sensor data (e.g., temperature, humidity, status) to a topic.
|
|
92
|
-
|
|
93
|
-
- **Example:**
|
|
94
|
-
|
|
95
|
-
```bash
|
|
96
|
-
python python/examples/dtable_transformer.py
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
Publishes a table with room statistics (temperature, humidity, etc.) to `sensors/summary/room1`.
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
---
|
|
103
|
-
|
|
104
|
-
### `api_handler.py`
|
|
105
|
-
|
|
106
|
-
Registers and handles an example API endpoint for querying data.
|
|
107
|
-
|
|
108
|
-
- **Description:**
|
|
109
|
-
Demonstrates registering an API endpoint (`example/summary-1`) with query parameters and returning JSON responses.
|
|
110
|
-
|
|
111
|
-
- **Example:**
|
|
112
|
-
|
|
113
|
-
```bash
|
|
114
|
-
python python/examples/api_handler.py
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
Then test it with:
|
|
118
|
-
|
|
119
|
-
```bash
|
|
120
|
-
http://<gateway-host>:<gateway-port>/api/example/summary-1?filter=test&limit=10
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
## Auth
|
|
124
|
-
|
|
125
|
-
- If `config.json` sets `uns.jwksWellKnownUrl`, the gateway enforces JWT via JWKS (and path rules), matching UnsApiProxy behavior.
|
|
126
|
-
- Otherwise, it uses a dev `jwtSecret` ("CHANGEME"). For local testing, you can:
|
|
127
|
-
- Remove JWKS settings in `config.json` and rely on the dev secret, or
|
|
128
|
-
- Provide a valid Bearer token as required by your environment.
|
|
129
|
-
|
|
130
|
-
## Notes
|
|
131
|
-
|
|
132
|
-
- The gateway binds to `--addr` or the `UNS_GATEWAY_ADDR` env var. Examples pass `--addr` explicitly.
|
|
133
|
-
- On Unix/macOS, a stable UDS path (e.g., `/tmp/uns-gateway.sock`) is recommended for simplicity.
|
|
134
|
-
- All examples will auto-start the gateway when `--auto` is used.
|
|
1
|
+
# Python Examples for the UNS gRPC Gateway
|
|
2
|
+
|
|
3
|
+
These examples demonstrate how to use the Node-based UNS Gateway (MQTT + UNS infra) from Python via gRPC. They mirror the TypeScript examples for data, table, cron-like publishing, and API endpoints.
|
|
4
|
+
|
|
5
|
+
The gateway centralizes all UNS rules (packet format, sequenceId, interval, produced topics, handover). Python focuses on business logic and ML/ETL while calling the gateway.
|
|
6
|
+
|
|
7
|
+
## Prerequisites
|
|
8
|
+
|
|
9
|
+
- Build the Node project once: `npm run build`
|
|
10
|
+
- Generate Python stubs and venv: `cd python && ./scripts/setup.sh && source venv/bin/activate`
|
|
11
|
+
- Ensure `config.json` is present at repo root (Node gateway reads brokers and UNS options from it)
|
|
12
|
+
|
|
13
|
+
## Gateway Address
|
|
14
|
+
|
|
15
|
+
- If `--addr` is omitted, each script auto‑generates a unique address:
|
|
16
|
+
- Unix/macOS: `unix:/tmp/uns-gateway-<script>-<pid>.sock`
|
|
17
|
+
- Windows: `127.0.0.1:<ephemeral_port>`
|
|
18
|
+
- You can still pass an explicit `--addr` if you want a fixed address.
|
|
19
|
+
|
|
20
|
+
All examples accept `--addr` and `--auto`. With `--auto`, the example will spawn the gateway via `npm run gateway` and wait until it's ready.
|
|
21
|
+
|
|
22
|
+
Imports note: Examples add the generated stubs folder (`python/gen`) to `sys.path` so you can run them from the repo root or from the `python/` folder. Ensure you’ve run `./scripts/setup.sh` so `gen` exists.
|
|
23
|
+
|
|
24
|
+
Readiness: Examples call the gateway’s `Ready()` RPC to wait for the requested components (publisher/subscriber/API) to be active before publishing or subscribing. No manual sleeps are required.
|
|
25
|
+
|
|
26
|
+
## Common Flags
|
|
27
|
+
|
|
28
|
+
- `--addr`: Gateway address (`unix:/path.sock` or `host:port`)
|
|
29
|
+
- `--auto`: Auto-start the gateway if not running
|
|
30
|
+
|
|
31
|
+
## Scripts
|
|
32
|
+
### `data_transformer.py`
|
|
33
|
+
|
|
34
|
+
Transforms incoming sensor data and republishes it to a target topic.
|
|
35
|
+
|
|
36
|
+
- **Description:**
|
|
37
|
+
Subscribes to `sensors/temperature`, applies a transformation (e.g., scales the value), and republishes it as processed data.
|
|
38
|
+
|
|
39
|
+
- **Example:**
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
python python/examples/data_transformer.py
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Transforms data from `sensors/temperature` and republishes to `sensors/temperature/room1` it with a modified value.
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
### `data_subscribe.py`
|
|
51
|
+
|
|
52
|
+
Subscribes to topics via the gateway and prints received messages.
|
|
53
|
+
|
|
54
|
+
- **Description:**
|
|
55
|
+
Useful for monitoring live data updates.
|
|
56
|
+
|
|
57
|
+
- **Example:**
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
python python/examples/data_subscribe.py
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Prints all messages received from `sensors/temperature`.
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
### `data_publish.py`
|
|
69
|
+
|
|
70
|
+
Publishes a single data point to a UNS topic.
|
|
71
|
+
|
|
72
|
+
- **Description:**
|
|
73
|
+
Sends a single temperature measurement (e.g., 22.5 °C) to the gateway, waits 10 seconds, then exits.
|
|
74
|
+
|
|
75
|
+
- **Example:**
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
python python/examples/data_publish.py
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Publishes one temperature value to `sensors/temperature/room1`.
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
### `table_transformer.py`
|
|
87
|
+
|
|
88
|
+
Publishes a structured table-like JSON object as UNS table data.
|
|
89
|
+
|
|
90
|
+
- **Description:**
|
|
91
|
+
Sends summarized or grouped sensor data (e.g., temperature, humidity, status) to a topic.
|
|
92
|
+
|
|
93
|
+
- **Example:**
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
python python/examples/dtable_transformer.py
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Publishes a table with room statistics (temperature, humidity, etc.) to `sensors/summary/room1`.
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
### `api_handler.py`
|
|
105
|
+
|
|
106
|
+
Registers and handles an example API endpoint for querying data.
|
|
107
|
+
|
|
108
|
+
- **Description:**
|
|
109
|
+
Demonstrates registering an API endpoint (`example/summary-1`) with query parameters and returning JSON responses.
|
|
110
|
+
|
|
111
|
+
- **Example:**
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
python python/examples/api_handler.py
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Then test it with:
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
http://<gateway-host>:<gateway-port>/api/example/summary-1?filter=test&limit=10
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Auth
|
|
124
|
+
|
|
125
|
+
- If `config.json` sets `uns.jwksWellKnownUrl`, the gateway enforces JWT via JWKS (and path rules), matching UnsApiProxy behavior.
|
|
126
|
+
- Otherwise, it uses a dev `jwtSecret` ("CHANGEME"). For local testing, you can:
|
|
127
|
+
- Remove JWKS settings in `config.json` and rely on the dev secret, or
|
|
128
|
+
- Provide a valid Bearer token as required by your environment.
|
|
129
|
+
|
|
130
|
+
## Notes
|
|
131
|
+
|
|
132
|
+
- The gateway binds to `--addr` or the `UNS_GATEWAY_ADDR` env var. Examples pass `--addr` explicitly.
|
|
133
|
+
- On Unix/macOS, a stable UDS path (e.g., `/tmp/uns-gateway.sock`) is recommended for simplicity.
|
|
134
|
+
- All examples will auto-start the gateway when `--auto` is used.
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
from gateway.client import Client
|
|
2
|
-
from uns_gateway_pb2 import ApiQueryParam, ApiEventResponse
|
|
3
|
-
import json
|
|
4
|
-
|
|
5
|
-
client = Client()
|
|
6
|
-
|
|
7
|
-
# Register API with structured query params
|
|
8
|
-
qp = [
|
|
9
|
-
ApiQueryParam(name="filter", type="string", required=True, description="Filter za podatke"),
|
|
10
|
-
ApiQueryParam(name="limit", type="number", required=False, description="Koliko podatkov želiš"),
|
|
11
|
-
]
|
|
12
|
-
|
|
13
|
-
client.register_api(
|
|
14
|
-
topic="example/",
|
|
15
|
-
attribute="summary-1",
|
|
16
|
-
desc="Example API endpoint",
|
|
17
|
-
tags=["example", "demo"],
|
|
18
|
-
query_params=qp
|
|
19
|
-
)
|
|
20
|
-
|
|
21
|
-
# Handle API events
|
|
22
|
-
def handle_api(ev):
|
|
23
|
-
print(f"API request: {ev.path}, query={dict(ev.query)}")
|
|
24
|
-
body = {"status": "OK", "path": ev.path, "query": dict(ev.query)}
|
|
25
|
-
return ApiEventResponse(id=ev.id, status=200, headers={"Content-Type": "application/json"},
|
|
26
|
-
body=json.dumps(body))
|
|
27
|
-
|
|
28
|
-
client.api_stream(handle_event=handle_api)
|
|
1
|
+
from gateway.client import Client
|
|
2
|
+
from uns_gateway_pb2 import ApiQueryParam, ApiEventResponse
|
|
3
|
+
import json
|
|
4
|
+
|
|
5
|
+
client = Client()
|
|
6
|
+
|
|
7
|
+
# Register API with structured query params
|
|
8
|
+
qp = [
|
|
9
|
+
ApiQueryParam(name="filter", type="string", required=True, description="Filter za podatke"),
|
|
10
|
+
ApiQueryParam(name="limit", type="number", required=False, description="Koliko podatkov želiš"),
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
client.register_api(
|
|
14
|
+
topic="example/",
|
|
15
|
+
attribute="summary-1",
|
|
16
|
+
desc="Example API endpoint",
|
|
17
|
+
tags=["example", "demo"],
|
|
18
|
+
query_params=qp
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
# Handle API events
|
|
22
|
+
def handle_api(ev):
|
|
23
|
+
print(f"API request: {ev.path}, query={dict(ev.query)}")
|
|
24
|
+
body = {"status": "OK", "path": ev.path, "query": dict(ev.query)}
|
|
25
|
+
return ApiEventResponse(id=ev.id, status=200, headers={"Content-Type": "application/json"},
|
|
26
|
+
body=json.dumps(body))
|
|
27
|
+
|
|
28
|
+
client.api_stream(handle_event=handle_api)
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
from gateway.client import Client
|
|
2
|
-
import time
|
|
3
|
-
# Publish a single data point
|
|
4
|
-
client = Client()
|
|
5
|
-
client.publish_data(
|
|
6
|
-
topic="sensors/temperature",
|
|
7
|
-
attribute="room1",
|
|
8
|
-
value=22.5,
|
|
9
|
-
uom="°C"
|
|
10
|
-
)
|
|
11
|
-
time.sleep(10)
|
|
1
|
+
from gateway.client import Client
|
|
2
|
+
import time
|
|
3
|
+
# Publish a single data point
|
|
4
|
+
client = Client()
|
|
5
|
+
client.publish_data(
|
|
6
|
+
topic="sensors/temperature",
|
|
7
|
+
attribute="room1",
|
|
8
|
+
value=22.5,
|
|
9
|
+
uom="°C"
|
|
10
|
+
)
|
|
11
|
+
time.sleep(10)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
from gateway.client import Client
|
|
2
|
-
|
|
3
|
-
def handle_message(msg):
|
|
4
|
-
print(f"Callback got {msg.topic}: {msg.payload}")
|
|
5
|
-
# You could also transform, save, or push to another service
|
|
6
|
-
|
|
7
|
-
client = Client()
|
|
8
|
-
client.subscribe(["sensors/temperature"], callback=handle_message)
|
|
1
|
+
from gateway.client import Client
|
|
2
|
+
|
|
3
|
+
def handle_message(msg):
|
|
4
|
+
print(f"Callback got {msg.topic}: {msg.payload}")
|
|
5
|
+
# You could also transform, save, or push to another service
|
|
6
|
+
|
|
7
|
+
client = Client()
|
|
8
|
+
client.subscribe(["sensors/temperature"], callback=handle_message)
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
from gateway.client import Client, iso_now
|
|
2
|
-
import json
|
|
3
|
-
|
|
4
|
-
client = Client()
|
|
5
|
-
|
|
6
|
-
def transform_data(value):
|
|
7
|
-
|
|
8
|
-
return value * 1.1
|
|
9
|
-
|
|
10
|
-
def handle_message(msg):
|
|
11
|
-
payload = json.loads(msg.payload)
|
|
12
|
-
value = float(payload["value"])
|
|
13
|
-
|
|
14
|
-
transformed_value = transform_data(value)
|
|
15
|
-
client.publish_data("sensors/temperature", "room1", value=transformed_value, uom="°C")
|
|
16
|
-
|
|
17
|
-
client.subscribe(["sensors/temperature"], callback=handle_message)
|
|
1
|
+
from gateway.client import Client, iso_now
|
|
2
|
+
import json
|
|
3
|
+
|
|
4
|
+
client = Client()
|
|
5
|
+
|
|
6
|
+
def transform_data(value):
|
|
7
|
+
|
|
8
|
+
return value * 1.1
|
|
9
|
+
|
|
10
|
+
def handle_message(msg):
|
|
11
|
+
payload = json.loads(msg.payload)
|
|
12
|
+
value = float(payload["value"])
|
|
13
|
+
|
|
14
|
+
transformed_value = transform_data(value)
|
|
15
|
+
client.publish_data("sensors/temperature", "room1", value=transformed_value, uom="°C")
|
|
16
|
+
|
|
17
|
+
client.subscribe(["sensors/temperature"], callback=handle_message)
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
from gateway.client import Client, iso_now
|
|
2
|
-
import time
|
|
3
|
-
|
|
4
|
-
client = Client()
|
|
5
|
-
client.publish_table(
|
|
6
|
-
topic="sensors/summary/",
|
|
7
|
-
attribute="room1",
|
|
8
|
-
obj={
|
|
9
|
-
"temperature": 22.5,
|
|
10
|
-
"humidity": 55.2,
|
|
11
|
-
"status": "ok",
|
|
12
|
-
"error": None
|
|
13
|
-
},
|
|
14
|
-
data_group="room_stats"
|
|
15
|
-
)
|
|
1
|
+
from gateway.client import Client, iso_now
|
|
2
|
+
import time
|
|
3
|
+
|
|
4
|
+
client = Client()
|
|
5
|
+
client.publish_table(
|
|
6
|
+
topic="sensors/summary/",
|
|
7
|
+
attribute="room1",
|
|
8
|
+
obj={
|
|
9
|
+
"temperature": 22.5,
|
|
10
|
+
"humidity": 55.2,
|
|
11
|
+
"status": "ok",
|
|
12
|
+
"error": None
|
|
13
|
+
},
|
|
14
|
+
data_group="room_stats"
|
|
15
|
+
)
|
|
16
16
|
time.sleep(10)
|
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
import argparse
|
|
2
|
-
from .manager import GatewayManager
|
|
3
|
-
from . import client
|
|
4
|
-
import uns_gateway_pb2_grpc as gw
|
|
5
|
-
from .client import make_channel
|
|
6
|
-
|
|
7
|
-
def main():
|
|
8
|
-
parser = argparse.ArgumentParser()
|
|
9
|
-
parser.add_argument("--addr", default=None)
|
|
10
|
-
sub = parser.add_subparsers(dest="cmd", required=True)
|
|
11
|
-
|
|
12
|
-
# --- Publish ---
|
|
13
|
-
p_pub = sub.add_parser("pub")
|
|
14
|
-
p_pub.add_argument("topic")
|
|
15
|
-
p_pub.add_argument("attribute")
|
|
16
|
-
p_pub.add_argument("time_iso")
|
|
17
|
-
p_pub.add_argument("value", type=float)
|
|
18
|
-
p_pub.add_argument("--uom", default="")
|
|
19
|
-
p_pub.add_argument("--group", default="")
|
|
20
|
-
p_pub.add_argument("--cumulative", action="store_true")
|
|
21
|
-
p_pub.add_argument("--auto", action="store_true")
|
|
22
|
-
|
|
23
|
-
# --- Subscribe ---
|
|
24
|
-
p_sub = sub.add_parser("sub")
|
|
25
|
-
p_sub.add_argument("topics", nargs="+")
|
|
26
|
-
p_sub.add_argument("--auto", action="store_true")
|
|
27
|
-
|
|
28
|
-
# --- Register API ---
|
|
29
|
-
p_reg = sub.add_parser("regapi")
|
|
30
|
-
p_reg.add_argument("topic")
|
|
31
|
-
p_reg.add_argument("attribute")
|
|
32
|
-
p_reg.add_argument("--desc", default="")
|
|
33
|
-
p_reg.add_argument("--tag", action="append", default=[])
|
|
34
|
-
p_reg.add_argument("--param", action="append", default=[])
|
|
35
|
-
p_reg.add_argument("--auto", action="store_true")
|
|
36
|
-
|
|
37
|
-
# --- Unregister API ---
|
|
38
|
-
p_unreg = sub.add_parser("unregapi")
|
|
39
|
-
p_unreg.add_argument("topic")
|
|
40
|
-
p_unreg.add_argument("attribute")
|
|
41
|
-
p_unreg.add_argument("--auto", action="store_true")
|
|
42
|
-
|
|
43
|
-
# --- API Stream ---
|
|
44
|
-
p_stream = sub.add_parser("apistream")
|
|
45
|
-
p_stream.add_argument("--echo", action="store_true")
|
|
46
|
-
p_stream.add_argument("--auto", action="store_true")
|
|
47
|
-
|
|
48
|
-
args = parser.parse_args()
|
|
49
|
-
mgr = GatewayManager(args.addr, auto=getattr(args, "auto", False))
|
|
50
|
-
addr = mgr.ensure_running()
|
|
51
|
-
|
|
52
|
-
if args.cmd == "pub":
|
|
53
|
-
client.publish_data(
|
|
54
|
-
addr, topic=args.topic, attribute=args.attribute,
|
|
55
|
-
time_iso=args.time_iso, value_number=args.value,
|
|
56
|
-
uom=args.uom, data_group=args.group,
|
|
57
|
-
value_is_cumulative=args.cumulative
|
|
58
|
-
)
|
|
59
|
-
elif args.cmd == "sub":
|
|
60
|
-
client.subscribe(addr, args.topics)
|
|
61
|
-
elif args.cmd == "regapi":
|
|
62
|
-
with make_channel(addr) as ch:
|
|
63
|
-
stub = gw.UnsGatewayStub(ch)
|
|
64
|
-
client.register_api(stub, args.topic, args.attribute, args.desc, args.tag, args.param)
|
|
65
|
-
print("registered")
|
|
66
|
-
elif args.cmd == "unregapi":
|
|
67
|
-
with make_channel(addr) as ch:
|
|
68
|
-
stub = gw.UnsGatewayStub(ch)
|
|
69
|
-
client.unregister_api(stub, args.topic, args.attribute)
|
|
70
|
-
print("unregistered")
|
|
71
|
-
elif args.cmd == "apistream":
|
|
72
|
-
client.api_stream(addr, echo=args.echo)
|
|
73
|
-
|
|
74
|
-
if __name__ == "__main__":
|
|
75
|
-
main()
|
|
1
|
+
import argparse
|
|
2
|
+
from .manager import GatewayManager
|
|
3
|
+
from . import client
|
|
4
|
+
import uns_gateway_pb2_grpc as gw
|
|
5
|
+
from .client import make_channel
|
|
6
|
+
|
|
7
|
+
def main():
|
|
8
|
+
parser = argparse.ArgumentParser()
|
|
9
|
+
parser.add_argument("--addr", default=None)
|
|
10
|
+
sub = parser.add_subparsers(dest="cmd", required=True)
|
|
11
|
+
|
|
12
|
+
# --- Publish ---
|
|
13
|
+
p_pub = sub.add_parser("pub")
|
|
14
|
+
p_pub.add_argument("topic")
|
|
15
|
+
p_pub.add_argument("attribute")
|
|
16
|
+
p_pub.add_argument("time_iso")
|
|
17
|
+
p_pub.add_argument("value", type=float)
|
|
18
|
+
p_pub.add_argument("--uom", default="")
|
|
19
|
+
p_pub.add_argument("--group", default="")
|
|
20
|
+
p_pub.add_argument("--cumulative", action="store_true")
|
|
21
|
+
p_pub.add_argument("--auto", action="store_true")
|
|
22
|
+
|
|
23
|
+
# --- Subscribe ---
|
|
24
|
+
p_sub = sub.add_parser("sub")
|
|
25
|
+
p_sub.add_argument("topics", nargs="+")
|
|
26
|
+
p_sub.add_argument("--auto", action="store_true")
|
|
27
|
+
|
|
28
|
+
# --- Register API ---
|
|
29
|
+
p_reg = sub.add_parser("regapi")
|
|
30
|
+
p_reg.add_argument("topic")
|
|
31
|
+
p_reg.add_argument("attribute")
|
|
32
|
+
p_reg.add_argument("--desc", default="")
|
|
33
|
+
p_reg.add_argument("--tag", action="append", default=[])
|
|
34
|
+
p_reg.add_argument("--param", action="append", default=[])
|
|
35
|
+
p_reg.add_argument("--auto", action="store_true")
|
|
36
|
+
|
|
37
|
+
# --- Unregister API ---
|
|
38
|
+
p_unreg = sub.add_parser("unregapi")
|
|
39
|
+
p_unreg.add_argument("topic")
|
|
40
|
+
p_unreg.add_argument("attribute")
|
|
41
|
+
p_unreg.add_argument("--auto", action="store_true")
|
|
42
|
+
|
|
43
|
+
# --- API Stream ---
|
|
44
|
+
p_stream = sub.add_parser("apistream")
|
|
45
|
+
p_stream.add_argument("--echo", action="store_true")
|
|
46
|
+
p_stream.add_argument("--auto", action="store_true")
|
|
47
|
+
|
|
48
|
+
args = parser.parse_args()
|
|
49
|
+
mgr = GatewayManager(args.addr, auto=getattr(args, "auto", False))
|
|
50
|
+
addr = mgr.ensure_running()
|
|
51
|
+
|
|
52
|
+
if args.cmd == "pub":
|
|
53
|
+
client.publish_data(
|
|
54
|
+
addr, topic=args.topic, attribute=args.attribute,
|
|
55
|
+
time_iso=args.time_iso, value_number=args.value,
|
|
56
|
+
uom=args.uom, data_group=args.group,
|
|
57
|
+
value_is_cumulative=args.cumulative
|
|
58
|
+
)
|
|
59
|
+
elif args.cmd == "sub":
|
|
60
|
+
client.subscribe(addr, args.topics)
|
|
61
|
+
elif args.cmd == "regapi":
|
|
62
|
+
with make_channel(addr) as ch:
|
|
63
|
+
stub = gw.UnsGatewayStub(ch)
|
|
64
|
+
client.register_api(stub, args.topic, args.attribute, args.desc, args.tag, args.param)
|
|
65
|
+
print("registered")
|
|
66
|
+
elif args.cmd == "unregapi":
|
|
67
|
+
with make_channel(addr) as ch:
|
|
68
|
+
stub = gw.UnsGatewayStub(ch)
|
|
69
|
+
client.unregister_api(stub, args.topic, args.attribute)
|
|
70
|
+
print("unregistered")
|
|
71
|
+
elif args.cmd == "apistream":
|
|
72
|
+
client.api_stream(addr, echo=args.echo)
|
|
73
|
+
|
|
74
|
+
if __name__ == "__main__":
|
|
75
|
+
main()
|