ESP8266 Form actions

Hello all!

I’m trying to program a webserver using an ESP8266 to control some motors. Currently I’m working on the server front end, so just the interface and whatnot users will interact with. Essentially the use is supposed to select a start time and end time for a motor to move, as well as the total angle the motor is supposed to move. To accomplish this, I’m using the following code:

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>


const char* WifiName="*****"; //In actual program uploaded to ESP8266 these fields are filled out
const char* WifiPass="******";
String webPage,notice;

ESP8266WebServer server(80);


const char htmlPage[]PROGMEM=R"=====(
<!DOCTYPE html>
<html>
<body>
<h3>Motor Control Page</h3>
<p>Motor 0 controls: </p>
<form action="/motor0Start">
  <label for="m0S">Start time:</label>
  <input type="time" id="m0S" name="motor0Start">
  <input type="submit" value="Submit">
</form>
<form action="/motor0End">
  <label for="m0E">End time:</label>
  <input type="time" id="m0E" name="motor0End">
  <input type="submit" value="Submit">
</form>

<FORM METHOD="POST"action="/motor0Sweep">
<input type="text" name="motor0Sweep" value="Sweep angle in degrees">
<input type="submit" value="Submit">
</form>

<p>Motor 1 controls: </p>
<form action="/motor1Start">
  <label for="m1S">Start time:</label>
  <input type="time" id="m1S" name="motor1Start">
  <input type="submit" value="Submit">
</form>
<form action="/motor1End">
  <label for="m1E">End time:</label>
  <input type="time" id="m1E" name="motor1End">
  <input type="submit" value="Submit">
</form>
<FORM METHOD="POST"action="/motor1Sweep">
<input type="text" name="motor1Sweep" value="Sweep angle in degrees">
<input type="submit" value="Submit">
</form>

</body>
</html>
)=====";

void handleMotor0Start()
{
 webPage=htmlPage;
 notice=server.arg("motor0Start");
 Serial.println("M0 Start time received, contents:");
 Serial.println(notice);
 server.send(200,"text/html",webPage);
}

void handleMotor0End()
{
 webPage=htmlPage;
 notice=server.arg("motor0End");
 Serial.println("M0 End time received, contents:");
 Serial.println(notice);
 server.send(200,"text/html",webPage);
}

void handleMotor0Sweep()
{
 webPage=htmlPage;
 notice=server.arg("motor0Sweep");
 Serial.println("M0 Sweep value received, contents:");
 Serial.println(notice);
 server.send(200,"text/html",webPage);
}

void handleMotor1Start()
{
 webPage=htmlPage;
 notice=server.arg("motor1Start");
 Serial.println("M1 Start time received, contents:");
 Serial.println(notice);
 server.send(200,"text/html",webPage);
}

void handleMotor1End()
{
 webPage=htmlPage;
 notice=server.arg("motor1End");
 Serial.println("M1 End time received, contents:");
 Serial.println(notice);
 server.send(200,"text/html",webPage);
}

void handleMotor1Sweep()
{
 webPage=htmlPage;
 notice=server.arg("motor1Sweep");
 Serial.println("M1 Sweep value received, contents:");
 Serial.println(notice);
 server.send(200,"text/html",webPage);
}

   void setup()
   {
    
  Serial.begin(115200);
  delay(10);
  Serial.println();
  Serial.print("Connecting");
  WiFi.begin(WifiName,WifiPass);
  
  server.on("/motor0Start",handleMotor0Start);
  server.on("/motor0End",handleMotor0End);
  server.on("/motor0Sweep",handleMotor0Sweep);
  server.on("/motor1Start",handleMotor1Start);
  server.on("/motor1End",handleMotor1End);
  server.on("/motor1Sweep",handleMotor1Sweep);
  
  while(WiFi.status()!= WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
    }
    
  Serial.println("");
  Serial.println("Wi-Fi Connected");
  Serial.println("IP Address is:");
  Serial.println(WiFi.localIP());
  Serial.println(notice);
  server.begin();
  Serial.println("HTTP Server Started");    

}


void loop() {
  server.handleClient();
  // put your main code here, to run repeatedly:

}

When I run this code, the webpage displays a blank white page that says " Not found/" I’m a bit new to HTML programming with form, so can anyone tell me why this is occurring?

Thanks, and all the best!

When I run this code, the webpage displays a blank white page that says " Not found/"

Well you haven't created a callback in case of just the root of the page being called, but if you would navigate to any of the defined pages, your page should show up.
If you addserver.on("/",handleRoot);to setup()
and create:

void handleRoot()
{
 webPage=htmlPage;
 server.send(200,"text/html",webPage);
}

It should work as you want.

So I uploaded this code with the code you suggested added:

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>


const char* WifiName="*****";
const char* WifiPass="******";
String webPage,notice;

ESP8266WebServer server(80);


const char htmlPage[]PROGMEM=R"=====(
<!DOCTYPE html>
<html>
<body>
<h3>Motor Control Page</h3>
<p>Motor 0 controls: </p>
<form action="/motor0Start">
  <label for="m0S">Start time:</label>
  <input type="time" id="m0S" name="motor0Start">
  <input type="submit" value="Submit">
</form>
<form action="/motor0End">
  <label for="m0E">End time:</label>
  <input type="time" id="m0E" name="motor0End">
  <input type="submit" value="Submit">
</form>

<FORM METHOD="POST"action="/motor0Sweep">
<input type="text" name="motor0Sweep" value="Sweep angle in degrees">
<input type="submit" value="Submit">
</form>

<p>Motor 1 controls: </p>
<form action="/motor1Start">
  <label for="m1S">Start time:</label>
  <input type="time" id="m1S" name="motor1Start">
  <input type="submit" value="Submit">
