# How to communicate vrep with ESP8266 via wifi to send and receive data

I'm looking for some guidance on a project that I've been doing for quite a long time; the project is about a 4WD robotic platform for obstacle avoidance with haptic feedback. If you know about the appropriate communication protocols for my project and can tell me something based on your experience with some similar projects - I will really appreciate it. So, I'm going to tell you what I've done so far.

I'm already taking the distances where the obstacle is located to my ESP8266. This is through a 340° detector made out of two Vl53L0X TOF sensors that use I2C CP, and a micro servo motor to make them turn around. With the same board, I control four Servos Dynamixel that use UART CP.

I command the robot through a web page and receive the data of each sensor in real-time (a delay of 2s) using TCPIP protocol and HTTP.

My questions are:

1. How can I read the data on the web page using VREP which is where the haptic control will be implemented?

2. Do you know any other way to connect via WIFI the ESP8266 with VREP and establish a bidirectional communication?

3. I tried using MATLAB to read the data from the web page and send it back to VREP afterward, but I haven't succeeded, yet. I can just write data, so far. All this using the function TCPIP and TCPCLIENT. Is it convenient to use MATLAB as a bridge between the ESP8266 and VREP? If so, What am I missing to succeed in this?

• It is not an answer to you question, but if you have a 2s communication delay, you will not be able to implement haptic control. For haptic control (if you mean impedance control by that, you would need a delay less then 10ms, ideally less then 1 ms) – 50k4 Jan 20 '20 at 13:48
• Thanks a lot. I didn't know this. I'll try to do some effort to reduce that delay. – Rubén Moreno G Jan 23 '20 at 22:19

VREP is a simulator system. you can develop plug-ins for it which can run custom code (i.e. communicate with your robot). Here is a short intro on how to start. You can establish a bidirectional TCP-IP Communication from the plug-in. You can make a C TCP-IP Server (as presented here) and run this on a different thread so it does not block your simulation. The message() function of the plug-in can then handle the inter-thread communication between V-REP and the TCP-IP Server. I would ditch HTTP as there is no need for it. You can also consider other protocols, like MQTT instead of TCP-IP (as there are some tutorials, like this, on getting this running on the ESP)