I would really recommend using C and the Arduino library for this since it is much simpler. There is a library for the esp8266 that makes it very easy to use. There is a straightforward connect method and sending data is just like normal socket programming. Let me know if you would be willing to use C and I will post the code. Good Luck!
Edit:
This is the example code given in the docs for Arduino and esp8266. As you can see it is very straightforward. I have added some comments to explain this a little better.
#include <ESP8266WiFi.h> //This is the library I was talking about
void setup()
{
Serial.begin(115200); //Turns on Serial monitor for debugging.
Serial.println();
WiFi.begin("network-name", "pass-to-network"); //The "begin" command uses the network name and password to connect to your network.
Serial.print("Connecting");
while (WiFi.status() != WL_CONNECTED) //This is just to wait as it connects.
{
delay(500);
Serial.print(".");
}
Serial.println();
Serial.print("Connected, IP address: ");
Serial.println(WiFi.localIP()); //This will print the esp's ip
}
void loop() {
//Add your code here to control the relay.
//use digitalWrite(pin,HIGH) to send a 5 volt output to the pin stated.
}
Let me know if this helps.
when connected to such clients... it is unclear if you are able to program the esp8266 or not ..... i think that the esp8266 that you bought has some kind of a demo program loaded ..... more info: http://www.instructables.com/id/How-to-use-the-ESP8266-01-pins/ – jsotola Jul 14 '18 at 21:43192.168.4.2/on- didnt work out – guyd Jul 15 '18 at 04:09192.168.4.2/ON1...192.168.4.2/ON2...192.168.4.2/OFF1...192.168.4.2/OFF2– jsotola Jul 15 '18 at 18:39192.168.4.2/ON1or other - does not work. PS - my LAN is192.168.2.1if it matters anyhow – guyd Jul 15 '18 at 18:48trying 192.168.4.2/on - didnt work out........... your PC and the ESP8266 are on different subnets. .... that is why it does not work – jsotola Jul 15 '18 at 19:30192.168.4.1/ON1– jsotola Jul 15 '18 at 19:52192.168.2.199, and192.168.2.1to gateway - still with no luch – guyd Jul 16 '18 at 03:21