Help with ESPwifi using arduino IDE

Hey guys,I know this is ESP related and not arduino but since they both use the IDE i thought i would ask here in hopes some ESP gurus can help, so i have my code written up but I want a web server to change some varibles ( led brightness, timer length etc) but while Im still very new and i got some code working, ive been watching countless youtube videos and just cannot get my head around the webserver stuff, Would anyone be able to help me please - It would be highly appreciated!

Thanks

Craig

craig-robbo:
Hey guys,I know this is ESP related and not arduino but since they both use the IDE i thought i would ask here in hopes some ESP gurus can help, so i have my code written up but I want a web server to change some varibles ( led brightness, timer length etc) but while Im still very new and i got some code working, ive been watching countless youtube videos and just cannot get my head around the webserver stuff, Would anyone be able to help me please - It would be highly appreciated!

Thanks

Craig

clear as mud

This kind of post is not going to get the help you want.

Be more specific.

.

ieee488:
clear as mud

This kind of post is not going to get the help you want.

Be more specific.

.

Im not sure what else to add, i want to change some varibles in my current code via a web page?

Im still fairly new to this so I would appreciate help or even help in knowing what information you want from me.

They'll want to know what code you got working.

.

The bit I underlined and put in bold are the values i would like to be editable via web interface

#include <ESP8266WiFi.h>

// ------- pin assignments -----------
const byte Amber1 = 14;   // Amber output switch
const byte Amber2 = 12;   
const byte Amber3 = 13;
const byte Amber4 = 15;
const byte Reds = 4;      // Red Output switch (group of 3 LED sets)
const byte Reds2 = 16;    // Red Output switch (single output cluster)
const byte Indicator = 5;  // Indicator input pin
// ------------ Change to re-configure the boards characteristics -----------
const boolean IndicatorOn = LOW;   // state of the indicator input when ON
const boolean RelayOn = HIGH; // active level state for switching output ON
[u][b]
// Indicator setup
const unsigned int amberIndicatorInterval = 200;  // mS to get amber full running
const int amberBrightnessIncreaseStepsCount = 1; // Steps for indicator fade
const int amberTopBrightness = 100; //Indicator brightness
const int amberIndicatorOffInterval = 150;
// ED



//const unsigned int IndicatorInterval = 70;  // mS to get fade full running

//Running light setup

const int RampMaxValue = 100;   //Running light brightness
unsigned int RedsInterval = 2000;   // mS delay before RED leds are switched back on after indicator released[/b]
const unsigned int RampIncrement = 1;    // determines the Fade ramp up speed of Reds when ON - [b][/b][/u]decrease to slow down the rampconst boolean RelayOff = !RelayOn;

