Hello everyone, I am new to this type of stuff. I wanted to create a remote control for my project using the internet as testing. I made code in JS to send a variable to the ESP server to tell the built-in light to turn off or turn on. I am sure that my JS code is working correctly, but my ESP code, I am not sure if the light turns on and off either by random or extreme slowness, and when it does turn off, it does this for half a second. Can anyone help a newbie?
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESPAsyncWebServer.h>
AsyncWebServer server(80);
String idd = "XXXXX ";
String pass = "XXXX"; // this is for privacy reasons;
bool forward = false;
// the setup function runs once when you press reset or power the board
void setup()
{
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
WiFi.begin(idd, pass);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.print("!!!");
Serial.print(WiFi.localIP());
// Initialize server and register routes
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
if (request->hasParam("forward"))
{
String forwardParam = request->getParam("forward")->value();
if (forwardParam == "true") {
forward = true;
} else if (forwardParam == "false") {
forward = false;
}
}
});
server.begin();
}
// the loop function runs over and over again forever
void loop()
{
digitalWrite(LED_BUILTIN, forward);
}