Need help guys. Newbie here.

I am getting this error message,

error: a function-definition is not allowed here before '{' token
void loop() {

please help me compile my work for our school requirement.
thank you so much,
here is the full sketch

--------------------------------------->

#include <WiFi.h>
const char* ssid     = "ESP32_ACCESS_POINT";
const char* password = "123456789";
WiFiServer server(80);
#include <esp_now.h>
#include "DHT.h"
#include "Adafruit_Sensor.h"
#include <DHT_U.h>
#define DHTPIN

#define DHTTYPE DHT11
const int DHTPin = 22;
DHT dht(DHTPin, DHTTYPE);
float localHum = 0;
float localTemp = 0;
float getWater() {
  float water = analogRead(32);
  water = map(water,3355,1500,0,100);
  return water;
}
float localSoil = getWater();


void connectWiFi(void)
{
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  // Print local IP address and start web server
  Serial.println("");
  Serial.println("WiFi connected.");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
  server.begin();
}

void setup()
{
  Serial.begin(115200);
  delay(10);
  connectWiFi();
  dht.begin();
}

int value = 0;



void getDHT()
{
  float tempIni = localTemp;
  float humIni = localHum;
  float soilIni = localSoil;
  localTemp = dht.readTemperature();
  localHum = dht.readHumidity();
  localSoil = getWater();
  if (isnan(localHum) || isnan(localTemp) || isnan(localSoil))
  {
    localSoil = soilIni;
    localTemp = tempIni;
    localHum = humIni;
    return;
  }
}



void WiFiLocalWebPageCtrl(void)
{


  WiFiClient client = server.available();   
  if (client) {                             
  Serial.println("new client");
    String currentLine = "";         
    while (client.connected()) {            
      if (client.available()) {             
        char c = client.read();             
        Serial.write(c);                    
        if (c == '\n') {                    
          if (currentLine.length() == 0) {
            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html");
            client.println();
            client.println("<center>");
            client.print("<font size='18'>");
              client.print("Temperature now is: ");
              client.print(localTemp);
              client.print("  oC
");
              client.print("
");
              client.print("Humidity now is:     ");
              client.print(localHum);
              client.print(" % 
");
              client.print("
");
              client.print("Water Content on Soil:     ");
              client.print(localSoil);
              client.print("%
");
              client.print("");
              client.print("
");
              if (localSoil < 30){
                client.print("Needs More Water!");
              }
              
          
      }
    }
    client.stop();
    Serial.println("Client Disconnected.");
  }
    }

void loop() {
 
  getDht ();
  WiFiLocalWebPageCtrl();
}

-------------------------->

-Newbeeee , (george pasion jr.)

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

float localSoil = getWater();

Too early. The hardware is not ready for business.

Auto-format (Ctrl + T) will reveal the trouble. Hint: you're short two.

I pressed ctrl T, i double checked "{" & "}" , if they dont have any pairs, but still, i get the same error please help.

again, plugging my code here ---------------->

#include <WiFi.h>
const char* ssid = "ESP32_ACCESS_POINT";
const char* password = "123456789";

WiFiServer server(80);
#include <esp_now.h>
#include "DHT.h"
#include "Adafruit_Sensor.h"
#include <DHT_U.h>
#define DHTPIN

#define DHTTYPE DHT11
const int DHTPin = 22;
DHT dht(DHTPin, DHTTYPE);
float localHum = 0;
float localTemp = 0;
float getWater() {
float water = analogRead(32);
water = map(water, 3355, 1500, 0, 100);
return water;
}
float localSoil = getWater();

void connectWiFi(void)
{
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
// Print local IP address and start web server
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
server.begin();
}

void setup()
{
Serial.begin(115200);
delay(10);
connectWiFi();
dht.begin();
}

int value = 0;

void getDHT()
{
float tempIni = localTemp;
float humIni = localHum;
float soilIni = localSoil;
localTemp = dht.readTemperature();
localHum = dht.readHumidity();
localSoil = getWater();
if (isnan(localHum) || isnan(localTemp) || isnan(localSoil))
{
localSoil = soilIni;
localTemp = tempIni;
localHum = humIni;
return;
}
}

void WiFiLocalWebPageCtrl(void)
{
WiFiClient client = server.available();
if (client) {
Serial.println("new client");
String currentLine = "";
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
if (c == '\n') {
if (currentLine.length() == 0) {
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println();
client.println("");
client.print("");
client.print("Temperature now is: ");
client.print(localTemp);
client.print(" oC
");
client.print("
");
client.print("Humidity now is: ");
client.print(localHum);
client.print(" %
");
client.print("
");
client.print("Water Content on Soil: ");
client.print(localSoil);
client.print("%
");
client.print("");
client.print("
");
if (localSoil < 30) {
client.print("Needs More Water!");
}

}
}
}
client.stop();
Serial.println("Client Disconnected.");
}
}

void loop()
{ getDHT();

WiFiLocalWebPageCtrl();
}

thanks in advance
newbeeee

Here is your code Auto formatted and in code tags

#include <WiFi.h>
const char* ssid     = "ESP32_ACCESS_POINT";
const char* password = "123456789";


WiFiServer server(80);
#include <esp_now.h>
#include "DHT.h"
#include "Adafruit_Sensor.h"
#include <DHT_U.h>
#define DHTPIN

#define DHTTYPE DHT11
const int DHTPin = 22;
DHT dht(DHTPin, DHTTYPE);
float localHum = 0;
float localTemp = 0;
float getWater()
{
  float water = analogRead(32);
  water = map(water, 3355, 1500, 0, 100);
  return water;
}
float localSoil = getWater();


void connectWiFi(void)
{
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  // Print local IP address and start web server
  Serial.println("");
  Serial.println("WiFi connected.");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
  server.begin();
}

void setup()
{
  Serial.begin(115200);
  delay(10);
  connectWiFi();
  dht.begin();
}

int value = 0;



void getDHT()
{
  float tempIni = localTemp;
  float humIni = localHum;
  float soilIni = localSoil;
  localTemp = dht.readTemperature();
  localHum = dht.readHumidity();
  localSoil = getWater();
  if (isnan(localHum) || isnan(localTemp) || isnan(localSoil))
  {
    localSoil = soilIni;
    localTemp = tempIni;
    localHum = humIni;
    return;
  }
}


void WiFiLocalWebPageCtrl(void)
{
  WiFiClient client = server.available();
  if (client)
  {
    Serial.println("new client");
    String currentLine = "";
    while (client.connected())
    {
      if (client.available())
      {
        char c = client.read();
        Serial.write(c);
        if (c == '\n')
        {
          if (currentLine.length() == 0)
          {
            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html");
            client.println();
            client.println("<center>");
            client.print("<font size='18'>");
            client.print("Temperature now is: ");
            client.print(localTemp);
            client.print("  oC
");
            client.print("
");
            client.print("Humidity now is:     ");
            client.print(localHum);
            client.print(" % 
");
            client.print("
");
            client.print("Water Content on Soil:     ");
            client.print(localSoil);
            client.print("%
");
            client.print("");
            client.print("
");
            if (localSoil < 30)
            {
              client.print("Needs More Water!");
            }
          }
        }
      }
      client.stop();
      Serial.println("Client Disconnected.");
    }
  }
  void loop()
  {
    getDHT();
    WiFiLocalWebPageCtrl();
  }

Now can you see the problem ?

HINT : note that the last } is not on the left margin as the close if each function should be

There are a few basic checks after Auto Formatting. One is that every function definition must start exactly on the left-hand margin.

Steve

WiFiLocalWebPageCtrl() has 7 open brackets and only 6 close brackets.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html . Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Looking at your code, it looks like an awful lot has been written before you got these errors.
Did you write your code in stages, and get each stage working before going onto the next.

For example, have you got code that JUST reads the sensor and shows results on the monitor.?
Have you got code that JUST connects to the WiFi and shows the results in the monitor?
Have you got code that JUST produces your web page?

Then combined them?

The number of { } problems tends to think your code was written in one go, then you compiled.

Tom.... :slight_smile: