Help with esp32 sketch

Chucky5889

New Member
View Badges
Joined
Oct 25, 2024
Messages
2
Reaction score
3
Location
United Kingdom
Rating - 0%
0   0   0
Sounds like you did not include the PathItterator library
Hi @firechild @Sral.

hoping I can shed some light on this for you as I have been digging around in all kinds of forums for at least the last week (seems like forever). So it turns out that since the sketch was created, most of the library API's have undergone a few changes, such as the esp32 library used to control the PWM ledcSetup/ledcAttachPin functions.

I also found some information on the URLTokenBindings issue also see code attached


I have managed to rebuild some of the code and actually now in a position that it will compile

sharing a link below to a Arduino forum where this question got answered in regards to the ledcSetup/ledcAttachPin not declared issues and highlighting the API version I am currently using (2.0.17, this is a roll back of the library to a point where it worked previously (easier for me as I am still finding it difficult in the programming world being new to all of this.) if you don't want to roll back the driver then you can check out the github link also which identifies the changes to the API.


hope this helps anyone that has been struggling with either of these issues.
 

Attachments

  • reef-pi updated URLTokenBindings.txt
    831 bytes · Views: 23
  • esp32 library version.png
    esp32 library version.png
    13.2 KB · Views: 20

Simonv92

Active Member
View Badges
Joined
Oct 21, 2014
Messages
148
Reaction score
106
Location
Italy
Rating - 0%
0   0   0
Hi All! I'm trying to compile the ESP32 Reef-Pi code. I've already fixed the ledcSetup problem using the new library. I also fix with @Chucky5889 post the UrlTokenBindings problema but I cannot compile my code... Here's the code I'm trying:

Code:
#include <WiFi.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <TokenIterator.h>
#include <UrlTokenBindings.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define OUTLET_COUNT 6
#define INLET_COUNT 4
#define JACK_COUNT 4
#define ANALOG_INPUT_COUNT 2
#define PWM_FREQ 5000
#define PWM_RESOLUTION 8



const char *ssid = "SET_SSID";
const char *password = "SET_PASSWORD";

const int outletPins[OUTLET_COUNT] = { 5, 16, 17, 18, 19, 23 };
const int inletPins[INLET_COUNT] = { 1, 3, 14, 36 };
const int jackPins[JACK_COUNT] = { 12, 13, 14, 27 };
const int pwmChannels[JACK_COUNT] = { 0, 1, 2, 3 };
const int analogInputPins[ANALOG_INPUT_COUNT] = { 32, 33 };
const int oneWirePin = 4;

OneWire oneWire(oneWirePin);
DallasTemperature ds18b20(&oneWire);
AsyncWebServer server(80);


void setup() {
  Serial.begin(115200);
  for (int i = 0; i < OUTLET_COUNT; i++) {
    pinMode(outletPins[i], OUTPUT);
  }

  for (int i = 0; i < INLET_COUNT; i++) {
    pinMode(inletPins[i], INPUT);
  }
  for (int i = 0; i < JACK_COUNT; i++) {
    ledcAttach(jackPins[i], PWM_FREQ, PWM_RESOLUTION);
    //ledcSetup(pwmChannels[i], PWM_FREQ, PWM_RESOLUTION);
    //ledcAttachPin(jackPins[i], pwmChannels[i]);
  }
  for (int i = 0; i < ANALOG_INPUT_COUNT; i++) {
    pinMode(analogInputPins[i], INPUT);
  }
  ds18b20.begin();

  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi..");
  }
  Serial.println(WiFi.localIP());
  server.on("/outlets/*", HTTP_POST, switchOutlet);
  server.on("/inlets/*", HTTP_GET, readInlet);
  server.on("/jacks/*", HTTP_POST, setJackValue);
  server.on("/analog_inputs/*", HTTP_GET, readAnalogInput);

  server.begin();
}

void loop() {
}

UrlTokenBindings parseURL(AsyncWebServerRequest *request, char templatePath[]) {
  if (!request) {
    auto emptyIterator = std::make_shared<TokenIterator>("", 0, '/');
    return UrlTokenBindings(emptyIterator, emptyIterator);
  }

  char urlBuffer[100];
  request->url().toCharArray(urlBuffer, sizeof(urlBuffer));
 
  int urlLength = strlen(urlBuffer);
  if (urlLength == 0 || urlLength >= sizeof(urlBuffer)) {
    auto emptyIterator = std::make_shared<TokenIterator>("", 0, '/');
    return UrlTokenBindings(emptyIterator, emptyIterator);
  }

  auto templateIterator = std::make_shared<TokenIterator>(templatePath, strlen(templatePath), '/');
  auto pathIterator = std::make_shared<TokenIterator>(urlBuffer, urlLength, '/');
 
  UrlTokenBindings bindings(templateIterator, pathIterator);
  return bindings;
}

void switchOutlet(AsyncWebServerRequest *request) {
  char path[] = "/outlets/:id/:action";
  UrlTokenBindings bindings = parseURL(request, path);

  int id = String(bindings.get("id")).toInt();
  if (id < 0 || id >= OUTLET_COUNT) {
    request->send(409, "text/plain", "invalid outlet pin id");
  }
  String action = String(bindings.get("action"));
  Serial.println("Outlet Pin:" + String(outletPins[id]) + ", Action:" + action);
  if (action.equals("on")) {
    digitalWrite(outletPins[id], HIGH);
    request->send(200, "text/plain", "high");
  } else if (action.equals("off")) {
    digitalWrite(outletPins[id], LOW);
    request->send(200, "text/plain", "low");
  } else {
    request->send(409, "text/plain", "unrecognized action");
  }
}

