# NEP+ middleware documentation

## What is NEP+?

**NEP+ middleware** is a software framework that acts as an intermediary between different applications, systems, or components, facilitating communication and data exchange between them. In simple words, NEP+ middleware allows different software components to interact with each other seamlessly, making it easier to develop complex software systems.

{% hint style="info" %}
In Japanese, NEP+ is pronounced as *ネプ プラス/nepu purasu*
{% endhint %}

{% hint style="info" %}
In English, the pronunciation *nepu* is kept. Examples: *nepu pləs*
{% endhint %}

## Empowering Human-Centered Development

NEP+ stands out as middleware for several reasons:

**Human-Centered Design:** NEP+ is specifically designed with human-centered principles in mind, focusing on simplicity, ease of use, and accessibility. This makes it particularly suitable for developers and users who may not have extensive technical expertise.&#x20;

**Cross-Platform Compatibility:** NEP+ is designed to seamlessly operate across various operating systems, including Windows, macOS, Linux, and Android. This broad compatibility ensures that NEP+ can be easily integrated into diverse software environments.

**Multi-Language Support:** NEP+ facilitates communication between components developed in different programming languages. This means that developers can leverage their preferred languages while still achieving interoperability within their applications.&#x20;

**Versatility:** NEP+ offers a range of options, tools, and interfaces tailored for various applications in Human-Robot Interaction (HRI) and Human-Machine Interaction (HMI) domains. This versatility enables developers to create a wide range of interactive applications, from robotics systems to digital twins.&#x20;

**Empowering Developers:** NEP+ aims to empower both novice and experienced developers by providing intuitive tools and interfaces for integrating human-machine interaction applications. This focus on empowerment makes NEP+ accessible to a broader audience, fostering innovation and collaboration in the development community.

## NEP+ middleware components:

<table data-view="cards" data-full-width="false"><thead><tr><th align="center"></th><th></th><th data-hidden></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td align="center"><mark style="color:blue;"><strong>NEP libraries</strong></mark></td><td>Comprise a collection of high-level communication libraries available for modern and widely-used programming languages. They empower the exchange of messages between programs executed on a single computer or across multiple computers using TCP sockets</td><td></td><td></td></tr><tr><td align="center"><mark style="color:blue;"><strong>NEP+ App</strong></mark></td><td>A graphical interface (GUI) designed for managing message routing between components and monitoring their communication flow. No expertise is necessary to use this interface, as it comes pre-installed as a ready-to-use application for Windows, Mac, and Ubuntu operating systems</td><td></td><td></td></tr><tr><td align="center"><mark style="color:blue;"><strong>NEP CLI</strong></mark></td><td><p>A command-line interface (CLI) for managing message routing between components and monitoring their communication flow. Tailored for command line enthusiasts seeking enhanced productivity, as well as for advanced or more traditional developers</p><p><br></p></td><td></td><td></td></tr></tbody></table>

