#include #include #include byte webTabId[20] = {}; byte webTabNumber[20] = {}; bool UpdateText_206775150_1; String Text_206775150_1; bool rTrig_206775150_1= true; bool rTrig2_206775150_1; uint16_t thisControl_206775150_1; int StartValue_216074591_1; int Value_216074591_1; bool rTrig_216074591_1= true; uint16_t thisControl_216074591_1; bool ESPControllerWifiClient_HRD = 0; bool ESPControllerWifiClient_status = 1; bool ESPControllerWifiClient_isDHCP = 0; bool ESPControllerWifiClient_IsNeedReconect = 0; bool ESPControllerWifiClient_workStatus = 0; char ESPControllerWifiClient_SSID[40] = "HTC32"; char ESPControllerWifiClient_password[40] = "11111111"; IPAddress ESPControllerWifiClient_ip(192, 168, 1, 42); IPAddress ESPControllerWifiClient_dns (192, 168, 1, 1); IPAddress ESPControllerWifiClient_gateway (192, 168, 1, 1); IPAddress ESPControllerWifiClient_subnet (255, 255, 255, 0); uint8_t ESPControllerWifiClient_mac[6] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0}; bool isNeededEEpromCommit = 0; int _gtv3; int _gtv1; bool _BitChange_1_OldSt = 0; bool _BitChange_1_Out = 0; bool _tim3I = 0; bool _tim3O = 0; unsigned long _tim3P = 0UL; bool _count1I = 0; bool _count1_SCST = 0; int _count1_Value = 0; bool _tim2I = 0; bool _tim2O = 0; unsigned long _tim2P = 0UL; bool _changeNumber1_Out = 0; int _changeNumber1_OLV; bool _changeNumber2_Out = 0; int _changeNumber2_OLV; bool _trgrt3 = 0; bool _trgrt3I = 0; bool _tim1I = 0; bool _tim1O = 0; unsigned long _tim1P = 0UL; bool _trgrt2 = 0; bool _trgrt2I = 0; bool _trgrt1 = 0; bool _trgrt1I = 0; bool _gen1I = 0; bool _gen1O = 0; unsigned long _gen1P = 0UL; bool _SysParRead_1_Out; bool _bounseInputD14S = 0; bool _bounseInputD14O = 0; unsigned long _bounseInputD14P = 0UL; bool _BitChange_2_OldSt = 0; bool _BitChange_2_Out = 0; bool _bounseInputD27S = 0; bool _bounseInputD27O = 0; unsigned long _bounseInputD27P = 0UL; void setup() { pinMode(36, INPUT); pinMode(39, INPUT); pinMode(34, INPUT); pinMode(27, INPUT); pinMode(14, INPUT); pinMode(19, OUTPUT); digitalWrite(19, 0); pinMode(18, OUTPUT); digitalWrite(18, 0); pinMode(5, OUTPUT); digitalWrite(5, 0); pinMode(1, OUTPUT); digitalWrite(1, 0); EEPROM.begin(1); ledcSetup(0, 1000, 8); ledcAttachPin(4, 0); WiFi.mode(WIFI_STA); _esp32WifiModuleClientReconnect(); _parseMacAddressString(WiFi.macAddress(), ESPControllerWifiClient_mac); _bounseInputD14O = digitalRead(14); _bounseInputD27O = digitalRead(27); if (0) { if (0) { ESPUI.beginSPIFFS("Регулятор мощности", "user", "pass"); } else { ESPUI.beginSPIFFS("Регулятор мощности"); } } else { if (0) { ESPUI.begin("Регулятор мощности", "user", "pass"); } else { ESPUI.begin("Регулятор мощности"); } } } void loop() { int _tempVariable_int; if (isNeededEEpromCommit){EEPROM.commit(); isNeededEEpromCommit=0;} if(ESPControllerWifiClient_IsNeedReconect) {_esp32WifiModuleClientReconnect(); ESPControllerWifiClient_IsNeedReconect = 0; } ESPControllerWifiClient_status = WiFi.status() == WL_CONNECTED; if (ESPControllerWifiClient_status) { if ( ! ESPControllerWifiClient_HRD) { ESPControllerWifiClient_ip = WiFi.localIP(); ESPControllerWifiClient_subnet = WiFi.subnetMask(); ESPControllerWifiClient_gateway = WiFi.gatewayIP(); ESPControllerWifiClient_dns = WiFi.dnsIP(); ESPControllerWifiClient_HRD = 1; }} else {ESPControllerWifiClient_HRD = 0;} bool _bounceInputTmpD27 = (digitalRead (27)); if (_bounseInputD27S) { if (millis() >= (_bounseInputD27P + 40)) {_bounseInputD27O= _bounceInputTmpD27; _bounseInputD27S=0;} } else { if (_bounceInputTmpD27 != _bounseInputD27O ) {_bounseInputD27S=1; _bounseInputD27P = millis();} } bool _bounceInputTmpD14 = (digitalRead (14)); if (_bounseInputD14S) { if (millis() >= (_bounseInputD14P + 40)) {_bounseInputD14O= _bounceInputTmpD14; _bounseInputD14S=0;} } else { if (_bounceInputTmpD14 != _bounseInputD14O ) {_bounseInputD14S=1; _bounseInputD14P = millis();} } //Плата:1 //Наименование:WEB интерфейс _SysParRead_1_Out = ESPControllerWifiClient_status; digitalWrite(1, !(ESPControllerWifiClient_status)); if (_changeNumber2_Out) {_changeNumber2_Out = 0;} else {_tempVariable_int = _gtv1; if (_tempVariable_int != _changeNumber2_OLV) {_changeNumber2_OLV = _tempVariable_int; _changeNumber2_Out = 1;} } if(_BitChange_1_Out) {_BitChange_1_Out = 0; } else {if( !(_BitChange_1_OldSt == _bounseInputD27O)) { _BitChange_1_OldSt = _bounseInputD27O; _BitChange_1_Out= 1; }} if(_BitChange_2_Out) {_BitChange_2_Out = 0; } else {if( !(_BitChange_2_OldSt == _bounseInputD14O)) { _BitChange_2_OldSt = _bounseInputD14O; _BitChange_2_Out= 1; }} UpdateText_206775150_1 = ( (_changeNumber2_Out) || (( (_BitChange_1_Out) || (_BitChange_2_Out) )) ); Text_206775150_1 = (((String(_gtv3, DEC))) + (String(" %"))); if (rTrig_206775150_1) { rTrig_206775150_1 = false; if (0 == 0) { thisControl_206775150_1 = ESPUI.addControl(ControlType::Label, "Мощность %", Text_206775150_1.c_str(), COLOR_EMERALD); } else { for (uint8_t i = 0; i < sizeof(webTabId); i++) { if (webTabId[i] == 0) { thisControl_206775150_1 = ESPUI.addControl(ControlType::Label, "Мощность %", Text_206775150_1.c_str(), COLOR_EMERALD, webTabNumber[i]); break; } } } } if (UpdateText_206775150_1) { if (!rTrig2_206775150_1) { rTrig2_206775150_1 = true; ESPUI.updateControlValue(thisControl_206775150_1, Text_206775150_1); } } else { rTrig2_206775150_1 = false; } ledcWrite(0, _gtv3); StartValue_216074591_1 = 0; if (rTrig_216074591_1) { rTrig_216074591_1 = false; Value_216074591_1 = StartValue_216074591_1; if (0 == 0) { thisControl_216074591_1 = ESPUI.addControl(ControlType::Slider, "Слайдер1", String(StartValue_216074591_1).c_str(), COLOR_EMERALD, Control::noParent, &slider_216074591_1); ESPUI.addControl(ControlType::Min, "Слайдер1", String(0), ControlColor::None, thisControl_216074591_1); ESPUI.addControl(ControlType::Max, "Слайдер1", String(100), ControlColor::None, thisControl_216074591_1); } else { for (uint8_t i = 0; i < sizeof(webTabId); i++) { if (webTabId[i] == 0) { thisControl_216074591_1 = ESPUI.addControl(ControlType::Slider, "Слайдер1", String(StartValue_216074591_1).c_str(), COLOR_EMERALD, webTabNumber[i], &slider_216074591_1); ESPUI.addControl(ControlType::Min, "Слайдер1", String(0), ControlColor::None, thisControl_216074591_1); ESPUI.addControl(ControlType::Max, "Слайдер1", String(100), ControlColor::None, thisControl_216074591_1); break; } } } } _gtv1 = Value_216074591_1; //Плата:2 //Наименование:Управление кнопками if (( (!(_bounseInputD27O)) || (!(_bounseInputD14O)) )) { if (! _gen1I) { _gen1I = 1; _gen1O = 1; _gen1P = millis(); } } else { _gen1I = 0 ; _gen1O= 0;} if (_gen1I) { if ( _isTimer ( _gen1P , 20 )) { _gen1P = millis(); _gen1O = ! _gen1O;}} if (_changeNumber1_Out) {_changeNumber1_Out = 0;} else {_tempVariable_int = _gtv1; if (_tempVariable_int != _changeNumber1_OLV) {_changeNumber1_OLV = _tempVariable_int; _changeNumber1_Out = 1;} } if (_changeNumber1_Out){ _count1_Value = _gtv1; } else { if (( (_gen1O) && (!(_bounseInputD27O)) )){ if ( ! _count1I) { _count1I = 1; if(_count1_Value < 100) {_count1_Value = _count1_Value + 1; }}} else { _count1I = 0;} if (( (_gen1O) && (!(_bounseInputD14O)) )){ if ( ! _count1_SCST) { _count1_SCST = 1; if(_count1_Value > 0) {_count1_Value = _count1_Value - 1; }}} else { _count1_SCST = 0;} } _gtv3 = _count1_Value; //Плата:3 //Наименование:Выход if ( (digitalRead (36))) { if (_trgrt1I) { _trgrt1 = 0;} else {_trgrt1 = 1; _trgrt1I = 1;} } else {_trgrt1 = 0; _trgrt1I = 0;}; if (!(_trgrt1)) { if (_tim1I) { if (_isTimerMicros(_tim1P, (map((_gtv3), (0), (100), (10000), (0))))) {_tim1O = 1;}} else {_tim1I =1; _tim1P = micros();}} else {_tim1O = 0; _tim1I = 0;} digitalWrite(19, _tim1O); if ( (digitalRead (39))) { if (_trgrt2I) { _trgrt2 = 0;} else {_trgrt2 = 1; _trgrt2I = 1;} } else {_trgrt2 = 0; _trgrt2I = 0;}; if (!(_trgrt2)) { if (_tim2I) { if (_isTimerMicros(_tim2P, (map((_gtv3), (0), (100), (10000), (0))))) {_tim2O = 1;}} else {_tim2I =1; _tim2P = micros();}} else {_tim2O = 0; _tim2I = 0;} digitalWrite(18, _tim2O); if ( (digitalRead (34))) { if (_trgrt3I) { _trgrt3 = 0;} else {_trgrt3 = 1; _trgrt3I = 1;} } else {_trgrt3 = 0; _trgrt3I = 0;}; if (!(_trgrt3)) { if (_tim3I) { if (_isTimerMicros(_tim3P, (map((_gtv3), (0), (100), (10000), (0))))) {_tim3O = 1;}} else {_tim3I =1; _tim3P = micros();}} else {_tim3O = 0; _tim3I = 0;} digitalWrite(5, _tim3O); } bool _isTimer(unsigned long startTime, unsigned long period ) { unsigned long currentTime; currentTime = millis(); if (currentTime>= startTime) {return (currentTime>=(startTime + period));} else {return (currentTime >=(4294967295-startTime+period));} } bool _isTimerMicros(unsigned long startTime, unsigned long period ) { unsigned long currentTime; currentTime = micros(); if (currentTime>= startTime) {return (currentTime>=(startTime + period));} else {return (currentTime >=(4294967295-startTime+period));} } void slider_216074591_1(Control* sender, int type) { Value_216074591_1 = sender->value.toInt(); } byte readByteFromEEPROM(int addres, byte bitAddres, byte chipAddres) { return EEPROM.readByte(addres); } void updateByteToEEPROM(int addres, byte bitAddres, byte chipAddres, byte value) { EEPROM.writeByte(addres, value); isNeededEEpromCommit = 1; return; } int hexStrToInt(String instring) { byte len = instring.length(); if (len == 0) return 0; int result = 0; for (byte i = 0; i < 8; i++) // только первые 8 цыфар влезуть в uint32 { char ch = instring[i]; if (ch == 0) break; result <<= 4; if (isdigit(ch)) result = result | (ch - '0'); else result = result | (ch - 'A' + 10); } return result; } void _esp32WifiModuleClientReconnect() { if( ESPControllerWifiClient_isDHCP) { WiFi.config(0U, 0U, 0U, 0U, 0U); } else { WiFi.config(ESPControllerWifiClient_ip, ESPControllerWifiClient_gateway, ESPControllerWifiClient_subnet, ESPControllerWifiClient_dns , ESPControllerWifiClient_dns ); } WiFi.begin(ESPControllerWifiClient_SSID, ESPControllerWifiClient_password); } bool _checkMacAddres(byte array[]) { bool result = 0; for (byte i = 0; i < 6; i++) { if (array[i] == 255) { return 0; } if (array[i] > 0 ) { result = 1; } } return result; } void _parseMacAddressString(String value, byte array[]) { int index; byte buffer[6] = {255, 255, 255, 255, 255, 255}; byte raz = 0; String tempString; while ((value.length() > 0) && (raz <= 6)) { index = value.indexOf(":"); if (index == -1) { tempString = value; value = ""; } else { tempString = value.substring(0, index); value = value.substring(index + 1); } buffer[raz] = byte(hexStrToInt(tempString)); raz++; } if ( _checkMacAddres(buffer)) { for (byte i = 0; i < 6; i++) { array[i] = buffer[i]; } } } bool _compareMacAddreses(byte array1[], byte array2[]) { for (byte i = 0; i < 6; i++) { if (array1[i] != array2[i]) { return 0; } } return 1; } bool _compareMacAddresWithString(byte array[], String value) { byte buffer[6] = {255, 255, 255, 255, 255, 255}; _parseMacAddressString(value, buffer); return _compareMacAddreses(array, buffer); } bool _checkMacAddresString(String value) { byte buffer[6] = {255, 255, 255, 255, 255, 255}; _parseMacAddressString(value, buffer); return _checkMacAddres( buffer); } String _macAddresToString(byte array[]) { String result = ""; String temp =""; for (byte i = 0; i < 6; i++) { temp=String(array[i],HEX); if (temp.length() < 2) {temp = String("0") + temp; } result = result + temp; if (i < 5) { result = result + String(":"); } } result.toUpperCase(); return result; }