void readInlet(AsyncWebServerRequest *request) {
  char path[] = "/inlets/:id";
  UrlTokenBindings bindings = parseURL(request, path);
  int id = String(bindings.get("id")).toInt();
  if (id < 0 || id >= INLET_COUNT) {
    request->send(409, "text/plain", "invalid inlet pin id");
  }
  int v = digitalRead(inletPins[id]);
  Serial.println("Inlet pin:" + String(inletPins[id]) + " Value:" + String(v));
  request->send(200, "text/plain", String(v));
}


void readAnalogInput(AsyncWebServerRequest *request) {
  char path[] = "/analog_inputs/:id";
  UrlTokenBindings bindings = parseURL(request, path);
  int id = String(bindings.get("id")).toInt();

  if (id < 0 || id > ANALOG_INPUT_COUNT) {
    request->send(409, "text/plain", "invalid inlet pin id");
  }
  float value;
  if (id == 0) {
    ds18b20.requestTemperatures();
    value = ds18b20.getTempCByIndex(0);
  } else {
    value = analogRead(analogInputPins[id]);
  }
  Serial.println("Analog Input pin:" + String(analogInputPins[id]) + " Value:" + String(value));
  request->send(200, "text/plain", String(value));
}



void setJackValue(AsyncWebServerRequest *request) {
  char path[] = "/jacks/:id/:value";
  UrlTokenBindings bindings = parseURL(request, path);
  int id = String(bindings.get("id")).toInt();
  int dc = String(bindings.get("value")).toInt();
  if (id < 0 || id >= JACK_COUNT) {
    request->send(409, "text/plain", "invalid inlet pin id");
  }
  if (dc > 255) {
    dc = 255;
  }
  if (dc < 0) {
    dc = 0;
  }
  Serial.println("PWM Pin" + String(jackPins[id]) + " DutyCycle:" + String(dc));
  ledcWrite(pwmChannels[id], dc);
  request->send(200, "text/plain", String(dc));
}

And here's the error code I have:

Code:
c:\Users\Simone\Documents\Arduino\libraries\ESPAsyncWebServer\src\WebAuthentication.cpp: In function 'bool getMD5(uint8_t*, uint16_t, char*)':
c:\Users\Simone\Documents\Arduino\libraries\ESPAsyncWebServer\src\WebAuthentication.cpp:74:3: error: 'mbedtls_md5_starts_ret' was not declared in this scope; did you mean 'mbedtls_md5_starts'?
   74 |   mbedtls_md5_starts_ret(&_ctx);
      |   ^~~~~~~~~~~~~~~~~~~~~~
      |   mbedtls_md5_starts
c:\Users\Simone\Documents\Arduino\libraries\ESPAsyncWebServer\src\WebAuthentication.cpp:75:3: error: 'mbedtls_md5_update_ret' was not declared in this scope; did you mean 'mbedtls_md5_update'?
   75 |   mbedtls_md5_update_ret(&_ctx, data, len);
      |   ^~~~~~~~~~~~~~~~~~~~~~
      |   mbedtls_md5_update
c:\Users\Simone\Documents\Arduino\libraries\ESPAsyncWebServer\src\WebAuthentication.cpp:76:3: error: 'mbedtls_md5_finish_ret' was not declared in this scope; did you mean 'mbedtls_md5_finish'?
   76 |   mbedtls_md5_finish_ret(&_ctx, _buf);
      |   ^~~~~~~~~~~~~~~~~~~~~~
      |   mbedtls_md5_finish
Multiple libraries were found for "ESPAsyncWebServer.h"
  Used: C:\Users\Simone\Documents\Arduino\libraries\ESPAsyncWebServer
  Not used: C:\Users\Simone\Documents\Arduino\libraries\ESP_Async_WebServer
Multiple libraries were found for "AsyncTCP.h"
  Used: C:\Users\Simone\Documents\Arduino\libraries\AsyncTCP
  Not used: C:\Users\Simone\Documents\Arduino\libraries\Async_TCP
exit status 1

Compilation error: exit status 1

What can it be? Thank you! Thank you @Ranjib and @Sral for your amazing work!!
Simone
 

reefsentinel85

New Member
View Badges
Joined
Jul 10, 2023
Messages
11
Reaction score
11
Location
France
Rating - 0%
0   0   0
Hi, there are several versions of ESPAsyncWebServer.h installed into the ide, check the librairies tab they can be removed/installed
 

TOP 10 Trending Threads

HAVE YOU EVER ACCIDENTALLY FLOODED AN AREA BECAUSE OF YOUR TANK?

  • Yes, It caused major damage.

    Votes: 18 7.7%
  • Yes, but it caused only minor damage.

    Votes: 65 27.7%
  • Yes, but there was no damage.

    Votes: 102 43.4%
  • No, thankfully!

    Votes: 49 20.9%
  • Other (please explain).

    Votes: 1 0.4%
Back
Top