diff --git a/Cmd.ino b/Cmd.ino index c157e56e..f22dc3e0 100644 --- a/Cmd.ino +++ b/Cmd.ino @@ -345,23 +345,41 @@ void stepper() { void stepperSet() { String stepper_number = sCmd.next(); String steps = sCmd.next(); + jsonWrite(optionJson, "steps" + stepper_number, steps); String stepper_speed = sCmd.next(); - String pin_step = selectToMarker (jsonRead(optionJson, "stepper" + stepper_number), " "); String pin_dir = deleteBeforeDelimiter (jsonRead(optionJson, "stepper" + stepper_number), " "); - - Serial.println(pin_step); - Serial.println(pin_dir); - + Serial.println(pin_step); + Serial.println(pin_dir); if (steps.toInt() > 0) digitalWrite(pin_dir.toInt(), HIGH); if (steps.toInt() < 0) digitalWrite(pin_dir.toInt(), LOW); - - for (int x = 0; x < abs(steps.toInt()); x++) - { - digitalWrite(pin_step.toInt(), HIGH); - delay(stepper_speed.toInt()); - digitalWrite(pin_step.toInt(), LOW); - delay(stepper_speed.toInt()); + if (stepper_number == "1") { + ts.add(STEPPER1, stepper_speed.toInt(), [&](void*) { + int steps_int = abs(jsonReadtoInt(optionJson, "steps1")); + static int count; + count++; + String pin_step = selectToMarker (jsonRead(optionJson, "stepper1"), " "); + digitalWrite(pin_step.toInt(), !digitalRead(pin_step.toInt())); + if (count > steps_int) { + digitalWrite(pin_step.toInt(), LOW); + ts.remove(STEPPER1); + count = 0; + } + }, nullptr, true); + } + if (stepper_number == "2") { + ts.add(STEPPER2, stepper_speed.toInt(), [&](void*) { + int steps_int = abs(jsonReadtoInt(optionJson, "steps2")); + static int count; + count++; + String pin_step = selectToMarker (jsonRead(optionJson, "stepper2"), " "); + digitalWrite(pin_step.toInt(), !digitalRead(pin_step.toInt())); + if (count > steps_int) { + digitalWrite(pin_step.toInt(), LOW); + ts.remove(STEPPER2); + count = 0; + } + }, nullptr, true); } } diff --git a/Init.ino b/Init.ino index 9549c6cd..b7ce28f2 100644 --- a/Init.ino +++ b/Init.ino @@ -233,10 +233,16 @@ void up_time() { Serial.println(out + ", mqtt_lost_error: " + String(mqtt_lost_error) + ", wifi_lost_error: " + String(wifi_lost_error)); } +void statistics_init() { + ts.add(STATISTICS, statistics_update, [&](void*) { + + statistics(); + + }, nullptr, true); +} + void statistics() { String urls = "http://backup.privet.lv/visitors/?"; - - //----------------------------------------------------------------- urls += WiFi.macAddress().c_str(); urls += "&"; @@ -259,7 +265,5 @@ void statistics() { //----------------------------------------------------------------- urls += DATE_COMPILING + "_" + firmware_version; //----------------------------------------------------------------- - - String stat = getURL(urls); } diff --git a/Upgrade.ino b/Upgrade.ino index e195f044..deeb5798 100644 --- a/Upgrade.ino +++ b/Upgrade.ino @@ -19,7 +19,7 @@ void initUpgrade() { jsonWrite(tmp, "class", "pop-up"); } else { upgrade_flag = true; - jsonWrite(tmp, "title", "Идет обновление прошивки... После завершения устройство перезагрузится."); + jsonWrite(tmp, "title", "Идет обновление прошивки... После завершения устройство перезагрузится. Подождите минуту..."); jsonWrite(tmp, "class", "pop-up"); } } else { @@ -41,7 +41,7 @@ void upgrade_firmware() { configSetup_for_update = configSetup; Serial.println("Start upgrade SPIFFS, please wait..."); - web_print("Start upgrade SPIFFS, please wait..."); + //web_print("Start upgrade SPIFFS, please wait..."); WiFiClient client_for_upgrade; @@ -63,8 +63,8 @@ void upgrade_firmware() { Serial.println("SPIFFS upgrade done!"); Serial.println("Start upgrade BUILD, please wait..."); - web_print("SPIFFS upgrade done!"); - web_print("Start upgrade BUILD, please wait..."); + //web_print("SPIFFS upgrade done!"); + //web_print("Start upgrade BUILD, please wait..."); #ifdef ESP32 //httpUpdate.rebootOnUpdate(true); @@ -76,8 +76,8 @@ void upgrade_firmware() { #endif if (ret == HTTP_UPDATE_OK) { - web_print("BUILD upgrade done!"); - web_print("Restart ESP...."); + //web_print("BUILD upgrade done!"); + //web_print("Restart ESP...."); Serial.println("BUILD upgrade done!"); Serial.println("Restart ESP...."); ESP.restart(); diff --git a/data/config-all.json b/data/config-all.json new file mode 100644 index 00000000..ac2b3828 --- /dev/null +++ b/data/config-all.json @@ -0,0 +1 @@ +{"SSDP":"MODULES","chipID":"905542-1458415","ssidAP":"WiFi","passwordAP":"","ssid":"your_ssid","password":"your_password","timezone":3,"mqttServer":"","mqttPort":0,"mqttUser":"","mqttPass":"","scenario":"1","timers":"0","pushingbox_id":"","web_login":"admin","web_pass":"admin"} \ No newline at end of file diff --git a/data/config-my.json b/data/config-my.json deleted file mode 100644 index ae16f518..00000000 --- a/data/config-my.json +++ /dev/null @@ -1 +0,0 @@ -{"SSDP":"MODULES","chipID":"905542-1458415","ssidAP":"WiFi","passwordAP":"","ssid":"rise","password":"hostel3333","timezone":3,"mqttServer":"m12.cloudmqtt.com","mqttPort":14053,"mqttUser":"lbscvzuj","mqttPass":"bLxlveOgaF8F","scenario":"1","timers":"0","pushingbox_id":"v7C133E426B0C69E","web_login":"admin","web_pass":"admin"} \ No newline at end of file diff --git a/data/configs/stepper.config.txt b/data/configs/stepper.config.txt index c9064aea..82b41ae2 100644 --- a/data/configs/stepper.config.txt +++ b/data/configs/stepper.config.txt @@ -1,10 +1,17 @@ -stepper 1 12 13 -button 1 na Открыть#штору Шторы 0 1 +stepper 1 12 4 +stepper 2 13 5 +button 1 na Открыть#штору#1 Шторы 0 1 +button 2 na Открыть#штору#2 Шторы 0 2 +//для подключения необходим драйвер шагового двигателя A4988 -//добавляем шаговый двигатель с параметрами: -//1 - номер шагового двигателя, 12 - номер пина количества шагов, 13 - номер пина напрвления +//stepper 1 12 4 шаговый двигатель с параметрами: 1 - номер шагового двигателя, +//12 - номер пина количества шагов, 4 - номер пина направления -//stepperSet 1 100 5 - прокрутить шаговик номер 1 на 100 шагов по часовой стрелке +//stepper 2 13 5 шаговый двигатель с параметрами: 2 - номер шагового двигателя, +//13 - номер пина количества шагов, 5 - номер пина направления + +//stepperSet 1 200 5 - прокрутить шаговик номер 1 на 200 шагов по часовой стрелке //с задержкой между шагами 5 милисекунд (чем меньше задержка тем больше скорость) -//если поставить -100 то будет вращаться против часовой стрелки \ No newline at end of file +//если поставить -200 то будет вращаться против часовой стрелки +//можно подключить не более двух шаговиков \ No newline at end of file diff --git a/data/configs/stepper.scenario.txt b/data/configs/stepper.scenario.txt index cb4cd521..89f9e3dd 100644 --- a/data/configs/stepper.scenario.txt +++ b/data/configs/stepper.scenario.txt @@ -1,6 +1,12 @@ button1 = 1 -stepperSet 1 100 5 +stepperSet 1 200 5 end button1 = 0 -stepperSet 1 -100 5 +stepperSet 1 -200 5 +end +button2 = 1 +stepperSet 2 200 5 +end +button2 = 0 +stepperSet 2 -200 5 end \ No newline at end of file diff --git a/data/configuration.json b/data/configuration.json index 24079b45..6ad2b5a7 100644 --- a/data/configuration.json +++ b/data/configuration.json @@ -52,7 +52,7 @@ "/level":"14.Контроль уровня в баке на сенсорах: JSN-SR04T, HC-SR04, HY-SRF05 (управление насосом)", "/moution_relay":"15.Датчик движения включающий свет", "/moution_security":"16.Охранный датчик движения", - "/stepper":"17.Система управления шаговым двигателем (открытие закрытие штор)", + "/stepper":"17.Система управления шаговыми двигателями на основе драйвера A4988 (открытие закрытие штор)", "/default":"Настройки по умолчанию" } }, diff --git a/data/index.json b/data/index.json index e168b134..4e8857fb 100644 --- a/data/index.json +++ b/data/index.json @@ -34,38 +34,11 @@ }, { "type": "h4", - "title": "SPIFFS version: 2.3" + "title": "SPIFFS version: 2.3+" }, - { + { "type": "hr" - }, - { - "type": "h6", - "title": "{{test1}}" - }, - { - "type": "h6", - "title": "{{test2}}" - }, - { - "type": "h6", - "title": "{{test3}}" - }, - { - "type": "h6", - "title": "{{test4}}" - }, - { - "type": "h6", - "title": "{{test5}}" - }, - { - "type": "h6", - "title": "{{test6}}" - }, - { - "type": "hr" - }, + }, { "type": "link", "title": "Конфигурация устройства", diff --git a/esp32-esp8266_iot-manager_modules_firmware.ino b/esp32-esp8266_iot-manager_modules_firmware.ino index 2cc12527..5d88d332 100644 --- a/esp32-esp8266_iot-manager_modules_firmware.ino +++ b/esp32-esp8266_iot-manager_modules_firmware.ino @@ -51,8 +51,8 @@ void setup() { Push_init(); Serial.println("[V] Push_init"); //-------------------------------------------------------------- - statistics(); - Serial.println("[V] statistics"); + statistics_init(); + Serial.println("[V] statistics_init"); //-------------------------------------------------------------- initUpgrade(); Serial.println("[V] initUpgrade"); @@ -71,13 +71,6 @@ void setup() { Serial.print("[i] Last firmware version: "); Serial.println(new_version); - - //ts.add(TEST, statistics_update, [&](void*) { - - // statistics(); - - //}, nullptr, false); - } void loop() { diff --git a/main.ino b/main.ino index 7e0f51a7..fceb78a5 100644 --- a/main.ino +++ b/main.ino @@ -278,16 +278,49 @@ void getMemoryLoad(String text) { //esp32 full memory = 362868 k bytes //esp8266 full memory = 53312 k bytes - +/* void web_print (String text) { + if (WiFi.status() == WL_CONNECTED) { + jsonWrite(json, "test1", jsonRead(json, "test2")); + jsonWrite(json, "test2", jsonRead(json, "test3")); + jsonWrite(json, "test3", jsonRead(json, "test4")); + jsonWrite(json, "test4", jsonRead(json, "test5")); + jsonWrite(json, "test5", jsonRead(json, "test6")); - jsonWrite(json, "test1", jsonRead(json, "test2")); - jsonWrite(json, "test2", jsonRead(json, "test3")); - jsonWrite(json, "test3", jsonRead(json, "test4")); - jsonWrite(json, "test4", jsonRead(json, "test5")); - jsonWrite(json, "test5", jsonRead(json, "test6")); + jsonWrite(json, "test6", GetTime() + " " + text); - jsonWrite(json, "test6", GetTime() + " " + text); - - ws.textAll(json); + ws.textAll(json); + } } + + { + "type": "hr" + }, + { + "type": "h6", + "title": "{{test1}}" + }, + { + "type": "h6", + "title": "{{test2}}" + }, + { + "type": "h6", + "title": "{{test3}}" + }, + { + "type": "h6", + "title": "{{test4}}" + }, + { + "type": "h6", + "title": "{{test5}}" + }, + { + "type": "h6", + "title": "{{test6}}" + }, + { + "type": "hr" + }, +*/ diff --git a/mqtt.ino b/mqtt.ino index aaee2113..72cacc2b 100644 --- a/mqtt.ino +++ b/mqtt.ino @@ -51,7 +51,7 @@ void MQTT_init() { Serial.println("[V] WiFi-ok"); if (client.connected()) { Serial.println("[V] MQTT-ok"); - web_print("MQTT-ok"); + //web_print("MQTT-ok"); } else { MQTT_Connecting(); mqtt_lost_error++; @@ -80,7 +80,7 @@ boolean MQTT_Connecting() { if ((mqtt_server != "")) { static boolean first = true; if (!first) Serial.println("[E] Lost MQTT connection, start reconnecting"); - web_print("Lost MQTT connection, start reconnecting"); + //web_print("Lost MQTT connection, start reconnecting"); first = false; //ssl//espClient.setCACert(local_root_ca1); client.setServer(mqtt_server.c_str(), jsonReadtoInt(configSetup, "mqttPort")); @@ -89,7 +89,7 @@ boolean MQTT_Connecting() { Serial.println("[V] Connecting to MQTT server commenced"); if (client.connect(chipID.c_str(), jsonRead(configSetup, "mqttUser").c_str(), jsonRead(configSetup, "mqttPass").c_str())) { Serial.println("[V] MQTT connected"); - web_print("MQTT connected"); + //web_print("MQTT connected"); client.setCallback(callback); client.subscribe(prefix.c_str()); // Для приема получения HELLOW и подтверждения связи client.subscribe((prefix + "/" + chipID + "/+/control").c_str()); // Подписываемся на топики control @@ -98,7 +98,7 @@ boolean MQTT_Connecting() { client.subscribe((prefix + "/ids").c_str()); // Подписываемся на топики ids sendMQTT("test", "work"); Serial.println("[V] Callback set, subscribe done"); - web_print("Callback set, subscribe done"); + //web_print("Callback set, subscribe done"); //if (out_date_send) outcoming_date(); //отправляем данные в виджеты return true; } else { @@ -109,7 +109,7 @@ boolean MQTT_Connecting() { } } else { Serial.println("[E] No date for MQTT connection"); - web_print("No date for MQTT connection"); + //web_print("No date for MQTT connection"); return false; } } diff --git a/set.h b/set.h index 604aa719..b9669606 100644 --- a/set.h +++ b/set.h @@ -1,10 +1,9 @@ -String firmware_version = "2.3"; +String firmware_version = "2.3+"; String new_version; - //#define OTA_enable //#define MDNS_enable -#define WS_enable +//#define WS_enable #define TIME_COMPILING String(__TIME__) #define DATE_COMPILING String(__DATE__) @@ -24,7 +23,7 @@ String new_version; #define dhtT_update_int 10000 #define dhtH_update_int 10000 #define dht_calculation_update_int 10000 -#define statistics_update 1000 * 60 * 60 * 12 +#define statistics_update 1000 * 60 * 60 * 4 //----------------------------------------------------------------- @@ -75,7 +74,7 @@ AsyncEventSource events("/events"); #include "time.h" #include TickerScheduler ts(30); -enum {ROUTER_SEARCHING, WIFI_MQTT_CONNECTION_CHECK, LEVEL, ANALOG_, DALLAS, DHTT, DHTH, DHTC, DHTP, DHTD, ANALOG_LOG, LEVEL_LOG, DALLAS_LOG, PH_LOG, CMD , TIMER_COUNTDOWN, TIMERS, TIME, TEST}; +enum {ROUTER_SEARCHING, WIFI_MQTT_CONNECTION_CHECK, LEVEL, ANALOG_, DALLAS, DHTT, DHTH, DHTC, DHTP, DHTD, STEPPER1, STEPPER2, ANALOG_LOG, LEVEL_LOG, DALLAS_LOG, PH_LOG, CMD, TIMER_COUNTDOWN, TIMERS, TIME, STATISTICS}; //ssl//#include "dependencies/WiFiClientSecure/WiFiClientSecure.h" //using older WiFiClientSecure #include