{% hint style="success" %}
**NEP libraries,** **NEP+ App** and **NEP CLI** were designed to empower **ZeroMQ** message libraries, enabling [<mark style="color:blue;">service discovery</mark>](#user-content-fn-1)[^1] and [<mark style="color:blue;">data serialization</mark>](#user-content-fn-2)[^2]
{% endhint %}

## Getting Started for Absolute Beginners with an Out-of-the-Box Example

Are you tired of the boring 'hello world' example that requires learning new concepts and installing numerous dependencies by writing commands in a terminal, sometimes leading to failures in achieving the intended results? Let's begin with a zero-code, zero-command-line, fully interactive 'hello world' example that uses your webcam and artificial intelligence to display your skeleton. I hope this example can provide a more enjoyable introduction for you in three simple steps:

Soon ...

## Getting Started for Command Line Enthusiasts with a Python Example

Here is the traditional  'hello world' in four simple steps:

**Requirements:**&#x20;

* [x] Python >= 2.7  or Python >= 3.6&#x20;
* [x] Node.js > 16

1.-Install the NEP CLI using **npm** and the nep Python library using **pip**

{% hint style="info" %}
**`npm`** is the package manager for Node.js, and **`pip`** is the package installer for Python
{% endhint %}

```
pip install nep
npm -g install nep-cli
```

2.- Run the **NEP master server** using the next line:

```
nep master
```

3.- Run the following Python script for sending messages:

```python
import nep
import time

# Create a new nep node
node = nep.node('publisher') 

# Create a publisher for the "test" topic using JSON format
pub = node.new_pub('test', 'json')

print ("Ctrl + C for stopping the program")
i = 0
while True:
    # Your analysis code goes here...
    i += 1
    
    # Prepare the message as a Python dictionary
    msg = {'result': i}
    
    # Publish the message
    pub.publish(msg)
    
    # Add a small time delay for visualization purposes
    time.sleep(1)     
```

4.- Run the following Python script for reading and displaying messages:

```python
import nep
import time

# Create a new nep node with a unique name
node = nep.node('susbcriber')

# Create a subscriber for the "test" topic using JSON format
sub = node.new_sub('test', 'json')

while True:
    # Read data in a non-blocking mode
    s, msg = sub.listen()

    # If there is data in the socket, print it and increment i
    if s:
        print(msg)
        print ("Ctrl + C for stopping the program")

    # A small sleep to reduce computational load
    time.sleep(0.0001)

```

## Getting Started for Sending Messages from Computer A to Computer B using Python

{% hint style="info" %}
The **NEP master server** must be executed using **NEP-CLI** or **NEP+ App** in either computer A or B.&#x20;
{% endhint %}

{% hint style="warning" %}
In this example, we will run the **NEP master** on computer B. Therefore, for programs on computer A that need to send and receive messages from computer B, it is necessary to specify the IP address of computer B.
{% endhint %}

**Requirements computer A (do not require installation of NEP-CLI):**&#x20;

1.- Install nep library

* [x] Python >= 2.7  or Python >= 3.6&#x20;

```
pip install -nep
```

**Requirements computer B ( require installation of NEP-CLI):**&#x20;

* [x] Python >= 2.7  or Python >= 3.6&#x20;
* [x] Node.js > 16

2.-Install the NEP CLI using **npm** and the nep Python library using **pip**

```
pip install nep
npm -g install nep-cli
```

{% hint style="info" %}
If you have already installed NEP+ libraries in Python, it is recommended to update to the latest version using **pip install -U nep**
{% endhint %}

3.- Run the **NEP master server** using the next line:

```
nep master
```

4.- Figure out the IP address of **computer B** (in the network connected to computer A). For that, you can use some of the next commands in **computer B:**

```
nep ip
```

**You will see something like this:**

```
Wi-Fi (Wi-Fi) IP Address: 192.168.0.1
Ethernet IP Address: 192.168.0.2
```

In this case, computer B can be connected to other computers in the network using Ethernet over the IP = 192.168.0.1  or Wi-Fi over the IP = 192.168.0.2

In this second example Ethernet connection is not available, therefore you must check your cable connection or networking configuration:&#x20;

```
Wi-Fi (Wi-Fi) IP Address: 192.168.0.1
No Ethernet IPv4 address found.
```

5.- In computer A using the IP address obtained in computer B run the next code:

{% hint style="warning" %}
Note: Update the IP value in <mark style="color:orange;">**line 8**</mark> with the correct address obtained in step 4. If communication is unsuccessful, ensure that the entered IP address is accurate
{% endhint %}

<pre class="language-python" data-line-numbers><code class="lang-python">import nep
import time

# Create a new nep node
node = nep.node('publisher') 

# Change this value with the IP address of computer B
<strong>conf = node.hybrid('192.168.0.101') 
</strong># Create a publisher for the "test" topic using JSON format
<strong>pub = node.new_pub('test', 'json', conf)
</strong>
print ("Ctrl + C for stopping the program")
i = 0
while True:
    # Your analysis code goes here...
    i += 1
    
    # Prepare the message as a Python dictionary
    msg = {'result': i}
    
    # Publish the message
    pub.publish(msg)
    
    # Add a small time delay for visualization purposes
    time.sleep(1)   
</code></pre>

6.- Run the following Python script for reading and displaying messages:

```python
import nep
import time

# Create a new nep node with a unique name
node = nep.node('susbcriber')

# Create a subscriber for the "test" topic using JSON format
sub = node.new_sub('test', 'json')

while True:
    # Read data in a non-blocking mode
    s, msg = sub.listen()

    # If there is data in the socket, print it and increment i
    if s:
        print(msg)
        print ("Ctrl + C for stopping the program")

    # A small sleep to reduce computational load
    time.sleep(0.0001)
```

{% hint style="info" %}
When executing programs on the computer running the **NEP master server** using **NEP-CLI** or **NEP+ App**, there's no need to specify the **IP address**. However, for communication with these programs from other computers, it's essential to define the **IP address** of the computer running the **NEP master server** in the code, such as in step 5.
{% endhint %}

## Installing NEP+ libraries in Python, C#, Node.js and Java

NEP+ supports a wide range of modern and popular programming languages, and installing them is as simple as a few command lines using official package managers.

{% tabs %}
{% tab title="Python" %}
Install the nep library for Python using **pip**

```shell
pip install nep
```

For users of **pycharm** just search the **nep** package, following [<mark style="color:blue;">these</mark> ](https://www.jetbrains.com/help/pycharm/installing-uninstalling-and-upgrading-packages.html)instructions.
{% endtab %}

{% tab title="C#" %}
In Visual Studio, select *Tools > NuGet Package Manager > Package Manager Console command*.

1.- Install **Newtonsoft.Json** package for C#

```shell
Install-Package Newtonsoft.Json -Version 13.0.1
```

2.- Install **NetMQ** package for C#

```
Install-Package NetMQ -Version 4.0.1.9
```

3.- Install **Nep** package for C#

```shell
Install-Package Nep -Version 0.0.0.9
```

{% endtab %}

{% tab title="Node.js (Javascript)" %}
Install nep-js library for node.js using **npm**

```shell
npm install nep-js
```

{% endtab %}
{% endtabs %}

## <mark style="color:red;">Issues using older library versions and older NEP-CLI and NEP+ App versions.</mark>

Previous versions of NEP implemented in Python, C#, Java, and JavaScript were connected to NEP-CLI and NEP+ App using a client-server pattern over port 7000. However, this port was also utilized by AirPlay in Apple devices, thereby limiting cross-platform capabilities. In the new versions of NEP+ tools, port 50000 is used instead.

Solution: update NEP libraries, NEP-CLI, and NEP+ App to the latest versions.

Example of applications:

1. **Integrating Sensors with IA algorithms and Robots:** NEP+ can help connect sensors like cameras to state-of-the-art AI algorithms and different types of robots, enabling them to perceive and interact with their environment.
2. **Controlling Robots from a Smartphone:** With NEP+, users can develop applications to control robots remotely using their smartphones, making it easy to operate robots from a distance.
3. **Visualizing Robot Data:** NEP+ can be used to create interfaces that display real-time data from robots, such as their current position or sensor readings, in a user-friendly format.

[^1]: Service discovery is the process of automatically detecting devices and services on a compueter network. It aims to reduce the manual configuration effort required from users and administrators.&#x20;

[^2]: Serialization is the process of translating a data structure or object state into a format that can be transmitted and reconstructed later (in a different component).
