espressif / arduino-esp32

Arduino core for the ESP32
GNU Lesser General Public License v2.1
12.95k stars 7.28k forks source link

HTTPS_OTA_Update and ESPAsyncWebServer #7588

Closed bearkillerPT closed 1 year ago

bearkillerPT commented 1 year ago

Board

ESP32 Dev Module

Device Description

plain model with wifi

Hardware Configuration

standard

Version

v2.0.5

IDE Name

Arduino IDE

Operating System

Windows

Flash frequency

40MHz

PSRAM enabled

yes

Upload speed

115200

Description

Hi! I currently have a web server running with some data of some sensors. I'm sending said data to my server and on the response body I can indicate which is the last available firmware version. I've tested https://github.com/espressif/arduino-esp32/blob/master/libraries/Update/examples/HTTPS_OTA_Update/HTTPS_OTA_Update.ino example and got it working fine with my certificates and credentials. But now I'm trying to get both working and can't because it doesn't compile... Is it not possible to have both? I found no other alternative to download the firmware from my server... Thank you!

Sketch

#include <Arduino.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include "HttpsOTAUpdate.h"
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include "SPIFFS.h"

#define statusTaskDefaultPeriod 30000
#define WifiScanTaskDefaultPeriod 30000

#define FW_VERSION 1
static HttpsOTAStatus_t otastatus;

String serverName = "https://example.com";

static const char *oldServerCertificate = "xxxx";

IPAddress PageIP(192, 168, 1, 1);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);

int wifi_status = WL_DISCONNECTED;
String ssid = "";
String password = "";

AsyncWebServer server(80);
const char *PARAM_INPUT_SSID = "ssid";
const char *PARAM_INPUT_PASSWORD = "password";

// HTML web page to handle the result of the WiFi configuration

const char res_html[] PROGMEM = R"rawliteral(
<!DOCTYPE HTML>
<html>
<head>
  <title>Heaboo</title>
  <meta name="viewport" content="width=device-width, initial-scale=1" charset="utf-8">
  <style>
    html {
      height: 100%%;
      overflow: hidden;
    }
    body {
      display: flex;
      background: linear-gradient(90deg, #00b3ba 0%%, #00ba8d 100%%);
      justify-content: center;
      align-items: center;
      height: 100%%;
    }
    a{
      max-width: 90%%;
      text-decoration: none;
      text-align: center;
      -webkit-appearance: none;
      color: #fff;
      margin-top: 3rem;
      padding: .5rem;
      border-radius: 10px;
      background-color: #198754;
      transition: color .15s ease-in-out, background-color .15s ease-in-out, border-color .15s ease-in-out, box-shadow .15s ease-in-out;
    }
    a:hover{
      color: #fff;
      background-color: #157347;
      cursor: pointer;
    }
    .resultContainer{
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      color: white;
      font-size: xx-large;
      font-weight: bold;
    }
    p {
      font-weight: bold;
      font-size: larger;
    }
  </style>
</head>

<body>
  <div class="resultContainer">
    %RESULT%
  </div>
</body>
</html>
)rawliteral";

// HTML web page to handle 3 input fields (input1, input2, input3)
const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE HTML><html><head>
  <title>Heaboo</title>
  <meta name="viewport" content="width=device-width, initial-scale=1" charset="utf-8">
  <style>
     body {
      background: linear-gradient(90deg, #00b3ba 0%%, #00ba8d 100%%);
    }
    .bodyContainer{
      display: flex;
      justify-content: center;
      align-items: center;
      flex-direction: column;
    }
    .formContainer {
      display: flex;
      padding: 1rem;
      border-radius: 10%%;
      background-color: rgb(40, 44, 52, .9);
    }

    form {
      display: flex;
      flex-direction: column;
      min-width: 40vh;
      padding: 1rem;
      border-radius: 7%%;
      background-color: rgb(73, 73, 73, 0.5);
      color: white;
    }

    .fieldContainer {
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      margin: 0;
      padding: 0;
    }

    select {
      color: white;
      background-color: #282c34;
      min-height: 1.5rem;
      font-size: 20px;
    }

    option {
      border-radius: 1%%;
      padding: .5rem;
      color: white;
      background-color: #282c34;
      flex: 1;
    }

    input {
      color: white;
      background-color: #282c34;
      font-size: 20px;
      min-height: 1.5rem;
    }
    #disconnect {
      margin: 0;
      background-color: #dc3545;
    }
    #disconnect:hover{
      background-color: #bb2d3b;
    }
    input[type=submit] {
      -webkit-appearance: none;
      width: 100%%;
      color: #fff;
      margin-top: 3rem;
      padding: .5rem;
      border-radius: 10px;
      background-color: #198754;
      transition: color .15s ease-in-out, background-color .15s ease-in-out, border-color .15s ease-in-out, box-shadow .15s ease-in-out;
    }

    input[type=submit]:hover {
      color: #fff;
      background-color: #157347;
      cursor: pointer;
    }
    h1 {
      font-size: 2rem;
      font-weight: bold;
      color: white;
    }
    p {
      font-weight: bold;
      font-size: larger;
      align-self: center;
    }
    @media screen and (max-width: 600px) {
      table {
        min-width: 90%%;
      }
    }
    table {
      border-collapse: collapse;
      border: none;
      width: 35%%;
      margin-left: auto;
      margin-right: auto;
      color: white;
    }

    tr {
      border: 1px solid #ddd;
      background-color: #282c34;
      padding: 12px;
    }

    tr:hover {
      background-color: rgb(40, 44, 52, .75);
    }

    td {
      border: none;
      padding: 12px;
    }

    .sensor {
      color: white;
      font-weight: bold;
      padding: 1px;
    }
  </style>
  </head><body>
  <div class="bodyContainer">
  %LOGIN_FORM%
  <h1>PLACE_XYZ LFC
      %POINT_TO%
    </h1>
    <table>
      <tr>
        <td>TempTank °c</td>
        <td><span class="sensor">
            %TTK%
          </span></td>
      </tr>
      <tr>
        <td>Tin
          %POINT_TO%
        </td>
        <td><span class="sensor">
          %TIN_POINT_TO%
          </span></td>
      </tr>
      <tr>
        <td>Tout
          %POINT_TO%
          °c</td>
        <td><span class="sensor">
          %TOUT_POINT_TO%
          </span></td>
      </tr>
      <tr>
        <td>LFCpumpOn: </td>
        <td><span class="sensor">
            %PUMP_IS_ON%
          </span></td>
      </tr>
      <tr>
        <td>STATE_BFe: </td>
        <td><span class="sensor">
          %ESTADO_BFe%
          </span></td>
      </tr>
      <tr>
        <td>CAUSE: </td>
        <td><span class="sensor">
          %CAUSE%
          </span></td>
      </tr>
      <tr>
        <td>TonLstStt: </td>
        <td><span class="sensor">
            %TIME_ONLST_STATE%
          </span></td>
      </tr>
      <tr>
        <td>nSwapUTC: </td>
        <td><span class="sensor">
            %SWAP_AT%
          </span></td>
      </tr>
      <tr>
        <td>STATE_Nxt: </td>
        <td><span class="sensor">
            %ESTADO_Nxt%
          </span></td>
      </tr>
      <tr>
        <td>STATE_cnt: </td>
        <td><span class="sensor">
            %STT_C%
          </span></td>
      </tr>
      <tr>
        <td>PostResponseCnt: </td>
        <td><span class="sensor">
            %SERVER_RESPONSE_CNT%
          </span></td>
      </tr>
    </table>
    <h1>Heaboo PLACE_XYZ
    </h1>
    <table>
      <tr>
        <td>WiFi SSID:</td>
        <td><span class="sensor">
            %SSID%
          </span></td>
      </tr>
      <tr>
        <td>wifiPwr (%%): </td>
        <td><span class="sensor">
            %WIFI_PWR%
          </span></td>
      </tr>
      <tr>
        <td>WiFi.localIP: </td>
        <td><span class="sensor">
            %SIP%
          </span></td>
      </tr>
      <tr>
        <td>FwVersion: </td>
        <td><span class="sensor">
            %FW_VERSION%
          </span></td>
      </tr>
      <tr>
        <td>heabooServer: </td>
        <td><span class="sensor">
            %HEABOO_SERVER_NAME%
          </span></td>
      </tr>
      <tr>
        <td>heabooUserID: </td>
        <td><span class="sensor">
            %HEABOO_USERID%
          </span></td>
      </tr>
      <tr>
        <td>PostDelay (ms): </td>
        <td><span class="sensor">
            %HEABOO_POST_DELAY%
          </span></td>
      </tr>
    </table>
    <p><input type="button" value="Update" onClick="document.location.reload(true)" </p>
  </div>

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

