Need code for ota http sever

when i compile the compiler gives me waring says,

'class ESP32HTTPUpdate' has no member named 'setup'

my ota code is,


ArduinoOTA.setPort(8266);

OTA_httpUpdater.setup(&OTA_httpServer);
OTA_httpServer.begin();
ArduinoOTA.setHostname("LCS_TM");

ArduinoOTA.onStart([]() {
  String type;
  if (ArduinoOTA.getCommand() == U_FLASH) {
    type = "sketch";
  } else { // U_FS
    type = "filesystem";
  }
});
ArduinoOTA.begin();

also if i put the code before wifi.begin the esp will infinite crash.

any suggestions?

here is my whole program, the update server should be on port 81 but for some reason its on port 80 when i try on port 81 it says file not found

#include <Wire.h> //I2C library
#include "RTClib.h"
//#include <ESP8266WiFi.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <WiFiUdp.h>
#include <EEPROM.h>
//#include <ESP8266WebServer.h>
//#include <ESP8266HTTPUpdateServer.h>
#include <ESP32WebServer.h>
#include <ESP32httpUpdate.h>
#include <ArduinoOTA.h>
#include <ArduinoJson.h>
//#include <LittleFS.h>
#include <SPIFFS.h>


#define flowSENSOR  18


char nodeID0[] = "NODTM1";
char nodeID1[] = "TM1ODE";
char nodePairID0[] = "TM1PAI";
char nodePairID1[] = "IAP1MT";


//ESP8266WebServer OTA_httpServer(81);
//ESP8266HTTPUpdateServer OTA_httpUpdater;
//ESP8266WebServer server(80);
ESP32WebServer OTA_httpServer(81);
ESP32HTTPUpdate OTA_httpUpdater;
ESP32WebServer server(80);

IPAddress local_IP(192, 168, 4, 1);
IPAddress subnet(255, 255, 255, 0);

WiFiUDP Udp;
RTC_DS3231 rtc;

unsigned int ServerPort = 4210;
unsigned int localUdpPort = 4220;
bool startupdelay = true;
unsigned long startupdelaymillis = 0;
const char* ssid = nodeID0;
const char* password = "a1b2c3d5";
bool pairMode = false;
bool adminEnabled = false;
bool apMode = false;
unsigned long apTimeout = 15000;
unsigned long apSwitchMillis = 0;
bool apState = false;
unsigned long lcdMillis = 0;
int photoSensor = 0;
char incomingPacket[255];  // buffer for incoming packets
int addr = 0;
int timerMode3State = 0;

int photoSensorpin = 35;
byte fullFloatSensor = 34; // float sensor1 pin
byte emptyFloatSensor = 23; // float sensor2 pin
const int relay[] = {26, 25, 33, 32};

unsigned long now7 = 0;
unsigned long now2 = 0;
unsigned long now4 = 0;
unsigned long now5 = 0;
unsigned long now0 = 0;
unsigned long now1 = 0;
unsigned long now10 = 0;
unsigned long epoch32Time = 0;
bool writeEEPROM = false;

int timerStates[4] {0, 0, 0, 0};

unsigned long timer1onMillis = 0;
unsigned long timer2onMillis = 0;
unsigned long timer3onMillis = 0;
unsigned long timer4onMillis = 0;
unsigned long timer1offMillis = 0;
unsigned long timer2offMillis = 0;
unsigned long timer3offMillis = 0;
unsigned long timer4offMillis = 0;
unsigned long secondstime =0;
int timerState = 1;
bool lightsOn = 1 ;
bool doseUsed = true;
bool fullFloatSensorStatus;
bool emptyFloatSensorStatus;
struct {
  int timerMode;
  char masterIP[20];
  bool timerEnabled[4];
  unsigned long timerRuntimes[4];
  bool timerRunning[4];
  unsigned long timerTimes[4][4];//1-4 on,off,onN,offN
  unsigned long frequency = 10;//timer mode 3 timer frequency
  unsigned long timerMode3WaterSolenoidDuration; //duration to activate water solenoid in seconds
  unsigned long timerMode3WaterPumpDuration; //duration to activate water pump in milliseconds
  unsigned long timerMode3LastCycletime;
  unsigned long timerMode3MaxML;
  int calibrationFactor; //defualt was float 4.5
  bool enabled = true;
  char sta_ssid[15];
  char sta_password[15];
  char system_password[15];
} _EEPROM;

long currentMillis = 0;
long previousMillis = 0;
int interval = 1000;

