Re: ESP32 ретро часы (разработка)
У меня нет в наличии этих часов поэтому вырезать секунды я не смогу, можно просто не подключать индикаторы и все.
Я добавил код мигающего индикатора, к свободному выходу который Вы укажите в скетче необходимо подключить высоковольтную отпопару аналогично как показано на общей схеме.
В этой сроке укажите свободный пин (xx):
#define DP xx
#define ID1 2
#define ID2 4
#define ID4 16
#define ID8 17
#define IN1 25
#define IN2 26
#define IN3 27
#define IN4 14
#define IN5 12
#define IN6 13
#define DP xx
#include <WiFi.h>
#include <NTPClient.h> // http://rcl-radio.ru/wp-content/uploads/2019/11/ntpclientmaster.zip
#include <WiFiUdp.h>
#include <WiFiClient.h>
#include <WebServer.h>
#include <ESPmDNS.h>
#include <EEPROM.h>
#include "esp_system.h"
#ifndef APSSID
#define APSSID "ESPap"
#define APPSK "12345678"
#endif
const char *ssid = APSSID;
const char *password = APPSK;
WebServer server(80);
WiFiUDP ntpUDP;
///////////////// https://www.ntppool.org/zone/@ - другие сервера /////////////////////////////
///////////////// для России - ru.pool.ntp.org //////////////////////////////////////////////////
NTPClient timeClient(ntpUDP, "pool.ntp.org", 21600,3601234);// 21600 - временной сдвиг в секундах от UTC
int dd,mon,yer,ss,mm,hh,i,an,segm,brignes,brignes_low, end_night,start_night,gas_d;
long a[6];
unsigned long times, sum, times1,times2;
byte len_ssid, len_pass;
int utc,annti;
String date_time,date;
int alarm1,alarm2,al1_h,al1_m,al2_h,al2_m,bip1,bip2,out_alarm1,out_alarm2;
char * d_n[7] = {"Воскресенье", "Понедельник", "Вторник", "Среда", "Четверг", "Пятница", "Суббота"};
char * mon_n[13] = {"","Января", "Февраля", "Марта", "Апреля", "Мая", "Июня", "Июля", "Августа", "Сентября", "Октября", "Ноября", "Декабря"};
hw_timer_t * timer = NULL;
volatile SemaphoreHandle_t timerSemaphore;
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
void IRAM_ATTR onTimer() {
portENTER_CRITICAL_ISR(&timerMux);
switch(i){
case 0: an=10;anod();delayMicroseconds(2000);segm=a[0]; an=0; segment();anod();break;
case 1: an=10;anod();delayMicroseconds(2000);segm=a[1]; an=1; segment();anod();break;
case 2: an=10;anod();delayMicroseconds(2000);segm=a[2]; an=2; segment();anod();break;
case 3: an=10;anod();delayMicroseconds(2000);segm=a[3]; an=3; segment();anod();break;
case 4: an=10;anod();delayMicroseconds(2000);segm=a[4]; an=4; segment();anod();break;
case 5: an=10;anod();delayMicroseconds(2000);segm=a[5]; an=5; segment();anod();break;
}
i++;if(i>5){i=0;}
portEXIT_CRITICAL_ISR(&timerMux);
xSemaphoreGiveFromISR(timerSemaphore, NULL);
}
void setup(){
timerSemaphore = xSemaphoreCreateBinary();
//////// GPIO ///////////////
pinMode(15,OUTPUT); // IRF840 PWM
pinMode(23,INPUT_PULLUP);// AP/STA
pinMode(22,OUTPUT);// ALARM PWM
pinMode(33,INPUT_PULLUP);// ALARM OFF
digitalWrite(15,HIGH);
Serial.begin(9600);
//////// AP /////////////////
if(digitalRead(23)==LOW){
WiFi.softAP(ssid, password);
IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(myIP);
server.on("/", handleRoot);
server.on("/ok", handleOk);
server.begin();
Serial.println("HTTP server started");
}
else{
//////// STA ///////////////
WiFi.mode( WIFI_STA);
EEPROM.begin(512);
len_ssid = EEPROM.read(96);
len_pass = EEPROM.read(97);
utc = EEPROM.read(201);
brignes = EEPROM.read(200);
brignes_low = EEPROM.read(202);
start_night = EEPROM.read(203);
end_night = EEPROM.read(204);
annti = EEPROM.read(205);
gas_d = EEPROM.read(206);
alarm1 = EEPROM.read(210);
al1_h = EEPROM.read(211);
al1_m = EEPROM.read(212);
alarm2 = EEPROM.read(220);
al2_h = EEPROM.read(221);
al2_m = EEPROM.read(222);
if(brignes > 150){brignes=150;}
if(brignes_low > 150){brignes_low=150;}
if(len_pass > 64) len_pass = 0;
/////// READ EEPROM
unsigned char* buf_ssid = new unsigned char[32];
unsigned char* buf_pass = new unsigned char[64];
for(byte i = 0; i < len_ssid; i++) buf_ssid[i] = char(EEPROM.read(i));
buf_ssid[len_ssid] = '\x0';
const char *ssid = (const char*)buf_ssid;
for(byte i = 0; i < len_pass; i++) buf_pass[i] = char(EEPROM.read(i + 32));
const char *pass = (const char*)buf_pass;
buf_pass[len_pass] = '\x0';
delay(2000);
Serial.print("SSID: ");Serial.print(ssid);Serial.print(" ");Serial.print("Password: ");Serial.println(pass);
/////// connection
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED){delay(100);Serial.print (".");digitalWrite(15,HIGH);}
Serial.println();Serial.print("Connected to ");Serial.println(ssid);Serial.print("IP address: ");Serial.println(WiFi.localIP());
server.begin();
server.on("/", web);
server.on("/reset", web0);
}
///////// PWM IRF840 //////////////////
ledcSetup(2, 25000, 8); // 25000 kHz / 8 bit / cannel 2
ledcAttachPin(15, 2); // D15 / cannel 2
ledcWrite(2, 255-brignes);
///////// PWM ALARM ///////////////////
ledcSetup(5, 2000, 8);
ledcAttachPin(22, 5);
ledcWrite(5, 0);
///////// TIMER 3 /////////////////////
timer = timerBegin(3, 8000, true);
timerAttachInterrupt(timer, &onTimer, false);
timerAlarmWrite(timer, 35, true);
timerAlarmEnable(timer);
///////////////////////////////////////
pinMode(IN1,OUTPUT);pinMode(IN2,OUTPUT);pinMode(IN3,OUTPUT); pinMode(IN4,OUTPUT); pinMode(IN5,OUTPUT);
pinMode(IN6,OUTPUT); pinMode(ID1,OUTPUT); pinMode(ID2,OUTPUT); pinMode(ID4,OUTPUT); pinMode(ID8,OUTPUT);
pinMode(DP,OUTPUT);
timeClient.setTimeOffset(utc*1800);
}
void loop(){
if(millis()-times2<500){digitalWrite(DP,LOW);}else{digitalWrite(DP,HIGH);}
if(millis()-times2>999){times2=millis();}
if(bip1==0 && bip2==0){delay(100);}
server.handleClient();
if(digitalRead(23)==HIGH){
/////////////// times ////////////////////////////
if(millis()-times>=1000){times=millis();
while(!timeClient.update()){timeClient.forceUpdate();}
hh = timeClient.getHours();
mm = timeClient.getMinutes();
ss = timeClient.getSeconds();
date_time = timeClient.getFormattedDate();
int index_date = date_time.indexOf("T");
date = date_time.substring(0, index_date);
char charBufVar[11];date.toCharArray(charBufVar, 11);
dd = int(charBufVar[0]-'0')*10+int(charBufVar[1]-'0');
mon = int(charBufVar[3]-'0')*10+int(charBufVar[4]-'0');
yer = int(charBufVar[8]-'0')*10+int(charBufVar[9]-'0');
Serial.print(hh/10);Serial.print(hh%10);Serial.print(":");Serial.print(mm/10);Serial.print(mm%10);Serial.print(":");Serial.print(ss/10);Serial.println(ss%10);
///// brightness
if(hh>=0&&hh<=end_night||hh>=start_night){ledcWrite(2, 255-brignes_low); }else {ledcWrite(2, 255-brignes);}
}
sum = hh*10000+mm*100+ss;
if(ss>=30&&ss<35&&gas_d==1){sum = dd*10000+mon*100+yer;}
///////// ///////////////
switch(annti){
case 1: if(mm==30&&ss<10){anti();}break;
case 2: if((mm==15||mm==45)&&ss<10){anti();}break;
case 3: if((mm==15||mm==30||mm==45)&&ss<10){anti();}break;
case 4: if((mm==5||mm==20||mm==35||mm==50)&&ss<10){anti();}break;
}
a[0]=sum/100000;
a[1]=sum/10000%10;
a[2]=sum/1000%10;
a[3]=sum/100%10;
a[4]=sum/10%10;
a[5]=sum%10;
//////// ALARM //////////////////
// 1 - каждый день, 2 - по будням, 3 - по выходным, 4 - откл.
// 0 вс 6 сб
if(out_alarm1==0 && alarm1==1 && hh*100+mm==al1_h*100+al1_m){bip1=1;}
else if(out_alarm1==0 && alarm1==2 && (timeClient.getDay()>0 && timeClient.getDay()<6) && hh*100+mm==al1_h*100+al1_m){bip1=1;}
else if(out_alarm1==0 && alarm1==3 && (timeClient.getDay()==0 || timeClient.getDay()==6) && hh*100+mm==al1_h*100+al1_m){bip1=1;}
else{bip1=0;}
if(out_alarm2==0 && alarm2==1 && hh*100+mm==al2_h*100+al2_m){bip2=1;}
else if(out_alarm2==0 && alarm2==2 && (timeClient.getDay()>0 && timeClient.getDay()<6) && hh*100+mm==al2_h*100+al2_m){bip2=1;}
else if(out_alarm2==0 && alarm2==3 && (timeClient.getDay()==0 || timeClient.getDay()==6) && hh*100+mm==al2_h*100+al2_m){bip2=1;}
else{bip2=0;}
if(digitalRead(33)==LOW){bip1=0;bip2=0;delay(200);out_alarm1=1;out_alarm2=1;}
if(hh*100+mm!=al1_h*100+al1_m){out_alarm1=0;}
if(hh*100+mm!=al2_h*100+al2_m){out_alarm2=0;}
if(bip1==1 || bip2==1){alarm_bip_on();}
if(bip1==0 && bip2==0){alarm_bip_off();}
Serial.println(bip1);
}
}// loop
void alarm_bip_on(){ledcWrite(5, 127);delay(200);ledcWrite(5, 0);delay(100);}
void alarm_bip_off(){ledcWrite(5, 0);}
void segment(){
switch(segm){
case 0: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,LOW);break; // DEC 0 = 0b0000
case 1: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,HIGH);break; // DEC 1 = 0b0001
case 2: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,HIGH);digitalWrite(ID1,LOW);break; // DEC 2 = 0b0010
case 3: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,HIGH);digitalWrite(ID1,HIGH);break; // DEC 3 = 0b0011
case 4: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,LOW);digitalWrite(ID1,LOW);break; // DEC 4 = 0b0100
case 5: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,LOW);digitalWrite(ID1,HIGH);break; // DEC 5 = 0b0101
case 6: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,HIGH);digitalWrite(ID1,LOW);break; // DEC 6 = 0b0110
case 7: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,HIGH);digitalWrite(ID1,HIGH);break; // DEC 7 = 0b0111
case 8: digitalWrite(ID8,HIGH);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,LOW);break; // DEC 8 = 0b1000
case 9: digitalWrite(ID8,HIGH);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,HIGH);break; // DEC 9 = 0b1001
case 10:digitalWrite(ID8,HIGH);digitalWrite(ID4,HIGH);digitalWrite(ID2,HIGH);digitalWrite(ID1,HIGH);break; // Пусто = 0b1111
}}
void anod(){
switch(an){
case 0: digitalWrite(IN1,HIGH);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;
case 1: digitalWrite(IN1,LOW);digitalWrite(IN2,HIGH);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;
case 2: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,HIGH);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;
case 3: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,HIGH);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;
case 4: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,HIGH);digitalWrite(IN6,LOW);break;
case 5: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,HIGH);break;
case 10:digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;
}}
void web(){
timerAlarmWrite(timer, 35, false);
delay(300);
String webPage = "<meta charset='utf-8'><meta name='viewport' content='width=480, user-scalable=no' />";
//style
webPage += "<head><style>.tab1 {background-color:#F5F5F5;border-radius: 5px;margin: auto;}";
webPage += "#menu1{list-style:none; width:100%; padding:0 0 0 0 ; margin: 0 0 0 0;background: #999;}";
webPage += "#menu1 li{float:left; font:bold 14px Arial;text-shadow: 1px 1px 0px #000;}";
webPage += "#menu1 a{color:#fff; display:block; height:36px; line-height:36px; padding:10px 10px 10px 10px; background:#4682B4; text-decoration:none;}";
webPage += "#menu1 a:hover{color:#fff; background:#555;}";
webPage += "#menu1 b{color:#fff; display:block; height:25px; line-height:36px; padding:10px 10px 10px 10px; background:#4682B4; text-decoration:none;}";
webPage += "</style></head>";
/////////////
webPage += "<TABLE class='tab1' align='center' width='470' BORDER='1' cellspacing='0' cellpadding='2'>";
webPage +="<td colspan='2'><h3><center>ESP32<br>Страница настройки Интернет часов</h3>";
webPage +="<tr><td colspan='2'><center>Время: ";
webPage += hh/10;webPage += hh%10; webPage +=":";webPage +=mm/10;
webPage += mm%10; webPage +=":";webPage +=ss/10;webPage += ss%10;
webPage += " | Дата: ";webPage += d_n[timeClient.getDay()];webPage += " ";
webPage += dd;webPage += " ";webPage += mon_n[mon];webPage += " ";webPage += " 20";webPage += yer;
webPage += "</center>";
webPage += "<form method='POST' action='reset' >";
webPage += "<tr><td colspan='2'><b> Будильник №1 </b><input name='alarm1' autocomplete='off' maxlength='3' size='1'>";
webPage += "<br><small> 1 - каждый день, 2 - по будням, 3 - по выходным, 4 - откл. Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(210);
webPage += "<br></small><input name='al1_h' autocomplete='off' maxlength='3' size='1'> : ";
webPage += "<input name='al1_m' autocomplete='off' maxlength='3' size='1'> (HH:MM) ";
webPage += "<small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(211)/10;webPage += EEPROM.read(211)%10;webPage += ":";
EEPROM.begin(512);webPage += EEPROM.read(212)/10;webPage += EEPROM.read(212)%10;
webPage += "<tr><td colspan='2'><b> Будильник №2 </b><input name='alarm2' autocomplete='off' maxlength='3' size='1'>";
webPage += "<br><small> 1 - каждый день, 2 - по будням, 3 - по выходным, 4 - откл. Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(220);
webPage += "<br></small><input name='al2_h' autocomplete='off' maxlength='3' size='1'> : ";
webPage += "<input name='al2_m' autocomplete='off' maxlength='3' size='1'> (HH:MM) ";
webPage += "<small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(221)/10;webPage += EEPROM.read(221)%10;webPage += ":";
EEPROM.begin(512);webPage += EEPROM.read(222)/10;webPage += EEPROM.read(222)%10;
webPage += "<tr><td colspan='2'><input name='time_utc' autocomplete='off' maxlength='3' size='1'> Временной сдвиг UTC (30 мин)";
webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(201);
webPage += " (";webPage += utc*0.5;webPage += " ч.)";
webPage += "<tr><td><input name='brignes' autocomplete='off' maxlength='3' size='1'> Яркость день 0-150";
webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(200);
webPage += "<td><input name='brignes_low' autocomplete='off' maxlength='3' size='1'> Яркость ночь 0-150";
webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(202);
webPage += "<tr><td colspan='2'><center> Время работы ночного режима подсветки <tr>";
webPage += "<tr><td> Начало (18-23 ч) <input name='start_night' autocomplete='off' maxlength='3' size='1'>";
webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(203);
webPage += "<td> Конец: (1-12 ч) <input name='end_night' autocomplete='off' maxlength='3' size='1'>";
webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(204);
webPage += "<tr><td colspan='2'><input name='annti' autocomplete='off' maxlength='3' size='1'> Антиотравление катодов индикаторов";
webPage += "<br><small>Перебор всех цифр 1...4 раза в час, 5 - отключено. Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(205);
webPage += "<tr><td colspan='2'><input name='gas_d' autocomplete='off' maxlength='3' size='1'> Индикация DD MM YY: 1 - вкл. | 2 - откл.";
webPage += "<br><small>Дата, месяц и год показывается 1 раз в минуту (в 30 сек). Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(206);
webPage += "<tr><td colspan='2'><center><br><input type=SUBMIT value='Сохранить настройки'>";
webPage += "</form>";
webPage += "<center><br><small>Заполните все ячейки формы, незаполненная ячейка формы не изменит ранее установленный параметр";
server.send(200, "text/html", webPage);
timerAlarmWrite(timer, 35, true);
timerAlarmEnable(timer);
}
void sumbit(){
if (server.args() > 0 ) {
for ( uint8_t i = 0; i < server.args(); i++ ) {
if (server.argName(i) == "brignes"){brignes = server.arg(i).toInt();}
if (server.argName(i) == "time_utc"){utc = server.arg(i).toInt();}
if (server.argName(i) == "brignes_low"){brignes_low = server.arg(i).toInt();}
if (server.argName(i) == "start_night"){start_night = server.arg(i).toInt();}
if (server.argName(i) == "end_night"){end_night = server.arg(i).toInt();}
if (server.argName(i) == "annti"){annti = server.arg(i).toInt();}
if (server.argName(i) == "gas_d"){gas_d = server.arg(i).toInt();}
if (server.argName(i) == "alarm1"){alarm1 = server.arg(i).toInt();}
if (server.argName(i) == "al1_h"){if(server.arg(i)==NULL){}else{al1_h = server.arg(i).toInt();EEPROM.write(211,al1_h);}}
if (server.argName(i) == "al1_m"){if(server.arg(i)==NULL){}else{al1_m = server.arg(i).toInt();EEPROM.write(212,al1_m);}}
if (server.argName(i) == "alarm2"){alarm2 = server.arg(i).toInt();}
if (server.argName(i) == "al2_h"){if(server.arg(i)==NULL){}else{al2_h = server.arg(i).toInt();EEPROM.write(221,al2_h);}}
if (server.argName(i) == "al2_m"){if(server.arg(i)==NULL){}else{al2_m = server.arg(i).toInt();EEPROM.write(222,al2_m);}}
}
Serial.println("Save");
if(brignes > 150){brignes=150;} if(brignes < 0){brignes=0;}
if(brignes_low > 150){brignes_low=150;} if(brignes_low < 0){brignes_low=0;}
if(brignes==NULL){}else{EEPROM.write(200,brignes);}
if(utc==NULL){}else{EEPROM.write(201,utc);}
if(brignes_low==NULL){}else{EEPROM.write(202,brignes_low);}
if(start_night==NULL){}else{EEPROM.write(203,start_night);}
if(end_night==NULL){}else{EEPROM.write(204,end_night);}
if(annti==NULL){}else{EEPROM.write(205,annti);}
if(gas_d==NULL){}else{EEPROM.write(206,gas_d);}
if(alarm1==NULL){}else{EEPROM.write(210,alarm1);}
if(alarm2==NULL){}else{EEPROM.write(220,alarm2);}
EEPROM.commit();
EEPROM.end();
EEPROM.begin(512);
brignes = EEPROM.read(200);
utc = EEPROM.read(201);
brignes_low = EEPROM.read(202);
start_night = EEPROM.read(203);
end_night = EEPROM.read(204);
annti = EEPROM.read(205);
gas_d = EEPROM.read(206);
alarm1 = EEPROM.read(210);
al1_h = EEPROM.read(211);
al1_m = EEPROM.read(212);
alarm2 = EEPROM.read(220);
al2_h = EEPROM.read(221);
al2_m = EEPROM.read(222);
timeClient.setTimeOffset(utc*1800);
if(hh>=0&&hh<=6||hh>=23){ledcWrite(2, 255-brignes_low);}else {ledcWrite(2, 255-brignes);}
}}
void handleRoot() {
timerAlarmWrite(timer, 35, false);
delay(300);
String str = "<meta charset='utf-8'><meta name='viewport' content='width=480, user-scalable=no' />";
//style
str += "<head><style>.tab1 {background-color:#F5F5F5;border-radius: 5px;margin: auto;}";
str += "#menu1{list-style:none; width:100%; padding:0 0 0 0 ; margin: 0 0 0 0;background: #999;}";
str += "#menu1 li{float:left; font:bold 14px Arial;text-shadow: 1px 1px 0px #000;}";
str += "#menu1 a{color:#fff; display:block; height:36px; line-height:36px; padding:10px 10px 10px 10px; background:#4682B4; text-decoration:none;}";
str += "#menu1 a:hover{color:#fff; background:#555;}";
str += "#menu1 b{color:#fff; display:block; height:25px; line-height:36px; padding:10px 10px 10px 10px; background:#4682B4; text-decoration:none;}";
str += "</style></head>";
////////////
str += "<TABLE class='tab1' align='center' width='470' BORDER='1' cellspacing='0' cellpadding='10'>";
str +="<td><h1><center>ESP32<br>Авторизация</h1>";
str += "<form method='POST' action='ok'>";
str += "<tr><td><input name='ssid' autocomplete='off'><big> Имя Wi-Fi сети";
str += "<tr><td><input name='pswd' autocomplete='off'><big> Пароль";
str += "<tr><td><center><input type=SUBMIT value='Сохранить настройки'>";
str += "</form>";
server.send ( 200, "text/html", str );
timerAlarmWrite(timer, 35, true);
timerAlarmEnable(timer);
}
void handleOk(){
timerAlarmWrite(timer, 35, false);
delay(300);
String ssid_ap;
String pass_ap;
unsigned char* buf = new unsigned char[64];
String str = "<meta charset='utf-8'><meta name='viewport' content='width=480, user-scalable=no' />";;
str += "<body>";
EEPROM.begin(512);
ssid_ap = server.arg(0);
pass_ap = server.arg(1);
if(ssid_ap != ""){
EEPROM.write(96,ssid_ap.length());
EEPROM.write(97,pass_ap.length());
ssid_ap.getBytes(buf, ssid_ap.length() + 1);
for(byte i = 0; i < ssid_ap.length(); i++)
EEPROM.write(i, buf[i]);
pass_ap.getBytes(buf, pass_ap.length() + 1);
for(byte i = 0; i < pass_ap.length(); i++)
EEPROM.write(i + 32, buf[i]);
EEPROM.commit();
EEPROM.end();
const char *ast_ssid_ap = ssid_ap.c_str();
const char *ast_pass_ap = pass_ap.c_str();
/////////////////////////
WiFi.begin(ast_ssid_ap, ast_pass_ap);
// Wait for connection
while (WiFi.status() != WL_CONNECTED){delay (10);Serial.print (".");}
///////////////////////////////////////////////////////////////////////////
str +="<big><center>Конфигурация сохранена в память<br>";
str +="<big><center>Уберите перемычку с D23 и перезагрузите ESP32</p><br>";
str +="<big><b><center>";
str += WiFi.localIP().toString();
str +="</b><hr>";
str +="<a href=\"/\">Return</a> to settings page</br>";
}
else {
str += "<big><center>No WIFI Net</br>\
<a href=\"/\">Return</a> to settings page</br>";
}
str += "</body></html>";
server.send ( 200, "text/html", str );
timerAlarmWrite(timer, 35, true);
timerAlarmEnable(timer);
}
void web0() {
timerAlarmWrite(timer, 35, false);
delay(300);
String str0 = "<meta charset='utf-8'><meta name='viewport' content='width=480, user-scalable=no' />";
str0 += "<center><b><big>Настройки сохранены.<br> Для возврата на предыдущую страницу перейдите по <a href='./'>ссылке</a>";
server.send (200, "text/html", str0);
sumbit();
timerAlarmWrite(timer, 35, true);
timerAlarmEnable(timer);
}
void anti(){
switch(ss){
case 0: sum=000000;break;
case 1: sum=111111;break;
case 2: sum=222222;break;
case 3: sum=333333;break;
case 4: sum=444444;break;
case 5: sum=555555;break;
case 6: sum=666666;break;
case 7: sum=777777;break;
case 8: sum=888888;break;
case 9: sum=999999;break;}
}