// ----------------------  Program variables and flags -----------------------
const boolean IndicatorOff = !IndicatorOn;
const boolean RelayOff = !RelayOn;
unsigned int IndicatorRunningTimer;
unsigned int RedsRunningTimer;
boolean IndicatorStatus;
boolean RedsDelay;
byte AmberPointer;
boolean PreviousIndicatorState;
boolean FirstPass;
boolean RedRamp;
unsigned int RampValue;
// -----------------------------------------------------------------------------
void setup() 
{  
  pinMode(Indicator,INPUT_PULLUP);  
  PreviousIndicatorState = digitalRead(Indicator);  
  if(PreviousIndicatorState == IndicatorOff)
  {   // indicator is OFF at start up so switch Reds on
    RedRamp = true; 
    RampValue = 0;  
    FirstPass = false; 
    pinMode(Reds,OUTPUT); 
    pinMode(Reds2,OUTPUT);  
  }
  else 
  {
    FirstPass = true; // indicator is on at start up so enable an Indicator sequence
    RedRamp = false;      
  }
  WiFi.disconnect();        // turn off WiFi radio section (reduce current consumption)
  WiFi.mode(WIFI_OFF);      // turn off WiFi radio section (reduce current consumption)
  WiFi.forceSleepBegin();   // turn off WiFi radio section (reduce current consumption)
  Serial.begin(115200);     // Serial port for debugging
  Serial.println("");
  Serial.println("Sequencer 3V0");
  Serial.println(""); 
  pinMode(Indicator,FUNCTION_3);    // reassign RX pin to be a normal GPIO
  pinMode(Indicator,INPUT_PULLUP);    
  AmberPointer = 0;         // reset Amber sequencer to amber 1 LED
  RedsDelay = false;        // disable Reds delay timer      
  IndicatorStatus = false;
  IndicatorRunningTimer = millis();
  RedsRunningTimer = millis();
}  // end of void Setup()
// ---------------------------------------------------------------------
void loop() 
{  
    if(digitalRead(Indicator) == IndicatorOn && (PreviousIndicatorState == IndicatorOff || FirstPass == true)) 
    {  // Indicator just switched on
      Serial.println("Indicator >> On");
      FirstPass = false;
      PreviousIndicatorState = IndicatorOn;
      IndicatorStatus = true;  // enable Indicator sequence
      RedsDelay = false;
      digitalWrite(Reds,RelayOff); 
      digitalWrite(Reds2,RelayOff);  
      Serial.println("Reds >> Off");
      AmberPointer = 0; 
      IndicatorRunningTimer = millis();          
    }
    else if(digitalRead(Indicator) == IndicatorOff && PreviousIndicatorState == IndicatorOn) 
    {  // Indicator just Switched off
      PreviousIndicatorState = IndicatorOff;
      IndicatorStatus = false; 
      digitalWrite(Amber1, RelayOff);
      digitalWrite(Amber2, RelayOff);
      digitalWrite(Amber3, RelayOff);   
      digitalWrite(Amber4, RelayOff);                         
      Serial.println("Indicator >> Off"); 
      RedsDelay = true;  // enable Red delay timer
      RedRamp = false;        
      RedsRunningTimer = millis();
    }
    
    // ED Please don't use delays unless you really need it. Delays are generally bad
    // practice which will lead to wasting process time and hurting time-sensitive functions
    //delay(10);
    // ED
    // ------------------------------------------------------------
delay(10);

    if(IndicatorStatus == true)  // if indicator has been switched on
   
    {
      AmberSequencer();      
    }   // end of if(IndicatorStatus == true)
    // --------------------------------------------------------------
    if(RedsDelay == true)
    {
      unsigned int RedsTimer = millis() - RedsRunningTimer;
      if (RedsTimer > RedsInterval)  // timer overflow
      {
          RedsRunningTimer = millis();
          RedsDelay = false;
          pinMode(Reds,OUTPUT);
          pinMode(Reds2,OUTPUT);
          //digitalWrite(Reds, RelayOn);
          RedRamp = true; // enable red to be able to ramped
          RampValue = 0;
          Serial.println("Reds ON");         
      }     
    }  // end of if(RedDelay == true)
    // ------- Ramp Red value brightness if enabled ----------------
    if(RedRamp == true)
    {
      analogWrite(Reds,RampValue);
      analogWrite(Reds2,RampValue);
      //Serial.println(RampValue);
      RampValue = RampValue + RampIncrement;   // increment brigntness value
      if(RampValue >= RampMaxValue){ RedRamp = false; } // if brightness > 100%, stop ramp
    }   
}  // end of void loop()
// -----------------------------------------------------

void AmberSequencer()
{

  int channelsTotalCount = 4;
  int brightnessLevelTiming  = 0;
  int singleCHannelTimeFrame = 0;
  unsigned int IndicatorDelta = millis() - IndicatorRunningTimer;
  unsigned int channelDelta = 0;
  int runningBrightness = 0;
  int isFadeIn = 1;

  int channelsMap[4] = {
    Amber1, Amber2, Amber3, Amber4
  };

  // here we will define limit for channels settings loop
  int IndicatorDeltaCounts = IndicatorDelta / (amberIndicatorInterval / channelsTotalCount);
  if(IndicatorDeltaCounts > 3) {
    IndicatorDeltaCounts = 3;
  }

  // iterating through channels
  for(int currentChannel = 0; currentChannel <= IndicatorDeltaCounts; currentChannel++) {
    isFadeIn = 1;
    
    // calculating how many brightmess channel must have
    channelDelta = IndicatorDelta - currentChannel * (amberIndicatorInterval / channelsTotalCount);
    if(channelDelta > amberIndicatorInterval + amberIndicatorOffInterval) {
        channelDelta = channelDelta - (amberIndicatorInterval + amberIndicatorOffInterval);
        isFadeIn = 0;
    }

    brightnessLevelTiming  = channelDelta / ((amberIndicatorInterval / channelsTotalCount) / amberBrightnessIncreaseStepsCount);
    runningBrightness = amberTopBrightness / amberBrightnessIncreaseStepsCount * brightnessLevelTiming;
    
    if(isFadeIn == 1) {
        runningBrightness = amberTopBrightness / amberBrightnessIncreaseStepsCount * brightnessLevelTiming;
    } else {
        runningBrightness = amberTopBrightness - (amberTopBrightness / amberBrightnessIncreaseStepsCount * brightnessLevelTiming);
    }
    
    if(runningBrightness > amberTopBrightness) {
        runningBrightness = amberTopBrightness;
    }
    
    if(runningBrightness < 0) {
        runningBrightness = 0;
    }
    
    analogWrite(channelsMap[currentChannel], runningBrightness);
  }
}

