Esempio n. 1
0
def run_pub(locator):
    z = zenoh.Zenoh(locator, 'user', 'password')
    r_name = '/test/thr'
    print('Declaring Publisher for {}', r_name)
    pub = z.declare_publisher(r_name)

    size = int(args['size'])
    bs = bytearray()
    for i in range(0, size):
        bs.append(i % 256)

    while True:
        z.stream_data(pub, bytes(bs))

    z.close()
Esempio n. 2
0
def run_pub(locator):
    z = zenoh.Zenoh(locator, 'user', 'password')
    r_name = '/demo/hello/piton'
    print('Declaring Publisher for {}', r_name)
    pub = z.declare_publisher(r_name)

    count = 0
    for _ in range(1, 30):
        print('Sending data...')
        msg = 'Salut des pitone'
        bs = bytearray()
        bs.append(len(msg))
        bs.extend(msg.encode())
        z.stream_data(pub, bytes(bs))
        z.write_data('/demo/hello/ruby', bytes(bs))
        z.write_data('/demo/hello/ruby', bytes(bs))
        count += 1
        time.sleep(0.5)

    z.close()
Esempio n. 3
0
    def client_test(self):
        global replies
        locator = "tcp/127.0.0.1:7447"

        z1 = zenoh.Zenoh(locator)
        z1_peer = z1.info()[zenoh.Z_INFO_PEER_KEY].decode().rstrip('\0')
        self.assertEqual(locator, z1_peer)
        z1_sub1 = z1.declare_subscriber("/test/python/client/**",
                                        zenoh.SubscriberMode.push(),
                                        z1_sub1_listener)
        z1_sto1 = z1.declare_storage("/test/python/client/**",
                                     z1_sto1_listener, z1_sto1_handler)
        z1_pub1 = z1.declare_publisher("/test/python/client/z1_pub1")

        z2 = zenoh.Zenoh(locator)
        z2_peer = z2.info()[zenoh.Z_INFO_PEER_KEY].decode().rstrip('\0')
        self.assertEqual(locator, z2_peer)
        z2_sub1 = z2.declare_subscriber("/test/python/client/**",
                                        zenoh.SubscriberMode.push(),
                                        z2_sub1_listener)
        z2_sto1 = z2.declare_storage("/test/python/client/**",
                                     z2_sto1_listener, z2_sto1_handler)
        z2_pub1 = z2.declare_publisher("/test/python/client/z2_pub1")

        time.sleep(1)

        self.assertTrue(z1.running)
        self.assertTrue(z2.running)

        sent_res = ("/test/python/client/z1_wr1", "z1_wr1_spl1".encode())
        z1.write_data(sent_res[0], sent_res[1])
        rcvd_res = z1_sub1_mvar.get()
        self.assertEqual(sent_res, rcvd_res)
        rcvd_res = z2_sub1_mvar.get()
        self.assertEqual(sent_res, rcvd_res)
        rcvd_res = z1_sto1_mvar.get()
        self.assertEqual(sent_res, rcvd_res)
        rcvd_res = z2_sto1_mvar.get()
        self.assertEqual(sent_res, rcvd_res)

        z1.query("/test/python/client/**", "", reply_handler)
        replies_mvar.get()
        self.assertEqual(2, len(replies))
        self.assertEqual(sent_res, replies[0])
        self.assertEqual(sent_res, replies[1])
        replies = []

        z2.query("/test/python/client/**", "", reply_handler)
        replies_mvar.get()
        self.assertEqual(2, len(replies))
        self.assertEqual(sent_res, replies[0])
        self.assertEqual(sent_res, replies[1])
        replies = []

        sent_res = ("/test/python/client/**", "z2_wr1_spl1".encode())
        z2.write_data(sent_res[0], sent_res[1])
        rcvd_res = z1_sub1_mvar.get()
        self.assertEqual(sent_res, rcvd_res)
        rcvd_res = z2_sub1_mvar.get()
        self.assertEqual(sent_res, rcvd_res)
        rcvd_res = z1_sto1_mvar.get()
        self.assertEqual(sent_res, rcvd_res)
        rcvd_res = z2_sto1_mvar.get()
        self.assertEqual(sent_res, rcvd_res)

        z1.query("/test/python/client/**", "", reply_handler)
        replies_mvar.get()
        self.assertEqual(2, len(replies))
        self.assertEqual(sent_res, replies[0])
        self.assertEqual(sent_res, replies[1])
        replies = []

        z2.query("/test/python/client/**", "", reply_handler)
        replies_mvar.get()
        self.assertEqual(2, len(replies))
        self.assertEqual(sent_res, replies[0])
        self.assertEqual(sent_res, replies[1])
        replies = []

        sent_res = ("/test/python/client/z1_pub1", "z1_pub1_spl1".encode())
        z1.stream_data(z1_pub1, sent_res[1])
        rcvd_res = z1_sub1_mvar.get()
        self.assertEqual(sent_res, rcvd_res)
        rcvd_res = z2_sub1_mvar.get()
        self.assertEqual(sent_res, rcvd_res)
        rcvd_res = z1_sto1_mvar.get()
        self.assertEqual(sent_res, rcvd_res)
        rcvd_res = z2_sto1_mvar.get()
        self.assertEqual(sent_res, rcvd_res)

        z1.query("/test/python/client/**", "", reply_handler)
        replies_mvar.get()
        self.assertEqual(2, len(replies))
        self.assertEqual(sent_res, replies[0])
        self.assertEqual(sent_res, replies[1])
        replies = []

        z2.query("/test/python/client/**", "", reply_handler)
        replies_mvar.get()
        self.assertEqual(2, len(replies))
        self.assertEqual(sent_res, replies[0])
        self.assertEqual(sent_res, replies[1])
        replies = []

        sent_res = ("/test/python/client/z2_pub1", "z2_pub1_spl1".encode())
        z2.stream_data(z2_pub1, sent_res[1])
        rcvd_res = z1_sub1_mvar.get()
        self.assertEqual(sent_res, rcvd_res)
        rcvd_res = z2_sub1_mvar.get()
        self.assertEqual(sent_res, rcvd_res)
        rcvd_res = z1_sto1_mvar.get()
        self.assertEqual(sent_res, rcvd_res)
        rcvd_res = z2_sto1_mvar.get()
        self.assertEqual(sent_res, rcvd_res)

        z1.query("/test/python/client/**", "", reply_handler)
        replies_mvar.get()
        self.assertEqual(2, len(replies))
        self.assertEqual(sent_res, replies[0])
        self.assertEqual(sent_res, replies[1])
        replies = []

        z2.query("/test/python/client/**", "", reply_handler)
        replies_mvar.get()
        self.assertEqual(2, len(replies))
        self.assertEqual(sent_res, replies[0])
        self.assertEqual(sent_res, replies[1])
        replies = []

        z1.undeclare_subscriber(z1_sub1)
        z2.undeclare_subscriber(z2_sub1)
        z1.undeclare_storage(z1_sto1)
        z2.undeclare_storage(z2_sto1)
        z1.undeclare_publisher(z1_pub1)
        z2.undeclare_publisher(z2_pub1)

        z1.close()
        z2.close()

        time.sleep(1)  # let time for close msg to comme back from router

        self.assertFalse(z1.running)
        self.assertFalse(z2.running)
