
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/client/3_manual_node_discovery.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_gallery_client_3_manual_node_discovery.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_gallery_client_3_manual_node_discovery.py:


Manual node discovery
=====================

This script showcases how the client can discover nodes
and query their description manually.

.. GENERATED FROM PYTHON SOURCE LINES 8-11

.. code-block:: Python


    from pyaseba.client import Client








.. GENERATED FROM PYTHON SOURCE LINES 12-13

We set up the client to not discover nodes automatically

.. GENERATED FROM PYTHON SOURCE LINES 13-18

.. code-block:: Python


    client = Client(automatic_query=False, ping_period_ms=0)
    connection = client.connect("tcp", port=33333)
    connection





.. rst-class:: sphx-glr-script-out

 .. code-block:: none


    1



.. GENERATED FROM PYTHON SOURCE LINES 19-20

With this configuration, waiting for nodes will not discover them

.. GENERATED FROM PYTHON SOURCE LINES 20-23

.. code-block:: Python


    client.wait_nodes(wait_ms=500)





.. rst-class:: sphx-glr-script-out

 .. code-block:: none


    {}



.. GENERATED FROM PYTHON SOURCE LINES 24-25

Instead, we need to first manually scan for node IDs

.. GENERATED FROM PYTHON SOURCE LINES 25-29

.. code-block:: Python


    scan = client.scan(wait_ms=500)
    scan





.. rst-class:: sphx-glr-script-out

 .. code-block:: none


    {1: {0}}



.. GENERATED FROM PYTHON SOURCE LINES 30-31

and then query them for a description

.. GENERATED FROM PYTHON SOURCE LINES 31-37

.. code-block:: Python


    for target, node_ids in scan.items():
        for node_id in node_ids:
            desc = client.query_description(node_id=node_id, wait_ms=500)
            print(f"Node {node_id}: {desc}")





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    Node 0: Description(name='SimpleNode', protocol_version=9, variables={'_productId': (34, 1), 'args': (2, 32), 'counter': (35, 1), 'id': (0, 1), 'source': (1, 1), 'value': (36, 1)}, local_events={'event': 'emitted at each control step after incrementing counter'}, user_events={}, functions={'duplicate': ('duplicates the input', [('input', 1), ('result', 1)]), 'square': ('set value to the square of the input', [('input', 1)])})




.. GENERATED FROM PYTHON SOURCE LINES 38-41

Once we have received them,
IDs and descriptions are accessible like
for automatically discovered nodes.

.. GENERATED FROM PYTHON SOURCE LINES 41-44

.. code-block:: Python


    client.descriptions





.. rst-class:: sphx-glr-script-out

 .. code-block:: none


    {1: {0: Description(name='SimpleNode', protocol_version=9, variables={'_productId': (34, 1), 'args': (2, 32), 'counter': (35, 1), 'id': (0, 1), 'source': (1, 1), 'value': (36, 1)}, local_events={'event': 'emitted at each control step after incrementing counter'}, user_events={}, functions={'duplicate': ('duplicates the input', [('input', 1), ('result', 1)]), 'square': ('set value to the square of the input', [('input', 1)])})}}



.. GENERATED FROM PYTHON SOURCE LINES 45-46

.. code-block:: Python

    client.close()








.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 1.034 seconds)


.. _sphx_glr_download_gallery_client_3_manual_node_discovery.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: 3_manual_node_discovery.ipynb <3_manual_node_discovery.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: 3_manual_node_discovery.py <3_manual_node_discovery.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: 3_manual_node_discovery.zip <3_manual_node_discovery.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