void statusLoop();
void updateNetworkScanList();

String networksAvailable[10];
int numSsid = 0;

unsigned long wifiScanStartMillis;
unsigned long statusStartMillis;
unsigned long currentMillis;
unsigned long statusPeriod = 0;
unsigned long wifiScanPeriod = WifiScanTaskDefaultPeriod;

void connectAp() {
  WiFi.mode(WIFI_MODE_APSTA);
  WiFi.softAPConfig(PageIP, gateway, subnet);
  WiFi.softAP("Heaboo", "");
}

void updateNetworkScanList() {
  numSsid = WiFi.scanNetworks();
  for (int thisNet = 0; thisNet < numSsid; thisNet++) {
    networksAvailable[thisNet] = String(WiFi.SSID(thisNet));
  }
}

int fileNonExistantOrEmpty(File conf_file) {
  updateNetworkScanList();
  String conf_data;
  if (!conf_file)
    return 1;
  conf_data = conf_file.readString();
  Serial.println("File contents: ");
  Serial.println(conf_data);
  if (conf_data == "")
    return 1;
  int comma_loc = conf_data.indexOf(',');
  ssid = conf_data.substring(0, comma_loc);
  password = conf_data.substring(comma_loc + 1, conf_data.length());
  for (int i = 0; i < sizeof(networksAvailable) / sizeof(networksAvailable[0]); i++)
    if (networksAvailable[i] == ssid)
      return 0;
  return 1;
}
AsyncWebServerRequest *current_req = NULL;

void setup() {
  Serial.begin(115200);

  // Initialize SPIFFS
  if (!SPIFFS.begin(true)) {
    Serial.println("An Error has occurred while mounting SPIFFS");
    return;
  }
  File conf_file = SPIFFS.open("/wifi_conf");
  if (!fileNonExistantOrEmpty(conf_file)) {  // If the file exists try to connect
    WiFi.begin(ssid.c_str(), password.c_str());
    int tries = 0;
    while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      tries++;
      if (tries >= 9) {
        SPIFFS.remove("/wifi_conf");
        Serial.println("Cant connect...");
        break;
      }
    }
    if (WiFi.status() == WL_CONNECTED) {
      Serial.println("Connected!");
      Serial.println(WiFi.localIP());
      statusPeriod = statusTaskDefaultPeriod;
    }
  } else
    Serial.println("No conf file saved!");
  Serial.println("Scanning networks");
  updateNetworkScanList();
  Serial.println("\n[*] Creating AP");
  connectAp();
  Serial.print("[+] AP Created with IP Gateway ");
  Serial.println(WiFi.softAPIP());

  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
    request->send_P(200, "text/html", index_html, processor);
  });
  server.on("/disconnect", HTTP_GET, [](AsyncWebServerRequest *request) {
    statusPeriod = 0;
    WiFi.disconnect();
    request->send_P(200, "text/html", index_html, processor);
  });

  // Send a GET request to <ESP_IP>/get?input1=<inputMessage>
  server.on("/get", HTTP_GET, [](AsyncWebServerRequest *request) {
    String inputMessage;
    String inputParam;
    if (request->hasParam(PARAM_INPUT_SSID) && request->hasParam(PARAM_INPUT_PASSWORD)) {
      ssid = request->getParam(PARAM_INPUT_SSID)->value();
      password = request->getParam(PARAM_INPUT_PASSWORD)->value();
      inputMessage = request->getParam(PARAM_INPUT_PASSWORD)->value();
      inputParam = PARAM_INPUT_PASSWORD;
    } else {
      inputMessage = "No message sent";
      inputParam = "none";
    }
    Serial.println(inputMessage);
    Serial.println(inputParam);
    Serial.println("Connecting!");
    WiFi.begin(ssid.c_str(), password.c_str());
    current_req = request;
  });
  server.onNotFound(notFound);
  server.begin();
}
void loop() {
  currentMillis = millis();                                                    // get the current "time" (actually the number of milliseconds since the program started)
  if (statusPeriod != 0 && currentMillis - statusStartMillis >= statusPeriod)  // test whether the period has elapsed
  {
    statusLoop();
    statusStartMillis = currentMillis;
  }
  while (current_req != NULL) {
    wifiConnectionLoop();
    delay(500);
  }
  if (wifiScanPeriod != 0 && currentMillis - wifiScanStartMillis >= wifiScanPeriod)  // test whether the period has elapsed
  {
    updateNetworkScanList();
    wifiScanStartMillis = currentMillis;
  }
}