Esempio n. 4
0
import time
import signal
import zenoh

ap = argparse.ArgumentParser()
ap.add_argument("-z",
                "--zenohd",
                required=True,
                help="ip:port for the zenoh broker")

args = vars(ap.parse_args())


def callback(reply):
    if reply.kind == zenoh.QueryReply.STORAGE_DATA:
        print('Received: ({}, {}) '.format(reply.rname, reply.data))
    elif reply.kind == zenoh.Z_STORAGE_FINAL:
        print('Received Storage Final')
    else:
        print('Received Reply Final')


if __name__ == '__main__':
    z = zenoh.Zenoh(args['zenohd'], 'user', 'password')
    selector = '/demo/**'

    print('Execuring query {}', selector)
    z.query(selector, "", callback)

    time.sleep(2)
Esempio n. 5
0
import grovepi
import zenoh
import sys
import signal
import json
import time

sensor = 6

blue = 0  # The Blue colored sensor.
white = 1  # The White colored sensor.

z = zenoh.Zenoh(sys.argv[1], 'user'.encode(), 'password'.encode())
r_name = '/demo/temperature/orange'
print('Declaring publisher...')
pub = z.declare_publisher(r_name)


def catch_sig(sig, frame):
    z.close()
    exit(0)


signal.signal(signal.SIGINT, catch_sig)

while True:
    try:
        # This example uses the blue colored sensor.
        # The first parameter is the port, the second parameter is the type of sensor.
        grovepi.dht(sensor, white)
        [temp, humidity] = grovepi.dht(sensor, blue)