Help changing password of ESP8266 web server

Hi there friends,

i'm currently working on a project envolving esp8266 and a keypad door lock. My issue involves the possibility of changing the code for opening the door via websever. any ideas on how i can do that?

Thank you so much guys and gals.

Your question is rather vague - what have you tried?

In general you need an option on the server that gives you the opportunity to enter the new password. For security the user should be required to enter the existing password to get authority to change the password.

I presume the ESP8266 has some EEPROM memory in which the password can be stored where it won't be lost if the power fails.

...R

The ESP8266 has its own built-in web server. That'd be the easiest. Set it up, and create a page where you can enter and submit the new code (as POST request), and have the ESP read the POST response and store the new code.

Then you can of course start making it more fancy, such as adding password protection of that web page.

Thank you all

my problem is that i can't turn on the webserver on the esp8266, as it stops the code from reading the keypad input, anyone with similar problem?

I think you're doing something wrong as the web server should be running in the background.

Pgoulao:
my problem is that i can't turn on the webserver on the esp8266, as it stops the code from reading the keypad input, anyone with similar problem?

You didn't tell us that in your Original Post.

Post the program that represents your best attempt and tell us in detail what it actually does and what you want it to do that is different. It will make it much easier to focus on the parts you need help with rather than wasting time on things that you can do.

...R

Hi there again and thank you for all the answers, i'm attaching the code.

The idea is to get the PARAM_INPUT_1 and modify the password variable. any ideas?

Thank you so much

door_lock.ino.ino (4.05 KB)

It's much easier for people to help you if you include short program directly in your Post - like this

#include <BearSSLHelpers.h>
#include <CertStoreBearSSL.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiAP.h>
#include <ESP8266WiFiGeneric.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266WiFiScan.h>
#include <ESP8266WiFiSTA.h>
#include <ESP8266WiFiType.h>
#include <WiFiClient.h>
#include <WiFiClientSecure.h>
#include <WiFiClientSecureAxTLS.h>
#include <WiFiClientSecureBearSSL.h>
#include <WiFiServer.h>
#include <WiFiServerSecure.h>
#include <WiFiServerSecureAxTLS.h>
#include <WiFiServerSecureBearSSL.h>
#include <WiFiUdp.h>
#include <Keypad.h>
#include <ESPAsyncWebServer.h>

AsyncWebServer server(80);

const char* PARAM_INPUT_1 = "input1";

// HTML web page to handle 3 input fields (input1, 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="/get">
    input1: <input type="text" name="input1">
    <input type="submit" value="Submit">
  </form>
</body></html>)rawliteral";

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

const char *ssid =  "WiFiLoja";
const char *pass =  "PauloGoulao";

WiFiClient client;


const byte n_rows = 4;
const byte n_cols = 4;

char* password = "1590";  // variavel com a password 4 numeros

char keys[n_rows][n_cols] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
 
byte colPins[n_rows] = {D3, D2, D1, D0};
byte rowPins[n_cols] = {D7, D6, D5, D4};
int RedpinLock = 3;
int GreenpinUnlock = 9;
int relayInput = 15; // pino de entrada para o relé
int position = 0;
volatile byte relayState = LOW;
 
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, n_rows, n_cols); 
 
void setup(){
  Serial.begin(115200);
         Serial.println("Ligando a ");
       Serial.println(ssid); 
 
       WiFi.begin(ssid, pass); 
       while (WiFi.status() != WL_CONNECTED) 
          {
            delay(500);
            Serial.print(".");
          }
      Serial.println("");
      Serial.println("WiFi Ligado");
      Serial.println(WiFi.localIP());  //mostra IP
      delay(1000);
       
  pinMode(RedpinLock, OUTPUT);
  pinMode(GreenpinUnlock, OUTPUT);
  pinMode(relayInput, OUTPUT); // inicializa o relay
  digitalWrite(relayInput, HIGH);

    // 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?input1=<inputMessage>
  server.on("/get", HTTP_GET, [] (AsyncWebServerRequest *request) {
    String inputMessage;
    String inputParam;
    // GET input1 value on <ESP_IP>/get?input1=<inputMessage>
    if (request->hasParam(PARAM_INPUT_1)) {
      inputMessage = request->getParam(PARAM_INPUT_1)->value();
      inputParam = PARAM_INPUT_1;
    }
    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();
}

 
void loop(){
  Serial.println("Introduza");
  char key = keypad.getKey();
  
  Serial.println(key);
  if (key == password[position])
  {
    position ++;
  }
  if (position == 4)

  {
    LockedPosition(false);
    position =0;
    LockedPosition(true);
  }
  delay(100);
}

void LockedPosition(int locked){
if (locked)
  {
    digitalWrite(RedpinLock, HIGH);
    digitalWrite(GreenpinUnlock, LOW);
    digitalWrite(relayInput, HIGH);
    Serial.println("fechado");
  }
  else
  {
    digitalWrite(RedpinLock, LOW);
    digitalWrite(GreenpinUnlock, HIGH);
    digitalWrite(relayInput, LOW);
    Serial.println("aberto");
    delay(2000);
  }
}

I'm not sufficiently familiar with web programming on the ESP8266 to be able to offer any advice beyond the general comment I have already made - sorry.

...R

Thank you any way

Other than the copious use of the String class nothing obviously wrong with this code.

@Pgoulao, just a stray thought ... the Title of this Thread says "Help with project of door lock" but your problem is not about door locks, it's about web programming.

Perhaps people with useful ideas would take an interest if you edit the Original Post and change the Title to "Help changing password of ESP8266 web server"

...R

Thanks I'll do that.

"My issue involves the possibility of changing the code for opening the door via websever. any ideas on how i can do that?"

It isn't really clear what you want to do. Do you want to change the login password on the esp8266, or do you want to change the password on a door lock? Do you successfully communicate with the esp8266 web server from a web client?

zoomkat:
"My issue involves the possibility of changing the code for opening the door via websever. any ideas on how i can do that?"

It isn't really clear what you want to do. Do you want to change the login password on the esp8266, or do you want to change the password on a door lock? Do you successfully communicate with the esp8266 web server from a web client?

Hello zoomcat

I need to change the door code, right now I can access the webserver via browser but I didn't figure out how to change the variable "char* password".

Thank you

I looked at the code and there is a lot of setup stuff I'm not familiar with. I didn't see an obvious place where you receive the contents of the the web page submit box. Do you have a line where what you receive from the submit box is printed to the serial monitor for verification? I guess my question is does anything about this code work, like uploading the submit page to the web browser? If not, you may have to drop back to code for a basic web server and then start from there.