volatile byte pulseCount;
byte pulse1Sec = 0;
float flowRate;
unsigned long flowMilliLitres;
unsigned int totalMilliLitres;
float flowLitres;
float totalLitres;

void IRAM_ATTR pulseCounter()
{
  pulseCount++;
}

const byte RelayCount = 4;
bool ARelayIsOn = false;


struct Relay
{
  const byte RelayPin;
  bool readyToTurnOn;
  bool isOn;
  unsigned long StartTime;
}

Relays[RelayCount] =
{
  {26, true, false, 0},
  {25, true, false, 0},
  {33,  true, false, 0},
  {32, true, false, 0}
};

void TurnRelayOn(int r)
{
  ARelayIsOn = true;
  Relays[r].readyToTurnOn = false;
  Relays[r].isOn = true;
  Relays[r].StartTime = millis();  // Start of OnInterval
  digitalWrite(Relays[r].RelayPin, LOW);  // LOW for ON
  _EEPROM.timerRuntimes[r]++;
}

void TurnRelayOff(int r)
{
  ARelayIsOn = false;  // Only one is on at a time
  Relays[r].readyToTurnOn = false;
  Relays[r].isOn = false;
  Relays[r].StartTime = millis();  // Start of OffInterval
  digitalWrite(Relays[r].RelayPin, HIGH);  // HIGH for OFF

}

String masterIP = "";


void _writeEEPROM () {
  EEPROM.put(addr, _EEPROM);
  EEPROM.commit();    //Store data to EEPROM
  Serial.println("EEPROM WRITE");
}
void sendStruct() {

  Udp.beginPacket(_EEPROM.masterIP, ServerPort);
  //  Udp.write(nodeID0);
  //  Udp.write((uint8_t*)&_EEPROM, sizeof(_EEPROM)); //cast to bytes
  //  Udp.write(nodeID1);
  Udp.print(nodeID0);
  Udp.write((uint8_t*)&_EEPROM, sizeof(_EEPROM)); //cast to bytes
  Udp.print(nodeID1);
  Udp.endPacket();
}

void default_params() {
  for (int i = 0; i <= 4; i++) {
    _EEPROM.timerTimes[0][i] = 30000;
    _EEPROM.timerTimes[1][i] = 30000;
    _EEPROM.timerTimes[2][i] = 30000;
    _EEPROM.timerTimes[3][i] = 30000;
    _EEPROM.timerRuntimes[i] = 0;
    _writeEEPROM ();
  }
  _EEPROM.frequency = 10;
  _EEPROM.sta_ssid[13] = '\0';
  _EEPROM.sta_password[13] = '\0';
  sprintf(_EEPROM.system_password, "%s", "password");
  _EEPROM.enabled = true;

  _EEPROM.timerMode = 3;
  _EEPROM.masterIP[19] = '\0';
  //  _EEPROM.timerEnabled[4] = '\0';
  //  _EEPROM.timerRunning[4] = '\0';
  _writeEEPROM ();
}

#include "handlePacket.h"
#include "timerModes.h"
#include "htmlFunctions.h"
#include "json.h"
void setup() {
  for (int i = 0; i <= 3; i++) {
    pinMode(relay[i], OUTPUT);
    digitalWrite(relay[i], HIGH);
    _EEPROM.timerRuntimes[i] = 0;
  }

  //Serial.println("001");
  // LittleFS.begin();
  SPIFFS.begin();
  //  Serial.println("001");
  Serial.begin(115200);
  Serial.println("001");
  EEPROM.begin(1024);  //Initialize EEPROM
  Serial.println("002");
  EEPROM.get(addr, _EEPROM);
  Serial.println("003");
  rtc.begin();   //Starts I2C
  Serial.println("001");
//  RtcDateTime epoch32 = rtc.GetDateTime();//
//  pinMode(4, OUTPUT);//fix
//  digitalWrite(4, LOW);//fix
//  pinMode(5, OUTPUT);//fix
//  digitalWrite(5, LOW);//fix
  pinMode(fullFloatSensor, INPUT_PULLUP); // PULL UP float sensor
  // pinMode(emptyFloatSensor, INPUT_PULLUP); // PULL UP float sensor
  //RtcDateTime currentTime = RtcDateTime(21, 4, 20, 4, 20, 20); //define date and time object
  // rtc.SetDateTime(currentTime); //configure the RTC with object
  //  if (epoch32.Epoch32Time() == 946684800) {//fix
  //    ESP.restart();
  //  }
  // pinMode(flowSENSOR, INPUT_PULLUP);
  pinMode(15, OUTPUT);
  digitalWrite(15, HIGH);
  pulseCount = 0;
  flowRate = 0.0;
  flowMilliLitres = 0;
  totalMilliLitres = 0;
  previousMillis = 0;
  attachInterrupt(digitalPinToInterrupt(flowSENSOR), pulseCounter, FALLING);
  WiFi.persistent(0);
  WiFi.mode(WIFI_AP_STA);
  WiFi.begin(_EEPROM.sta_ssid, _EEPROM.sta_password);

  sprintf(_EEPROM.system_password, "%s", "password");
  _EEPROM.sta_ssid[14] = '\0';
  _EEPROM.sta_password[14] = '\0';
  Serial.println("booted");
  delay(10000);
  Udp.begin(localUdpPort);
  #include "OTA.h" 
#include "serverHandles.h"
  server.begin();
  sprintf(_EEPROM.system_password, "%s", "password");
  _EEPROM.sta_ssid[14] = '\0';
  _EEPROM.sta_password[14] = '\0';
  // _EEPROM.timerMode3WaterPumpDuration = 5000;
  //_EEPROM.timerMode = 3;
  //_EEPROM.enabled = false;
  // _EEPROM.calibrationFactor  = 4.5; //amount of seconds to wait before turning on
  //_EEPROM.timerMode3MaxML = 200;
  //  _EEPROM.timerMode3Duration = 2000; //how long to turn on for
  // _writeEEPROM();
  //default_params();
}

