Skip to content

Commit 0a2aaab

Browse files
committed
examples: standalone: move communicaton config section up the readme
1 parent 6a0cfea commit 0a2aaab

File tree

1 file changed

+41
-31
lines changed

1 file changed

+41
-31
lines changed

examples/standalone/README.md

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
# Standalone
22

3-
## Basic Implementation
3+
## Communication Config
44

5-
The most straightforward way to implement your own standalone device is:
5+
To connect your device to Enapter Cloud, you first need to generate a
6+
communication config.
67

7-
1. Subclass `enapter.standalone.Device`.
8-
2. Override `async def run(self) -> None` method to send telemetry and properties.
9-
3. Pass an instance of your device to `enapter.standalone.run`.
8+
> [!NOTE]
9+
> The following instruction applies only to v3 sites. If you have a v1 site,
10+
> follow [this
11+
> tutorial](https://developers.enapter.com/docs/tutorial/software-ucms/standalone)
12+
> to generate your communication config.
13+
14+
Generate a communication config using [Enapter
15+
CLI](https://github.com/Enapter/enapter-cli):
16+
17+
```bash
18+
enapter3 device communication-config generate --device-id "$YOUR_DEVICE_ID" --protocol MQTTS | jq .config | base64 --wrap=0
19+
```
20+
21+
## Device Implementation
1022

1123
Here's a basic example:
1224

@@ -30,6 +42,30 @@ if __name__ == "__main__":
3042
asyncio.run(main())
3143
```
3244

45+
<details>
46+
<summary>What's going on?</summary>
47+
48+
The most straightforward way to implement your own standalone device is:
49+
50+
1. Subclass `enapter.standalone.Device`.
51+
2. Override `async def run(self) -> None` method to send telemetry and
52+
properties.
53+
3. Pass an instance of your device to `enapter.standalone.run`.
54+
55+
`enapter.standalone.run` will take care of loading the communication config and
56+
connecting your device to an upstream.
57+
58+
</details>
59+
60+
## Running
61+
62+
Use the generated communication config to run your device:
63+
64+
```bash
65+
export ENAPTER_STANDALONE_COMMUNICATION_CONFIG="$YOUR_COMMUNICATION_CONFIG"
66+
python my_device.py
67+
```
68+
3369
## Handling Commands
3470

3571
`enapter.standalone.Device` dispatches incoming command execution requests to
@@ -73,32 +109,6 @@ Instead, use `asyncio.to_thread` to offload such work to a thread pool:
73109
await asyncio.to_thread(blocking_call())
74110
```
75111

76-
## Communication Config
77-
78-
> [!NOTE]
79-
> The following instruction applies only to v3 sites. If you have a v1 site,
80-
> follow [this
81-
> tutorial](https://developers.enapter.com/docs/tutorial/software-ucms/standalone)
82-
> to generate your communication config.
83-
84-
Generate a communication config using [Enapter
85-
CLI](https://github.com/Enapter/enapter-cli):
86-
87-
```bash
88-
enapter3 device communication-config generate --device-id "$YOUR_DEVICE_ID" --protocol MQTTS | jq .config | base64 --wrap=0
89-
```
90-
91-
</details>
92-
93-
## Running
94-
95-
Use the generated communication config to run your device:
96-
97-
```bash
98-
export ENAPTER_STANDALONE_COMMUNICATION_CONFIG="$YOUR_COMMUNICATION_CONFIG"
99-
python my_device.py
100-
```
101-
102112
## Running In Docker
103113

104114
Here's an example of a simple `Dockerfile`:

0 commit comments

Comments
 (0)