String getTableEntry(const String &var) {
  int wifiPwr = WiFi.getTxPower();
  char wifiPwrStr[3];
  sprintf(wifiPwrStr, "%d", wifiPwr);
  if (var == "POINT_TO")
    return "1";
  else if (var == "TTK")
    return "1";
  else if (var == "TIN_POINT_TO")
    return "1";
  else if (var == "TOUT_POINT_TO")
    return "1";
  else if (var == "PUMP_IS_ON")
    return "1";
  else if (var == "ESTADO_BFe")
    return "1";
  else if (var == "CAUSE")
    return "1";
  else if (var == "TIME_ONLST_STATE")
    return "1";
  else if (var == "SWAP_AT")
    return "1";
  else if (var == "ESTADO_Nxt")
    return "1";
  else if (var == "STT_C")
    return "1";
  else if (var == "SERVER_RESPONSE_CNT")
    return "1";
  else if (var == "SSID")
    return ssid;
  else if (var == "WIFI_PWR")
    return wifiPwrStr;
  else if (var == "SIP")
    return WiFi.localIP().toString();
  else if (var == "FW_VERSION")
    return "" + FW_VERSION;
  else if (var == "HEABOO_SERVER_NAME")
    return "1";
  else if (var == "HEABOO_USERID")
    return "1";
  else if (var == "HEABOO_POST_DELAY")
    return "1";
  return "";
}

String processor(const String &var) {
  // Serial.println(var);
  if (var == "LOGIN_FORM") {
    if (statusPeriod == 0) {
      String res = "<div class=\"formContainer\">";
      res += "<form action =\"/get\">";
      res += "<div class=\"fieldContainer\">";
      res += "<p>SSID</p><select name=\"ssid\">";
      if (numSsid == -1) {
        Serial.println("Couldn't get a wifi connection");
        res += "<option>Couldn't get a wifi connection</option>";
      } else {
        for (int thisNet = 0; thisNet < numSsid; thisNet++) {
          res += "<option ";
          res += "value=\"" + String(networksAvailable[thisNet]) + "\">";
          res += String(networksAvailable[thisNet]);
          res += "</option>";
        }
      }
      res += "</select></div><br>";
      res += "<div class=\"fieldContainer\"><p>Password</p>";
      res += "<input type=\"password\" name=\"password\"></div>";
      res += "<input type=\"submit\" value=\"Conectar\"></form></div>";
      return res;
    } else
      return "<form action=\"disconnect\"><p>" + ssid + "</p><input type=\"submit\" value=\"Desconectar\" id=\"disconnect\"></form>";
  } else if (var == "RESULT") {
    if (WiFi.status() == WL_CONNECTED) {
      return "<p>Conexão estabelecida! Ligado à rede: " + String(WiFi.SSID()) + " com IP: " + WiFi.localIP().toString() + "</p><br><a href=\"/\">Voltar à página anterior</a>";
    } else {
      return "A ligação falhou!<br><a href=\"/\">Voltar à página anterior</a>";
    }
  } else
    return getTableEntry(var);
}
void notFound(AsyncWebServerRequest *request) {
  request->send(404, "text/plain", "Not found");
}

int tries = 0;
void wifiConnectionLoop() {
  tries++;
  if (WiFi.status() == WL_CONNECTED) {
    wifi_status = WL_CONNECTED;
    current_req->send_P(200, "text/html", res_html, processor);
    SPIFFS.remove("/wifi_conf");
    File conf_file = SPIFFS.open("/wifi_conf", FILE_WRITE);
    if (!conf_file)
      Serial.println("Error opening the config file for writing!");
    else {
      String conf = ssid + "," + password;
      conf_file.print(conf);
    }
    Serial.print("IP Address: ");
    Serial.println(WiFi.localIP());
    // Start sending data to the server
    tries = 0;
    current_req = NULL;
    statusPeriod = statusTaskDefaultPeriod;
    wifiScanPeriod = 0;
  } else if (tries > 3) {
    Serial.println("Wrong combination!");
    current_req->send_P(200, "text/html", res_html, processor);
    current_req = NULL;
    tries = 0;
  } else
    Serial.println("Not Connected!");
}

void statusLoop() {
  WiFi.softAPdisconnect(true);
  WiFi.begin(ssid.c_str(), password.c_str());
  delay(500);
  while (WiFi.status() != WL_CONNECTED)
    delay(500);
  Serial.println("WiFi connected");
  if (WiFi.status() == WL_CONNECTED) {
    HTTPClient http;
    // Your Domain name with URL path or IP address with path
    String charts_api = serverName + "/status";
    http.begin(charts_api.c_str());
    http.addHeader("Content-Type", "application/json");
    String userID = "-NAFyV0o-j8pwyLvVWl1";
    // http.addHeader("access-token", "AIzaSyC32VOvybxJdpI-BSWVdOmqp1m9l8lALYQ");
    String body = "{";
    body += "\"userID\": \"" + String("-NAFyV0o-j8pwyLvVWl1") + "\",";
    body += "\"LFC_NUM\": " + String("1,");
    body += "\"STATE_BFe\": " + String("1,");
    body += "\"CAUSE\": " + String("1,");
    body += "\"TOnLstStt\": " + String("1,");
    body += "\"nSwapUTC\": " + String("1,");
    body += "\"STATE_Nxt\": " + String("1,");
    body += "\"STATE_cnt\": " + String("1,");
    body += "\"serverResponseCnt\": " + String("1,");
    body += "\"WifiPwr\": " + String("1,");
    body += "\"MyIP\": " + String("1,");
    body += "\"MyMac\": " + String("1,");
    body += "\"Version\": " + String("1}");
    int httpResponseCode = http.POST(body);
    if (httpResponseCode > 0) {
      Serial.print("HTTP Response code: ");
      Serial.println(httpResponseCode);
      String payload = http.getString();
      Serial.println(payload);
    } else {
      Serial.print("Error code: ");
      Serial.println(httpResponseCode);
    }
    // Free resources
    http.end();
  }
  connectAp();
}

