# Connecting ROS to non-ROS nodes using NEP+ tools

We will explore three different methods:

<table><thead><tr><th width="182.02081397402162">Method</th><th>When is recommended?</th><th>Comments</th></tr></thead><tbody><tr><td>Direct</td><td>When your software architecture uses mainly ROS and is only needed to connect a single node/computer that does not support ROS</td><td>It can be annoying to deal with IP addresses and port numbers for NEP nodes. You manually create the bridge between NEP and ROS</td></tr><tr><td>nep-cli</td><td>When one or more modules not supporting ROS need to be connected with a ROS architecture</td><td>You need to use the same IP address for all your NEP nodes.</td></tr><tr><td><p></p><p>Nep+ App</p></td><td>If you don't want to code at all the bridges between NEP and ROS</td><td>Can be more complex to use at the beginning, still in a beta version</td></tr></tbody></table>

## Direct method

{% hint style="warning" %}
Before following this tutorial, read [#using-a-direct-connection](../connecting-2-scripts-in-a-local-network-e.g.-two-computers-on-the-same-wifi-network#using-a-direct-connection "mention")
{% endhint %}

### Bridge NEP Publishers to ROS Subscribers in Python

Let's imagine that Computer B, defined in tutorial [#using-a-direct-connection](../connecting-2-scripts-in-a-local-network-e.g.-two-computers-on-the-same-wifi-network#using-a-direct-connection "mention"), has Ubuntu and ROS installed and that it is required to send the data produced in the **NEP Publisher** to a **ROS Subscriber.**

For this example, we will use ROS Standart String messages to link a **NEP Publisher** with ROS. We will define a **bridge script** that creates a **NEP Subscriber and ROS Publisher.**

![Main idea behind connecting NEP Publishers and ROS Subscribers in a direct method](https://423882023-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9aELFWec9V26rEZKHjDA%2Fuploads%2FjZ4gyR6RjgFDBf66bgvk%2FNEP2ROS.png?alt=media\&token=67934e9d-a844-48d4-876b-bdce50614698)

The code of the **bridge script** is shown below.

{% tabs %}
{% tab title="Python" %}
```python
import nep
import time
import rospy
from std_msgs.msg import String

ros_pub = rospy.Publisher('chatter', String, queue_size=10)
rospy.init_node('talker', anonymous=True)

# Create a new nep node
node = nep.node("receiver")     
# Set a direct connection using port <3000> and in <'one2many'> mode
# Important: 	You need to change the IP address <'127.0.0.1'> by 
# 		the IP address of you PC running the publisher node                                                   
conf = node.direct(ip = "127.0.0.1", port =  3000, mode ="one2many")                         
# Create a new nep subscriber with the topic <'test'>
sub = node.new_sub("test_subcriber", "json", conf) 

while True:
    # Read data in a non-blocking mode
    s, msg = sub.listen() 
    # if s == True, then there is data in the socket      
    if s:                       
        print(msg)
        # msg is a python dictionary
        # we convert the value of msg["result"] to string 
        ros_pub.publish(str(msg["result"]))
    else:
        # An small sleep will reduce computational load
        time.sleep(.0001)

```
{% endtab %}
{% endtabs %}

{% hint style="info" %}
Using correctly **rospy.Rate** will require more complex code, we will update an example soon.
{% endhint %}

### Bridge ROS Publishers to NEP Subscribers in Python

Soon..
