You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/docs/getting-started/first-app.md
+28-29Lines changed: 28 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,10 +10,10 @@ Let us take a step-by-step approach in putting together your first Zenoh applica
10
10
As the first step, let us see how we get some data from a temperature sensor in our kitchen.
11
11
Then we see how we can route this data to store and perform some analytics.
12
12
13
-
Before cranking some code, let's define some terminology.
13
+
Before cranking some code, let's define some terminology.
14
14
15
15
<b>Zenoh</b> deals with <i>keys/values</i> where each key is a <i>path</i> and is associated to a <i>value</i>. A key looks like just a Unix file system path, such as ```myhome/kitchen/temp```. The value can be defined with different
16
-
encodings (string, JSON, raw bytes buffer...).
16
+
encodings (string, JSON, raw bytes buffer...).
17
17
<!-- To query the values stored by Zenoh, we use <i>selectors</i>. As the name suggest, a <i>selector</i> can use wildcards, such as <b>*</b> and <b>**</b> to represent a set of paths, such as, ```myhome/*/temp```. -->
18
18
19
19
Let's get started!
@@ -37,15 +37,15 @@ def read_temp():
37
37
return random.randint(15, 30)
38
38
39
39
if__name__=="__main__":
40
-
session =zenoh.open(zenoh.Config())
41
-
key ='myhome/kitchen/temp'
42
-
pub = session.declare_publisher(key)
43
-
whileTrue:
44
-
t = read_temp()
45
-
buf =f"{t}"
46
-
print(f"Putting Data ('{key}': '{buf}')...")
47
-
pub.put(buf)
48
-
time.sleep(1)
40
+
withzenoh.open(zenoh.Config())as session:
41
+
key ='myhome/kitchen/temp'
42
+
pub = session.declare_publisher(key)
43
+
whileTrue:
44
+
t = read_temp()
45
+
buf =f"{t}"
46
+
print(f"Putting Data ('{key}': '{buf}')...")
47
+
pub.put(buf)
48
+
time.sleep(1)
49
49
```
50
50
51
51
Now we need a subscriber, `z_subscriber.py` that can receive the measurements:
0 commit comments