void otaUpdateLoop() {
  WiFi.softAPdisconnect(true);
  WiFi.begin(ssid.c_str(), password.c_str());
  delay(500);
  while (WiFi.status() != WL_CONNECTED)
    delay(500);
  Serial.println("WiFi connected");
  if (WiFi.status() == WL_CONNECTED) {
    String updateURL = serverName + "/update";
    static const char *url = "https://example.con/esp_fw.bin";  //state url of your firmware image
    HttpsOTA.begin(url, oldServerCertificate);
    Serial.println("Starting OTA");
    otastatus = HttpsOTA.status();
    while (otastatus != HTTPS_OTA_SUCCESS) {
      if (otastatus == HTTPS_OTA_FAIL) {
        Serial.println("Firmware Upgrade Fail");
      }
      delay(1000);
    }
    Serial.println("Firmware written successfully. To reboot device, call API ESP.restart() or PUSH restart button on device");
    ESP.restart();
  }
}

Debug Message

In file included from C:\Users\gil-t\Desktop\dev\HeabooComercial\esp32_code\esp32_code.ino:6:
c:\Users\gil-t\Desktop\dev\HeabooComercial\esp32_code\libraries\ESPAsyncWebServer\src/ESPAsyncWebServer.h:62:18: error: 'HTTP_GET' conflicts with a previous declaration
   HTTP_GET     = 0b00000001,
                  ^~~~~~~~~~
In file included from C:\Users\gil-t\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5/tools/sdk/esp32/include/esp_http_client/include/esp_http_client.h:11,
                 from C:\Users\gil-t\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5\libraries\Update\src/HttpsOTAUpdate.h:3,
                 from C:\Users\gil-t\Desktop\dev\HeabooComercial\esp32_code\esp32_code.ino:4:
C:\Users\gil-t\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5/tools/sdk/esp32/include/nghttp/port/include/http_parser.h:138:31: note: previous declaration 'http_method HTTP_GET'
 #define XX(num, name, string) HTTP_##name = num,
                               ^~~~~
C:\Users\gil-t\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5/tools/sdk/esp32/include/nghttp/port/include/http_parser.h:96:3: note: in expansion of macro 'XX'
   XX(1,  GET,         GET)          \
   ^~
C:\Users\gil-t\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5/tools/sdk/esp32/include/nghttp/port/include/http_parser.h:139:3: note: in expansion of macro 'HTTP_METHOD_MAP'
   HTTP_METHOD_MAP(XX)
   ^~~~~~~~~~~~~~~
In file included from C:\Users\gil-t\Desktop\dev\HeabooComercial\esp32_code\esp32_code.ino:6:
c:\Users\gil-t\Desktop\dev\HeabooComercial\esp32_code\libraries\ESPAsyncWebServer\src/ESPAsyncWebServer.h:63:18: error: 'HTTP_POST' conflicts with a previous declaration
   HTTP_POST    = 0b00000010,
                  ^~~~~~~~~~
In file included from C:\Users\gil-t\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5/tools/sdk/esp32/include/esp_http_client/include/esp_http_client.h:11,
                 from C:\Users\gil-t\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5\libraries\Update\src/HttpsOTAUpdate.h:3,
                 from C:\Users\gil-t\Desktop\dev\HeabooComercial\esp32_code\esp32_code.ino:4:
C:\Users\gil-t\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5/tools/sdk/esp32/include/nghttp/port/include/http_parser.h:138:31: note: previous declaration 'http_method HTTP_POST'
 #define XX(num, name, string) HTTP_##name = num,
                               ^~~~~
C:\Users\gil-t\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5/tools/sdk/esp32/include/nghttp/port/include/http_parser.h:98:3: note: in expansion of macro 'XX'
   XX(3,  POST,        POST)         \
   ^~
C:\Users\gil-t\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5/tools/sdk/esp32/include/nghttp/port/include/http_parser.h:139:3: note: in expansion of macro 'HTTP_METHOD_MAP'
   HTTP_METHOD_MAP(XX)
   ^~~~~~~~~~~~~~~
In file included from C:\Users\gil-t\Desktop\dev\HeabooComercial\esp32_code\esp32_code.ino:6:
c:\Users\gil-t\Desktop\dev\HeabooComercial\esp32_code\libraries\ESPAsyncWebServer\src/ESPAsyncWebServer.h:64:18: error: 'HTTP_DELETE' conflicts with a previous declaration
   HTTP_DELETE  = 0b00000100,
                  ^~~~~~~~~~
In file included from C:\Users\gil-t\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5/tools/sdk/esp32/include/esp_http_client/include/esp_http_client.h:11,
                 from C:\Users\gil-t\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5\libraries\Update\src/HttpsOTAUpdate.h:3,
                 from C:\Users\gil-t\Desktop\dev\HeabooComercial\esp32_code\esp32_code.ino:4:
C:\Users\gil-t\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5/tools/sdk/esp32/include/nghttp/port/include/http_parser.h:138:31: note: previous declaration 'http_method HTTP_DELETE'
 #define XX(num, name, string) HTTP_##name = num,
                               ^~~~~
C:\Users\gil-t\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5/tools/sdk/esp32/include/nghttp/port/include/http_parser.h:95:3: note: in expansion of macro 'XX'
   XX(0,  DELETE,      DELETE)       \
   ^~
C:\Users\gil-t\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5/tools/sdk/esp32/include/nghttp/port/include/http_parser.h:139:3: note: in expansion of macro 'HTTP_METHOD_MAP'
   HTTP_METHOD_MAP(XX)
   ^~~~~~~~~~~~~~~
In file included from C:\Users\gil-t\Desktop\dev\HeabooComercial\esp32_code\esp32_code.ino:6:
c:\Users\gil-t\Desktop\dev\HeabooComercial\esp32_code\libraries\ESPAsyncWebServer\src/ESPAsyncWebServer.h:65:18: error: 'HTTP_PUT' conflicts with a previous declaration
   HTTP_PUT     = 0b00001000,
                  ^~~~~~~~~~
