def main(address, selector):
    # client configuration
    conf = {
        'mode': 'client',
        'peer': '{}'.format(address),
    }

    print("Openning session...")
    zenoh = Zenoh(conf)

    print("New workspace...")
    workspace = zenoh.workspace()

    # getting the data from zenoh, it can come from a storage or an eval
    print("Get Data from '{}'...".format(selector))

    output_data = []
    for data in workspace.get(selector):
        _, _, m, s, n = data.path.split('/')
        m = int(m)
        s = int(s)
        n = int(n)
        output_entry = {
            'm': m,
            's': s,
            'n': n,
            'value': data.value.get_content(),
            'timestamp': data.timestamp
        }
        output_data.append(output_entry)

    sorted_output_data = sorted(output_data, key=lambda k: k['n'])

    for data in sorted_output_data:
        print(data)

    zenoh.close()
Esempio n. 2
0
parser.add_argument('--selector', '-s', dest='selector',
                    default='/demo/example/**',
                    type=str,
                    help='The selection of resources to get.')

args = parser.parse_args()
conf = { "mode": args.mode }
if args.peer is not None:
    conf["peer"] = ",".join(args.peer)
if args.listener is not None:
    conf["listener"] = ",".join(args.listener)
selector = args.selector

# zenoh-net code  --- --- --- --- --- --- --- --- --- --- ---

# initiate logging
zenoh.init_logger()

print("Openning session...")
zenoh = Zenoh(conf)

print("New workspace...")
workspace = zenoh.workspace()

print("Get Data from '{}'...".format(selector))
for data in workspace.get(selector):
    print('  {} : {}  (encoding: {} , timestamp: {})'.format(
        data.path, data.value.get_content(), data.value.encoding_descr(), data.timestamp))

zenoh.close()
    sample_id = 0

    conf = {
        'mode': 'client',
        'peer': '{}'.format(address),
    }

    print("Opening Zenoh session...")
    zenoh = Zenoh(conf)

    # Create a new storage called my-storage
    path = '/@/router/local/plugin/storages/backend/memory/storage/my-storage'

    # Workspace creation
    print("New Zenoh workspace...")
    storage = zenoh.workspace()

    # Clearing the router
    print("Clearing the router first..")
    try:
        storage.delete(storage_path)
        print("Clear router")
    except Exception:
        print("Router is good")
        pass

    # Storage creation
    print("Creating storage...")
    value = {"path_expr": storage_path + '/**'}
    storage.put(path, value)
    workspace = zenoh.workspace(storage_path)