Unity and Arduino Socket Communication?

Hello people,

I am currently working on a home automation project using mobile device and arduino with esp8266 WiFi module. I am building the mobile app in Unity3D editor. For now, the objective is to control an LED connected to Arduino by a clickable event from the unity app with arduino being the server and the mobile device being the client. I am able to successfully send only a click event, which turns on the LED, but am unable to send the second click event as there is socket shutdown.

I am uploading the Arduino code for this project, can someone please help me out with this issue.( I think the issue is that the arduino script is executing the loop only once and shuts down the socket communication after receiving the first click event).

WiFiWebServerardunity.ino (4.49 KB)

I have some experience with Unity and I certainly have experience with serial communication (over bluetooth) between Android apps and Windows MFC apps and Arduinos.

You need at HC-05 module connected to a hardware or software serial port on the arduino.

I use Arduino Mega due to the extra hardware serial ports - Serial1 and Serial2

And hardware serial is supposed to be faster and more efficient.

With both android apps and Windows you need to pair with the HC-05 module within the operating system first.

In windows the connection appears as a COM port and I do a simple handshake routine in my windows app to determine which com port is the right one. I.E. Send out the string "arduino" and if I get "arduino back" then I know I have the right COM port.

For Android I use MIT App Inventor 2 and establishing a connection with the HC-05 (after it is paired) is somewhat simpler.

Now I don't know how Unity handles serial communication but I suspect it will be closer to MIT app Inventor given both these software packages are roughly the same vintage.

MS Visual Studio and MFC have been around since the late 90s