In file included from C:\Users\gil-t\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5/tools/sdk/esp32/include/esp_http_client/include/esp_http_client.h:11,
                 from C:\Users\gil-t\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5\libraries\Update\src/HttpsOTAUpdate.h:3,
                 from C:\Users\gil-t\Desktop\dev\HeabooComercial\esp32_code\esp32_code.ino:4:
C:\Users\gil-t\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5/tools/sdk/esp32/include/nghttp/port/include/http_parser.h:138:31: note: previous declaration 'http_method HTTP_PUT'
 #define XX(num, name, string) HTTP_##name = num,
                               ^~~~~
C:\Users\gil-t\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5/tools/sdk/esp32/include/nghttp/port/include/http_parser.h:99:3: note: in expansion of macro 'XX'
   XX(4,  PUT,         PUT)          \
   ^~
C:\Users\gil-t\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5/tools/sdk/esp32/include/nghttp/port/include/http_parser.h:139:3: note: in expansion of macro 'HTTP_METHOD_MAP'
   HTTP_METHOD_MAP(XX)
   ^~~~~~~~~~~~~~~
In file included from C:\Users\gil-t\Desktop\dev\HeabooComercial\esp32_code\esp32_code.ino:6:
c:\Users\gil-t\Desktop\dev\HeabooComercial\esp32_code\libraries\ESPAsyncWebServer\src/ESPAsyncWebServer.h:66:18: error: 'HTTP_PATCH' conflicts with a previous declaration
   HTTP_PATCH   = 0b00010000,
                  ^~~~~~~~~~
In file included from C:\Users\gil-t\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5/tools/sdk/esp32/include/esp_http_client/include/esp_http_client.h:11,
                 from C:\Users\gil-t\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5\libraries\Update\src/HttpsOTAUpdate.h:3,
                 from C:\Users\gil-t\Desktop\dev\HeabooComercial\esp32_code\esp32_code.ino:4:
C:\Users\gil-t\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5/tools/sdk/esp32/include/nghttp/port/include/http_parser.h:138:31: note: previous declaration 'http_method HTTP_PATCH'
 #define XX(num, name, string) HTTP_##name = num,
                               ^~~~~
C:\Users\gil-t\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5/tools/sdk/esp32/include/nghttp/port/include/http_parser.h:128:3: note: in expansion of macro 'XX'
   XX(28, PATCH,       PATCH)        \
   ^~
C:\Users\gil-t\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5/tools/sdk/esp32/include/nghttp/port/include/http_parser.h:139:3: note: in expansion of macro 'HTTP_METHOD_MAP'
   HTTP_METHOD_MAP(XX)
   ^~~~~~~~~~~~~~~
In file included from C:\Users\gil-t\Desktop\dev\HeabooComercial\esp32_code\esp32_code.ino:6:
c:\Users\gil-t\Desktop\dev\HeabooComercial\esp32_code\libraries\ESPAsyncWebServer\src/ESPAsyncWebServer.h:67:18: error: 'HTTP_HEAD' conflicts with a previous declaration
   HTTP_HEAD    = 0b00100000,
                  ^~~~~~~~~~
In file included from C:\Users\gil-t\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5/tools/sdk/esp32/include/esp_http_client/include/esp_http_client.h:11,
                 from C:\Users\gil-t\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5\libraries\Update\src/HttpsOTAUpdate.h:3,
                 from C:\Users\gil-t\Desktop\dev\HeabooComercial\esp32_code\esp32_code.ino:4:
C:\Users\gil-t\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5/tools/sdk/esp32/include/nghttp/port/include/http_parser.h:138:31: note: previous declaration 'http_method HTTP_HEAD'
 #define XX(num, name, string) HTTP_##name = num,
                               ^~~~~
C:\Users\gil-t\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5/tools/sdk/esp32/include/nghttp/port/include/http_parser.h:97:3: note: in expansion of macro 'XX'
   XX(2,  HEAD,        HEAD)         \
   ^~
C:\Users\gil-t\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5/tools/sdk/esp32/include/nghttp/port/include/http_parser.h:139:3: note: in expansion of macro 'HTTP_METHOD_MAP'
   HTTP_METHOD_MAP(XX)
   ^~~~~~~~~~~~~~~
In file included from C:\Users\gil-t\Desktop\dev\HeabooComercial\esp32_code\esp32_code.ino:6:
c:\Users\gil-t\Desktop\dev\HeabooComercial\esp32_code\libraries\ESPAsyncWebServer\src/ESPAsyncWebServer.h:68:18: error: 'HTTP_OPTIONS' conflicts with a previous declaration
   HTTP_OPTIONS = 0b01000000,
                  ^~~~~~~~~~
In file included from C:\Users\gil-t\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5/tools/sdk/esp32/include/esp_http_client/include/esp_http_client.h:11,
                 from C:\Users\gil-t\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5\libraries\Update\src/HttpsOTAUpdate.h:3,
                 from C:\Users\gil-t\Desktop\dev\HeabooComercial\esp32_code\esp32_code.ino:4:
C:\Users\gil-t\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5/tools/sdk/esp32/include/nghttp/port/include/http_parser.h:138:31: note: previous declaration 'http_method HTTP_OPTIONS'
 #define XX(num, name, string) HTTP_##name = num,
                               ^~~~~
C:\Users\gil-t\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5/tools/sdk/esp32/include/nghttp/port/include/http_parser.h:102:3: note: in expansion of macro 'XX'
   XX(6,  OPTIONS,     OPTIONS)      \
   ^~
C:\Users\gil-t\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5/tools/sdk/esp32/include/nghttp/port/include/http_parser.h:139:3: note: in expansion of macro 'HTTP_METHOD_MAP'
   HTTP_METHOD_MAP(XX)
   ^~~~~~~~~~~~~~~

Other Steps to Reproduce

A combination of trying to use the HTTPS_OTA_Update and ESPAsyncWebServer in the same sketch, My idea is to have a local server that shows some sensor data and then there's a loop that sends said data to my server. In the response body it will be included the last available version served on my server.

I have checked existing issues, online documentation and the Troubleshooting Guide

mrengineer7777 commented 1 year ago

