Skip to content

Commit e7023c5

Browse files
committed
Adding the counter sample
1 parent 68beb16 commit e7023c5

File tree

1 file changed

+71
-19
lines changed

1 file changed

+71
-19
lines changed

articles/iot-operations/develop-edge-apps/quickstart-get-started-sdks.md

Lines changed: 71 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -266,22 +266,6 @@ After Azure IoT Operations is deployed, you need to configure it for development
266266
1. Create the trust bundle ConfigMap for the Broker to authentication x509 clients
267267
1. Configure a `BrokerListener` and `BrokerAuthentication` resources for SAT and x509 auth
268268

269-
## Shell configuration
270-
271-
The samples within [Azure IoT Operations SDKs github repository](https://github.com/Azure/iot-operations-sdks) read configuration from environment variables. We have provided an `.env` file in the repository root that exports the variables used by the samples to connect to the MQTT Broker. Edit the `.env` file to set the values for your environment, or use the default values provided in the file:
272-
273-
1. Navigate to the repository root directory:
274-
275-
```bash
276-
cd <REPOSITORY ROOT>
277-
```
278-
279-
1. Load the environment variables into your shell:
280-
281-
```bash
282-
source .env
283-
```
284-
285269
<!-- TODO: Check why this only works with VSCode Dev Containers when I do: kubectl port-forward -n azure-iot-operations service/aio-broker-external 8883:8883 -->
286270
## Testing the installation
287271

@@ -311,11 +295,79 @@ To test the setup is working correctly, use `mosquitto_pub` to connect to the MQ
311295
mosquitto_pub -L mqtts://localhost:8884/hello -m world --cafile $SESSION/broker-ca.crt -D CONNECT authentication-method K8S-SAT -D CONNECT authentication-data $(cat $SESSION/token.txt) --debug
312296
```
313297

314-
## Testing MQTT session client sample
298+
## Run a Sample
299+
300+
This sample demonstrates a simple communication between a client and a server using [telemetry](https://github.com/Azure/iot-operations-sdks/blob/main/doc/reference/telemetry.md) and [remote procedure call (RPC)](https://github.com/Azure/iot-operations-sdks/blob/main/doc/reference/rpc-protocol.md). The server tracks the value of a counter and accepts RPC requests from the client to either read or increment that counter.
301+
302+
1. Install the [.NET 9.0 SDK](https://dotnet.microsoft.com/download/dotnet/9.0)
303+
304+
1. The samples within [Azure IoT Operations SDKs github repository](https://github.com/Azure/iot-operations-sdks) read configuration from environment variables. We have provided an `.env` file in the repository root that exports the variables used by the samples to connect to the MQTT Broker. Edit the `.env` file to set the values for your environment, or use the default values provided in the file.
305+
306+
1. Navigate to the `CounterServer` sample directory:
307+
308+
```bash
309+
cd <REPOSITORY ROOT>/dotnet/samples/Protocol/Counter/CounterServer/
310+
```
311+
312+
1. Build the sample:
313+
314+
```bash
315+
dotnet build
316+
```
317+
318+
1. Run the sample:
319+
320+
```bash
321+
source `git rev-parse --show-toplevel`/.env; export AIO_MQTT_CLIENT_ID=counter-server; dotnet run
322+
```
323+
324+
1. Open a new shell and navigate to the `CounterClient` sample directory:
325+
326+
```bash
327+
cd <REPOSITORY ROOT>/dotnet/samples/Protocol/Counter/CounterClient/
328+
```
329+
330+
1. Build the sample:
331+
332+
```bash
333+
dotnet build
334+
```
335+
336+
1. Run the sample:
337+
338+
```bash
339+
source `git rev-parse --show-toplevel`/.env; export AIO_MQTT_CLIENT_ID=counter-client; export COUNTER_SERVER_ID=counter-server; dotnet run
340+
```
341+
342+
1. You should see the client and server communicating, with the client sending requests to read and increment the counter value. This is an example of the output you might see:
343+
344+
```output
345+
info: CounterClient.CounterClient[0]
346+
Telemetry received from counter-server: CounterValue=1
347+
info: CounterClient.CounterClient[0]
348+
Telemetry received from counter-server: CounterValue=2
349+
info: CounterClient.CounterClient[0]
350+
Telemetry received from counter-server: CounterValue=3
351+
...
352+
```
353+
354+
<!-- ## Shell configuration
355+
356+
The samples within [Azure IoT Operations SDKs github repository](https://github.com/Azure/iot-operations-sdks) read configuration from environment variables. We have provided an `.env` file in the repository root that exports the variables used by the samples to connect to the MQTT Broker. Edit the `.env` file to set the values for your environment, or use the default values provided in the file:
357+
358+
1. Navigate to the repository root directory:
315359

316-
This sample demonstrates connecting to MQTT broker using the MQTT session client, and sending and receiving telemetry.
360+
```bash
361+
cd <REPOSITORY ROOT>
362+
```
363+
364+
1. Load the environment variables into your shell:
365+
366+
```bash
367+
source .env
368+
```
369+
-->
317370

318-
- TODO
319371

320372
## Configuration summary
321373

0 commit comments

Comments
 (0)