|
| 1 | +# KUKSA.val Quickstart |
| 2 | + |
| 3 | +The quickest possible way to get KUKSA.val up and running |
| 4 | + |
| 5 | +*Note: The examples in this document do not use TLS or access control.* |
| 6 | + |
| 7 | +## Starting broker |
| 8 | +First we want to run KUKSA.val databroker |
| 9 | + |
| 10 | +``` |
| 11 | +docker run -it --rm --net=host ghcr.io/eclipse/kuksa.val/databroker:master --insecure |
| 12 | +``` |
| 13 | + |
| 14 | + |
| 15 | +## Reading and Writing VSS data via CLI |
| 16 | +You can interact with the VSS datapoints using the cli clients. The first option is databroker-cli. |
| 17 | + |
| 18 | +This is, how you start it: |
| 19 | + |
| 20 | +``` |
| 21 | +docker run -it --rm --net=host ghcr.io/eclipse/kuksa.val/databroker-cli:master |
| 22 | +``` |
| 23 | + |
| 24 | +Here is how you can use it: |
| 25 | + |
| 26 | +``` |
| 27 | +client> get Vehicle.Speed |
| 28 | +-> Vehicle.Speed: ( NotAvailable ) |
| 29 | +client> feed Vehicle.Speed 200 |
| 30 | +-> Ok |
| 31 | +client> get Vehicle.Speed |
| 32 | +-> Vehicle.Speed: 200.00 |
| 33 | +client> quit |
| 34 | +Bye bye! |
| 35 | +
|
| 36 | +``` |
| 37 | + |
| 38 | +An alternative is the kuksa-client CLI (based on our Python client library). |
| 39 | + |
| 40 | +Here is how you start it: |
| 41 | + |
| 42 | +``` |
| 43 | +docker run -it --rm --net=host ghcr.io/eclipse-kuksa/kuksa-python-sdk/kuksa-client:main |
| 44 | +``` |
| 45 | + |
| 46 | +Here is how you can use it: |
| 47 | + |
| 48 | + |
| 49 | +``` |
| 50 | +Test Client> getValue Vehicle.Speed |
| 51 | +{ |
| 52 | + "path": "Vehicle.Speed" |
| 53 | +} |
| 54 | +
|
| 55 | +Test Client> setValue Vehicle.Speed 200 |
| 56 | +OK |
| 57 | +
|
| 58 | +Test Client> getValue Vehicle.Speed |
| 59 | +{ |
| 60 | + "path": "Vehicle.Speed", |
| 61 | + "value": { |
| 62 | + "value": 200.0, |
| 63 | + "timestamp": "2023-01-16T12:43:57.305350+00:00" |
| 64 | + } |
| 65 | +} |
| 66 | +
|
| 67 | +Test Client> quit |
| 68 | +gRPC channel disconnected. |
| 69 | +
|
| 70 | +``` |
| 71 | + |
| 72 | +## Reading and Writing VSS data with code |
| 73 | + |
| 74 | +To realize your ideas with KUKSA.val you need to write programs that interact with its API. The easiest way to achieve this is using our Python library. |
| 75 | + |
| 76 | +### Generating data |
| 77 | +Create a file `speed_provider.py` with the following content |
| 78 | + |
| 79 | +```python |
| 80 | +from kuksa_client.grpc import VSSClient |
| 81 | +from kuksa_client.grpc import Datapoint |
| 82 | + |
| 83 | +import time |
| 84 | + |
| 85 | +with VSSClient('127.0.0.1', 55555) as client: |
| 86 | + for speed in range(0,100): |
| 87 | + client.set_current_values({ |
| 88 | + 'Vehicle.Speed': Datapoint(speed), |
| 89 | + }) |
| 90 | + print(f"Feeding Vehicle.Speed to {speed}") |
| 91 | + time.sleep(1) |
| 92 | +print("Finished.") |
| 93 | +``` |
| 94 | + |
| 95 | +Do a `pip install kuksa-client` and start with |
| 96 | + |
| 97 | +``` |
| 98 | +python ./speed_provider.py |
| 99 | +``` |
| 100 | + |
| 101 | +### Subscribing data: |
| 102 | +Create a file `speed_subscriber.py` with the following content |
| 103 | + |
| 104 | +```python |
| 105 | +from kuksa_client.grpc import VSSClient |
| 106 | + |
| 107 | +with VSSClient('127.0.0.1', 55555) as client: |
| 108 | + |
| 109 | + for updates in client.subscribe_current_values([ |
| 110 | + 'Vehicle.Speed', |
| 111 | + ]): |
| 112 | + speed = updates['Vehicle.Speed'].value |
| 113 | + print(f"Received updated speed: {speed}") |
| 114 | +``` |
| 115 | + |
| 116 | +Do a `pip install kuksa-client` and start with |
| 117 | + |
| 118 | +``` |
| 119 | +python ./speed_subscriber.py |
| 120 | +``` |
| 121 | + |
| 122 | +## FAQ & Notes |
| 123 | +Frequently anticipated questions and tips. |
| 124 | + |
| 125 | +### This is not working on OS X |
| 126 | +Unfortunately OS X has a bug that does not allow you to use the Databroker default port 55555. To change when starting the server: |
| 127 | + |
| 128 | +``` |
| 129 | +docker run -it --rm --net=host ghcr.io/eclipse/kuksa.val/databroker:master --port 55556 --insecure |
| 130 | +``` |
| 131 | + |
| 132 | +Using the databroker-cli |
| 133 | + |
| 134 | +``` |
| 135 | +docker run -it --rm --net=host -e KUKSA_DATA_BROKER_PORT=55556 ghcr.io/eclipse/kuksa.val/databroker-cli:master |
| 136 | +``` |
| 137 | + |
| 138 | +Using kuksa-client CLI |
| 139 | + |
| 140 | +``` |
| 141 | +docker run -it --rm --net=host ghcr.io/eclipse-kuksa/kuksa-python-sdk/kuksa-client:main grpc://127.0.0.1:55556 |
| 142 | +``` |
| 143 | + |
| 144 | +### Docker desktop: Host networking not supported |
| 145 | +The examples above all used docker's `--net=host` option. That is quite convenient for development, as basically your containers "share" your hosts networking and there is no need for any port publishing. |
| 146 | + |
| 147 | +However when using Docker Desktop on Mac OS or Windows, [host networking is not supported](https://docs.docker.com/network/host/). |
| 148 | + |
| 149 | +One alternative is using a Docker distribution, that does support it even on Mac OS or Windows. [Rancher Desktop](https://rancherdesktop.io) is an alternative that does. |
| 150 | + |
| 151 | +With Docker Desktop you can still forward ports, so this should work: |
| 152 | + |
| 153 | +``` |
| 154 | +docker run -it --rm --publish 55556:55556 ghcr.io/eclipse/kuksa.val/databroker:master --port 55556 --insecure |
| 155 | +``` |
| 156 | + |
| 157 | +From your host computer you can now reach databroker at `127.0.0.1:55556`. To connect from another container, you need to use your computers IP address (**not** 127.0.0.1), i.e. to use the client |
| 158 | + |
| 159 | +``` |
| 160 | +docker run -it --rm -e KUKSA_DATA_BROKER_PORT=55556 -e KUKSA_DATA_BROKER_ADDR=<YOUR_IP> ghcr.io/eclipse/kuksa.val/databroker-cli:master |
| 161 | +``` |
| 162 | + |
| 163 | +Recent versions of the databroker-cli also support command line arguments, so you can also write |
| 164 | + |
| 165 | +``` |
| 166 | +docker run -it --rm ghcr.io/eclipse/kuksa.val/databroker-cli:master --server http://<YOUR_IP>:55556 |
| 167 | +``` |
| 168 | + |
| 169 | + |
| 170 | + |
| 171 | +### feed/set: Why is my data not updated? |
| 172 | +Some VSS points are "sensors", e.g. Vehicle.Speed. You can read/get Vehicle speed, but we are not expecting to be able to influence it via VSS. |
| 173 | +Historically components, that gather the actual vehicle speed from some sensors/busses in a vehicle and providing a VSS representation to kuksa.val have been called `feeders`. Hence, to update the current speed in the Rust-cli, you use |
| 174 | + |
| 175 | +``` |
| 176 | +feed Vehicle.Speed 200 |
| 177 | +``` |
| 178 | + |
| 179 | +while in the Python-cli you use |
| 180 | + |
| 181 | +``` |
| 182 | +set Vehicle.Speed 200 |
| 183 | +``` |
| 184 | + |
| 185 | +The other thing, that VSS provides you are "actuators" `Vehicle.Body.Trunk.Rear.IsOpen`. The most important thing to remember about actuators: Every actuators is also a sensor, so everything written on top applies as well! |
| 186 | +The second-most important thing is: For VSS actuatorss, it is expected that you might be able to influence the state of the real Vehicle by writing to them. So while being used as a sensor, you will get the current position of the Window in the example, you might also want to set the _desired_ position. |
| 187 | + |
| 188 | +You express this in the databroker-cli as |
| 189 | + |
| 190 | +``` |
| 191 | +set Vehicle.Body.Trunk.Rear.IsOpen true |
| 192 | +``` |
| 193 | + |
| 194 | +In kuksa-client cli you do |
| 195 | + |
| 196 | +``` |
| 197 | +Test Client> setValue -a targetValue Vehicle.Body.Trunk.Rear.IsOpen True |
| 198 | +``` |
| 199 | + |
| 200 | +In the code examples above you would do |
| 201 | + |
| 202 | +```python |
| 203 | +client.set_target_values({ |
| 204 | + 'Vehicle.Body.Trunk.Rear.IsOpen': Datapoint(True), |
| 205 | + }) |
| 206 | +``` |
| 207 | + |
| 208 | + |
| 209 | +### All I see is Python, shouldn't this be high-performance? |
| 210 | +Our Python library makes it easy to interact with databroker. While this is often sufficient for many applications, you are not limited by it: Databroker's native interface is based on GRPC, a high-performance GRPC framework. GRPC enables you to generate bindings for _any_ language. Check the [GRPC website](https://grpc.io) and take a look at the [databroker interface definitions](https://github.com/eclipse/kuksa.val/tree/master/proto/kuksa/val/v1). |
0 commit comments