Perhaps a better title for your issue is: Conflicting defines for HTTP Methods http_parser.h, ESPAsyncWebServer.h

Description: Conflicting defines for HTTP Methods between http_parser.h and ESPAsyncWebServer.h.

     \esp32\2.0.5\libraries\Update\src/HttpsOTAUpdate.h:3
   ->\esp32\2.0.5/tools/sdk/esp32/include/esp_http_client/include/esp_http_client.h
  -->\esp32\2.0.5/tools/sdk/esp32/include/nghttp/port/include/http_parser.h
        HTTP_METHOD_MAP
           HTTP_GET, etc.

http_parser.h:

/* Request Methods */
#define HTTP_METHOD_MAP(XX)         \
  XX(0,  DELETE,      DELETE)       \
  XX(1,  GET,         GET)          \
  XX(2,  HEAD,        HEAD)         \
  XX(3,  POST,        POST)         \
  XX(4,  PUT,         PUT)          \
  /* pathological */                \
  XX(5,  CONNECT,     CONNECT)      \
  XX(6,  OPTIONS,     OPTIONS)      \
  XX(7,  TRACE,       TRACE)        \
  /* WebDAV */                      \
  XX(8,  COPY,        COPY)         \
  XX(9,  LOCK,        LOCK)         \
  XX(10, MKCOL,       MKCOL)        \
  XX(11, MOVE,        MOVE)         \
  XX(12, PROPFIND,    PROPFIND)     \
  XX(13, PROPPATCH,   PROPPATCH)    \
  XX(14, SEARCH,      SEARCH)       \
  XX(15, UNLOCK,      UNLOCK)       \
  XX(16, BIND,        BIND)         \
  XX(17, REBIND,      REBIND)       \
  XX(18, UNBIND,      UNBIND)       \
  XX(19, ACL,         ACL)          \
  /* subversion */                  \
  XX(20, REPORT,      REPORT)       \
  XX(21, MKACTIVITY,  MKACTIVITY)   \
  XX(22, CHECKOUT,    CHECKOUT)     \
  XX(23, MERGE,       MERGE)        \
  /* upnp */                        \
  XX(24, MSEARCH,     M-SEARCH)     \
  XX(25, NOTIFY,      NOTIFY)       \
  XX(26, SUBSCRIBE,   SUBSCRIBE)    \
  XX(27, UNSUBSCRIBE, UNSUBSCRIBE)  \
  /* RFC-5789 */                    \
  XX(28, PATCH,       PATCH)        \
  XX(29, PURGE,       PURGE)        \
  /* CalDAV */                      \
  XX(30, MKCALENDAR,  MKCALENDAR)   \
  /* RFC-2068, section 19.6.1.2 */  \
  XX(31, LINK,        LINK)         \
  XX(32, UNLINK,      UNLINK)       \

enum http_method
  {
#define XX(num, name, string) HTTP_##name = num,
  HTTP_METHOD_MAP(XX)
#undef XX
  };

ESPAsyncWebServer.h:

#ifndef WEBSERVER_H
typedef enum {
  HTTP_GET     = 0b00000001,
  HTTP_POST    = 0b00000010,
  HTTP_DELETE  = 0b00000100,
  HTTP_PUT     = 0b00001000,
  HTTP_PATCH   = 0b00010000,
  HTTP_HEAD    = 0b00100000,
  HTTP_OPTIONS = 0b01000000,
  HTTP_ANY     = 0b01111111,
} WebRequestMethod;
#endif

Unfortunately ESPAsyncWebServer isn't part of this repository, and it doesn't look like it will be updated in the near future.

We are successfully using both ESPAsyncWebServer.h and Update.h (HTTP not HTTPS), but they are in different modules and compiled using VSCode + PlatformIO.

mrengineer7777 commented 1 year ago

Sigh... After looking at those files now my project doesn't compile either.

mrengineer7777 commented 1 year ago

Ok I was able to get my project to compile by removing the following includes from my command parser module:

#include <AsyncJson.h>
#include <ESPAsyncWebServer.h>

Instead I use #include <ArduinoJson.h> there. I only call ESPAsyncWebServer.h from the module that serves webpages. Caution: AsyncJson.h includes ESPAsyncWebServer.h.

bearkillerPT commented 1 year ago

I can't seem to find those includes on my http_parser.h:

/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to
 * deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 */
