Help with the code for ESP32

Hi, I wrote a code for a project using multiple different websites. Now i am facing an error idk how to solve. Can someone please help me and make my code better.


  #include <WiFi.h>
  #include <ESPAsyncWebServer.h>
  #include <SPIFFS.h>
int x = 0; //Reset to 0 
int y = 0;
int z = 0;  

//*FSR sensors*/
#define noFSRs 3 // Number of FSRs connected
#define FSR1 12  //Analogue ports
#define FSR2 13 
#define FSR3 14 

float fsrVoltageArray[3];       // The analog reading converted and                                      //scaled to voltage as a floating point                                  //number
float fsrForceArray[3];         // The force in Newton
float fsrWeightInGramsArray[3]; // Weight converted to grams

int   pinArray[3]       = {FSR1, FSR2, FSR3};    // The pin ID for the                                                    //three devices
float forceMaxArray[3]  = {100.0, 100.0, 100.0}; // Maximum forces                                                        //supported

float million = 1000000.0; // Unit for "1/micro
float conversionToKgrams = 1.0/9.80665;

long K       = 1000;
long R       = 10*K;    // R in K Ohm
long Vcc     = 5000;    // 5V=5000mV, 3.3V = 3300 mV
float voltageMax = 0.98 * Vcc; // Maximum voltage set to 95% of Vcc. Set                               //the force to the maximum beyond this                                 //value.


// Replace with your network credentials
const char* ssid = "Loading...";
const char* password = "verybigpp";

// Create AsyncWebServer object on port 80
AsyncWebServer server(80);



void setup(){
  // Serial port for debugging purposes
  Serial.begin(115200);
  
  bool status; 
  
  // Initialize SPIFFS
  if(!SPIFFS.begin()){
    Serial.println("An Error has occurred while mounting SPIFFS");
    return;
  }

  // Connect to Wi-Fi
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi..");
  }

  // Print ESP32 Local IP Address
  Serial.println(WiFi.localIP());


for (int FSR = 0; FSR < noFSRs; FSR++) {   

      fsrVoltageArray[FSR] = 0.0; //Reset values upon entry
      fsrForceArray[FSR]   = 0.0;
      
      int fsrPin   = pinArray[FSR];     
      int fsrReading = analogRead(fsrPin); 
       
      fsrVoltageArray[FSR] = (float) map(fsrReading, 0, 1023, 0, 5000);

for (int FSR = 0; FSR < noFSRs; FSR++) {  
    
         // The value of the force F as a function of the voltage V is           ///computed as: F(V) = (Fmax/Vmax) * V

         float force_value = (forceMaxArray[FSR]/voltageMax) * fsrVoltageArray[FSR];

         // Three situations are distinguished:
         //
         // 1. If V is too close to the maximum (as defined by voltageMax          // ), the force can
         //    go to infinity. This is avoided by setting it the maximum          //value as soon as it is higher than our threshold voltageMax.
         //
         // 2. If the computed force F is too small, we set it to zero to          // avoid noise effects.
         //
         // 3. In all other cases, we take the logarithmic value to 
         //reduce the sloop and better distinguish small changes.

         if ( fsrVoltageArray[FSR] < voltageMax ) {

           // V is not too high in this branch

           if ( force_value <= 1.00 ) {
              fsrForceArray[FSR] = 0.0; // Force is too small, set it to                                        // zero
           } else {
             fsrForceArray[FSR] = log10(force_value); // Value is okay,                                                       //take the log of                                                       //this
           }

        } else {

           // Cap the force if the voltage is too close to Vcc (for Vcc            //it would be infinity)

           fsrForceArray[FSR] = log10(forceMaxArray[FSR]);

           Serial.print("Cut off activated for FSR = "); Serial.println(FSR);
        }
for (int FSR = 0; FSR < noFSRs; FSR++) {  
      fsrWeightInGramsArray[FSR] = fsrForceArray[FSR] * conversionToKgrams * 1000.0;
    }
      
   



      

  // Route for root / web page
  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send(SPIFFS, "/index.html");
  });
  server.on("/1", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/plain", fsrWeightInGramsArray[0]);
  });
  server.on("/2", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/plain", fsrWeightInGramsArray[1]);
  });
  server.on("/3", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/plain", fsrWeightInGramsArray[2]);
  });

  // Start server
  server.begin();
}
 
