# NEP CLI

## Installation

{% hint style="info" %}
**Good to know:** You need to have installed in your computer [node.js](https://nodejs.org/en/) 18 or above
{% endhint %}

After installing [node.js](https://nodejs.org/en/) > 18.0, you can install **NEP CLI** using the following command in **Windows**:

```shell
npm install -g nep-cli
```

In **Linux** and **macOS** you may need to use sudo

<pre><code><strong>sudo npm install -g nep-cli
</strong></code></pre>

Verify that NEP CLI is installed correctly using the following command:

```shell
nep help
```

### If using Intune (Windows)

To verify, navigate to Control Panel -> System and Security -> Windows Defender Firewall -> Allow an app or feature through Windows Defender Firewall. Ensure that Node.js JavaScript Runtime is listed as an allowed app or feature. If it is not listed, click on the "Allow another app" button and add Node.js (C:\Program Files\nodejs\nodejs.exe).

## Manage connection between nodes:

| Commands   | Action                                                          |
| ---------- | --------------------------------------------------------------- |
| nep master | Start master for managing NEP+ topics                           |
| nep ip     | Display current Wi-Fi and Ethernet IP addresses of the computer |

### Connection of NEP+ nodes&#x20;

Use the following command to connect NEP nodes within a local network. This is applicable when the nodes are on the same computer or connected via Wi-Fi or Ethernet.

```
nep master
```

This command will display the next output:

```
Starting NEP master in terminal
New Master in: tcp://0.0.0.0:50000
Master info in: tcp://0.0.0.0:500001
```

This command initiates a NEP master node on your local network. NEP nodes within your network can connect to this master node to communicate with each other.

{% hint style="info" %}
Ensure your network is properly configured and nodes can reach the master node. If you encounter connectivity issues, check your firewall settings and network configurations.
{% endhint %}

### See the Wi-Fi and Ethernet IP address of your PC

This command displays the current Wi-Fi and Ethernet IP addresses of the computer where this command is run. It identifies the operating system and accordingly fetches the network interfaces.&#x20;

```
nep ip
```

For each identified Wi-Fi interface, it fetches and prints the IP address. It also fetches and prints the IP address of the Ethernet interface.  An example is show bellow:

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

{% hint style="info" %}
The command assumes that the Wi-Fi and Ethernet interfaces follow certain naming conventions which are common but not guaranteed for every system. If the command does not display the IP addresses as expected, check the naming conventions of your network interfaces.
{% endhint %}

## Topics registered

| Commands   | Action                           |
| ---------- | -------------------------------- |
| nep topics | Displays the list of NEP+ topics |

```
nep topics
```

This command displays the list of NEP+ topics. It connects to the NEP master node at the local IP address (127.0.0.1) and sends a request for the list of topics.  The command waits for a response from the master node or a timeout, whichever comes first.

{% hint style="info" %}
This command assumes that the NEP master node is running at the local IP address and that the network is properly configured. If the command does not display the list of topics as expected, check the status of the NEP master node and your network configuration.
{% endhint %}

## Publish a JSON message:

| Command                         | Action                                                               |
| ------------------------------- | -------------------------------------------------------------------- |
| nep publish \<topic> \<message> | Publish a message to a NEP+ topic (only JSON messages are supported) |

Let's imagine that the topic `test/json` is already registered in NEP+ master, and it is required to send the message `{'msg':'hello'}` to a node subscribed to this topic using the command line interface.

This is possible with the command `nep publish <topic> <message>` as follow:

```
nep publish test/json "{'msg':'hello'}"
```

{% hint style="warning" %}
If the message to send:`{'msg':'hello'}` is written as: `{"msg":"hello"}` it will produce an error. Therefore, use `' '`  and not `" "`
{% endhint %}

{% hint style="info" %}
The default approach for encoding messages in NEP+ is the use of the Javascript Object Notation (JSON)
{% endhint %}

{% hint style="success" %}
In these examples, change `test/json` by the topic you would like to publish a message. To see the list of registered topics, use the `nep topics` command .
{% endhint %}

## Display messages:

<table><thead><tr><th width="331">Command</th><th>Action</th></tr></thead><tbody><tr><td>nep show [topic] [index]</td><td>Displays messages published to a specified NEP+ topic in the default browser.  The [index] parameter specifies the index of the message to display and must be a number between 0 and 49.</td></tr><tr><td>nep echo [topic]</td><td>Subscribe to a NEP+ topic and display raw string messages</td></tr></tbody></table>

### show

This command is used to display messages send in a specific topic in the default browser . The topic and index are optional parameters.

If no parameters are provided, the user will be prompted to select one of the available topics.

The index is used to identify a specific server instance when multiple servers are running. It helps in routing the messages correctly to the intended server for display in the web browser.

{% hint style="warning" %}
It's important to assign a unique index value for each topic. Duplicate index values can lead to confusion and incorrect routing of messages.&#x20;
{% endhint %}

{% hint style="info" %}
This command assumes that the NEP master node is running
{% endhint %}

Example:

```
nep show test/json 0
```

### echo

This command subscribes to a NEP+ topic and displays raw string messages. The topic is an optional parameter. If no topic is provided, the user will be prompted to select one of the available topics.

{% hint style="info" %}
This command assumes that the NEP master node is running
{% endhint %}

Example:

```
nep echo test/json
```

## Comunication monitoring:

<table><thead><tr><th width="331">Command</th><th>Action</th></tr></thead><tbody><tr><td>hz [topic]</td><td>Monitor the publishing rate of a NEP+ topic</td></tr><tr><td>delay [topic]</td><td>Monitor the delay between messages of a NEP+ topic</td></tr><tr><td>bw [topic]</td><td>Monitor the bandwidth used by a NEP+ topic</td></tr></tbody></table>

These commands are used to monitor various aspects of a NEP+ topic. The topic is an optional parameter. If no topic is provided, the user will be prompted to select one of the available topics.

### hz

This command is used to monitor the publishing rate of a NEP+ topic. It displays the rate at which messages are being published to the specified topic.&#x20;

Example:

```
nep hz test/json
```

### delay

This command is used to monitor the delay in message delivery for a NEP+ topic. It displays the time taken for messages to be delivered from the publisher to the subscriber for the specified topic.

Example:

```
nep delay test/json
```

### bw

This command is used to monitor the bandwidth usage of a NEP+ topic. It displays the amount of data being transmitted over the network for the specified topic.

Example:

```
nep bw test/json
```

{% hint style="info" %}
These command sassumes that the NEP master node is running
{% endhint %}

## Bag (record and play messages)

<table><thead><tr><th width="331">Command</th><th>Action</th></tr></thead><tbody><tr><td>record [topic]</td><td>Record messages from a NEP+ topic to a JSON bag file</td></tr><tr><td>nep play &#x3C;bagfile> &#x3C;topic></td><td>Play messages from a bag file to a NEP+ topic</td></tr></tbody></table>

These commands are used to record and playback messages from a NEP+ topic.

### record

This command is used to record messages from a specified NEP+ topic. If no topic is not provided, the user will be prompted to select one of the available topics.  User can prompt a timeout (in miliseconds)

Example:

```
nep record
```

### play

This command is used to playback messages from a recorded file. The bagfile must be a JSON file created by nep record command.&#x20;

```
nep play
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://coronadoenrique.gitbook.io/nep+/developer-tools/nep-cli.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
