WeMos D1 mini Relay

Hi I'm trying to controll my lights via a WeMos D1 mini with a relay via a http link.
I got that to work but now I want to turn the ligts on if they're off and off if the're on via the same url.
But now i can only turn them off and no longer on.

This is the code:

#include <ESP8266WiFi.h>

const char* ssid = "xxxxxxxx";
const char* password = "xxxxxxxxx";

int RelayPin = D1;
WiFiServer server(80);
IPAddress ip(192, 168, 0, 97); // where xx is the desired IP Address
IPAddress gateway(192, 168, 0, 1); // set gateway to match your network

void setup() {
WiFi.mode(WIFI_STA);
Serial.begin(115200);
delay(10);

pinMode(RelayPin, OUTPUT);
digitalWrite(RelayPin, HIGH );

Serial.print(F("Setting static ip to : "));
Serial.println(ip);

// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
IPAddress subnet(255, 255, 255, 0); // set subnet mask to match your network
WiFi.config(ip, gateway, subnet);
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");

// Start the server
server.begin();
Serial.println("Server started");

// Print the IP address
Serial.print("Use this URL : ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");

}

void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}

// Wait until the client sends some data
Serial.println("new client");
while(!client.available()){
delay(1);
}

// Read the first line of the request
String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();

// Match the request

int value = HIGH;
if (request.indexOf("/GO") != -1) {
if (RelayPin != LOW)
{
digitalWrite(RelayPin, LOW);
}
else
{
digitalWrite(RelayPin, HIGH);
}

}

}

if (digitalRead(RelayPin))
  Serial.println(request);

What does this actually print?

    if (RelayPin != LOW)

Well, you declared RelayPin to have the value of D1, and you never change it, so, unless D1 is LOW, then this will always be true. So, it's lights out...

The web server class has an HTTP parser built-in, and you can just add handlers to certain URIs, for example:

#include <ESP8266WebServer.h>

ESP8266WebServer server(80);  // Create a webserver object that listens for HTTP request on port 80

void setup() {
  server.on("/GO", go);  // Execute function 'go()' every time a client requests the "/GO" URI
}
void loop() {
  server.handleClient();  // Listen for HTTP requests from clients, and execute 'go()' if "/GO" is requested
}
void go() {
  bool relayState = digitalRead(RelayPin);  // Read the pin's state, not the pin number
  digitalWrite(RelayPin, ! relayState);  // Invert the state using the not operator (!) and write this to the output
}

Find a complete example here:
https://tttapa.github.io/ESP8266/Chap10 - Simple Web Server.html

Pieter

thanks it works now but how do I close this quesion now?

svnmstrs:
thanks it works now but how do I close this quesion now?

You can't close anything. You can edit the title. to include SOLVED and most people will stop responding.