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?