// end of void AmberSequencer()
// ----------------------------------------------------------------

(Next time, useCode tags, not Quote tags please. It’s the </> button on the menu.
Thanks, Moderator)

Thanks for link. I've spent all morning studying it and honestly I think I'm in over my head.

I appreciate the help but just a bit too complicated for me.

Tha ks all the same

So i tried implement the example you gave me, and I can get it to show the page, but i cannot get it to change the values i require

What am I doing wrong?

Code here:

#include <ESP8266WiFi.h>
#include <Arduino.h>

  #include <ESP8266WiFi.h>
  #include <ESPAsyncTCP.h>

#include <ESPAsyncWebServer.h>

AsyncWebServer server(80);


// REPLACE WITH YOUR NETWORK CREDENTIALS
const char* ssid = "SKYC1BB3";
const char* password = "DSPWXTFDBC";

const char* PARAM_INPUT_1 = "input1";
const char* PARAM_INPUT_2 = "input2";
const char* PARAM_INPUT_3 = "input3";

// HTML web page to handle 3 input fields (Indicator, input2, input3)
const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE HTML><html><head>
  <title>ESP Input Form</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  </head><body>
  <form action="RampMaxValue">
    input1: <input type="text" name="input1">
    <input type="submit" value="Submit">
  </form>

  <form action="amberTopBrightness">
    input2: <input type="text" name="input2">
    <input type="submit" value="Submit">
  </form>

  <form action="RampIncrement">
    input3: <input type="text" name="input3">
    <input type="submit" value="Apply">
  </form>
</body></html>)rawliteral";

void notFound(AsyncWebServerRequest *request) {
  request->send(404, "text/plain", "Not found");
}

// ------- pin assignments -----------
const byte Amber1 = 14;   // Amber output switch
const byte Amber2 = 12;   
const byte Amber3 = 13;
const byte Amber4 = 15;
const byte Reds = 4;      // Red Output switch (group of 3 LED sets)
const byte Reds2 = 16;    // Red Output switch (single output cluster)
const byte Indicator = 5;  // Indicator input pin
// ------------ Change to re-configure the boards characteristics -----------
const boolean IndicatorOn = LOW;   // state of the indicator input when ON
const boolean RelayOn = HIGH; // active level state for switching output ON

//////////////////////////////////////////////////////////////////////////////////////////////////////
//these values in this area in web server//
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Indicator setup
const unsigned int amberIndicatorInterval = 200;  // Indicator on animation (mS)
const int amberBrightnessIncreaseStepsCount = 1; // Indicator inter-segment Fade
const int amberTopBrightness = 100; //Indicator brightness
const int amberIndicatorOffInterval = 150; // Indicator off animation  (mS)


//Running light setup
const int RampMaxValue = 100;   // Running light brightness
unsigned int RedsInterval = 2000;   // Running light Delay (mS)
const unsigned int RampIncrement = 1;    // Running light Fade speed

////////////////////////////////////////////////////////////////////////////////////////////////////////
//end of web server area//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// ----------------------  Program variables and flags -----------------------
const boolean IndicatorOff = !IndicatorOn;
const boolean RelayOff = !RelayOn;
unsigned int IndicatorRunningTimer;
unsigned int RedsRunningTimer;
boolean IndicatorStatus;
boolean RedsDelay;
byte AmberPointer;
boolean PreviousIndicatorState;
boolean FirstPass;
boolean RedRamp;
unsigned int RampValue;
// -----------------------------------------------------------------------------
void setup() 