void loop(){
  
}

this is the code for the ESP32

<!DOCTYPE HTML><html>
<!-- Rui Santos - Complete project details at https://RandomNerdTutorials.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software. -->
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <script src="https://code.highcharts.com/highcharts.js"></script>
  <style>
    body {
      min-width: 310px;
    	max-width: 800px;
    	height: 400px;
      margin: 0 auto;
    }
    h2 {
      font-family: Arial;
      font-size: 2.5rem;
      text-align: center;
    }
  </style>
</head>
<body>
  <h2>Pressure distribution</h2>
  <div id="chart-1" class="container"></div>
  <div id="chart-2" class="container"></div>
  <div id="chart-3" class="container"></div>
</body>
<script>
var chartT = new Highcharts.Chart({
  chart:{ renderTo : 'chart-1' },
  title: { text: '1' },
  series: [{
    showInLegend: false,
    data: []
  }],
  plotOptions: {
    line: { animation: false,
      dataLabels: { enabled: true }
    },
    series: { color: '#059e8a' }
  },
  xAxis: { type: 'datetime',
    dateTimeLabelFormats: { second: '%H:%M:%S' }
  },
  yAxis: {
    title: { text: 'gram' }
    //title: { text: 'gram' }
  },
  credits: { enabled: false }
});
setInterval(function ( ) {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      var x = (new Date()).getTime(),
          y = parseFloat(this.responseText);
      //console.log(this.responseText);
      if(chartT.series[0].data.length > 40) {
        chartT.series[0].addPoint([x, y], true, true, true);
      } else {
        chartT.series[0].addPoint([x, y], true, false, true);
      }
    }
  };
  xhttp.open("GET", "/1", true);
  xhttp.send();
}, 30000 ) ;

var chartH = new Highcharts.Chart({
  chart:{ renderTo:'chart-2' },
  title: { text: '2' },
  series: [{
    showInLegend: false,
    data: []
  }],
  plotOptions: {
    line: { animation: false,
      dataLabels: { enabled: true }
    }
  },
  xAxis: {
    type: 'datetime',
    dateTimeLabelFormats: { second: '%H:%M:%S' }
  },
  yAxis: {
    title: { text: 'Gram' }
  },
  credits: { enabled: false }
});
setInterval(function ( ) {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      var x = (new Date()).getTime(),
          y = parseFloat(this.responseText);
      //console.log(this.responseText);
      if(chartH.series[0].data.length > 40) {
        chartH.series[0].addPoint([x, y], true, true, true);
      } else {
        chartH.series[0].addPoint([x, y], true, false, true);
      }
    }
  };
  xhttp.open("GET", "/2", true);
  xhttp.send();
}, 30000 ) ;

var chartP = new Highcharts.Chart({
  chart:{ renderTo:'3' },
  title: { text: '3' },
  series: [{
    showInLegend: false,
    data: []
  }],
  plotOptions: {
    line: { animation: false,
      dataLabels: { enabled: true }
    },
    series: { color: '#18009c' }
  },
  xAxis: {
    type: 'datetime',
    dateTimeLabelFormats: { second: '%H:%M:%S' }
  },
  yAxis: {
    title: { text: 'Gram' }
  },
  credits: { enabled: false }
});
setInterval(function ( ) {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      var x = (new Date()).getTime(),
          y = parseFloat(this.responseText);
      //console.log(this.responseText);
      if(chartP.series[0].data.length > 40) {
        chartP.series[0].addPoint([x, y], true, true, true);
      } else {
        chartP.series[0].addPoint([x, y], true, false, true);
      }
    }
  };
  xhttp.open("GET", "/3", true);
  xhttp.send();
}, 30000 ) ;
</script>
</html>

