|
| 1 | +*Copyright (C) 2025, Axis Communications AB, Lund, Sweden. All Rights Reserved.* |
| 2 | + |
| 3 | +# ACAP application that subscribes on Nexus |
| 4 | + |
| 5 | +This application is part of the *acap-communication* example. It is recommended to first |
| 6 | +read the README file of the *object_detector* application. |
| 7 | + |
| 8 | +## Introduction |
| 9 | + |
| 10 | +This application subscribes to a topic created by another application and logs the received data. |
| 11 | + |
| 12 | +### Connecting to Nexus |
| 13 | + |
| 14 | +The application creates a client and connects. The `Connect` function uses the current Linux user as |
| 15 | +the username, which in this case is *acap-object_consumer*. |
| 16 | + |
| 17 | +### Subscribing to a topic |
| 18 | + |
| 19 | +The application creates a `TopicDataSubscriber` to subscribe to *acap.object_detector*. |
| 20 | +The `ObjectLogger` listener class handles incoming data by logging it. |
| 21 | + |
| 22 | +> [!NOTE] |
| 23 | +> You can subscribe to topics that don't exist yet. Data will arrive once the topic is created and |
| 24 | +> published to. |
| 25 | +
|
| 26 | +## Access rights |
| 27 | + |
| 28 | +By default, an ACAP application can only access its own topics (prefixed with `acap.<appname>`) and |
| 29 | +public topics. Since *acap.object_detector* belongs to another application, this application needs |
| 30 | +permission to read from it. |
| 31 | + |
| 32 | +The *object_detector* application grants this permission in its manifest, |
| 33 | +giving *acap-object_consumer* read access to *acap.object_detector* and all sub-topics. |
| 34 | + |
| 35 | +## The manifest |
| 36 | + |
| 37 | +To be able to connect to Nexus, enable Nexus in the manifest: |
| 38 | + |
| 39 | +```json |
| 40 | +"resources": { |
| 41 | + "nexus_beta1": { |
| 42 | + "enabled": true |
| 43 | + } |
| 44 | +} |
| 45 | +``` |
| 46 | + |
| 47 | +The application will get access rights to create, delete, write to and subscribe to the topic |
| 48 | +*acap.object_consumer* and all topics that have this topic as a prefix. However, this |
| 49 | +application never creates any such topic. Instead, the application subscribes to the topic |
| 50 | +*acap.object_detector*. The access rights to read data from that topic is given to this |
| 51 | +application by the *object_detector* application. |
| 52 | + |
| 53 | +## Nexus API documentation |
| 54 | + |
| 55 | +[Link to documentation](https://developer.axis.com/acap/api/src/api/nexus-client-cpp/html/index.html) |
| 56 | + |
| 57 | +## Build the application |
| 58 | + |
| 59 | +> [!NOTE] |
| 60 | +> |
| 61 | +> For detailed information on how to build, install, and run ACAP applications, refer to the official ACAP documentation: [Build, install, and run](https://developer.axis.com/acap/develop/build-install-run/). |
| 62 | +> |
| 63 | +> Depending on the network your local build machine is connected to, you may need to add proxy |
| 64 | +> settings for Docker. See |
| 65 | +> [Proxy in build time](https://developer.axis.com/acap/develop/proxy/#proxy-in-build-time). |
| 66 | +
|
| 67 | +Standing in your working directory, run the following commands: |
| 68 | + |
| 69 | +```sh |
| 70 | +docker build --platform=linux/amd64 --build-arg ARCH=<ARCH> --tag <APP_IMAGE> . |
| 71 | +``` |
| 72 | + |
| 73 | +- `<ARCH>` is the SDK architecture, `armv7hf` or `aarch64`. |
| 74 | +- `<APP_IMAGE>` is the name to tag the image with, e.g., `consumer:1.0` |
| 75 | + |
| 76 | +Copy the result from the container image to a local directory `build`: |
| 77 | + |
| 78 | +```sh |
| 79 | +docker cp $(docker create --platform=linux/amd64 <APP_IMAGE>):/opt/app ./build |
| 80 | +``` |
| 81 | + |
| 82 | +The `build` directory contains the build artifacts, where the ACAP application |
| 83 | +is found with the suffix `.eap`. Depending on which SDK architecture that was |
| 84 | +chosen, one of following files should be found: |
| 85 | + |
| 86 | +- `object_consumer_1_0_0_aarch64.eap` |
| 87 | +- `object_consumer_1_0_0_armv7hf.eap` |
| 88 | + |
| 89 | +## Install and start the application |
| 90 | + |
| 91 | +Browse to the application page of the Axis device: |
| 92 | + |
| 93 | +```sh |
| 94 | +http://<AXIS_DEVICE_IP>/index.html#apps |
| 95 | +``` |
| 96 | + |
| 97 | +- Click on the tab `Apps` in the device GUI |
| 98 | +- Enable `Allow unsigned apps` toggle |
| 99 | +- Click `(+ Add app)` button to upload the application file |
| 100 | +- Browse to the newly built ACAP application, and select it |
| 101 | +- Click `Install` |
| 102 | +- Run the application by enabling the `Start` switch |
| 103 | + |
| 104 | +## Expected output |
| 105 | + |
| 106 | +To find the application log, browse to the *Apps* page, click on the |
| 107 | +three dots to the right of the application and select `App log`. |
| 108 | + |
| 109 | +If the *object_detector* application has also started, you will see |
| 110 | +messages about the received data in the log. Each message contains an object |
| 111 | +(human, bird or dog) and a distance. |
| 112 | + |
| 113 | +The log output may look like this: |
| 114 | + |
| 115 | +```text |
| 116 | +[log prefix] object_consumer[429721]: Application started |
| 117 | +[log prefix] object_consumer[429721]: Received data: {"distance":90,"object":"human"} |
| 118 | +[log prefix] object_consumer[429721]: Received data: {"distance":150,"object":"bird"} |
| 119 | +[log prefix] object_consumer[429721]: Received data: {"distance":120,"object":"dog"} |
| 120 | +[log prefix] object_consumer[429721]: Received data: {"distance":89,"object":"human"} |
| 121 | +[log prefix] object_consumer[429721]: Received data: {"distance":155,"object":"bird"} |
| 122 | +[log prefix] object_consumer[429721]: Received data: {"distance":122,"object":"dog"} |
| 123 | +[log prefix] object_consumer[429721]: Application terminated |
| 124 | +``` |
| 125 | + |
| 126 | +## License |
| 127 | + |
| 128 | +**[MIT License](./app/LICENSE)** |
0 commit comments