</form>
<form action="/motor1End">
  <label for="m1E">End time:</label>
  <input type="time" id="m1E" name="motor1End">
  <input type="submit" value="Submit">
</form>
<FORM METHOD="POST"action="/motor1Sweep">
<input type="text" name="motor1Sweep" value="Sweep angle in degrees">
<input type="submit" value="Submit">
</form>

</body>
</html>
)=====";

void handleRoot()
{
 webPage=htmlPage;
 server.send(200,"text/html",webPage);
}

void handleMotor0Start()
{
 webPage=htmlPage;
 notice=server.arg("motor0Start");
 Serial.println("M0 Start time received, contents:");
 Serial.println(notice);
 server.send(200,"text/html",webPage);
}

void handleMotor0End()
{
 webPage=htmlPage;
 notice=server.arg("motor0End");
 Serial.println("M0 End time received, contents:");
 Serial.println(notice);
 server.send(200,"text/html",webPage);
}

void handleMotor0Sweep()
{
 webPage=htmlPage;
 notice=server.arg("motor0Sweep");
 Serial.println("M0 Sweep value received, contents:");
 Serial.println(notice);
 server.send(200,"text/html",webPage);
}

void handleMotor1Start()
{
 webPage=htmlPage;
 notice=server.arg("motor1Start");
 Serial.println("M1 Start time received, contents:");
 Serial.println(notice);
 server.send(200,"text/html",webPage);
}

void handleMotor1End()
{
 webPage=htmlPage;
 notice=server.arg("motor1End");
 Serial.println("M1 End time received, contents:");
 Serial.println(notice);
 server.send(200,"text/html",webPage);
}

void handleMotor1Sweep()
{
 webPage=htmlPage;
 notice=server.arg("motor1Sweep");
 Serial.println("M1 Sweep value received, contents:");
 Serial.println(notice);
 server.send(200,"text/html",webPage);
}

   void setup()
   {
    
  Serial.begin(115200);
  delay(10);
  Serial.println();
  Serial.print("Connecting");
  WiFi.begin(WifiName,WifiPass);

  server.on("/",handleRoot);
  server.on("/motor0Start",handleMotor0Start);
  server.on("/motor0End",handleMotor0End);
  server.on("/motor0Sweep",handleMotor0Sweep);
  server.on("/motor1Start",handleMotor1Start);
  server.on("/motor1End",handleMotor1End);
  server.on("/motor1Sweep",handleMotor1Sweep);
  
  while(WiFi.status()!= WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
    }
    
  Serial.println("");
  Serial.println("Wi-Fi Connected");
  Serial.println("IP Address is:");
  Serial.println(WiFi.localIP());
  Serial.println(notice);
  server.begin();
  Serial.println("HTTP Server Started");    

}


void loop() {
  server.handleClient();
  // put your main code here, to run repeatedly:

}

And I’m now getting this error in the Serial Monitor

Connecting...........
Wi-Fi Connected
IP Address is:
192.168.1.121

HTTP Server Started

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

Exception (3):
epc1=0x4000bf64 epc2=0x00000000 epc3=0x00000000 excvaddr=0x4023d9d1 depc=0x00000000


>>stack>>>


ctx: cont
sp: 3ffffd00 end: 3fffffc0 offset: 0190
3ffffe90: 00000001 3ffee49c 3ffee478 00000001
3ffffea0: 4023d9d1 3ffffef0 00000000 40206230
3ffffeb0: 3fffff10 3fffff10 3ffee568 40203300
3ffffec0: 00000001 402086a8 3ffef954 40208676
3ffffed0: 3fffff10 3ffee4b8 3ffef954 401000e1
3ffffee0: 3ffef954 3ffee4b8 3ffef954 40201318
3ffffef0: 3ffe0000 00000000 80000281 8010065b
3fffff00: 3ffef954 3ffee4b8 3ffee478 402035f2
3fffff10: 0000002f 80ffff70 81ff0400 0000009f
3fffff20: 80005054 4bc6a7f0 00004e48 3ffee628
3fffff30: 3ffee4b8 00000000 4bc6a7f0 00000001
3fffff40: 00000001 3ffef954 40100212 de76c8b4
3fffff50: 00000000 3fff0204 3ffee478 3ffee628
3fffff60: 00000001 3ffee49c 3ffee478 402038b3
3fffff70: 40208ae8 00000000 00001388 8000646e
3fffff80: 00000000 3fff0204 00000001 40100170
3fffff90: 3fffdad0 00000000 3ffee5e8 40203958
3fffffa0: 3fffdad0 00000000 3ffee5e8 40206b04
3fffffb0: feefeffe feefeffe 3ffe84ec 40100b9d
<<<stack<<<

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

ets Jan 8 2013,rst cause:2, boot mode:(3,7)

load 0x4010f000, len 3584, room 16
tail 0
chksum 0xb0
csum 0xb0
v2843a5ac
~ld

Connecting.........
Wi-Fi Connected
IP Address is:
192.168.1.121

HTTP Server Started

Am I missing something? What’s causing this issue, looks like a LoadStoreErrorCause.

Figured out the issue. I had to create a new .h file, paste the PRGMEM html const char into there, the only reference htmlPage in the server.send commands

to know the error you must go to the esp exception decoder and find it out and also download the decoder from the github , after installing it go to the arduino files and paste in the tools sections of the computer
i hope this will help u.

So that was a different issue. I anyway find it a little odd that you first put your page in progmem, and then copy it to a String and send it unaltered. The great thing about using Strings in this case is that you can create your webpage dynamically, adding values and optional text depending on values etc. On an ESP the memory restrictions aren't a real issue for webpages normally, so putting a page into progmem is not really required, and if you copy it to a String it really doesn't save any memory.