#ifndef http_parser_h
#define http_parser_h
#ifdef __cplusplus
extern "C" {
#endif

/* Also update SONAME in the Makefile whenever you change these. */
#define HTTP_PARSER_VERSION_MAJOR 2
#define HTTP_PARSER_VERSION_MINOR 7
#define HTTP_PARSER_VERSION_PATCH 0

#include <sys/types.h>
#if defined(_WIN32) && !defined(__MINGW32__) && \
  (!defined(_MSC_VER) || _MSC_VER<1600) && !defined(__WINE__)
#include <BaseTsd.h>
#include <stddef.h>
typedef __int8 int8_t;
typedef unsigned __int8 uint8_t;
typedef __int16 int16_t;
typedef unsigned __int16 uint16_t;
typedef __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
#else
#include <stdint.h>
#endif

/* Compile with -DHTTP_PARSER_STRICT=0 to make less checks, but run
 * faster
 */
#ifndef HTTP_PARSER_STRICT
# define HTTP_PARSER_STRICT 1
#endif

/* Maximium header size allowed. If the macro is not defined
 * before including this header then the default is used. To
 * change the maximum header size, define the macro in the build
 * environment (e.g. -DHTTP_MAX_HEADER_SIZE=<value>). To remove
 * the effective limit on the size of the header, define the macro
 * to a very large number (e.g. -DHTTP_MAX_HEADER_SIZE=0x7fffffff)
 */
#ifndef HTTP_MAX_HEADER_SIZE
# define HTTP_MAX_HEADER_SIZE (80*1024)
#endif

typedef struct http_parser http_parser;
typedef struct http_parser_settings http_parser_settings;

/* Callbacks should return non-zero to indicate an error. The parser will
 * then halt execution.
 *
 * The one exception is on_headers_complete. In a HTTP_RESPONSE parser
 * returning '1' from on_headers_complete will tell the parser that it
 * should not expect a body. This is used when receiving a response to a
 * HEAD request which may contain 'Content-Length' or 'Transfer-Encoding:
 * chunked' headers that indicate the presence of a body.
 *
 * Returning `2` from on_headers_complete will tell parser that it should not
 * expect neither a body nor any futher responses on this connection. This is
 * useful for handling responses to a CONNECT request which may not contain
 * `Upgrade` or `Connection: upgrade` headers.
 *
 * http_data_cb does not return data chunks. It will be called arbitrarily
 * many times for each string. E.G. you might get 10 callbacks for "on_url"
 * each providing just a few characters more data.
 */
typedef int (*http_data_cb) (http_parser*, const char *at, size_t length);
typedef int (*http_cb) (http_parser*);
/* Request Methods */
#define HTTP_METHOD_MAP(XX)         \
  XX(0,  DELETE,      DELETE)       \
  XX(1,  GET,         GET)          \
  XX(2,  HEAD,        HEAD)         \
  XX(3,  POST,        POST)         \
  XX(4,  PUT,         PUT)          \
  /* pathological */                \
  XX(5,  CONNECT,     CONNECT)      \
  XX(6,  OPTIONS,     OPTIONS)      \
  XX(7,  TRACE,       TRACE)        \
  /* WebDAV */                      \
  XX(8,  COPY,        COPY)         \
  XX(9,  LOCK,        LOCK)         \
  XX(10, MKCOL,       MKCOL)        \
  XX(11, MOVE,        MOVE)         \
  XX(12, PROPFIND,    PROPFIND)     \
  XX(13, PROPPATCH,   PROPPATCH)    \
  XX(14, SEARCH,      SEARCH)       \
  XX(15, UNLOCK,      UNLOCK)       \
  XX(16, BIND,        BIND)         \
  XX(17, REBIND,      REBIND)       \
  XX(18, UNBIND,      UNBIND)       \
  XX(19, ACL,         ACL)          \
  /* subversion */                  \
  XX(20, REPORT,      REPORT)       \
  XX(21, MKACTIVITY,  MKACTIVITY)   \
  XX(22, CHECKOUT,    CHECKOUT)     \
  XX(23, MERGE,       MERGE)        \
  /* upnp */                        \
  XX(24, MSEARCH,     M-SEARCH)     \
  XX(25, NOTIFY,      NOTIFY)       \
  XX(26, SUBSCRIBE,   SUBSCRIBE)    \
  XX(27, UNSUBSCRIBE, UNSUBSCRIBE)  \
  /* RFC-5789 */                    \
  XX(28, PATCH,       PATCH)        \
  XX(29, PURGE,       PURGE)        \
  /* CalDAV */                      \
  XX(30, MKCALENDAR,  MKCALENDAR)   \
  /* RFC-2068, section 19.6.1.2 */  \
  XX(31, LINK,        LINK)         \
  XX(32, UNLINK,      UNLINK)       \

enum http_method
  {
#define XX(num, name, string) HTTP_##name = num,
  HTTP_METHOD_MAP(XX)
#undef XX
  };

enum http_parser_type { HTTP_REQUEST, HTTP_RESPONSE, HTTP_BOTH };

/* Flag values for http_parser.flags field */
enum flags
  { F_CHUNKED               = 1 << 0
  , F_CONNECTION_KEEP_ALIVE = 1 << 1
  , F_CONNECTION_CLOSE      = 1 << 2
  , F_CONNECTION_UPGRADE    = 1 << 3
  , F_TRAILING              = 1 << 4
  , F_UPGRADE               = 1 << 5
  , F_SKIPBODY              = 1 << 6
  , F_CONTENTLENGTH         = 1 << 7
  };

/* Map for errno-related constants
 *
 * The provided argument should be a macro that takes 2 arguments.
 */
#define HTTP_ERRNO_MAP(XX)                                           \
  /* No error */                                                     \
  XX(OK, "success")                                                  \
                                                                     \
  /* Callback-related errors */                                      \
  XX(CB_message_begin, "the on_message_begin callback failed")       \
  XX(CB_url, "the on_url callback failed")                           \
  XX(CB_header_field, "the on_header_field callback failed")         \
  XX(CB_header_value, "the on_header_value callback failed")         \
  XX(CB_headers_complete, "the on_headers_complete callback failed") \
  XX(CB_body, "the on_body callback failed")                         \
  XX(CB_message_complete, "the on_message_complete callback failed") \
  XX(CB_status, "the on_status callback failed")                     \
  XX(CB_chunk_header, "the on_chunk_header callback failed")         \
  XX(CB_chunk_complete, "the on_chunk_complete callback failed")     \
                                                                     \
  /* Parsing-related errors */                                       \
  XX(INVALID_EOF_STATE, "stream ended at an unexpected time")        \
  XX(HEADER_OVERFLOW,                                                \
     "too many header bytes seen; overflow detected")                \
  XX(CLOSED_CONNECTION,                                              \
     "data received after completed connection: close message")      \
  XX(INVALID_VERSION, "invalid HTTP version")                        \
  XX(INVALID_STATUS, "invalid HTTP status code")                     \
  XX(INVALID_METHOD, "invalid HTTP method")                          \
  XX(INVALID_URL, "invalid URL")                                     \
  XX(INVALID_HOST, "invalid host")                                   \
  XX(INVALID_PORT, "invalid port")                                   \
  XX(INVALID_PATH, "invalid path")                                   \
  XX(INVALID_QUERY_STRING, "invalid query string")                   \
  XX(INVALID_FRAGMENT, "invalid fragment")                           \
  XX(LF_EXPECTED, "LF character expected")                           \
  XX(INVALID_HEADER_TOKEN, "invalid character in header")            \
  XX(INVALID_CONTENT_LENGTH,                                         \
     "invalid character in content-length header")                   \
  XX(UNEXPECTED_CONTENT_LENGTH,                                      \
     "unexpected content-length header")                             \
  XX(INVALID_CHUNK_SIZE,                                             \
     "invalid character in chunk size header")                       \
  XX(INVALID_CONSTANT, "invalid constant string")                    \
  XX(INVALID_INTERNAL_STATE, "encountered unexpected internal state")\
  XX(STRICT, "strict mode assertion failed")                         \
  XX(PAUSED, "parser is paused")                                     \
  XX(UNKNOWN, "an unknown error occurred")

/* Define HPE_* values for each errno value above */
#define HTTP_ERRNO_GEN(n, s) HPE_##n,
enum http_errno {
  HTTP_ERRNO_MAP(HTTP_ERRNO_GEN)
};
#undef HTTP_ERRNO_GEN

/* Get an http_errno value from an http_parser */
#define HTTP_PARSER_ERRNO(p)            ((enum http_errno) (p)->http_errno)

struct http_parser {
  /** PRIVATE **/
  unsigned int type : 2;         /* enum http_parser_type */
  unsigned int flags : 8;        /* F_* values from 'flags' enum; semi-public */
  unsigned int state : 7;        /* enum state from http_parser.c */
  unsigned int header_state : 7; /* enum header_state from http_parser.c */
  unsigned int index : 7;        /* index into current matcher */
  unsigned int lenient_http_headers : 1;

  uint32_t nread;          /* # bytes read in various scenarios */
  uint64_t content_length; /* # bytes in body (0 if no Content-Length header) */

  /** READ-ONLY **/
  unsigned short http_major;
  unsigned short http_minor;
  unsigned int status_code : 16; /* responses only */
  unsigned int method : 8;       /* requests only */
  unsigned int http_errno : 7;

  /* 1 = Upgrade header was present and the parser has exited because of that.
   * 0 = No upgrade header present.
   * Should be checked when http_parser_execute() returns in addition to
   * error checking.
   */
  unsigned int upgrade : 1;

  /** PUBLIC **/
  void *data; /* A pointer to get hook to the "connection" or "socket" object */
};

struct http_parser_settings {
  http_cb      on_message_begin;
  http_data_cb on_url;
  http_data_cb on_status;
  http_data_cb on_header_field;
  http_data_cb on_header_value;
  http_cb      on_headers_complete;
  http_data_cb on_body;
  http_cb      on_message_complete;
  /* When on_chunk_header is called, the current chunk length is stored
   * in parser->content_length.
   */
  http_cb      on_chunk_header;
  http_cb      on_chunk_complete;
};

enum http_parser_url_fields
  { UF_SCHEMA           = 0
  , UF_HOST             = 1
  , UF_PORT             = 2
  , UF_PATH             = 3
  , UF_QUERY            = 4
  , UF_FRAGMENT         = 5
  , UF_USERINFO         = 6
  , UF_MAX              = 7
  };

/* Result structure for http_parser_parse_url().
 *
 * Callers should index into field_data[] with UF_* values iff field_set
 * has the relevant (1 << UF_*) bit set. As a courtesy to clients (and
 * because we probably have padding left over), we convert any port to
 * a uint16_t.
 */
struct http_parser_url {
  uint16_t field_set;           /* Bitmask of (1 << UF_*) values */
  uint16_t port;                /* Converted UF_PORT string */

  struct {
    uint16_t off;               /* Offset into buffer in which field starts */
    uint16_t len;               /* Length of run in buffer */
  } field_data[UF_MAX];
};

/* Returns the library version. Bits 16-23 contain the major version number,
 * bits 8-15 the minor version number and bits 0-7 the patch level.
 * Usage example:
 *
 *   unsigned long version = http_parser_version();
 *   unsigned major = (version >> 16) & 255;
 *   unsigned minor = (version >> 8) & 255;
 *   unsigned patch = version & 255;
 *   printf("http_parser v%u.%u.%u\n", major, minor, patch);
 */
unsigned long http_parser_version(void);

void http_parser_init(http_parser *parser, enum http_parser_type type);

/* Initialize http_parser_settings members to 0
 */
void http_parser_settings_init(http_parser_settings *settings);

/* Executes the parser. Returns number of parsed bytes. Sets
 * `parser->http_errno` on error. */
size_t http_parser_execute(http_parser *parser,
                           const http_parser_settings *settings,
                           const char *data,
                           size_t len);

/* If http_should_keep_alive() in the on_headers_complete or
 * on_message_complete callback returns 0, then this should be
 * the last message on the connection.
 * If you are the server, respond with the "Connection: close" header.
 * If you are the client, close the connection.
 */
int http_should_keep_alive(const http_parser *parser);

/* Returns a string version of the HTTP method. */
const char *http_method_str(enum http_method m);

/* Return a string name of the given error */
const char *http_errno_name(enum http_errno err);

/* Return a string description of the given error */
const char *http_errno_description(enum http_errno err);

/* Initialize all http_parser_url members to 0 */
void http_parser_url_init(struct http_parser_url *u);

/* Parse a URL; return nonzero on failure */
int http_parser_parse_url(const char *buf, size_t buflen,
                          int is_connect,
                          struct http_parser_url *u);

/* Pause or un-pause the parser; a nonzero value pauses */
void http_parser_pause(http_parser *parser, int paused);

/* Checks if this is the final chunk of the body. */
int http_body_is_final(const http_parser *parser);

#ifdef __cplusplus
}
#endif
#endif

