diff --git a/include/i18n/en.h b/include/i18n/en.h index 3da4dc6..5f50c9d 100644 --- a/include/i18n/en.h +++ b/include/i18n/en.h @@ -182,7 +182,7 @@ #define YASOLR_LBL_176 "D Term (W)" #define YASOLR_LBL_177 "Chart Reset" #define YASOLR_LBL_178 "Debug Information" -#define YASOLR_LBL_179 +#define YASOLR_LBL_179 "ZCD Disabled" #define YASOLR_LBL_180 #define YASOLR_LBL_181 #define YASOLR_LBL_182 diff --git a/include/i18n/fr.h b/include/i18n/fr.h index d331fc3..e66f7ec 100644 --- a/include/i18n/fr.h +++ b/include/i18n/fr.h @@ -182,7 +182,7 @@ #define YASOLR_LBL_176 "Terme D (W)" #define YASOLR_LBL_177 "Réinitialisation graphique" #define YASOLR_LBL_178 "Informations de debug" -#define YASOLR_LBL_179 +#define YASOLR_LBL_179 "ZCD Désactivé" #define YASOLR_LBL_180 #define YASOLR_LBL_181 #define YASOLR_LBL_182 diff --git a/lib/MycilaDimmer/MycilaDimmer.cpp b/lib/MycilaDimmer/MycilaDimmer.cpp index 2bb58da..0024292 100644 --- a/lib/MycilaDimmer/MycilaDimmer.cpp +++ b/lib/MycilaDimmer/MycilaDimmer.cpp @@ -36,7 +36,7 @@ extern Mycila::Logger logger; static const uint16_t TABLE_PHASE_DELAY[TABLE_PHASE_LEN] PROGMEM{0xefea, 0xdfd4, 0xd735, 0xd10d, 0xcc12, 0xc7cc, 0xc403, 0xc094, 0xbd6a, 0xba78, 0xb7b2, 0xb512, 0xb291, 0xb02b, 0xaddc, 0xaba2, 0xa97a, 0xa762, 0xa557, 0xa35a, 0xa167, 0x9f7f, 0x9da0, 0x9bc9, 0x99fa, 0x9831, 0x966e, 0x94b1, 0x92f9, 0x9145, 0x8f95, 0x8de8, 0x8c3e, 0x8a97, 0x88f2, 0x8750, 0x85ae, 0x840e, 0x826e, 0x80cf, 0x7f31, 0x7d92, 0x7bf2, 0x7a52, 0x78b0, 0x770e, 0x7569, 0x73c2, 0x7218, 0x706b, 0x6ebb, 0x6d07, 0x6b4f, 0x6992, 0x67cf, 0x6606, 0x6437, 0x6260, 0x6081, 0x5e99, 0x5ca6, 0x5aa9, 0x589e, 0x5686, 0x545e, 0x5224, 0x4fd5, 0x4d6f, 0x4aee, 0x484e, 0x4588, 0x4296, 0x3f6c, 0x3bfd, 0x3834, 0x33ee, 0x2ef3, 0x28cb, 0x202c, 0x1016}; void Mycila::Dimmer::begin(const int8_t pin) { - if (_enabled) + if (_dimmer) return; if (GPIO_IS_VALID_OUTPUT_GPIO(pin)) { @@ -52,15 +52,13 @@ void Mycila::Dimmer::begin(const int8_t pin) { pinMode(_pin, OUTPUT); digitalWrite(_pin, LOW); - _dimmer = new Thyristor(_pin); _duty = 0; - _enabled = true; + _dimmer = new Thyristor(_pin); } void Mycila::Dimmer::end() { - if (_enabled) { + if (_dimmer) { LOGI(TAG, "Disable Dimmer on pin %" PRId8, _pin); - _enabled = false; _duty = 0; _dimmer->turnOff(); digitalWrite(_pin, LOW); @@ -71,7 +69,12 @@ void Mycila::Dimmer::end() { } void Mycila::Dimmer::setDuty(uint16_t newDuty) { - if (!_enabled) + if (!_dimmer) + return; + + const uint16_t semiPeriod = _zcd->getSemiPeriod(); + + if (semiPeriod == 0) return; // ensure newDuty is within bounds @@ -81,8 +84,6 @@ void Mycila::Dimmer::setDuty(uint16_t newDuty) { if (_duty == newDuty) return; - const uint16_t semiPeriod = _zcd->getSemiPeriod(); - if (newDuty == 0) { _dimmer->setDelay(semiPeriod); diff --git a/lib/MycilaDimmer/MycilaDimmer.h b/lib/MycilaDimmer/MycilaDimmer.h index b45f183..9835db1 100644 --- a/lib/MycilaDimmer/MycilaDimmer.h +++ b/lib/MycilaDimmer/MycilaDimmer.h @@ -30,7 +30,7 @@ namespace Mycila { bool isOnAtFullPower() const { return _duty >= MYCILA_DIMMER_MAX_DUTY; } gpio_num_t getPin() const { return _pin; } - bool isEnabled() const { return _enabled; } + bool isEnabled() const { return _dimmer != nullptr; } void toJson(const JsonObject& root) const { const float angle = getPhaseAngle(); @@ -39,9 +39,8 @@ namespace Mycila { root["delay"] = getFiringDelay(); root["duty"] = _duty; root["duty_cycle"] = getDutyCycle(); - root["enabled"] = _enabled; + root["enabled"] = _dimmer != nullptr; root["state"] = _duty > 0 ? "on" : "off"; - _zcd->toJson(root["zcd"].to()); } // Power Duty Cycle [0, MYCILA_DIMMER_MAX_DUTY] @@ -58,20 +57,20 @@ namespace Mycila { // Where semi-period = 1000000 / 2 / frequency (50h: 10000 us, 60Hz: 8333 us) // At 0% power, delay is equal to the semi-period // At 100% power, the delay is 0 us - uint16_t getFiringDelay() const { return _dimmer->getDelay(); } + uint16_t getFiringDelay() const { return isEnabled() ? _dimmer->getDelay() : 0; } // Phase angle [0, PI] rad // At 0% power, the phase angle is equal to PI // At 100% power, the phase angle is equal to 0 float getPhaseAngle() const { // angle_rad = PI * delay_us / period_us - return PI * getFiringDelay() / _zcd->getSemiPeriod(); + uint16_t semiPeriod = _zcd->getSemiPeriod(); + return semiPeriod == 0 ? PI : PI * getFiringDelay() / semiPeriod; } private: ZCD* _zcd; gpio_num_t _pin = GPIO_NUM_NC; - bool _enabled = false; Thyristor* _dimmer = nullptr; uint16_t _duty = 0; }; diff --git a/lib/MycilaDimmer/MycilaZCD.cpp b/lib/MycilaDimmer/MycilaZCD.cpp index c7bdfed..ed8c416 100644 --- a/lib/MycilaDimmer/MycilaZCD.cpp +++ b/lib/MycilaDimmer/MycilaZCD.cpp @@ -64,7 +64,7 @@ void Mycila::ZCD::end() { } } -uint16_t Mycila::ZCD::getSemiPeriod() const { return _enabled ? Thyristor::getSemiPeriod() : 0; } +uint16_t Mycila::ZCD::getSemiPeriod() const { return Thyristor::getSemiPeriod(); } float Mycila::ZCD::getPulseFrequency() const { return _enabled ? Thyristor::getPulseFrequency() : 0; } uint16_t Mycila::ZCD::getAvgPulseWidth() const { return _enabled ? Thyristor::getPulseWidth() : 0; } diff --git a/platformio.ini b/platformio.ini index e26fb3b..0811b6a 100644 --- a/platformio.ini +++ b/platformio.ini @@ -23,7 +23,7 @@ board = esp32dev monitor_filters = esp32_exception_decoder, log2file monitor_speed = 115200 upload_protocol = esptool -upload_speed = 921600 +; upload_speed = 921600 ; upload_protocol = custom ; upload_url = http://192.168.125.119 extra_scripts = @@ -48,8 +48,7 @@ lib_deps = bblanchon/ArduinoJson @ 7.1.0 olikraus/U8g2 @ 2.35.19 robtillaart/CRC @ 1.0.3 - # mathieucarbou/Async TCP @ 3.1.4 - https://github.com/mathieucarbou/AsyncTCP#dev + mathieucarbou/Async TCP @ 3.1.4 mathieucarbou/ESP Async WebServer @ 3.0.6 mathieucarbou/MycilaConfig @ 3.0.1 mathieucarbou/MycilaDS18 @ 3.0.4 diff --git a/src/Website.cpp b/src/Website.cpp index b8a27ed..fd45075 100644 --- a/src/Website.cpp +++ b/src/Website.cpp @@ -750,10 +750,10 @@ void YaSolR::WebsiteClass::updateCards() { // Hardware (status) _status(_jsy, KEY_ENABLE_JSY, jsy.isEnabled(), jsy.isConnected(), YASOLR_LBL_110); _status(_mqtt, KEY_ENABLE_MQTT, mqtt.isEnabled(), mqtt.isConnected(), mqtt.getLastError() ? mqtt.getLastError() : YASOLR_LBL_113); - _status(_output1Dimmer, KEY_ENABLE_OUTPUT1_DIMMER, dimmerO1.isEnabled()); + _status(_output1Dimmer, KEY_ENABLE_OUTPUT1_DIMMER, dimmerO1.isEnabled(), zcd.getSemiPeriod() > 0, YASOLR_LBL_179); _status(_output1DS18, KEY_ENABLE_OUTPUT1_DS18, ds18O1.isEnabled(), ds18O1.getLastTime() > 0, YASOLR_LBL_114); _status(_output1PZEM, KEY_ENABLE_OUTPUT1_PZEM, pzemO1.isEnabled(), pzemO1.isConnected(), YASOLR_LBL_110); - _status(_output2Dimmer, KEY_ENABLE_OUTPUT2_DIMMER, dimmerO2.isEnabled()); + _status(_output2Dimmer, KEY_ENABLE_OUTPUT2_DIMMER, dimmerO2.isEnabled(), zcd.getSemiPeriod() > 0, YASOLR_LBL_179); _status(_output2DS18, KEY_ENABLE_OUTPUT2_DS18, ds18O2.isEnabled(), ds18O2.getLastTime() > 0, YASOLR_LBL_114); _status(_output2PZEM, KEY_ENABLE_OUTPUT2_PZEM, pzemO2.isEnabled(), pzemO2.isConnected(), YASOLR_LBL_110); _status(_routerDS18, KEY_ENABLE_DS18_SYSTEM, ds18Sys.isEnabled(), ds18Sys.getLastTime() > 0, YASOLR_LBL_114); diff --git a/src/init/REST.cpp b/src/init/REST.cpp index 7f5e7f2..9d7a18c 100644 --- a/src/init/REST.cpp +++ b/src/init/REST.cpp @@ -13,16 +13,28 @@ Mycila::Task initRestApiTask("Init REST API", [](void* params) { // debug webServer - .on("/api/debug", HTTP_GET, [](AsyncWebServerRequest* request) { + .on("/api/debug/router", HTTP_GET, [](AsyncWebServerRequest* request) { AsyncJsonResponse* response = new AsyncJsonResponse(); JsonObject root = response->getRoot(); - ds18Sys.toJson(root["ds18Sys"].to()); grid.toJson(root["grid"].to()); - lights.toJson(root["leds"].to()); relay1.toJson(root["relay1"].to()); relay2.toJson(root["relay2"].to()); router.toJson(root["router"].to(), grid.getVoltage()); + zcd.toJson(root["zcd"].to()); + + response->setLength(); + request->send(response); + }) + .setAuthentication(YASOLR_ADMIN_USERNAME, config.get(KEY_ADMIN_PASSWORD)); + + webServer + .on("/api/debug/system", HTTP_GET, [](AsyncWebServerRequest* request) { + AsyncJsonResponse* response = new AsyncJsonResponse(); + JsonObject root = response->getRoot(); + + ds18Sys.toJson(root["ds18Sys"].to()); + lights.toJson(root["leds"].to()); Mycila::TaskMonitor.toJson(root["stack"].to()); core0TaskManager.toJson(root[core0TaskManager.getName()].to()); @@ -37,6 +49,22 @@ Mycila::Task initRestApiTask("Init REST API", [](void* params) { }) .setAuthentication(YASOLR_ADMIN_USERNAME, config.get(KEY_ADMIN_PASSWORD)); + webServer + .on("/api/debug", HTTP_GET, [](AsyncWebServerRequest* request) { + AsyncJsonResponse* response = new AsyncJsonResponse(); + JsonObject root = response->getRoot(); + + String base = "http://"; + base.concat(ESPConnect.getIPAddress().toString()); + base.concat("/api/debug"); + + root["router"] = base + "/router"; + root["system"] = base + "/system"; + + response->setLength(); + request->send(response); + }) + .setAuthentication(YASOLR_ADMIN_USERNAME, config.get(KEY_ADMIN_PASSWORD)); // config webServer diff --git a/src/main.cpp b/src/main.cpp index 9cf9452..2550e83 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -60,8 +60,8 @@ void setup() { initMqttSubscribersTask.forceRun(); initDashboardCards.forceRun(); - assert( core0TaskManager.asyncStart(512 * 6, 1, 0, 100, true)); // NOLINT - assert( core1TaskManager.asyncStart(512 * 6, 1, 1, 100, true)); // NOLINT + assert( core0TaskManager.asyncStart(512 * 7, 1, 0, 100, true)); // NOLINT + assert( core1TaskManager.asyncStart(512 * 7, 1, 1, 100, true)); // NOLINT assert( ioTaskManager.asyncStart(512 * 9, 1, 1, 100, false)); // NOLINT assert( jsyTaskManager.asyncStart(512 * 4, 5, 0, 100, true)); // NOLINT assert( pzemTaskManager.asyncStart(512 * 4, 5, 0, 100, true)); // NOLINT