@alwaysai/device-agent 0.0.20 → 0.1.0
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/package.json +1 -1
- package/readme.md +138 -20
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -36,7 +36,7 @@ and add the following line to the end of the file:
|
|
|
36
36
|
|
|
37
37
|
On the target device, run:
|
|
38
38
|
|
|
39
|
-
```
|
|
39
|
+
```bash
|
|
40
40
|
$ curl -fsSL https://artifacts.alwaysai.co/device-agent/install-device-agent.sh | sudo -E bash -
|
|
41
41
|
```
|
|
42
42
|
|
|
@@ -52,7 +52,7 @@ Provisioning the device performs the following:
|
|
|
52
52
|
|
|
53
53
|
Run the following command on the target device to provision it:
|
|
54
54
|
|
|
55
|
-
```
|
|
55
|
+
```bash
|
|
56
56
|
$ curl -fsSL https://artifacts.alwaysai.co/device-agent/provision.sh | bash -s -- --email <email> --password <password> [--device-name <device_name>]
|
|
57
57
|
```
|
|
58
58
|
|
|
@@ -74,7 +74,7 @@ $ pm2 list
|
|
|
74
74
|
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
-
To restart the Device Agent run the following command:
|
|
77
|
+
To restart and update the Device Agent run the following command:
|
|
78
78
|
|
|
79
79
|
```bash
|
|
80
80
|
$ pm2 restart aai-agent
|
|
@@ -91,7 +91,7 @@ Use --update-env to update environment variables
|
|
|
91
91
|
If you'd like to only provision the device, but not start the Device Agent in
|
|
92
92
|
the background (skip step 3), run with the `--provision-only` flag:
|
|
93
93
|
|
|
94
|
-
```
|
|
94
|
+
```bash
|
|
95
95
|
$ curl -fsSL https://artifacts.alwaysai.co/device-agent/provision.sh | bash -s -- --email <email> --password <password> [--device-name <device_name>] --provision-only
|
|
96
96
|
```
|
|
97
97
|
|
|
@@ -116,11 +116,129 @@ project page of the alwaysAI Dashboard as well!
|
|
|
116
116
|
|
|
117
117
|
Now you can deploy to your device from the alwaysAI Dashboard.
|
|
118
118
|
|
|
119
|
+
## Enable Analytics through the alwaysAI Device Agent
|
|
120
|
+
|
|
121
|
+
### Configure the Device Agent
|
|
122
|
+
You can send information from your device to the alwaysAI cloud securely using
|
|
123
|
+
the Device Agent. These instructions assume you have provisioned your device
|
|
124
|
+
using the default script parameters and have the Device agent running (i.e. the
|
|
125
|
+
provisioning script was not run with the `--provision-only` flag set).
|
|
126
|
+
|
|
127
|
+
First, the Device Agent must be configured to enable Analytics Pass-through support. Confirm that the `ALWAYSAI_ANALYTICS_PASSTHROUGH` environment variable is set:
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
$ pm2 env 0 | grep ALWAYSAI
|
|
131
|
+
ALWAYSAI_ANALYTICS_PASSTHROUGH: 1
|
|
132
|
+
ALWAYSAI_LOG_TO_CONSOLE:
|
|
133
|
+
ALWAYSAI_LOG_LEVEL: debug
|
|
134
|
+
ALWAYSAI_DEVICE_AGENT_MODE: cloud
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Then confirm the RabbitMQ container is up and running:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
$ docker ps
|
|
141
|
+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
|
142
|
+
596157124a4b rabbitmq:3.11 "docker-entrypoint.s…" 32 minutes ago Up 21 minutes 4369/tcp, 5671/tcp, 15691-15692/tcp, 25672/tcp, 0.0.0.0:5672->5672/tcp alwaysAIRabbitMQContainer
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Configure the Application
|
|
146
|
+
|
|
147
|
+
From the application side, the `ALWAYSAI_CONNECT_TO_DEVICE_AGENT` environment
|
|
148
|
+
variable must be set. There are a few options:
|
|
149
|
+
|
|
150
|
+
#### In the app source
|
|
151
|
+
|
|
152
|
+
In your `app.py` file, make sure the top of your import statements looks like
|
|
153
|
+
this:
|
|
154
|
+
|
|
155
|
+
```python
|
|
156
|
+
import os
|
|
157
|
+
os.environ['ALWAYSAI_CONNECT_TO_DEVICE_AGENT']='1'
|
|
158
|
+
import edgeiq
|
|
159
|
+
```
|
|
160
|
+
You can import any other modules after `edgeiq`, but the other orders must be
|
|
161
|
+
maintained.
|
|
162
|
+
|
|
163
|
+
#### In the Dockerfile
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
ENV ALWAYSAI_CONNECT_TO_DEVICE_AGENT=1
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
#### In a docker-compose.yaml
|
|
170
|
+
|
|
171
|
+
Add the following section to the service for your app:
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
environment:
|
|
175
|
+
- ALWAYSAI_CONNECT_TO_DEVICE_AGENT=1
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Enable Publishing to Cloud
|
|
179
|
+
|
|
180
|
+
To enable cloud publishing for your application you can either run
|
|
181
|
+
`aai app enable-cloud-publish`, or update your `alwaysai.app.json` by adding the
|
|
182
|
+
following component in addition to any `models` or `scripts` components:
|
|
183
|
+
|
|
184
|
+
```json
|
|
185
|
+
"analytics: {
|
|
186
|
+
"enable_cloud_publish": true
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
So, a valid `alwaysai.app.json` for publishing analytics might look like this:
|
|
191
|
+
|
|
192
|
+
```json
|
|
193
|
+
{
|
|
194
|
+
"scripts": {
|
|
195
|
+
"start": "python app.py"
|
|
196
|
+
},
|
|
197
|
+
"models": {
|
|
198
|
+
"alwaysai/mobilenet_ssd": 4
|
|
199
|
+
},
|
|
200
|
+
"analytics": {
|
|
201
|
+
"enable_cloud_publish": true
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Finally, add a command to publish analytics to your `app.py`. Whenever this
|
|
207
|
+
command is used, it will publish the contents of the analytics message to the
|
|
208
|
+
cloud -- you can choose to call this every frame, or once every event
|
|
209
|
+
occurrence, however your app is designed. Each core computer vision service has
|
|
210
|
+
it's own `publish_analytics` method, which is called on the instance of the
|
|
211
|
+
class. Or, you can published a JSON-serializable message with
|
|
212
|
+
`edgeiq.publish_analytics()`. For instance, to publish object detection results
|
|
213
|
+
you can use:
|
|
214
|
+
|
|
215
|
+
```python
|
|
216
|
+
results = obj_detect.detect_objects(frame, confidence_level=.5)
|
|
217
|
+
try:
|
|
218
|
+
obj_detect.publish_analytics(results, tag=frame_count)
|
|
219
|
+
except edgeiq.PublishError as e:
|
|
220
|
+
print(e)
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
Finally, make sure to save all of your changes, and publish your application with
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
$ aai app publish
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
You can test that analytics are being viewed with `wscat`, using your application's project ID and a secure API key:
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
$ wscat -c "wss://analytics.alwaysai.co?projectId=[PROJECT_ID]&apiKey=[API_KEY]"
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Please contact the alwaysAI team if you need a secure API key.
|
|
236
|
+
|
|
119
237
|
## The alwaysAI Device Agent Command Line interface
|
|
120
238
|
|
|
121
239
|
The Device Agent can also be used directly on the device with it's command line interface.
|
|
122
240
|
|
|
123
|
-
```
|
|
241
|
+
```bash
|
|
124
242
|
$ aai-agent --help
|
|
125
243
|
Usage: aai-agent <subcommand> ...
|
|
126
244
|
|
|
@@ -152,8 +270,8 @@ Subcommands:
|
|
|
152
270
|
|
|
153
271
|
To see the output logs, run the following command:
|
|
154
272
|
|
|
155
|
-
```
|
|
156
|
-
export ALWAYSAI_LOG_TO_CONSOLE=1
|
|
273
|
+
```bash
|
|
274
|
+
$ export ALWAYSAI_LOG_TO_CONSOLE=1
|
|
157
275
|
```
|
|
158
276
|
|
|
159
277
|
### Install the application on the device
|
|
@@ -161,7 +279,7 @@ export ALWAYSAI_LOG_TO_CONSOLE=1
|
|
|
161
279
|
Now you can install the application on the device using the device agent. Run
|
|
162
280
|
the following on the device where the Device Agent is installed:
|
|
163
281
|
|
|
164
|
-
```
|
|
282
|
+
```bash
|
|
165
283
|
$ aai-agent app install --project <project_id> --release <release_hash>
|
|
166
284
|
```
|
|
167
285
|
|
|
@@ -170,27 +288,27 @@ $ aai-agent app install --project <project_id> --release <release_hash>
|
|
|
170
288
|
Run the following commands on the device where the Device Agent is installed:
|
|
171
289
|
|
|
172
290
|
Get application status:
|
|
173
|
-
```
|
|
291
|
+
```bash
|
|
174
292
|
$ aai-agent app status --project <project_id>
|
|
175
293
|
```
|
|
176
294
|
|
|
177
295
|
Start the application:
|
|
178
|
-
```
|
|
296
|
+
```bash
|
|
179
297
|
$ aai-agent app start --project <project_id>
|
|
180
298
|
```
|
|
181
299
|
|
|
182
300
|
Show the application logs:
|
|
183
|
-
```
|
|
301
|
+
```bash
|
|
184
302
|
$ aai-agent app logs --project <project_id>
|
|
185
303
|
```
|
|
186
304
|
|
|
187
305
|
Stop the application:
|
|
188
|
-
```
|
|
306
|
+
```bash
|
|
189
307
|
$ aai-agent app stop --project <project_id>
|
|
190
308
|
```
|
|
191
309
|
|
|
192
310
|
Uninstall the application:
|
|
193
|
-
```
|
|
311
|
+
```bash
|
|
194
312
|
$ aai-agent app uninstall --project <project_id>
|
|
195
313
|
```
|
|
196
314
|
|
|
@@ -204,7 +322,7 @@ If a new version of a model is published for an existing model ID, and an
|
|
|
204
322
|
application is already configured to be using that model ID, updating to the
|
|
205
323
|
new model can simply be done with:
|
|
206
324
|
|
|
207
|
-
```
|
|
325
|
+
```bash
|
|
208
326
|
$ aai-agent app stop --project <project_id>
|
|
209
327
|
$ aai-agent app update-models --project <project_id>
|
|
210
328
|
$ aai-agent app start --project <project_id>
|
|
@@ -215,7 +333,7 @@ $ aai-agent app start --project <project_id>
|
|
|
215
333
|
If you'd like to install an entirely new model to an application, replacing the
|
|
216
334
|
model the app was originally configured with, run the following command:
|
|
217
335
|
|
|
218
|
-
```
|
|
336
|
+
```bash
|
|
219
337
|
$ aai-agent app stop --project <project_id>
|
|
220
338
|
$ aai-agent app replace-models --project <project_id> --models <model_id_1> [<model_id_2> ...]
|
|
221
339
|
$ aai-agent app start --project <project_id>
|
|
@@ -225,7 +343,7 @@ If you plan on using this method, you can make your application source model ID
|
|
|
225
343
|
agnostic by providing the model ID to edgeIQ in the following way:
|
|
226
344
|
|
|
227
345
|
Select the first model in the config list:
|
|
228
|
-
```
|
|
346
|
+
```python
|
|
229
347
|
obj_detect = edgeiq.ObjectDetection(edgeiq._globals.MODEL_ID_LIST[0])
|
|
230
348
|
```
|
|
231
349
|
|
|
@@ -233,13 +351,13 @@ obj_detect = edgeiq.ObjectDetection(edgeiq._globals.MODEL_ID_LIST[0])
|
|
|
233
351
|
|
|
234
352
|
To download a model package from the alwaysAI cloud and unpack to a specific directory, run:
|
|
235
353
|
|
|
236
|
-
```
|
|
354
|
+
```bash
|
|
237
355
|
$ aai-agent get-model-package <model ID> [--path <destination path>]
|
|
238
356
|
```
|
|
239
357
|
|
|
240
358
|
For example, to download `alwaysai/yolo_v3` to `~/alwaysai` run:
|
|
241
359
|
|
|
242
|
-
```
|
|
360
|
+
```bash
|
|
243
361
|
$ aai-agent get-model-package alwaysai/yolo_v3 --path ~/alwaysai
|
|
244
362
|
```
|
|
245
363
|
|
|
@@ -251,13 +369,13 @@ Once the command completes, you'll see the model package in the
|
|
|
251
369
|
The Device Agent enables you to set and update environment variables for all
|
|
252
370
|
services or a single service of you application.
|
|
253
371
|
|
|
254
|
-
```
|
|
372
|
+
```bash
|
|
255
373
|
$ aai-agent app set-env <key=val> --project <project_id> [--service <service>]
|
|
256
374
|
```
|
|
257
375
|
|
|
258
376
|
For example, to set the following environment variable for the `alwaysai`
|
|
259
377
|
service run the following command on the device:
|
|
260
378
|
|
|
261
|
-
```
|
|
379
|
+
```bash
|
|
262
380
|
$ aai-agent app set-env TEST_ENV=1 --project <project_id> --service alwaysai
|
|
263
381
|
```
|