this is the code for the website

And you are facing an error that only you know about at the moment.

patient on the phone saying to the doctor: "I have a problem can you help me"

doctor: "what kind of problem do you have"

patient: "I feel bad"

doctor: "what does that mean?"

patient: "I feel pain"

doctor: "What kind of pain"

....
got the picture?
You should provide as much information as you can
what shall your code do ?
what error-message to you get?
is this a compiler-error or an error in your browser?

etc. etc.
You are working on an informatic project. And what is needed most in an informatic project is information.

Did you write it? ... or did you copy it from someone else without understanding how it works?

... are you able to share the error?

I am so so sorry this was very late at night and my brain had stopped functioning.

This project is basically three force sensitive resistors kept on the three main pressure points of the feet. It detects the force applied and through the ESP32 sends the data to a website which plots it into a graph. I used codes form various sources to make it tried to understand as much as i could and patched most of the holes but things i didnt understand like the website is where i am struggling

Arduino: 1.8.19 (Mac OS X), Board: "ESP32-WROOM-DA Module, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), 240MHz (WiFi/BT), QIO, 80MHz, 4MB (32Mb), 921600, Core 1, Core 1, None, Disabled"











/Users/binuandrajesh/Documents/Arduino/ESP_Chart_Web_Server/ESP_Chart_Web_Server.ino: In lambda function:
ESP_Chart_Web_Server:132:64: error: no matching function for call to 'AsyncWebServerRequest::send_P(int, const char [11], float&)'
     request->send_P(200, "text/plain", fsrWeightInGramsArray[0]);
                                                                ^
In file included from /Users/binuandrajesh/Documents/Arduino/ESP_Chart_Web_Server/ESP_Chart_Web_Server.ino:13:
/Users/binuandrajesh/Documents/Arduino/libraries/ESPAsyncWebServer-master/src/ESPAsyncWebServer.h:243:10: note: candidate: 'void AsyncWebServerRequest::send_P(int, const String&, const uint8_t*, size_t, AwsTemplateProcessor)'
     void send_P(int code, const String& contentType, const uint8_t * content, size_t len, AwsTemplateProcessor callback=nullptr);
          ^~~~~~
/Users/binuandrajesh/Documents/Arduino/libraries/ESPAsyncWebServer-master/src/ESPAsyncWebServer.h:243:10: note:   candidate expects 5 arguments, 3 provided
/Users/binuandrajesh/Documents/Arduino/libraries/ESPAsyncWebServer-master/src/ESPAsyncWebServer.h:244:10: note: candidate: 'void AsyncWebServerRequest::send_P(int, const String&, const char*, AwsTemplateProcessor)'
     void send_P(int code, const String& contentType, PGM_P content, AwsTemplateProcessor callback=nullptr);
          ^~~~~~
/Users/binuandrajesh/Documents/Arduino/libraries/ESPAsyncWebServer-master/src/ESPAsyncWebServer.h:244:10: note:   no known conversion for argument 3 from 'float' to 'const char*'
/Users/binuandrajesh/Documents/Arduino/ESP_Chart_Web_Server/ESP_Chart_Web_Server.ino: In lambda function:
ESP_Chart_Web_Server:135:64: error: no matching function for call to 'AsyncWebServerRequest::send_P(int, const char [11], float&)'
     request->send_P(200, "text/plain", fsrWeightInGramsArray[1]);
                                                                ^
In file included from /Users/binuandrajesh/Documents/Arduino/ESP_Chart_Web_Server/ESP_Chart_Web_Server.ino:13:
/Users/binuandrajesh/Documents/Arduino/libraries/ESPAsyncWebServer-master/src/ESPAsyncWebServer.h:243:10: note: candidate: 'void AsyncWebServerRequest::send_P(int, const String&, const uint8_t*, size_t, AwsTemplateProcessor)'
     void send_P(int code, const String& contentType, const uint8_t * content, size_t len, AwsTemplateProcessor callback=nullptr);
          ^~~~~~