I'm somewhat new to the arduino environment :)

mrengineer7777 commented 1 year ago

You won't find it by searching. It's a macro "HTTP_METHOD_MAP" that creates the definitions.

bearkillerPT commented 1 year ago

So, to confirm, the only way would be to switch to VSCode + PlatformIO? My boss doens't want me to use this option.... I personally love vscode! If i use the switch to the normal webServer will it work?

mrengineer7777 commented 1 year ago

@bearkillerPT You might be able to create multiple headers and split up functionality in your program to avoid the compile issue. That said, using PlatformIO has been a joy once I got past the learning curve. Highly recommended!

Since the conflict is with the definition in ESPAsyncWebserver.h, switching to the standard Webserver in Arduino would avoid the issue.

Unfortunately I'll be traveling for a few days, so I won't be available to answer further questions.

bearkillerPT commented 1 year ago

I've already given a shot at that and I managed to compile the sketch but unfortunately it crashed when updating... The asying web server was working properly but then i got a Guru panick....

Yeh I wish I could give at a try but I'm working with a guy that really doesn't want to go through the hassle 😂. I'll probably just rewrite everything with the standard Webserver in Arduino.

Was making good use of the processor function that allowed to substitute vars in the html for values like a StringBuilder. Should i build the html in the on() function with the variable manually or is there a better way? I'm really restricted on space aswell.... Can't really afford to add more libs...

Thank you for your help!