Newbie,Trying to use href to produce a digitalWrite

Greetings on the following code i have tried to make a href to make a digital write on one of the GPIO pins from D1 to D4 on the nodemcu to control a robot via Wi-Fi, but so far all tries have been futile, any help will be appreciated. Don know if Im putting the server.on function in the right place or I need to use a completely different function.
Note: No error codes so far.
thanks!

#include <SPI.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
MDNSResponder mdns;
ESP8266WebServer server(80);

String readString; 

  
String webTime,javaScript,XML,Websitexml;
String webPage="";
 
int gpio5_pin = D1;
int gpio4_pin = D2;
int gpio0_pin = D3;
int gpio2_pin = D4;


void buildWebsite()
{
  buildJavascript();
  webTime="<!DOCTYPE HTML>\n";
  webTime+=javaScript;
  webTime+="<BODY onload='process()'>\n";
  webTime+="<h1><center>Robot Connection Runtime: </center></h1>\n";
  webTime+="<center>\n";
  webTime+="<p>Total Runtime(Connection Active Confirmation) = <A id='runtime'></p></A>\n";
  webTime+="</center>\n";
  webTime += "<h1><center>Robot Wi-Fi Control</center></h1>";
  webTime += "<h1><center></center></h1>";
  webTime += "<center><p>Arduino Wi-Fi Connection</p></center><center><a href=\"?socket3arduion\"><button>Connect</button></a>&nbsp;&nbsp;&nbsp;&nbsp<a href=\"?socket3arduioff\"><button>Disconnect</button></center></a>";
  webTime+= "<p><center>Directional Control</center></p><center><a href=\"?socket1Forward\"><button>Forward</button></a>&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"?socket1Reverse\"><button>Reverse</button></center></a>";   
  webTime+= "<h1><center></center></h1>";
  webTime+= "<center><a href=\"?socketstop\"><button>Stop</button></center></a>";
  webTime += "<h1><center></center></h1>";
  webTime += "<center><a href=\"?socket2Left\"><button>Left</button></a>&nbsp;&nbsp;&nbsp;&nbsp<a href=\"?socket2Right\"><button>Rigth</button></center></a>";
  webTime += "<p><center>Rotation Angle</center></p>";
  webTime += "<h1><center></center></h1>";
  webTime += "<center><p> Rotate 30 Degrees </p></center><center><a href=\"?Rotation1\"><button>CounterClockWise</button></a>&nbsp;&nbsp;&nbsp;&nbsp<a href=\"?Rotation2\"><button>ClockWise</button></center></a>";
  webTime += "<h1><center></center></h1>";
  webTime += "<p><center>Running on a <b>NodeMCU ESP8266-12E LUA IoT</b></center></p>\n";
  webTime += "<p><center>Code written  by Alvaro Lloreda Droz y Emmanuelle Gutierrez Garcia</i></center></p>\n";
  webTime += "<table width=\"100%\" bgcolor=\"black\" cellpadding=\"12\" border=\"0\">\n";
  webTime += "<tr><td><p style = \"color: white; background: black;font-size: 0.8em;";
  webTime += "font-weight: bold; text-align: center; margin: 0px 10px 0px 10px;\">\n";
  webTime += "<a href = \"http://www.pupr.edu\">Alvaro Lloreda Droz y Emmanuelle Gutierrez Garcia</a> &copy; 2018</p></td></tr>";
  webTime+="</BODY>\n";
  webTime+="</HTML>\n";
  response();
 
}