void handleTimers(bool a, bool b, bool c, bool d) {
  digitalWrite(relay[0], a);
  digitalWrite(relay[1], b);
  digitalWrite(relay[2], c);
  digitalWrite(relay[3], d);
}


void handleTimerStates(int a, int b, int c, int d) {
  timerStates[0] = a;
  timerStates[1] = b;
  timerStates[2] = c;
  timerStates[3] = d;
}

void handleGetTime() {


  DateTime currentTime = rtc.now();    //get the time from the RTC
  char str[20];   //declare a string as an array of chars
  sprintf(str, "%d/%d/%d %d:%d:%d",     //%d allows to print an integer to the string
          currentTime.year(),   //get year method
          currentTime.month(),  //get month method
          currentTime.day(),    //get day method
          currentTime.hour(),   //get hour method
          currentTime.minute(), //get minute method
          currentTime.second()  //get second method
         );
  Serial.println(str); //print the string to the serial port
}
void loop() {
  DateTime now = rtc.now();
  secondstime = now.secondstime();
  processTimers();
  server.handleClient();//Checks for web server activity
  recPacket();

  if (adminEnabled) {
    OTA_httpServer.handleClient(); //ota server "htt p://x.x.x.x:81/update"
    ArduinoOTA.handle();
  }

  if (WiFi.status() == WL_CONNECTED) {
    apSwitchMillis = millis();
 //   Serial.println("wifi connected");
    if (millis() - lcdMillis >= 5000) {

      WiFi.softAPdisconnect (true);
      lcdMillis = millis();
    }
  } else {
    if (millis() - apSwitchMillis >= apTimeout) {
      if (!apState) {
  //      Serial.println("wifi not connected");
        WiFi.softAP(ssid, password, 11, false, 8);
        WiFi.softAPConfig(local_IP, local_IP, subnet);
        apState = true;
      }
      apSwitchMillis = millis();
    }
  }

  if (millis() - now2 >= 5000) {
    handleGetTime();
    if (_EEPROM.timerMode != 3) {
      photoSensor = analogRead(photoSensorpin);
      if (photoSensor >= 55) {
        lightsOn = true;
      } else {
        lightsOn = false;
      }


    } else {
      lightsOn = true;
    }
    now2 = millis();
  }

  if (millis() - now4 >= 800) {

    for (int i = 0; i <= 3; i++) {
      _EEPROM.timerRunning[i] = digitalRead(relay[i]);
    }
    sendStruct();
    Serial.print("empty sensor");
    Serial.println(analogRead(emptyFloatSensor) );
    Serial.print("full  sensor");
    Serial.println(digitalRead(fullFloatSensor));
    now4 = millis();
  }


}

if i remove "OTA_httpUpdater.setup(&OTA_httpServer);" from ota the page loads on port 80. it allows me to upload the file but does not reset or retain the new program?

i ran this example,

#include <Arduino.h>

#include <WiFi.h>

#include <HTTPClient.h>
#include <ESP32httpUpdate.h>

#define USE_SERIAL Serial