/Users/binuandrajesh/Documents/Arduino/libraries/ESPAsyncWebServer-master/src/ESPAsyncWebServer.h:243:10: note:   candidate expects 5 arguments, 3 provided
/Users/binuandrajesh/Documents/Arduino/libraries/ESPAsyncWebServer-master/src/ESPAsyncWebServer.h:244:10: note: candidate: 'void AsyncWebServerRequest::send_P(int, const String&, const char*, AwsTemplateProcessor)'
     void send_P(int code, const String& contentType, PGM_P content, AwsTemplateProcessor callback=nullptr);
          ^~~~~~
/Users/binuandrajesh/Documents/Arduino/libraries/ESPAsyncWebServer-master/src/ESPAsyncWebServer.h:244:10: note:   no known conversion for argument 3 from 'float' to 'const char*'
/Users/binuandrajesh/Documents/Arduino/ESP_Chart_Web_Server/ESP_Chart_Web_Server.ino: In lambda function:
ESP_Chart_Web_Server:138:64: error: no matching function for call to 'AsyncWebServerRequest::send_P(int, const char [11], float&)'
     request->send_P(200, "text/plain", fsrWeightInGramsArray[2]);
                                                                ^
In file included from /Users/binuandrajesh/Documents/Arduino/ESP_Chart_Web_Server/ESP_Chart_Web_Server.ino:13:
/Users/binuandrajesh/Documents/Arduino/libraries/ESPAsyncWebServer-master/src/ESPAsyncWebServer.h:243:10: note: candidate: 'void AsyncWebServerRequest::send_P(int, const String&, const uint8_t*, size_t, AwsTemplateProcessor)'
     void send_P(int code, const String& contentType, const uint8_t * content, size_t len, AwsTemplateProcessor callback=nullptr);
          ^~~~~~
/Users/binuandrajesh/Documents/Arduino/libraries/ESPAsyncWebServer-master/src/ESPAsyncWebServer.h:243:10: note:   candidate expects 5 arguments, 3 provided
/Users/binuandrajesh/Documents/Arduino/libraries/ESPAsyncWebServer-master/src/ESPAsyncWebServer.h:244:10: note: candidate: 'void AsyncWebServerRequest::send_P(int, const String&, const char*, AwsTemplateProcessor)'
     void send_P(int code, const String& contentType, PGM_P content, AwsTemplateProcessor callback=nullptr);
          ^~~~~~
/Users/binuandrajesh/Documents/Arduino/libraries/ESPAsyncWebServer-master/src/ESPAsyncWebServer.h:244:10: note:   no known conversion for argument 3 from 'float' to 'const char*'
/Users/binuandrajesh/Documents/Arduino/ESP_Chart_Web_Server/ESP_Chart_Web_Server.ino: In function 'void setup()':
ESP_Chart_Web_Server:145:12: error: a function-definition is not allowed here before '{' token
 void loop(){
            ^
ESP_Chart_Web_Server:147:1: error: expected '}' at end of input
 }
 ^
/Users/binuandrajesh/Documents/Arduino/ESP_Chart_Web_Server/ESP_Chart_Web_Server.ino:73:40: note: to match this '{'
 for (int FSR = 0; FSR < noFSRs; FSR++) {
                                        ^
ESP_Chart_Web_Server:147:1: error: expected '}' at end of input
 }
 ^
/Users/binuandrajesh/Documents/Arduino/ESP_Chart_Web_Server/ESP_Chart_Web_Server.ino:50:13: note: to match this '{'
 void setup(){
             ^
exit status 1
no matching function for call to 'AsyncWebServerRequest::send_P(int, const char [11], float&)'


This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

this is the error and the Arduino and website code is above.

Again really sorry for the lack of info before please do help me as i have very little idea about this and want to learn more about it.

xxx

The message about

gives the OP no clues?

Has the OP did a Autoformat on their code? If so the OP will see that the code does not align. A equal number } should exist for each {. Also the { and } needs to be in the right spots.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.