diff --git a/Samovar.h b/Samovar.h index 1f98d5b8..a00daef3 100644 --- a/Samovar.h +++ b/Samovar.h @@ -5,7 +5,7 @@ #error This code is designed to run on ESP32 platform, not Arduino nor ESP8266! Please check your Tools->Board setting. #endif -#define SAMOVAR_VERSION "5.17" +#define SAMOVAR_VERSION "5.18" //#define __SAMOVAR_DEBUG #include @@ -15,7 +15,7 @@ #ifdef __SAMOVAR_DEBUG #ifndef USE_WEB_SERIAL -#define USE_WEB_SERIAL //использовать библиотеку WebSerial для отладки +//#define USE_WEB_SERIAL //использовать библиотеку WebSerial для отладки #endif #endif @@ -382,8 +382,6 @@ GStepper< STEPPER2WIRE> stepper(STEPPER_STEPS, STEPPER_STEP, STEPPER_DIR, STEPPE File fileToAppend; -//AsyncMqttClient mqttClient; - #ifdef SERVO_PIN Servo servo; // create servo object to control a servo #endif diff --git a/WebServer.ino b/WebServer.ino index 1e866ab7..59926d9e 100644 --- a/WebServer.ino +++ b/WebServer.ino @@ -1,3 +1,5 @@ +#include + void web_command(AsyncWebServerRequest *request); void handleSave(AsyncWebServerRequest *request); void get_data_log(AsyncWebServerRequest *request); @@ -11,6 +13,8 @@ String get_DSAddressList(String Address); void set_pump_speed(float pumpspeed, bool continue_process); void start_self_test(void); void stop_self_test(void); +void get_web_file(String fn); + #ifdef USE_LUA void start_lua_script(); void load_lua_script(); @@ -74,6 +78,7 @@ void WebServerInit(void) { server.serveStatic("/program_grain.txt", SPIFFS, "/program_grain.txt"); server.serveStatic("/program_shugar.txt", SPIFFS, "/program_shugar.txt"); server.serveStatic("/brewxml.htm", SPIFFS, "/brewxml.htm").setTemplateProcessor(indexKeyProcessor); + server.serveStatic("/test.txt", SPIFFS, "/test.txt").setTemplateProcessor(indexKeyProcessor); #ifdef USE_LUA server.serveStatic("/btn_button1.lua", SPIFFS, "/btn_button1.lua"); @@ -149,6 +154,9 @@ void WebServerInit(void) { #ifdef __SAMOVAR_DEBUG Serial.println("HTTP server started"); #endif + +// get_web_file("http://worldtimeapi.org/api/timezone/Europe/London.txt"); + } String indexKeyProcessor(const String &var) { @@ -805,3 +813,29 @@ void get_old_data_log(AsyncWebServerRequest *request) { response->addHeader("Cache-Control", "no-cache"); request->send(response); } + +void get_web_file(String fn) { + asyncHTTPrequest request; + //request.setDebug(true); + request.setTimeout(10); //Таймаут три секунды + request.open(String("GET").c_str(), fn.c_str()); //URL + while (request.readyState() < 1) { + vTaskDelay(5 / portTICK_PERIOD_MS); + } + vTaskDelay(65 / portTICK_PERIOD_MS); + request.send(); + while (request.readyState() != 4) { + vTaskDelay(5 / portTICK_PERIOD_MS); + } + if (request.responseHTTPcode() >= 0) { + //Serial.println(request.responseHTTPcode()); + File wf = SPIFFS.open("/test.txt", FILE_WRITE); + wf.print(request.responseText()); + wf.close(); + Serial.println("Done"); + } + else { + Serial.println("error"); + Serial.println(request.responseHTTPcode()); + } +} diff --git a/libraries/GyverButton/src/GyverButton.cpp b/libraries/GyverButton/src/GyverButton.cpp index 3c0f3ad3..1feec744 100644 --- a/libraries/GyverButton/src/GyverButton.cpp +++ b/libraries/GyverButton/src/GyverButton.cpp @@ -45,6 +45,7 @@ void GButton::setTickMode(bool tickMode) { flags.tickMode = tickMode; } + // ==================== IS ==================== boolean GButton::isPress() { if (flags.tickMode) GButton::tick(); @@ -146,6 +147,14 @@ void GButton::resetStates() { flags.counter_flag = false; last_hold_counter = 0; last_counter = 0; +/////////////////////////////// +//!!!!!NOT REMOVE!!!!!! +/////////////////////////////// + btn_state = false; + btn_timer = 0; + btn_flag = false; + flags.hold_flag = false; +/////////////////////////////// } // ==================== TICK ==================== diff --git a/libraries/asyncHTTPrequest/examples/sample.cpp b/libraries/asyncHTTPrequest/examples/sample.cpp index 166a74d1..9e3f9330 100644 --- a/libraries/asyncHTTPrequest/examples/sample.cpp +++ b/libraries/asyncHTTPrequest/examples/sample.cpp @@ -45,6 +45,7 @@ void requestCB(void* optParm, asyncHTTPrequest* request, int readyState){ request->setDebug(false); } } + void setup(){ Serial.begin(115200); diff --git a/libraries/asyncHTTPrequest/src/asyncHTTPrequest.h b/libraries/asyncHTTPrequest/src/asyncHTTPrequest.h index 34e20d06..203e5dfc 100644 --- a/libraries/asyncHTTPrequest/src/asyncHTTPrequest.h +++ b/libraries/asyncHTTPrequest/src/asyncHTTPrequest.h @@ -116,7 +116,7 @@ class asyncHTTPrequest { bool open(const char* /*GET/POST*/, const char* URL); // Initiate a request void onReadyStateChange(readyStateChangeCB, void* arg = 0); // Optional event handler for ready state change // or you can simply poll readyState() - void setTimeout(int); // overide default timeout (seconds) + void setTimeout(int); // overide default timeout (seconds) void setReqHeader(const char* name, const char* value); // add a request header void setReqHeader(const char* name, const __FlashStringHelper* value); void setReqHeader(const __FlashStringHelper *name, const char* value); diff --git a/logic.h b/logic.h index 91853a66..9e3d43aa 100644 --- a/logic.h +++ b/logic.h @@ -558,9 +558,11 @@ void IRAM_ATTR check_alarm() { if (program[ProgramNum].WType != "C") { set_buzzer(true); SendMsg(F("Сработал датчик захлёба!"), ALARM_MSG); +#ifdef SAMOVAR_USE_POWER alarm_c_min = 0; alarm_c_low_min = 0; prev_target_power_volt = 0; +#endif } else { #ifdef SAMOVAR_USE_POWER //запускаем счетчик - TIME_C минут, нужен для возврата заданного напряжения diff --git a/lua.h b/lua.h index 3edd5821..b0fa0cfe 100644 --- a/lua.h +++ b/lua.h @@ -591,6 +591,10 @@ static int lua_wrapper_http_request(lua_State *lua_state) { if (n == 1) { RequestType = "GET"; request.open(RequestType.c_str(), Var.c_str()); //URL + while (request.readyState() < 1) { + vTaskDelay(5 / portTICK_PERIOD_MS); + } + vTaskDelay(65 / portTICK_PERIOD_MS); request.send(); } else { String ContentType; @@ -618,12 +622,16 @@ static int lua_wrapper_http_request(lua_State *lua_state) { lua_pop(lua_state, 1); request.open(RequestType.c_str(), Var.c_str()); //URL + while (request.readyState() < 1) { + vTaskDelay(5 / portTICK_PERIOD_MS); + } + vTaskDelay(65 / portTICK_PERIOD_MS); request.setReqHeader(String("Content-Type").c_str(), getValue(ContentType, ':', 1).c_str()); request.send(Body); } while (request.readyState() != 4) { - vTaskDelay(10 / portTICK_PERIOD_MS); + vTaskDelay(5 / portTICK_PERIOD_MS); } if (request.responseHTTPcode() >= 0) { payload = request.responseText(); diff --git a/sensorinit.h b/sensorinit.h index 7db824bd..d7ac661d 100644 --- a/sensorinit.h +++ b/sensorinit.h @@ -368,8 +368,11 @@ void IRAM_ATTR reset_sensor_counter(void) { set_capacity(0); alarm_h_min = 0; alarm_t_min = 0; +#ifdef SAMOVAR_USE_POWER alarm_c_min = 0; alarm_c_low_min = 0; + prev_target_power_volt = 0; +#endif d_s_time_min = 0; d_s_temp_finish = 0; @@ -409,6 +412,10 @@ void IRAM_ATTR reset_sensor_counter(void) { boil_started = false; + if (xSemaphore != NULL) xSemaphoreGive(xSemaphore); +#ifdef SAMOVAR_USE_SEM_AVR + if (xSemaphoreAVR != NULL) xSemaphoreGive(xSemaphoreAVR); +#endif set_power(false); sam_command_sync = SAMOVAR_NONE;