Hi! Programming beginner here looking for help.
Im trying to write a simple code for arduino and Unity3d that allows me to send and recieve a string from my arduino mega to unity 3d via wifi. I have connected a ESP8266-01 to my arduino and succesfully connected to my home wifi. Im using the EEPROM to store the data needed for the communication (IP, pass, SSID, etc).
This is my first attempt at any non-serial communication and I must admit Im way over my head here. Not sure which port i can/should use. Not sure if the IP is correct (using the one shown for my PC on my router)
Im basically looking for a short guide or sample code which allows back and forth string commuication.
There is a lot of stuff online like videos showing the result but not the code.
The portion (method) of my arduino code which is supposed start the communication looks like this:
while (true) // just for testing, dont hate me :D
{
String host = "192.168.0.220";
int hostPort = 25001;
WiFiClient client;
if (client.connect(host, hostPort)) {
Serial.println("Connected to host server");
client.println("hello");
while (client.connected()) {
if (client.available()) {
String inputClient = client.readString();
Serial.println(inputClient);
}
if (Serial.available() > 0)
{
String inputSerial = Serial.readString(); // reads and saves incoming string
client.println(inputSerial);
if (inputSerial == "disc")
{
break;
}
}
}
client.stop();
Serial.println("Disconected");
}
else {
Serial.println("Connection failed!");
client.stop();
}
delay(5000); //also just for testing
}
Im also very unexperienced in Unity so any example codes in that part would be appreciated.
Thank you!