{  
  pinMode(Indicator,INPUT_PULLUP);  
  PreviousIndicatorState = digitalRead(Indicator);  
  if(PreviousIndicatorState == IndicatorOff)
  {   // indicator is OFF at start up so switch Reds on
    RedRamp = true; 
    RampValue = 0;  
    FirstPass = false; 
    pinMode(Reds,OUTPUT); 
    pinMode(Reds2,OUTPUT);  
  }
  else 
  {
    FirstPass = true; // indicator is on at start up so enable an Indicator sequence
    RedRamp = false;      
  }

  Serial.begin(115200);     // Serial port for debugging
  Serial.println("");
  Serial.println("Sequencer 3V0");
  Serial.println(""); 
  pinMode(Indicator,FUNCTION_3);    // reassign RX pin to be a normal GPIO
  pinMode(Indicator,INPUT_PULLUP);    
  AmberPointer = 0;         // reset Amber sequencer to amber 1 LED
  RedsDelay = false;        // disable Reds delay timer      
  IndicatorStatus = false;
  IndicatorRunningTimer = millis();
  RedsRunningTimer = millis();

  {
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  if (WiFi.waitForConnectResult() != WL_CONNECTED) {
    Serial.println("WiFi Failed!");
    return;
  }
  Serial.println();
  Serial.print("IP Address: ");
  Serial.println(WiFi.localIP());

  // Send web page with input fields to client
  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/html", index_html);
  });

  // Send a GET request to <ESP_IP>/get?Indicator=<inputMessage>
  server.on("/get", HTTP_GET, [] (AsyncWebServerRequest *request) {
    String inputMessage;
    String inputParam;
    // GET Indicator value on <ESP_IP>/get?Indicator=<inputMessage>
    if (request->hasParam(PARAM_INPUT_1)) {
      inputMessage = request->getParam(PARAM_INPUT_1)->value();
      inputParam = PARAM_INPUT_1;
    }
    // GET input2 value on <ESP_IP>/get?input2=<inputMessage>
    else if (request->hasParam(PARAM_INPUT_2)) {
      inputMessage = request->getParam(PARAM_INPUT_2)->value();
      inputParam = PARAM_INPUT_2;
    }
    // GET input3 value on <ESP_IP>/get?input3=<inputMessage>
    else if (request->hasParam(PARAM_INPUT_3)) {
      inputMessage = request->getParam(PARAM_INPUT_3)->value();
      inputParam = PARAM_INPUT_3;
    }
    else {
      inputMessage = "No message sent";
      inputParam = "none";
    }
    Serial.println(inputMessage);
    request->send(200, "text/html", "HTTP GET request sent to your ESP on input field (" 
                                     + inputParam + ") with value: " + inputMessage +
                                     "
<a href=\"/\">Return to Home Page</a>");
  });
  server.onNotFound(notFound);
  server.begin();
}
}  // end of void Setup()
// ---------------------------------------------------------------------
void loop() 
{  
    if(digitalRead(Indicator) == IndicatorOn && (PreviousIndicatorState == IndicatorOff || FirstPass == true)) 
    {  // Indicator just switched on
      Serial.println("Indicator >> On");
      FirstPass = false;
      PreviousIndicatorState = IndicatorOn;
      IndicatorStatus = true;  // enable Indicator sequence
      RedsDelay = false;
      digitalWrite(Reds,RelayOff); 
      digitalWrite(Reds2,RelayOff);  
      Serial.println("Reds >> Off");
      AmberPointer = 0; 
      IndicatorRunningTimer = millis();          
    }
    else if(digitalRead(Indicator) == IndicatorOff && PreviousIndicatorState == IndicatorOn) 
    {  // Indicator just Switched off
      PreviousIndicatorState = IndicatorOff;
      IndicatorStatus = false; 
      digitalWrite(Amber1, RelayOff);
      digitalWrite(Amber2, RelayOff);
      digitalWrite(Amber3, RelayOff);   
      digitalWrite(Amber4, RelayOff);                         
      Serial.println("Indicator >> Off"); 
      RedsDelay = true;  // enable Red delay timer
      RedRamp = false;        
      RedsRunningTimer = millis();
    }
    
    // ------------------------------------------------------------
delay(10);

    if(IndicatorStatus == true)  // if indicator has been switched on
   
    {
      AmberSequencer();      
    }   // end of if(IndicatorStatus == true)
    // --------------------------------------------------------------

// ----------------------------------------------------------------

I had to cut the code short due to char limit, However I have cut the bit off that wasnt part of the web server stuff

You need to contact the person who wrote the tutorial.

.

another tutorial in 10 parts ESP8266 and the Arduino IDE | Martyn Currey

.