C++ and Arduino Communication via Ethernet shield ( Local Network)

I m new at arduinos and i have some questions for that.
I m creating a project that is about home automation. I want to manage some devices of home like the lights from a C++ Application that i create at PC. With Serial Communication everything work like i want.
The problem is that i want to move my arduino to another room, and connect this with my PC via ethernet cable and a router.
I dont know how to make a communication via ethernet between arduino and c++ application that i made , as result to can send values from pc to arduino and arduino to pc .

Can someone give me a way and an idea to search about how to do it ?

Thanks in advance,

Can someone give me a way and an idea to search about how to do it ?

When you disconnected your Arduino from the serial port, you can no longer use the serial port to communicate with it.

When you added the ethernet shield, and connected it to the network, you made a choice that the Arduino would be either a client, making requests for data and responding appropriately, or a server, accepting requests with data and responding appropriately.

You didn't tell us which role the Arduino is going to play. You didn't tell us what role the PC running the C++ application is going to play.

The C++ application could store data in a file that the script on the server accesses, when the Arduino as client makes a request for data. The problem with that is that the Arduino would have no idea when to ask for new data. Too often, and 99% of the requests are going to get the same data. Too infrequent, and there will be a lag between when the C++ application reacts to a user request, writes the data to the file, and the Arduino asks for it, and reacts to it.

So, the Arduino as client is probably not a good choice. The Arduino as server is a better choice, and the C++ application can make GET requests, when the user, interacting with the GUI, makes a change.

The role is like that. c++ Application have some button like turn on/off lights. When i press the turn on button ,i want to give the arduino the value c= 3 and with cases at arduino will open the pin. code is something like that

if c=3 { digitalWrite(turnONled , HIGH); }

My problem is how to send the value c=3 via ethernet from pc to arduino.


PS: It's a lot easier in C#. Windows forms are much easier, too.

i use Visual Studio 2015.

My code for connection is like that at serial mode

private: System::Void ConnectButton_Click(System::Object^ sender, System::EventArgs^ e) { ConnectionArduinoSerialPort->PortName = ConectionCOMComboBox->Text; ConnectionArduinoSerialPort->Open(); DisconnectButton->Enabled = true; ConnectButton->Enabled = false; BedroomLightingTrackBar->Enabled = true; KidRoomLightingTrackBar->Enabled = true; LivingRoomLightingTrackBar->Enabled = true; KitchenLightingTrackBar->Enabled = true; GeneralLightingTrackBar->Enabled = true; ConectionCOMComboBox->Enabled = false;


After that at when i press a button to open light it looks like that

private: System::Void BedroomLightingTrackBar_ValueChanged(System::Object^ sender, System::EventArgs^ e) { if (BedroomLightingTrackBar->Value == 1) { ConnectionArduinoSerialPort->Write("1"); } else if (BedroomLightingTrackBar->Value == 0) { ConnectionArduinoSerialPort->Write("0"); } }

At arduino, there are some cases like if value is 1 then open led 1 , if led value is 0 close led 1.

I want to create this exactly, with sending the value via ethernet at IP that i will give to my arduino ethernet shield.

Can someone give me a way and an idea to search about how to do it ?

You might consider making a web page GUI to control your devices instead of a pc application.

This project is a homework that i had from my university .

So the terms is to use a c++ application communicates with arduino board to control these devices.

I look something like "Sockets" but i think that is something difficult and no simple for the reason that i want to do.

Any other ideas plz?

P.S thx to all that answer to me and trying to help me ..