void setup() {

    USE_SERIAL.begin(115200);
    // USE_SERIAL.setDebugOutput(true);

    USE_SERIAL.println();
    USE_SERIAL.println();
    USE_SERIAL.println();

    for(uint8_t t = 4; t > 0; t--) {
        USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
        USE_SERIAL.flush();
        delay(1000);
    }

    WiFi.begin("SSID", "PASSWORD");

}

void loop() {
    // wait for WiFi connection
    if((WiFi.status() == WL_CONNECTED)) {

        USE_SERIAL.println("Update SPIFFS...");
        t_httpUpdate_return ret = ESPhttpUpdate.updateSpiffs("http://server/spiffs.bin");
        if(ret == HTTP_UPDATE_OK) {
            USE_SERIAL.println("Update sketch...");
            ret = ESPhttpUpdate.update("http://server/file.bin");

            switch(ret) {
                case HTTP_UPDATE_FAILED:
                    USE_SERIAL.printf("HTTP_UPDATE_FAILED Error (%d): %s", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str());
                    break;

                case HTTP_UPDATE_NO_UPDATES:
                    USE_SERIAL.println("HTTP_UPDATE_NO_UPDATES");
                    break;

                case HTTP_UPDATE_OK:
                    USE_SERIAL.println("HTTP_UPDATE_OK");
                    break;
            }
        }
    }
}

my http server log just show it requesting "spiffs.bin" over and over again. the file exists on the server and is accessible. the esp will not update what am i doing wrong. i really dont want to poll for an update file. i really want to update from my update.html file. someone please help

i just used the GitHub - ayushsharma82/AsyncElegantOTA: Perform OTAs for ESP8266 / ESP32 Elegantly! Uses AsyncWebServer and it worked. this requires asyncWebserver. my code is not directly compatible with async. why dont it work the other 2 ways?

There does not seem to be much support for http ota on the esp32. there are just a few ways i found on google and most of them dont work. its jsut one problem after the next. i am at a screeching halt idk what to do

i tried to use this library esp32-http-update/examples at master · suculent/esp32-http-update · GitHub

its piss poor examples of http update do not work. this is a port from esp8266 version which i used and works on esp8266 but on esp32 i get error mention in very first post.

i can confirm that the server opens the port 81. but it does not attach updating service because of error.

someone has got to know something about this.

it would be nice to get some help around here. i guess no one here knows anything about esp32? i doubt it. love wasting all my time !!!

Hi,

This forum is a 24/7 place, so a suitable answer from an informed forum member may take time.

Sorry I am not fully into network systems, ESP32 yes, but only basic WiFi connections.

There are people here who can probably help you, but be patient, your helper may still be at work or bed.

Have you looked on the "Randon Nerd" website?

Thanks.. Tom.. :grinning: :+1: :coffee: :australia:

yes i looked. as much as it may seem like it , this is not the first place i come as soon as i have a problem. i really hate asking questions here so much.

bump

Please help i really need ota to work.

This example works the way i want it, as a matter a fact its the only ota example that works at all.

#include <WiFi.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <AsyncElegantOTA.h>

const char* ssid = "........";
const char* password = "........";

AsyncWebServer server(80);


void setup(void) {
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  Serial.println("");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
    request->send(200, "text/plain", "Hi! I am ESP32.");
  });

  AsyncElegantOTA.begin(&server);    // Start ElegantOTA
  server.begin();
  Serial.println("HTTP server started");
}

void loop(void) {
  AsyncElegantOTA.loop();
} server.onNotFound i been asking for help for 20 hours

If i donate money to your forum will you help me? what does it take

there,i donated money now please help me

none of your attempts look anything like the elegantota examples given in the lib
this works perfectly on my esp32 dev board, i would start from there

#include <WiFi.h>
#include <WiFiClient.h>
#include <WebServer.h>
#include <ElegantOTA.h>

const char* ssid = "....";
const char* password = "....";

WebServer server(80);


void setup(void) {
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  Serial.println("");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  server.on("/", []() {
    server.send(200, "text/plain", "Hi! I am ESP32.");
  });

  ElegantOTA.begin(&server);    // Start ElegantOTA
  server.begin();
  Serial.println("HTTP server started");
}

void loop(void) {
  server.handleClient();
}
1 Like

YOU are a life saver. too bad theresno way to add karma. that is a different library that the elegant library i was using. thankyou soo much!!

I got AsyncElegantota from here ESP32 OTA (Over-the-Air) Updates - AsyncElegantOTA Arduino | Random Nerd Tutorials

i was not aware of a non async elegantota thankyou soo much!!

Hi,

Click on the "heart" symbol in the post.

Tom... :grinning: :+1: :coffee: :australia:

1 Like

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