From a788bfd834c0f50662f6379ef24b4c5ee37c5431 Mon Sep 17 00:00:00 2001 From: Charles-Schleich Date: Thu, 19 Sep 2024 15:46:56 +0000 Subject: [PATCH] deploy: 9382d7223bb1123cb090a0aaf52df9d2402a1905 --- docs/getting-started/first-app/index.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/getting-started/first-app/index.html b/docs/getting-started/first-app/index.html index a521463c..767170ea 100644 --- a/docs/getting-started/first-app/index.html +++ b/docs/getting-started/first-app/index.html @@ -1,9 +1,10 @@ Your first Zenoh app · Zenoh - pub/sub, geo distributed storage, query

Your first Zenoh app

Let us take a step-by-step approach in putting together your first Zenoh application in Python. +

Your first Zenoh app

Let us take a step-by-step approach in putting together your first Zenoh application in Python. As the first step, let us see how we get some data from a temperature sensor in our kitchen. Then we see how we can route this data to store and perform some analytics.

Before cranking some code, let’s define some terminology.

Zenoh deals with keys/values where each key is a path and is associated to a value. A key looks like just a Unix file system path, such as myhome/kitchen/temp. The value can be defined with different -encodings (string, JSON, raw bytes buffer…).

Let’s get started!

Pub/sub in Zenoh

First, let’s write an application, z_sensor.py that will produce temperature measurements at each second:

import zenoh, random, time
+encodings (string, JSON, raw bytes buffer…).

Let’s get started!

Pub/sub in Zenoh

First thing first, we need to install the zenoh Python library.

pip install eclipse-zenoh==1.0.0b2
+

The examples are updated to use the 1.0 version currently in beta, which is why version must be specified in the installation command. You can find more information about the 1.0 changes in the migration guides.

Then, let’s write an application, z_sensor.py that will produce temperature measurements at each second:

import zenoh, random, time
 
 random.seed()
 
@@ -29,9 +30,8 @@
     session = zenoh.open()
     sub = session.declare_subscriber('myhome/kitchen/temp', listener)
     time.sleep(60)
-

Install the library and start the subscriber

python3 z_subscriber.py
-

The subscriber waits for an update on myhome/kitchen/temp. -Now start z_sensor.py as follows

python3 z_sensor.py
+

Start the subscriber:

python3 z_subscriber.py
+

The subscriber waits for an update on myhome/kitchen/temp.

Now start z_sensor.py as follows

python3 z_sensor.py
 

You can see the values produced by the sensor being consumed by the subscriber.

Store and Query in Zenoh

As the next step, let’s see how the value generated by a publisher can be stored in Zenoh. For this, we use Zenoh router (zenohd). By default, a Zenoh router starts without any storage. In order to store the temperature, we need to configure one.