0

I'm trying to use the ESP32 board to control an LED, buzzer, and motor (ABA) through an access point.

I got some code from this page: https://lastminuteengineers.com/creating-esp32-web-server-arduino-ide/ Which is amazing! I changed some names here and there and evrything okay (to control ONLY 2 things).

Now that I wanted to add the 3rd device, the code is not compiling.

I get this error:

exit status 1

too few arguments to function 'String SendHTML(uint8_t, uint8_t, uint8_t)'

With the line in bold marked.

server.send(200, "text/html", SendHTML(ABA1status,false));

#include <ETH.h>
#include <WiFi.h>
#include <WiFiAP.h>
#include <WiFiClient.h>
#include <WiFiGeneric.h>
#include <WiFiMulti.h>
#include <WiFiScan.h>
#include <WiFiServer.h>
#include <WiFiSTA.h>
#include <WiFiType.h>
#include <WiFiUdp.h>

#include <HTTP_Method.h>
#include <WebServer.h>




/* Put your SSID & Password */
const char* ssid = "ESP32DeltaSolutions";  // Enter SSID here
const char* password = "deltasolutions123";  //Enter Password here

/* Put IP Address details */
IPAddress local_ip(192,168,1,2);
IPAddress gateway(192,168,1,1);
IPAddress subnet(255,255,255,0);

WebServer server(80);

uint8_t LED1pin = 25;
bool LED1status = LOW;

uint8_t BUZZ1pin = 32;
bool BUZZ1status = LOW;

uint8_t ABA1pin = 35;
bool ABA1status = LOW;



void setup() {
  Serial.begin(115200);
  pinMode(LED1pin, OUTPUT);
  pinMode(BUZZ1pin, OUTPUT);
  pinMode(ABA1pin, OUTPUT);

  WiFi.softAP(ssid, password);
  WiFi.softAPConfig(local_ip, gateway, subnet);
  delay(100);

  server.on("/", handle_OnConnect);
  server.on("/led1on", handle_led1on);
  server.on("/led1off", handle_led1off);
  server.on("/buzz1on", handle_buzz1on);
  server.on("/buzz1off", handle_buzz1off);
  server.on("/aba1on", handle_aba1on);
  server.on("/aba1off", handle_aba1off);
  server.onNotFound(handle_NotFound);

  server.begin();
  Serial.println("HTTP server started");
}
void loop() {
  server.handleClient();
  if(LED1status)
  {digitalWrite(LED1pin, HIGH);}
  else
  {digitalWrite(LED1pin, LOW);}

  if(BUZZ1status)
  {digitalWrite(BUZZ1pin, HIGH);}
  else
  {digitalWrite(BUZZ1pin, LOW);}

  if(ABA1status)
  {digitalWrite(ABA1pin, HIGH);}
  else
  {digitalWrite(ABA1pin, LOW);}

}

void handle_OnConnect() {
  LED1status = LOW;
  BUZZ1status = LOW;
  ABA1status = LOW;
  Serial.println("GPIO4 Status: OFF | GPIO5 Status: OFF");
  server.send(200, "text/html", SendHTML(LED1status,BUZZ1status,ABA1status)); 
}

void handle_led1on() {
  LED1status = HIGH;
  Serial.println("GPIO4 Status: ON");
  server.send(200, "text/html", SendHTML(true,LED1status)); 
}

void handle_led1off() {
  LED1status = LOW;
  Serial.println("GPIO4 Status: OFF");
  server.send(200, "text/html", SendHTML(false,LED1status)); 
}

void handle_buzz1on() {
  BUZZ1status = HIGH;
  Serial.println("GPIO5 Status: ON");
  server.send(200, "text/html", SendHTML(BUZZ1status,true)); 
}

void handle_buzz1off() {
  BUZZ1status = LOW;
  Serial.println("GPIO5 Status: OFF");
  server.send(200, "text/html", SendHTML(BUZZ1status,false)); 
}

void handle_aba1on() {
  ABA1status = HIGH;
  Serial.println("GPI35 Status: ON");
  server.send(200, "text/html", SendHTML(ABA1status,true)); 
}

void handle_aba1off() {
  BUZZ1status = LOW;
  Serial.println("GPI35 Status: OFF");
  **server.send(200, "text/html", SendHTML(ABA1status,false));** 
}

void handle_NotFound(){
  server.send(404, "text/plain", "Not found");
}

String SendHTML(uint8_t LED1status,uint8_t BUZZ1status,uint8_t ABA1status){
  String ptr = "<!DOCTYPE html> <html>\n";
  ptr +="<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\">\n";
  ptr +="<title>LED Control</title>\n";
  ptr +="<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}\n";
  ptr +="body{margin-top: 50px;} h1 {color: #444444;margin: 50px auto 30px;} h3 {color: #444444;margin-bottom: 50px;}\n";
  ptr +=".button {display: block;width: 80px;background-color: #3498db;border: none;color: white;padding: 13px 30px;text-decoration: none;font-size: 25px;margin: 0px auto 35px;cursor: pointer;border-radius: 4px;}\n";
  ptr +=".button-on {background-color: #3498db;}\n";
  ptr +=".button-on:active {background-color: #2980b9;}\n";
  ptr +=".button-off {background-color: #34495e;}\n";
  ptr +=".button-off:active {background-color: #2c3e50;}\n";
  ptr +="p {font-size: 14px;color: #888;margin-bottom: 10px;}\n";
  ptr +="</style>\n";
  ptr +="</head>\n";
  ptr +="<body>\n";
  ptr +="<h1>ESP32 Web Server</h1>\n";
  ptr +="<h3>Using Access Point(AP) Mode</h3>\n";
  ptr +="<h3>Delta solutions</h3>\n";

   if(led1stat)
  {ptr +="<p>LED1 Status: ON</p><a class=\"button button-off\" href=\"/led1off\">OFF</a>\n";}
  else
  {ptr +="<p>LED1 Status: OFF</p><a class=\"button button-on\" href=\"/led1on\">ON</a>\n";}

  if(buzz1stat)
  {ptr +="<p>BUZZ1 Status: ON</p><a class=\"button button-off\" href=\"/buzz1off\">OFF</a>\n";}
  else
  {ptr +="<p>BUZZ1 Status: OFF</p><a class=\"button button-on\" href=\"/buzz1on\">ON</a>\n";}

  if(aba1stat)
  {ptr +="<p>ABA1 Status: ON</p><a class=\"button button-off\" href=\"/aba1off\">OFF</a>\n";}
  else
  {ptr +="<p>ABA1 Status: OFF</p><a class=\"button button-on\" href=\"/aba1on\">ON</a>\n";}

  ptr +="</body>\n";
  ptr +="</html>\n";
  return ptr;

Any suggestions?

Thanks!

  • SendHTML has 3 parameters, but you only provide 2. Its clear that the compiler gives you that error – chrisl Oct 5 at 22:20
1

The syntax of six SendHTML you use with true and false is actually wrong.

By defining a function like this String SendHTML(uint8_t LED1status,uint8_t BUZZ1status,uint8_t ABA1status), you mean that first, second and third input to this function are Status of LED1, Status of BUZZ1 and Status of ABA1.

So try replacing all six SendHTML with true and false functions to this SendHTML(LED1status,BUZZ1status,ABA1status)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.