void buildJavascript(){
  javaScript="<SCRIPT>\n";
  javaScript+="var xmlHttp=createXmlHttpObject();\n";

  javaScript+="function createXmlHttpObject(){\n";
  javaScript+=" if(window.XMLHttpRequest){\n";
  javaScript+="    xmlHttp=new XMLHttpRequest();\n";
  javaScript+=" }else{\n";
  javaScript+="    xmlHttp=new ActiveXObject('Microsoft.XMLHTTP');\n";
  javaScript+=" }\n";
  javaScript+=" return xmlHttp;\n";
  javaScript+="}\n";

  javaScript+="function process(){\n";
  javaScript+=" if(xmlHttp.readyState==0 || xmlHttp.readyState==4){\n";
  javaScript+="   xmlHttp.open('PUT','xml',true);\n";
  javaScript+="   xmlHttp.onreadystatechange=handleServerResponse;\n"; // no brackets?????
  javaScript+="   xmlHttp.send(null);\n";
  javaScript+=" }\n";
  javaScript+=" setTimeout('process()',1000);\n";
  javaScript+="}\n";
  
  javaScript+="function handleServerResponse(){\n";
  javaScript+=" if(xmlHttp.readyState==4 && xmlHttp.status==200){\n";
  javaScript+="   xmlResponse=xmlHttp.responseXML;\n";
  javaScript+="   xmldoc = xmlResponse.getElementsByTagName('response');\n";
  javaScript+="   message = xmldoc[0].firstChild.nodeValue;\n";
  javaScript+="   document.getElementById('runtime').innerHTML=message;\n";
  javaScript+=" }\n";
  javaScript+="}\n";
  javaScript+="</SCRIPT>\n";
}

void buildXML(){
  XML="<?xml version='1.0'?>";
  XML+="<response>";
  XML+=millis2time();
  XML+="</response>";
}
void response(){
          server.on("?socket1Forward", [](){
    digitalWrite(gpio5_pin, HIGH);
    delay(1000);
  });
  server.on("?socket1Reverse", [](){
    digitalWrite(gpio4_pin, HIGH);
    delay(1000); 
  });
  server.on("?socket2Left", [](){
    digitalWrite(gpio0_pin, HIGH);
    delay(1000);
  });
  server.on("?socket2Right", [](){
    digitalWrite(gpio2_pin, HIGH);
    delay(1000); 
  });
  
}
String millis2time(){
  String Time="";
  unsigned long ss;
  byte mm,hh;
  ss=millis()/1000;
  hh=ss/3600;
  mm=(ss-hh*3600)/60;
  ss=(ss-hh*3600)-mm*60;
  if(hh<10)Time+="0";
  Time+=(String)hh+":";
  if(mm<10)Time+="0";
  Time+=(String)mm+":";
  if(ss<10)Time+="0";
  Time+=(String)ss;
  return Time;
}

void handleWebsite(){
  buildWebsite();
  server.send(200,"text/html",webTime);

}


void handleXML(){
  buildXML();
  server.send(200,"text/xml",XML);
}


void GetSwitchState(){

   digitalWrite(gpio5_pin, HIGH);
}

void setup() {
  WiFi.mode(WIFI_AP); //CREATING AN ACCESS POINT(SOFT ACCESS POINT)
WiFi.softAP("Nasa_Mars_Robot", "Capstone2"); //PROVIDE THE (SSID,PASSWORD) FOR THE COMPETITION PASSWORD MINIMAL 8 CHARACTERS, ONE CAN ALSO MAKE THE SSID INVISSIBLE . 
server.begin(); // Start the HTTP Server
Serial.begin(115200); //START COMMUNICATION BETWEEN THE ESP8266-12E AND THE SERIAL MONITOR
IPAddress HTTPS_ServerIP= WiFi.softAPIP(); //OBTAIN THE IP ADDRESS OF THE SER SO ONCE CONNECTED WITH ROBOT, WE CAN CONNECT ON A BROWSER TO THE ROBOT
Serial.print("Server IP is: "); // SHOWS THE IP ADDRESS OF THE ESP8266-12E ON THE SERIAL MONITOR
Serial.println(HTTPS_ServerIP);  //HTML WEBSITE CONFIGURATION, BASIC HTML KNOWLEDGE NEEDED TO CONFIGURE
  pinMode(gpio5_pin, OUTPUT);  //CONFIGURES THE SPECIFIED PIN(PIN,I/O), TO BEHAVE AS AN OUTPUT
  pinMode(gpio4_pin, OUTPUT);// SAME AS ABOVE,BUT WITH DIFFERRENT PINS
  pinMode(gpio0_pin, OUTPUT);// SAME AS ABOVE,BUT WITH DIFFERRENT PINS
  pinMode(gpio2_pin, OUTPUT);// SAME AS ABOVE,BUT WITH DIFFERRENT PINS
  server.on("/",handleWebsite);
  server.on("/xml",handleXML);

}


void loop() 
{
           server.handleClient();
 }

This is where is believe the problem lies:

void response(){
          server.on("?socket1Forward", [](){
    digitalWrite(gpio5_pin, HIGH);
    delay(1000);
  });
  server.on("?socket1Reverse", [](){
    digitalWrite(gpio4_pin, HIGH);
    delay(1000); 
  });
  server.on("?socket2Left", [](){
    digitalWrite(gpio0_pin, HIGH);
    delay(1000);
  });
  server.on("?socket2Right", [](){
    digitalWrite(gpio2_pin, HIGH);
    delay(1000); 
  });

I am no electrical engineer and a newbie really myself. But I learned everything by religiously studying all this stuff in my own self designed google degree lol

If you are actually using a node MCU it is a wifi 32 not 8266. All your libraries are for everyday wifi units like wemos d1 mini or a esp13. What are you using to run your board? The board should be running on NodeMCU32S. You have so many libraries running when I can write that code just with Wifi.h, wificlient.h and esp32.h.

Do you have the esp32 Arduino bundle loaded in your boards list? It has got Windora, Lora, homebill, intorobot, lolin, adafruit etc all esp32 specific.

I think I got my list ages ago when I wasted my time playing with crappy Uber expensive Blynk( $6grand walk away for only one sub standard android and Mac app that you can’t alter or can be ruined by updates is Luny tunes). Actually I remember now I downloaded it as a json via the old school git method doing something much more productive. I am sure a quick look and you will find it.

But you have a lot of code and you seem to really want to java it up.

if you want the simplest HTML code to trigger an output
<a href=\wr.htm?A\”style= Whatevs name the button”;

Then in loop - if(getfile==‘A’)
{digitalWrite( xx, HIGH)};

Too easy. If you don’t mind a nasty webhost page. Ha. Hope I helped. D

If you are actually using a node MCU it is a wifi 32 not 8266.

Is that really the case ?

UKHeliBob:
Is that really the case ?

No.

Funny to say flatly without reason “no”. Riddle me this then.

If you read what is on the wifi chip from an esp13 or wemos d1 it has written on it

“Wifi Esp8266”

Whereas if you read the details written on the wifi chip of the nodeMCU it has written on it

“Wifi WROOM 32s”

I am simply suggesting to use libraries specifically designed for wifiWROOM32s which happen to be the wifi units on all my nodeMCU hardware.

NodeMCU is an open source IoT platform.[4][5]
It includes firmware which runs on the ESP8266 Wi-Fi SoC from Espressif Systems, and hardware which is based on the ESP-12 module.[6][7]
The term "NodeMCU" by default refers to the firmware rather than the development kits.
he firmware uses the Lua scripting language.
It is based on the eLua project, and built on the Espressif Non-OS SDK for ESP8266.
It uses many open source projects, such as lua-cjson,[8] and spiffs.[9]

There is now a new board development called "NodeMCU ESP-32S". It does indeed use the ESP-32S. However it is still not shown on the 'official' NodeMCU website.
A number of firms have taken the NodeMCU concept and run with it.

[is a NodeMCU an ESP8266 or an ESP32?]

"NodeMCU" is a development framework, sort of like "Arduino." It includes a bunch of libraries and and whatnot, and is (properly speaking) "something that allows IoT programs in Lua on a small MCU board."
The initial MCU board was ESP8266-based thing. Some newer boards have an ESP32.
It's a bit like trying to help an "Arduino user" with a problem on the forums. You can get ten messages into a thread before the OP says "oh, this is an Arduino Zero - does that make a difference?" (grr!) But that doesn't mean that we shouldn't assume that "Most" beginers are using an AVR-based Arduino.
Most "nodeMCU" boards are ESP8266.
It's only a happy coincidence that this board trying to run Lua will also run Arduino code...

I understand and thanks man. I did not realise nodeMCU boards were built with 8266 wifi in previous models. I don’t believe what I wrote would be regarded useless information. I just saw a lot of code that could have been very much simplified. I do believe though my answer to the initial question to trigger a gpio is correct. A few lines rather than pages of script surely saves the headaches. :wink:

If ppl were a bit clued on they could use blynk local server, that allows virtual pins and bridge function between wifi units that doesn’t require widgets. Don’t use the apps and make your own web host. Now you have your idea running on your local server that they just happen to give you for no charge. With a wifi router with ip reservations you can have your home system totally controlled without need for net connection at all, very stable and free. Yay. Cloud free home automation.