mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-07-28 12:17:05 +00:00
Compare commits
13
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
40757016e1 | ||
|
|
8edae2146a | ||
|
|
741b702c85 | ||
|
|
18eedf6616 | ||
|
|
3ec78b68a2 | ||
|
|
63217fb341 | ||
|
|
66bba2caae | ||
|
|
90b37e4bd0 | ||
|
|
b708d6f6d4 | ||
|
|
b3b8a9fd59 | ||
|
|
2c29ec467b | ||
|
|
8d275631b3 | ||
|
|
ddce8865b9 |
Vendored
+19
@@ -1,3 +1,22 @@
|
||||
-------------------------------------------------
|
||||
Changes in release mega-20190107 (since mega-20190106)
|
||||
-------------------------------------------------
|
||||
|
||||
Release date: Mon Jan 7 04:00:07 CET 2019
|
||||
|
||||
CaptainRoot (5):
|
||||
Update _P076_HLW8012.ino
|
||||
add predefind pin settings for some energy meter sockets to HLW8012 / BL0937
|
||||
Revert changes to platformio.ini
|
||||
Update platformio.ini
|
||||
movepredefind pin settings to PROGMEM
|
||||
|
||||
TD-er (3):
|
||||
Add new Nodetype RPIEasy #2206
|
||||
[HLW8012] Fix some issues when selecting device
|
||||
[HLW8012] Update documentation
|
||||
|
||||
|
||||
-------------------------------------------------
|
||||
Changes in release mega-20190106 (since mega-20181231)
|
||||
-------------------------------------------------
|
||||
|
||||
+16
-13
@@ -19,16 +19,28 @@ GitHub: |P076_github|_
|
||||
|
||||
Maintainer: |P076_maintainer|
|
||||
|
||||
Used library: |P076_library|_
|
||||
|
||||
Configuration
|
||||
-------------
|
||||
|
||||
The easiest way to configure this plugin, is to select the right device from the ``Device`` list in the "Predefined Pin settings".
|
||||
After saving the settings, all parameters will be set.
|
||||
|
||||
When enabling the device, it will load the default calibration values.
|
||||
|
||||
If some specific setting is needed to support some device not in the list, this ``Device`` selection must be set to ``Custom``.
|
||||
|
||||
|
||||
Supported hardware
|
||||
------------------
|
||||
|
||||
|P076_usedby|
|
||||
|
||||
.. Commands available
|
||||
.. ^^^^^^^^^^^^^^^^^^
|
||||
Commands available
|
||||
^^^^^^^^^^^^^^^^^^
|
||||
|
||||
.. .. include:: P076_commands.repl
|
||||
.. include:: P076_commands.repl
|
||||
|
||||
Change log
|
||||
----------
|
||||
@@ -37,13 +49,4 @@ Change log
|
||||
...
|
||||
|
||||
|added|
|
||||
Major overhaul for 2.0 release.
|
||||
|
||||
.. versionadded:: 1.0
|
||||
...
|
||||
|
||||
|added|
|
||||
Initial release version.
|
||||
|
||||
|
||||
|
||||
2019-01-06 Added pre-defined config selector for several devices this sensor is used in.
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
.. csv-table::
|
||||
:header: "Command (GPIO/Value)", "Extra information"
|
||||
:widths: 20, 30
|
||||
|
||||
"
|
||||
``hlwcalibrate,<CalibVolt>,<CalibCurr>,<CalibAcPwr>``
|
||||
|
||||
Examples:
|
||||
|
||||
``hlwcalibrate,229`` to set the current reported voltage to 229V AC
|
||||
|
||||
``hlwcalibrate,0,0.1`` To set the calibration to report 100 mA as actual current.
|
||||
","
|
||||
Will set the used calibration factors to some known current value.
|
||||
For example, if the device using this sensor is plugged into mains power, it may report 200 Volt AC, while it actually is 229V.
|
||||
So the value given to this command should then be ``229``, since that's what is supposed to be read.
|
||||
|
||||
The last two parameters are optional, but their position determines what unit it represents.
|
||||
If the setting for current has to be updated, at least 2 parameters must be given of which the first must then be set to ``0``.
|
||||
"
|
||||
"
|
||||
``hlwreset``
|
||||
|
||||
","
|
||||
Will reset the calibration values used in the sensor's library.
|
||||
"
|
||||
@@ -19,6 +19,7 @@ GitHub: |P082_github|_
|
||||
|
||||
Maintainer: |P082_maintainer|
|
||||
|
||||
Used library: |P082_library|_
|
||||
|
||||
Supported hardware
|
||||
------------------
|
||||
|
||||
@@ -65,16 +65,18 @@
|
||||
.. |P075_maintainer| replace:: `.`
|
||||
.. |P075_compileinfo| replace:: `.`
|
||||
|
||||
.. |P076_name| replace:: :cyan:`HLW8012`
|
||||
.. |P076_name| replace:: :cyan:`HLW8012/BL0937`
|
||||
.. |P076_type| replace:: :cyan:`Energy (AC)`
|
||||
.. |P076_typename| replace:: :cyan:`Energy (AC) - HLW8012`
|
||||
.. |P076_typename| replace:: :cyan:`Energy (AC) - HLW8012/BL0937`
|
||||
.. |P076_status| replace:: :yellow:`TESTING`
|
||||
.. |P076_github| replace:: P076_HLW8012.ino
|
||||
.. _P076_github: https://github.com/letscontrolit/ESPEasy/blob/mega/src/_P076_HLW8012.ino
|
||||
.. |P076_usedby| replace:: `.`
|
||||
.. |P076_shortinfo| replace:: `.`
|
||||
.. |P076_maintainer| replace:: `.`
|
||||
.. |P076_usedby| replace:: Sonoff POW (r1), Huafan SS, KMC 70011, Aplic WDP303075, SK03 Outdoor, BlitzWolf SHP, Teckin, Teckin US, Gosund SP1 v23
|
||||
.. |P076_shortinfo| replace:: Power measuring sensor used to measure (AC) voltage, current, power and power factor.
|
||||
.. |P076_maintainer| replace:: TD-er
|
||||
.. |P076_compileinfo| replace:: `.`
|
||||
.. |P076_library| replace:: xoseperez/hlw8012 v1.1.1
|
||||
.. _P076_library: https://github.com/xoseperez/hlw8012/tree/1.1.1
|
||||
|
||||
.. |P077_name| replace:: :cyan:`CSE7766`
|
||||
.. |P077_type| replace:: :cyan:`Energy (AC)`
|
||||
|
||||
@@ -30,3 +30,5 @@
|
||||
.. |P082_shortinfo| replace:: `Determine position and sync system time using a GPS receiver communicating via serial`
|
||||
.. |P082_maintainer| replace:: `TD-er`
|
||||
.. |P082_compileinfo| replace:: `.`
|
||||
.. |P082_library| replace:: mikalhart/TinyGPSPlus v1.0.2 (plus own patches)
|
||||
.. _P082_library: https://github.com/mikalhart/TinyGPSPlus/tree/v1.0.2
|
||||
|
||||
+6
-16
@@ -198,6 +198,7 @@
|
||||
// and some may need less memory. (which is stack allocated)
|
||||
|
||||
#define NODE_TYPE_ID_ESP_EASY_STD 1
|
||||
#define NODE_TYPE_ID_RPI_EASY_STD 5 // https://github.com/enesbcs/rpieasy
|
||||
#define NODE_TYPE_ID_ESP_EASYM_STD 17
|
||||
#define NODE_TYPE_ID_ESP_EASY32_STD 33
|
||||
#define NODE_TYPE_ID_ARDUINO_EASY_STD 65
|
||||
@@ -425,6 +426,7 @@
|
||||
|
||||
// Forward declaration
|
||||
struct ControllerSettingsStruct;
|
||||
String getUnknownString();
|
||||
void scheduleNextDelayQueue(unsigned long id, unsigned long nextTime);
|
||||
String LoadControllerSettings(int ControllerIndex, ControllerSettingsStruct& controller_settings);
|
||||
String get_formatted_Controller_number(int controller_index);
|
||||
@@ -453,20 +455,8 @@ enum SettingsType {
|
||||
SettingsType_MAX
|
||||
|
||||
};
|
||||
String getSettingsTypeString(SettingsType settingsType);
|
||||
bool getSettingsParameters(SettingsType settingsType, int index, int& offset, int& max_size);
|
||||
String getSettingsTypeString(SettingsType settingsType) {
|
||||
switch (settingsType) {
|
||||
case BasicSettings_Type: return F("Settings");
|
||||
case TaskSettings_Type: return F("TaskSettings");
|
||||
case CustomTaskSettings_Type: return F("CustomTaskSettings");
|
||||
case ControllerSettings_Type: return F("ControllerSettings");
|
||||
case CustomControllerSettings_Type: return F("CustomControllerSettings");
|
||||
case NotificationSettings_Type: return F("NotificationSettings");
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return String();
|
||||
}
|
||||
bool showSettingsFileLayout = false;
|
||||
|
||||
/*
|
||||
@@ -1869,7 +1859,7 @@ String getPluginFunctionName(int function) {
|
||||
case PLUGIN_UNCONDITIONAL_POLL: return F("UNCONDITIONAL_POLL");
|
||||
case PLUGIN_REQUEST: return F("REQUEST");
|
||||
}
|
||||
return F("Unknown");
|
||||
return getUnknownString();
|
||||
}
|
||||
|
||||
bool mustLogFunction(int function) {
|
||||
@@ -1918,7 +1908,7 @@ String getCPluginCFunctionName(int function) {
|
||||
case CPLUGIN_INIT: return F("CPLUGIN_INIT");
|
||||
case CPLUGIN_UDP_IN: return F("CPLUGIN_UDP_IN");
|
||||
}
|
||||
return F("Unknown");
|
||||
return getUnknownString();
|
||||
}
|
||||
|
||||
bool mustLogCFunction(int function) {
|
||||
@@ -2042,7 +2032,7 @@ String getMiscStatsName(int stat) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return F("Unknown");
|
||||
return getUnknownString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -599,22 +599,6 @@ void runPeriodicalMQTT() {
|
||||
}
|
||||
}
|
||||
|
||||
String getMQTT_state() {
|
||||
switch (MQTTclient.state()) {
|
||||
case MQTT_CONNECTION_TIMEOUT : return F("Connection timeout");
|
||||
case MQTT_CONNECTION_LOST : return F("Connection lost");
|
||||
case MQTT_CONNECT_FAILED : return F("Connect failed");
|
||||
case MQTT_DISCONNECTED : return F("Disconnected");
|
||||
case MQTT_CONNECTED : return F("Connected");
|
||||
case MQTT_CONNECT_BAD_PROTOCOL : return F("Connect bad protocol");
|
||||
case MQTT_CONNECT_BAD_CLIENT_ID : return F("Connect bad client_id");
|
||||
case MQTT_CONNECT_UNAVAILABLE : return F("Connect unavailable");
|
||||
case MQTT_CONNECT_BAD_CREDENTIALS: return F("Connect bad credentials");
|
||||
case MQTT_CONNECT_UNAUTHORIZED : return F("Connect unauthorized");
|
||||
default: return "";
|
||||
}
|
||||
}
|
||||
|
||||
void updateMQTTclient_connected() {
|
||||
if (MQTTclient_connected != MQTTclient.connected()) {
|
||||
MQTTclient_connected = !MQTTclient_connected;
|
||||
|
||||
+2
-2
@@ -768,7 +768,7 @@ String SDKwifiStatusToString(uint8_t sdk_wifistatus) {
|
||||
case STATION_CONNECT_FAIL: return F("STATION_CONNECT_FAIL");
|
||||
case STATION_GOT_IP: return F("STATION_GOT_IP");
|
||||
}
|
||||
return F("Unknown");
|
||||
return getUnknownString();
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -913,7 +913,7 @@ String getLastDisconnectReason() {
|
||||
case WIFI_DISCONNECT_REASON_AUTH_FAIL: reason += F("Auth fail"); break;
|
||||
case WIFI_DISCONNECT_REASON_ASSOC_FAIL: reason += F("Assoc fail"); break;
|
||||
case WIFI_DISCONNECT_REASON_HANDSHAKE_TIMEOUT: reason += F("Handshake timeout"); break;
|
||||
default: reason += F("Unknown"); break;
|
||||
default: reason += getUnknownString(); break;
|
||||
}
|
||||
return reason;
|
||||
}
|
||||
|
||||
+35
-12
@@ -137,24 +137,47 @@ void checkResetFactoryPin(){
|
||||
/********************************************************************************************\
|
||||
Hardware specific configurations
|
||||
\*********************************************************************************************/
|
||||
String getDeviceModelString(DeviceModel model) {
|
||||
|
||||
String getDeviceModelBrandString(DeviceModel model) {
|
||||
switch (model) {
|
||||
case DeviceModel_Sonoff_Basic: return F("Sonoff Basic");
|
||||
case DeviceModel_Sonoff_TH1x: return F("Sonoff TH1x");
|
||||
case DeviceModel_Sonoff_S2x: return F("Sonoff S2x");
|
||||
case DeviceModel_Sonoff_TouchT1: return F("Sonoff TouchT1");
|
||||
case DeviceModel_Sonoff_TouchT2: return F("Sonoff TouchT2");
|
||||
case DeviceModel_Sonoff_TouchT3: return F("Sonoff TouchT3");
|
||||
case DeviceModel_Sonoff_4ch: return F("Sonoff 4ch");
|
||||
case DeviceModel_Sonoff_POW: return F("Sonoff POW");
|
||||
case DeviceModel_Sonoff_POWr2: return F("Sonoff POW-r2");
|
||||
case DeviceModel_Shelly1: return F("Shelly1");
|
||||
case DeviceModel_Sonoff_Basic:
|
||||
case DeviceModel_Sonoff_TH1x:
|
||||
case DeviceModel_Sonoff_S2x:
|
||||
case DeviceModel_Sonoff_TouchT1:
|
||||
case DeviceModel_Sonoff_TouchT2:
|
||||
case DeviceModel_Sonoff_TouchT3:
|
||||
case DeviceModel_Sonoff_4ch:
|
||||
case DeviceModel_Sonoff_POW:
|
||||
case DeviceModel_Sonoff_POWr2: return F("Sonoff");
|
||||
case DeviceModel_Shelly1: return F("Shelly");
|
||||
|
||||
//case DeviceModel_default:
|
||||
default: return F("default");
|
||||
default: return "";
|
||||
}
|
||||
}
|
||||
|
||||
String getDeviceModelString(DeviceModel model) {
|
||||
String result;
|
||||
result.reserve(16);
|
||||
result = getDeviceModelBrandString(model);
|
||||
switch (model) {
|
||||
case DeviceModel_Sonoff_Basic: result += F(" Basic"); break;
|
||||
case DeviceModel_Sonoff_TH1x: result += F(" TH1x"); break;
|
||||
case DeviceModel_Sonoff_S2x: result += F(" S2x"); break;
|
||||
case DeviceModel_Sonoff_TouchT1: result += F(" TouchT1"); break;
|
||||
case DeviceModel_Sonoff_TouchT2: result += F(" TouchT2"); break;
|
||||
case DeviceModel_Sonoff_TouchT3: result += F(" TouchT3"); break;
|
||||
case DeviceModel_Sonoff_4ch: result += F(" 4ch"); break;
|
||||
case DeviceModel_Sonoff_POW: result += F(" POW"); break;
|
||||
case DeviceModel_Sonoff_POWr2: result += F(" POW-r2"); break;
|
||||
case DeviceModel_Shelly1: result += '1'; break;
|
||||
|
||||
//case DeviceModel_default:
|
||||
default: result += F("default");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool modelMatchingFlashSize(DeviceModel model) {
|
||||
uint32_t size_MB = getFlashRealSizeInBytes() >> 20;
|
||||
// TODO TD-er: Add checks for ESP8266/ESP8285/ESP32
|
||||
|
||||
+220
-164
@@ -1,3 +1,223 @@
|
||||
/*********************************************************************************************\
|
||||
ESPEasy specific strings
|
||||
\*********************************************************************************************/
|
||||
|
||||
String getUnknownString() { return F("Unknown"); }
|
||||
|
||||
String getNodeTypeDisplayString(byte nodeType) {
|
||||
switch (nodeType)
|
||||
{
|
||||
case NODE_TYPE_ID_ESP_EASY_STD: return F("ESP Easy");
|
||||
case NODE_TYPE_ID_ESP_EASYM_STD: return F("ESP Easy Mega");
|
||||
case NODE_TYPE_ID_ESP_EASY32_STD: return F("ESP Easy 32");
|
||||
case NODE_TYPE_ID_RPI_EASY_STD: return F("RPI Easy");
|
||||
case NODE_TYPE_ID_ARDUINO_EASY_STD: return F("Arduino Easy");
|
||||
case NODE_TYPE_ID_NANO_EASY_STD: return F("Nano Easy");
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
String getSettingsTypeString(SettingsType settingsType) {
|
||||
switch (settingsType) {
|
||||
case BasicSettings_Type: return F("Settings");
|
||||
case TaskSettings_Type: return F("TaskSettings");
|
||||
case CustomTaskSettings_Type: return F("CustomTaskSettings");
|
||||
case ControllerSettings_Type: return F("ControllerSettings");
|
||||
case CustomControllerSettings_Type: return F("CustomControllerSettings");
|
||||
case NotificationSettings_Type: return F("NotificationSettings");
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
String getMQTT_state() {
|
||||
switch (MQTTclient.state()) {
|
||||
case MQTT_CONNECTION_TIMEOUT : return F("Connection timeout");
|
||||
case MQTT_CONNECTION_LOST : return F("Connection lost");
|
||||
case MQTT_CONNECT_FAILED : return F("Connect failed");
|
||||
case MQTT_DISCONNECTED : return F("Disconnected");
|
||||
case MQTT_CONNECTED : return F("Connected");
|
||||
case MQTT_CONNECT_BAD_PROTOCOL : return F("Connect bad protocol");
|
||||
case MQTT_CONNECT_BAD_CLIENT_ID : return F("Connect bad client_id");
|
||||
case MQTT_CONNECT_UNAVAILABLE : return F("Connect unavailable");
|
||||
case MQTT_CONNECT_BAD_CREDENTIALS: return F("Connect bad credentials");
|
||||
case MQTT_CONNECT_UNAUTHORIZED : return F("Connect unauthorized");
|
||||
default: break;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/********************************************************************************************\
|
||||
Get system information
|
||||
\*********************************************************************************************/
|
||||
String getLastBootCauseString() {
|
||||
switch (lastBootCause)
|
||||
{
|
||||
case BOOT_CAUSE_MANUAL_REBOOT: return F("Manual reboot");
|
||||
case BOOT_CAUSE_DEEP_SLEEP: //nobody should ever see this, since it should sleep again right away.
|
||||
return F("Deep sleep");
|
||||
case BOOT_CAUSE_COLD_BOOT:
|
||||
return F("Cold boot");
|
||||
case BOOT_CAUSE_EXT_WD:
|
||||
return F("External Watchdog");
|
||||
}
|
||||
return getUnknownString();
|
||||
}
|
||||
|
||||
#ifdef ESP32
|
||||
// See https://github.com/espressif/esp-idf/blob/master/components/esp32/include/rom/rtc.h
|
||||
String getResetReasonString(byte icore) {
|
||||
bool isDEEPSLEEP_RESET(false);
|
||||
switch (rtc_get_reset_reason( (RESET_REASON) icore)) {
|
||||
case NO_MEAN : return F("NO_MEAN");
|
||||
case POWERON_RESET : return F("Vbat power on reset");
|
||||
case SW_RESET : return F("Software reset digital core");
|
||||
case OWDT_RESET : return F("Legacy watch dog reset digital core");
|
||||
case DEEPSLEEP_RESET : isDEEPSLEEP_RESET = true; break;
|
||||
case SDIO_RESET : return F("Reset by SLC module, reset digital core");
|
||||
case TG0WDT_SYS_RESET : return F("Timer Group0 Watch dog reset digital core");
|
||||
case TG1WDT_SYS_RESET : return F("Timer Group1 Watch dog reset digital core");
|
||||
case RTCWDT_SYS_RESET : return F("RTC Watch dog Reset digital core");
|
||||
case INTRUSION_RESET : return F("Instrusion tested to reset CPU");
|
||||
case TGWDT_CPU_RESET : return F("Time Group reset CPU");
|
||||
case SW_CPU_RESET : return F("Software reset CPU");
|
||||
case RTCWDT_CPU_RESET : return F("RTC Watch dog Reset CPU");
|
||||
case EXT_CPU_RESET : return F("for APP CPU, reseted by PRO CPU");
|
||||
case RTCWDT_BROWN_OUT_RESET : return F("Reset when the vdd voltage is not stable");
|
||||
case RTCWDT_RTC_RESET : return F("RTC Watch dog reset digital core and rtc module");
|
||||
default: break;
|
||||
}
|
||||
if (isDEEPSLEEP_RESET) {
|
||||
String reason = F("Deep Sleep, Wakeup reason (");
|
||||
reason += rtc_get_wakeup_cause();
|
||||
reason += ')';
|
||||
return reason;
|
||||
}
|
||||
return getUnknownString();
|
||||
}
|
||||
#endif
|
||||
|
||||
String getResetReasonString() {
|
||||
#ifdef ESP32
|
||||
String reason = F("CPU0: ");
|
||||
reason += getResetReasonString(0);
|
||||
reason += F(" CPU1: ");
|
||||
reason += getResetReasonString(1);
|
||||
return reason;
|
||||
#else
|
||||
return ESP.getResetReason();
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t getFlashRealSizeInBytes() {
|
||||
#if defined(ESP32)
|
||||
return ESP.getFlashChipSize();
|
||||
#else
|
||||
return ESP.getFlashChipRealSize(); //ESP.getFlashChipSize();
|
||||
#endif
|
||||
}
|
||||
|
||||
String getSystemBuildString() {
|
||||
String result;
|
||||
result += BUILD;
|
||||
result += ' ';
|
||||
result += F(BUILD_NOTES);
|
||||
return result;
|
||||
}
|
||||
|
||||
String getPluginDescriptionString() {
|
||||
String result;
|
||||
#ifdef PLUGIN_BUILD_NORMAL
|
||||
result += F(" [Normal]");
|
||||
#endif
|
||||
#ifdef PLUGIN_BUILD_TESTING
|
||||
result += F(" [Testing]");
|
||||
#endif
|
||||
#ifdef PLUGIN_BUILD_DEV
|
||||
result += F(" [Development]");
|
||||
#endif
|
||||
#ifdef PLUGIN_DESCR
|
||||
result += " [";
|
||||
result += F(PLUGIN_DESCR);
|
||||
result += ']';
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
String getSystemLibraryString() {
|
||||
String result;
|
||||
#if defined(ESP32)
|
||||
result += F("ESP32 SDK ");
|
||||
result += ESP.getSdkVersion();
|
||||
#else
|
||||
result += F("ESP82xx Core ");
|
||||
result += ESP.getCoreVersion();
|
||||
result += F(", NONOS SDK ");
|
||||
result += system_get_sdk_version();
|
||||
result += F(", LWIP: ");
|
||||
result += getLWIPversion();
|
||||
#endif
|
||||
if (puyaSupport()) {
|
||||
result += F(" PUYA support");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifndef ESP32
|
||||
String getLWIPversion() {
|
||||
String result;
|
||||
result += LWIP_VERSION_MAJOR;
|
||||
result += '.';
|
||||
result += LWIP_VERSION_MINOR;
|
||||
result += '.';
|
||||
result += LWIP_VERSION_REVISION;
|
||||
if (LWIP_VERSION_IS_RC) {
|
||||
result += F("-RC");
|
||||
result += LWIP_VERSION_RC;
|
||||
} else if (LWIP_VERSION_IS_DEVELOPMENT) {
|
||||
result += F("-dev");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool puyaSupport() {
|
||||
bool supported = false;
|
||||
#ifdef PUYA_SUPPORT
|
||||
// New support starting core 2.5.0
|
||||
if (PUYA_SUPPORT) supported = true;
|
||||
#endif
|
||||
#ifdef PUYASUPPORT
|
||||
// Old patch
|
||||
supported = true;
|
||||
#endif
|
||||
return supported;
|
||||
}
|
||||
|
||||
uint8_t getFlashChipVendorId() {
|
||||
#ifdef PUYA_SUPPORT
|
||||
return ESP.getFlashChipVendorId();
|
||||
#else
|
||||
#if defined(ESP8266)
|
||||
uint32_t flashChipId = ESP.getFlashChipId();
|
||||
return (flashChipId & 0x000000ff);
|
||||
#else
|
||||
return 0xFF; // Not an existing function for ESP32
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
bool flashChipVendorPuya() {
|
||||
uint8_t vendorId = getFlashChipVendorId();
|
||||
return vendorId == 0x85; // 0x146085 PUYA
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************************************\
|
||||
Memory management
|
||||
\*********************************************************************************************/
|
||||
|
||||
// clean up tcp connections that are in TIME_WAIT status, to conserve memory
|
||||
// In future versions of WiFiClient it should be possible to call abort(), but
|
||||
// this feature is not in all upstream versions yet.
|
||||
@@ -1029,170 +1249,6 @@ unsigned long FreeMem(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
/********************************************************************************************\
|
||||
Get system information
|
||||
\*********************************************************************************************/
|
||||
String getLastBootCauseString() {
|
||||
switch (lastBootCause)
|
||||
{
|
||||
case BOOT_CAUSE_MANUAL_REBOOT: return F("Manual reboot");
|
||||
case BOOT_CAUSE_DEEP_SLEEP: //nobody should ever see this, since it should sleep again right away.
|
||||
return F("Deep sleep");
|
||||
case BOOT_CAUSE_COLD_BOOT:
|
||||
return F("Cold boot");
|
||||
case BOOT_CAUSE_EXT_WD:
|
||||
return F("External Watchdog");
|
||||
}
|
||||
return F("Unknown");
|
||||
}
|
||||
|
||||
#ifdef ESP32
|
||||
// See https://github.com/espressif/esp-idf/blob/master/components/esp32/include/rom/rtc.h
|
||||
String getResetReasonString(byte icore) {
|
||||
bool isDEEPSLEEP_RESET(false);
|
||||
switch (rtc_get_reset_reason( (RESET_REASON) icore)) {
|
||||
case NO_MEAN : return F("NO_MEAN");
|
||||
case POWERON_RESET : return F("Vbat power on reset");
|
||||
case SW_RESET : return F("Software reset digital core");
|
||||
case OWDT_RESET : return F("Legacy watch dog reset digital core");
|
||||
case DEEPSLEEP_RESET : isDEEPSLEEP_RESET = true; break;
|
||||
case SDIO_RESET : return F("Reset by SLC module, reset digital core");
|
||||
case TG0WDT_SYS_RESET : return F("Timer Group0 Watch dog reset digital core");
|
||||
case TG1WDT_SYS_RESET : return F("Timer Group1 Watch dog reset digital core");
|
||||
case RTCWDT_SYS_RESET : return F("RTC Watch dog Reset digital core");
|
||||
case INTRUSION_RESET : return F("Instrusion tested to reset CPU");
|
||||
case TGWDT_CPU_RESET : return F("Time Group reset CPU");
|
||||
case SW_CPU_RESET : return F("Software reset CPU");
|
||||
case RTCWDT_CPU_RESET : return F("RTC Watch dog Reset CPU");
|
||||
case EXT_CPU_RESET : return F("for APP CPU, reseted by PRO CPU");
|
||||
case RTCWDT_BROWN_OUT_RESET : return F("Reset when the vdd voltage is not stable");
|
||||
case RTCWDT_RTC_RESET : return F("RTC Watch dog reset digital core and rtc module");
|
||||
default: break;
|
||||
}
|
||||
if (isDEEPSLEEP_RESET) {
|
||||
String reason = F("Deep Sleep, Wakeup reason (");
|
||||
reason += rtc_get_wakeup_cause();
|
||||
reason += ')';
|
||||
return reason;
|
||||
}
|
||||
return F("Unknown");
|
||||
}
|
||||
#endif
|
||||
|
||||
String getResetReasonString() {
|
||||
#ifdef ESP32
|
||||
String reason = F("CPU0: ");
|
||||
reason += getResetReasonString(0);
|
||||
reason += F(" CPU1: ");
|
||||
reason += getResetReasonString(1);
|
||||
return reason;
|
||||
#else
|
||||
return ESP.getResetReason();
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t getFlashRealSizeInBytes() {
|
||||
#if defined(ESP32)
|
||||
return ESP.getFlashChipSize();
|
||||
#else
|
||||
return ESP.getFlashChipRealSize(); //ESP.getFlashChipSize();
|
||||
#endif
|
||||
}
|
||||
|
||||
String getSystemBuildString() {
|
||||
String result;
|
||||
result += BUILD;
|
||||
result += ' ';
|
||||
result += F(BUILD_NOTES);
|
||||
return result;
|
||||
}
|
||||
|
||||
String getPluginDescriptionString() {
|
||||
String result;
|
||||
#ifdef PLUGIN_BUILD_NORMAL
|
||||
result += F(" [Normal]");
|
||||
#endif
|
||||
#ifdef PLUGIN_BUILD_TESTING
|
||||
result += F(" [Testing]");
|
||||
#endif
|
||||
#ifdef PLUGIN_BUILD_DEV
|
||||
result += F(" [Development]");
|
||||
#endif
|
||||
#ifdef PLUGIN_DESCR
|
||||
result += " [";
|
||||
result += F(PLUGIN_DESCR);
|
||||
result += ']';
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
String getSystemLibraryString() {
|
||||
String result;
|
||||
#if defined(ESP32)
|
||||
result += F("ESP32 SDK ");
|
||||
result += ESP.getSdkVersion();
|
||||
#else
|
||||
result += F("ESP82xx Core ");
|
||||
result += ESP.getCoreVersion();
|
||||
result += F(", NONOS SDK ");
|
||||
result += system_get_sdk_version();
|
||||
result += F(", LWIP: ");
|
||||
result += getLWIPversion();
|
||||
#endif
|
||||
if (puyaSupport()) {
|
||||
result += F(" PUYA support");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifndef ESP32
|
||||
String getLWIPversion() {
|
||||
String result;
|
||||
result += LWIP_VERSION_MAJOR;
|
||||
result += '.';
|
||||
result += LWIP_VERSION_MINOR;
|
||||
result += '.';
|
||||
result += LWIP_VERSION_REVISION;
|
||||
if (LWIP_VERSION_IS_RC) {
|
||||
result += F("-RC");
|
||||
result += LWIP_VERSION_RC;
|
||||
} else if (LWIP_VERSION_IS_DEVELOPMENT) {
|
||||
result += F("-dev");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool puyaSupport() {
|
||||
bool supported = false;
|
||||
#ifdef PUYA_SUPPORT
|
||||
// New support starting core 2.5.0
|
||||
if (PUYA_SUPPORT) supported = true;
|
||||
#endif
|
||||
#ifdef PUYASUPPORT
|
||||
// Old patch
|
||||
supported = true;
|
||||
#endif
|
||||
return supported;
|
||||
}
|
||||
|
||||
uint8_t getFlashChipVendorId() {
|
||||
#ifdef PUYA_SUPPORT
|
||||
return ESP.getFlashChipVendorId();
|
||||
#else
|
||||
#if defined(ESP8266)
|
||||
uint32_t flashChipId = ESP.getFlashChipId();
|
||||
return (flashChipId & 0x000000ff);
|
||||
#else
|
||||
return 0xFF; // Not an existing function for ESP32
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
bool flashChipVendorPuya() {
|
||||
uint8_t vendorId = getFlashChipVendorId();
|
||||
return vendorId == 0x85; // 0x146085 PUYA
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
+4
-30
@@ -1057,25 +1057,7 @@ void handle_root() {
|
||||
if (it->second.build)
|
||||
TXBuffer += String(it->second.build);
|
||||
html_TD();
|
||||
if (it->second.nodeType)
|
||||
switch (it->second.nodeType)
|
||||
{
|
||||
case NODE_TYPE_ID_ESP_EASY_STD:
|
||||
TXBuffer += F("ESP Easy");
|
||||
break;
|
||||
case NODE_TYPE_ID_ESP_EASYM_STD:
|
||||
TXBuffer += F("ESP Easy Mega");
|
||||
break;
|
||||
case NODE_TYPE_ID_ESP_EASY32_STD:
|
||||
TXBuffer += F("ESP Easy 32");
|
||||
break;
|
||||
case NODE_TYPE_ID_ARDUINO_EASY_STD:
|
||||
TXBuffer += F("Arduino Easy");
|
||||
break;
|
||||
case NODE_TYPE_ID_NANO_EASY_STD:
|
||||
TXBuffer += F("Nano Easy");
|
||||
break;
|
||||
}
|
||||
TXBuffer += getNodeTypeDisplayString(it->second.nodeType);
|
||||
html_TD();
|
||||
html_add_wide_button_prefix();
|
||||
TXBuffer += F("http://");
|
||||
@@ -3788,7 +3770,7 @@ void handle_tools() {
|
||||
bool otaEnabled = OTA_possible(maxSketchSize, use2step);
|
||||
addFormSubHeader(F("Firmware"));
|
||||
html_TR_TD_height(30);
|
||||
addWideButton(F("update"), F("Load"), "", otaEnabled);
|
||||
addWideButton(F("update"), F("Update Firmware"), "", otaEnabled);
|
||||
addHelpButton(F("EasyOTA"));
|
||||
html_TD();
|
||||
TXBuffer += F("Load a new firmware");
|
||||
@@ -4339,15 +4321,7 @@ void handle_json()
|
||||
}
|
||||
|
||||
if (it->second.nodeType) {
|
||||
String platform;
|
||||
switch (it->second.nodeType)
|
||||
{
|
||||
case NODE_TYPE_ID_ESP_EASY_STD: platform = F("ESP Easy"); break;
|
||||
case NODE_TYPE_ID_ESP_EASYM_STD: platform = F("ESP Easy Mega"); break;
|
||||
case NODE_TYPE_ID_ESP_EASY32_STD: platform = F("ESP Easy 32"); break;
|
||||
case NODE_TYPE_ID_ARDUINO_EASY_STD: platform = F("Arduino Easy"); break;
|
||||
case NODE_TYPE_ID_NANO_EASY_STD: platform = F("Nano Easy"); break;
|
||||
}
|
||||
String platform = getNodeTypeDisplayString(it->second.nodeType);
|
||||
if (platform.length() > 0)
|
||||
stream_next_json_object_value(F("platform"), platform);
|
||||
}
|
||||
@@ -6348,7 +6322,7 @@ void handle_sysinfo() {
|
||||
case FM_DIO: TXBuffer += F("DIO"); break;
|
||||
case FM_DOUT: TXBuffer += F("DOUT"); break;
|
||||
default:
|
||||
TXBuffer += F("Unknown"); break;
|
||||
TXBuffer += getUnknownString(); break;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
+255
-74
@@ -1,13 +1,13 @@
|
||||
#ifdef USES_P076
|
||||
//#######################################################################################################
|
||||
//#################### Plugin 076 HLW8012 AC Current and Voltage measurement
|
||||
// sensor #####################
|
||||
//#################### Plugin 076 HLW8012 AC Current and Voltage measurement sensor #####################
|
||||
//#######################################################################################################
|
||||
//
|
||||
// This plugin is interfacing with HLW8012 IC which is use with some commercial
|
||||
// devices:
|
||||
// This plugin is interfacing with HLW8012 and BL0937 IC which is use with some
|
||||
// commercial devices like:
|
||||
// -- Sonoff POW
|
||||
// -- ElectroDragon HLW8012 Breakout board
|
||||
// --- and more
|
||||
//
|
||||
// The Sonoff POW uses the following PINs: SEL=GPIO05(D1), CF1=GPIO13(D8),
|
||||
// CF=GPIO14(D5)
|
||||
@@ -22,23 +22,12 @@ HLW8012 *Plugin_076_hlw = NULL;
|
||||
#define PLUGIN_076
|
||||
#define PLUGIN_ID_076 76
|
||||
#define PLUGIN_076_DEBUG true // activate extra log info in the debug
|
||||
#ifdef PLUGIN_SET_SONOFF_POW
|
||||
#define PLUGIN_NAME_076 "Energy (AC) - HLW8012 (POW r1) [TESTING]"
|
||||
#else
|
||||
#define PLUGIN_NAME_076 "Energy (AC) - HLW8012 [TESTING]"
|
||||
#endif
|
||||
#define PLUGIN_VALUENAME1_076 "Voltage (V)"
|
||||
#define PLUGIN_VALUENAME2_076 "Current (A)"
|
||||
#define PLUGIN_VALUENAME3_076 "Active Power (W)"
|
||||
#define PLUGIN_VALUENAME4_076 "Power Factor (%)"
|
||||
#define PLUGIN_NAME_076 "Energy (AC) - HLW8012/BL0937 [TESTING]"
|
||||
#define PLUGIN_VALUENAME1_076 "Voltage"
|
||||
#define PLUGIN_VALUENAME2_076 "Current"
|
||||
#define PLUGIN_VALUENAME3_076 "Power"
|
||||
#define PLUGIN_VALUENAME4_076 "PowerFactor"
|
||||
|
||||
//----------------- HLW8012 Default parameters
|
||||
//--------------------------------------------------
|
||||
// Set SEL_PIN to HIGH to sample current
|
||||
// This is the case for Itead's Sonoff POW, where the SEL_PIN drives a
|
||||
// transistor that pulls down
|
||||
// the SEL pin in the HLW8012 when closed
|
||||
#define HLW_CURRENT_MODE HIGH
|
||||
#define HLW_DELAYREADING 500
|
||||
|
||||
// These are the nominal values for the resistors in the circuit
|
||||
@@ -46,7 +35,6 @@ HLW8012 *Plugin_076_hlw = NULL;
|
||||
#define HLW_VOLTAGE_RESISTOR_UP (5 * 470000) // Real: 2280k
|
||||
#define HLW_VOLTAGE_RESISTOR_DOWN (1000) // Real 1.009k
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
|
||||
byte StoredTaskIndex;
|
||||
byte p076_read_stage = 0;
|
||||
unsigned long p076_timer = 0;
|
||||
@@ -56,6 +44,51 @@ unsigned int p076_hvoltage = 0;
|
||||
unsigned int p076_hpower = 0;
|
||||
unsigned int p076_hpowfact = 0;
|
||||
|
||||
struct p076_PredefinedDevice_struct {
|
||||
int Id;
|
||||
PGM_P Device_Name;
|
||||
byte SEL_Pin;
|
||||
byte CF_Pin;
|
||||
byte CF1_Pin;
|
||||
byte Current_Read;
|
||||
byte CF_Trigger;
|
||||
byte CF1_Trigger;
|
||||
|
||||
};
|
||||
|
||||
typedef struct p076_PredefinedDevice_struct P076_PredefinedDevice;
|
||||
|
||||
//When adding new device increase counter, too
|
||||
const int p076_PinSettingsCount = 10;
|
||||
const char string_Custom[] PROGMEM = "Custom";
|
||||
const char string_Sonoff[] PROGMEM = "Sonoff Pow (r1)";
|
||||
const char string_Huafan[] PROGMEM = "Huafan SS";
|
||||
const char string_KMC[] PROGMEM = "KMC 70011";
|
||||
const char string_Aplic[] PROGMEM = "Aplic WDP303075";
|
||||
const char string_SK03[] PROGMEM = "SK03 Outdoor";
|
||||
const char string_BlitzWolf[] PROGMEM = "BlitzWolf SHP";
|
||||
const char string_Teckin[] PROGMEM = "Teckin";
|
||||
const char string_TeckinUS[] PROGMEM = "Teckin US";
|
||||
const char string_Gosund[] PROGMEM = "Gosund SP1 v23";
|
||||
static const P076_PredefinedDevice p076_PredefinedDevices[] PROGMEM =
|
||||
{
|
||||
//Device_Name,SEL_PIN, CF_PIN, CF1_PIN, Current_Read, CF_Trigger, CF1_Trigger
|
||||
//HLW8012 Devices
|
||||
{ 0, string_Custom, 0, 0, 0, LOW, LOW, LOW},
|
||||
{ 1, string_Sonoff, 5, 14, 13, HIGH, CHANGE, CHANGE},
|
||||
{ 2, string_Huafan, 13, 14, 12, HIGH, CHANGE, CHANGE},
|
||||
{ 3, string_KMC, 12, 4, 5, HIGH, CHANGE, CHANGE},
|
||||
{ 4, string_Aplic, 12, 4, 5, LOW, CHANGE, CHANGE},
|
||||
{ 5, string_SK03, 12, 4, 5, LOW, CHANGE, CHANGE},
|
||||
|
||||
//BL093 Devices
|
||||
{ 6, string_BlitzWolf, 12, 5, 14, LOW, FALLING, CHANGE},
|
||||
{ 7, string_Teckin, 12, 4, 5, LOW, FALLING, CHANGE},
|
||||
{ 8, string_TeckinUS, 12, 5, 14, LOW, FALLING, CHANGE},
|
||||
{ 9, string_Gosund, 12, 4, 5, LOW, FALLING, CHANGE}
|
||||
};
|
||||
|
||||
|
||||
boolean Plugin_076(byte function, struct EventStruct *event, String &string) {
|
||||
boolean success = false;
|
||||
|
||||
@@ -100,23 +133,73 @@ boolean Plugin_076(byte function, struct EventStruct *event, String &string) {
|
||||
}
|
||||
|
||||
case PLUGIN_WEBFORM_LOAD: {
|
||||
addFormNote(
|
||||
F("Sonoff POW: 1st(SEL)=GPIO-5, 2nd(CF1)=GPIO-13, 3rd(CF)=GPIO-14"));
|
||||
|
||||
byte currentRead = Settings.TaskDevicePluginConfig[event->TaskIndex][4];
|
||||
byte cf_trigger = Settings.TaskDevicePluginConfig[event->TaskIndex][5];
|
||||
byte cf1_trigger = Settings.TaskDevicePluginConfig[event->TaskIndex][6];
|
||||
|
||||
byte devicePinSettings = Settings.TaskDevicePluginConfig[event->TaskIndex][7];
|
||||
|
||||
String predefinedNames[p076_PinSettingsCount];
|
||||
int predefinedId[p076_PinSettingsCount];
|
||||
|
||||
for (int i = 0; i < p076_PinSettingsCount; i++)
|
||||
{
|
||||
predefinedNames[i] = p076_PredefinedDevices[i].Device_Name;
|
||||
predefinedId[i] = p076_PredefinedDevices[i].Id;
|
||||
}
|
||||
|
||||
String modeRaise[4];
|
||||
modeRaise[0] = F("LOW");
|
||||
modeRaise[1] = F("CHANGE");
|
||||
modeRaise[2] = F("RISING");
|
||||
modeRaise[3] = F("FALLING");
|
||||
|
||||
int modeValues[4];
|
||||
modeValues[0] = LOW;
|
||||
modeValues[1] = CHANGE;
|
||||
modeValues[2] = RISING;
|
||||
modeValues[3] = FALLING;
|
||||
|
||||
String modeCurr[2];
|
||||
modeCurr[0] = F("LOW");
|
||||
modeCurr[1] = F("HIGH");
|
||||
|
||||
int modeCurrValues[2];
|
||||
modeCurrValues[0] = LOW;
|
||||
modeCurrValues[1] = HIGH;
|
||||
|
||||
addFormSubHeader(F("Predefined Pin settings"));
|
||||
addFormSelector(F("Device"),
|
||||
F("p076_preDefDevSel"), p076_PinSettingsCount,
|
||||
predefinedNames, predefinedId, devicePinSettings );
|
||||
|
||||
addFormSubHeader(F("Custom Pin settings (choose Custom above)"));
|
||||
addFormSelector(F("Current (A) Reading"), F("p076_curr_read"), 2,
|
||||
modeCurr, modeCurrValues, currentRead );
|
||||
addFormSelector(F("CF Interrupt Edge"), F("p076_cf_edge"), 4,
|
||||
modeRaise, modeValues, cf_trigger );
|
||||
addFormSelector(F("CF1 Interrupt Edge"), F("p076_cf1_edge"), 4,
|
||||
modeRaise, modeValues, cf1_trigger);
|
||||
|
||||
addFormSubHeader(F("Calibration Values"));
|
||||
double hlwMultipliers[3];
|
||||
LoadCustomTaskSettings(event->TaskIndex, (byte *)&hlwMultipliers,
|
||||
sizeof(hlwMultipliers));
|
||||
double current, voltage, power;
|
||||
Plugin076_LoadMultipliers(event->TaskIndex, current, voltage, power);
|
||||
|
||||
addFormTextBox(F("Current Multiplier"), F("p076_currmult"),
|
||||
String(hlwMultipliers[0], 2), 25);
|
||||
String(current, 2), 25);
|
||||
addFormTextBox(F("Voltage Multiplier"), F("p076_voltmult"),
|
||||
String(hlwMultipliers[1], 2), 25);
|
||||
String(voltage, 2), 25);
|
||||
addFormTextBox(F("Power Multiplier"), F("p076_powmult"),
|
||||
String(hlwMultipliers[2], 2), 25);
|
||||
String(power, 2), 25);
|
||||
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
|
||||
case PLUGIN_WEBFORM_SAVE: {
|
||||
|
||||
//Set Multipliers
|
||||
double hlwMultipliers[3];
|
||||
String tmpString, arg1;
|
||||
arg1 = F("p076_currmult");
|
||||
@@ -130,19 +213,56 @@ boolean Plugin_076(byte function, struct EventStruct *event, String &string) {
|
||||
hlwMultipliers[2] = atof(tmpString.c_str());
|
||||
SaveCustomTaskSettings(event->TaskIndex, (byte *)&hlwMultipliers,
|
||||
sizeof(hlwMultipliers));
|
||||
|
||||
if (PLUGIN_076_DEBUG) {
|
||||
String log = F("HLW8012: Saved Calibration from Config Page");
|
||||
addLog(LOG_LEVEL_INFO, log);
|
||||
String log = F("P076: Saved Calibration from Config Page");
|
||||
addLog(LOG_LEVEL_INFO, log);
|
||||
}
|
||||
|
||||
if (Plugin_076_hlw) {
|
||||
Plugin_076_hlw->setCurrentMultiplier(hlwMultipliers[0]);
|
||||
Plugin_076_hlw->setVoltageMultiplier(hlwMultipliers[1]);
|
||||
Plugin_076_hlw->setPowerMultiplier(hlwMultipliers[2]);
|
||||
Plugin_076_hlw->setCurrentMultiplier(hlwMultipliers[0]);
|
||||
Plugin_076_hlw->setVoltageMultiplier(hlwMultipliers[1]);
|
||||
Plugin_076_hlw->setPowerMultiplier(hlwMultipliers[2]);
|
||||
}
|
||||
|
||||
if (PLUGIN_076_DEBUG) {
|
||||
String log = F("HLW8012: Multipliers Reassigned");
|
||||
String log = F("P076: Multipliers Reassigned");
|
||||
addLog(LOG_LEVEL_INFO, log);
|
||||
}
|
||||
|
||||
//Set Pin settings
|
||||
byte selectedDevice = getFormItemInt(F("p076_preDefDevSel"));
|
||||
|
||||
Settings.TaskDevicePluginConfig[event->TaskIndex][7] = selectedDevice;
|
||||
|
||||
if (selectedDevice == 0){
|
||||
Settings.TaskDevicePluginConfig[event->TaskIndex][4] = getFormItemInt(F("p076_curr_read"));
|
||||
Settings.TaskDevicePluginConfig[event->TaskIndex][5] = getFormItemInt(F("p076_cf_edge"));
|
||||
Settings.TaskDevicePluginConfig[event->TaskIndex][6] = getFormItemInt(F("p076_cf1_edge"));
|
||||
}
|
||||
else if (selectedDevice < p076_PinSettingsCount){
|
||||
//Fetch Predefined Pin Setting from PROGMEM
|
||||
Settings.TaskDevicePluginConfig[event->TaskIndex][4] = p076_PredefinedDevices[selectedDevice].Current_Read;
|
||||
Settings.TaskDevicePluginConfig[event->TaskIndex][5] = p076_PredefinedDevices[selectedDevice].CF_Trigger;
|
||||
Settings.TaskDevicePluginConfig[event->TaskIndex][6] = p076_PredefinedDevices[selectedDevice].CF1_Trigger;
|
||||
|
||||
Settings.TaskDevicePin1[event->TaskIndex] = p076_PredefinedDevices[selectedDevice].SEL_Pin;
|
||||
Settings.TaskDevicePin2[event->TaskIndex] = p076_PredefinedDevices[selectedDevice].CF1_Pin;
|
||||
Settings.TaskDevicePin3[event->TaskIndex] = p076_PredefinedDevices[selectedDevice].CF_Pin;
|
||||
}
|
||||
|
||||
if (PLUGIN_076_DEBUG) {
|
||||
String log = F("P076: PIN Settings ");
|
||||
|
||||
log += " curr_read: ";
|
||||
log += Settings.TaskDevicePluginConfig[event->TaskIndex][4];
|
||||
log += " cf_edge: ";
|
||||
log += Settings.TaskDevicePluginConfig[event->TaskIndex][5];
|
||||
log += " cf1_edge: ";
|
||||
log += Settings.TaskDevicePluginConfig[event->TaskIndex][6];
|
||||
addLog(LOG_LEVEL_INFO, log);
|
||||
}
|
||||
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
@@ -193,7 +313,7 @@ boolean Plugin_076(byte function, struct EventStruct *event, String &string) {
|
||||
// Measurement is complete.
|
||||
p076_read_stage = 0;
|
||||
if (PLUGIN_076_DEBUG) {
|
||||
String log = F("HLW8012: Read values");
|
||||
String log = F("P076: Read values");
|
||||
log += F(" - V=");
|
||||
log += p076_hvoltage;
|
||||
log += F(" - A=");
|
||||
@@ -214,52 +334,62 @@ boolean Plugin_076(byte function, struct EventStruct *event, String &string) {
|
||||
}
|
||||
break;
|
||||
|
||||
case PLUGIN_EXIT: {
|
||||
Plugin076_Reset(event->TaskIndex);
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
|
||||
case PLUGIN_INIT:
|
||||
Plugin076_Reset(event->TaskIndex);
|
||||
if (!Plugin_076_hlw) {
|
||||
p076_read_stage = 0;
|
||||
Plugin_076_hlw = new HLW8012;
|
||||
|
||||
// This initializes the HWL8012 library.
|
||||
const byte CF_PIN = Settings.TaskDevicePin3[event->TaskIndex];
|
||||
const byte CF1_PIN = Settings.TaskDevicePin2[event->TaskIndex];
|
||||
const byte SEL_PIN = Settings.TaskDevicePin1[event->TaskIndex];
|
||||
|
||||
Plugin_076_hlw->begin(CF_PIN, CF1_PIN, SEL_PIN, HLW_CURRENT_MODE,
|
||||
byte currentRead = Settings.TaskDevicePluginConfig[event->TaskIndex][4];
|
||||
byte cf_trigger = Settings.TaskDevicePluginConfig[event->TaskIndex][5];
|
||||
byte cf1_trigger = Settings.TaskDevicePluginConfig[event->TaskIndex][6];
|
||||
|
||||
Plugin_076_hlw->begin(CF_PIN, CF1_PIN, SEL_PIN, currentRead,
|
||||
true); // set use_interrupts to true to use
|
||||
// interrupts to monitor pulse widths
|
||||
if (PLUGIN_076_DEBUG)
|
||||
addLog(LOG_LEVEL_INFO, F("HLW8012: Init object done"));
|
||||
if (PLUGIN_076_DEBUG){
|
||||
addLog(LOG_LEVEL_INFO, F("P076: Init object done"));
|
||||
}
|
||||
Plugin_076_hlw->setResistors(HLW_CURRENT_RESISTOR,
|
||||
HLW_VOLTAGE_RESISTOR_UP,
|
||||
HLW_VOLTAGE_RESISTOR_DOWN);
|
||||
if (PLUGIN_076_DEBUG)
|
||||
addLog(LOG_LEVEL_INFO, F("HLW8012: Init Basic Resistor Values done"));
|
||||
// If multipliers are empty load default ones and save all of them as
|
||||
// "CustomTaskSettings"
|
||||
double hlwMultipliers[3];
|
||||
LoadCustomTaskSettings(event->TaskIndex, (byte *)&hlwMultipliers,
|
||||
sizeof(hlwMultipliers));
|
||||
if (hlwMultipliers[0] == 0) {
|
||||
hlwMultipliers[0] = Plugin_076_hlw->getCurrentMultiplier();
|
||||
if (PLUGIN_076_DEBUG){
|
||||
addLog(LOG_LEVEL_INFO, F("P076: Init Basic Resistor Values done"));
|
||||
}
|
||||
if (hlwMultipliers[1] == 0) {
|
||||
hlwMultipliers[1] = Plugin_076_hlw->getVoltageMultiplier();
|
||||
|
||||
double current, voltage, power;
|
||||
if (Plugin076_LoadMultipliers(event->TaskIndex, current, voltage, power)) {
|
||||
if (PLUGIN_076_DEBUG){
|
||||
addLog(LOG_LEVEL_INFO, F("P076: Saved Calibration after INIT"));
|
||||
}
|
||||
|
||||
Plugin_076_hlw->setCurrentMultiplier(current);
|
||||
Plugin_076_hlw->setVoltageMultiplier(voltage);
|
||||
Plugin_076_hlw->setPowerMultiplier(power);
|
||||
} else {
|
||||
Plugin076_ResetMultipliers();
|
||||
}
|
||||
if (hlwMultipliers[2] == 0) {
|
||||
hlwMultipliers[2] = Plugin_076_hlw->getPowerMultiplier();
|
||||
|
||||
if (PLUGIN_076_DEBUG){
|
||||
addLog(LOG_LEVEL_INFO, F("P076: Applied Calibration after INIT"));
|
||||
}
|
||||
if (PLUGIN_076_DEBUG)
|
||||
addLog(LOG_LEVEL_INFO, F("HLW8012: Saved Calibration after INIT"));
|
||||
Plugin_076_hlw->setCurrentMultiplier(hlwMultipliers[0]);
|
||||
Plugin_076_hlw->setVoltageMultiplier(hlwMultipliers[1]);
|
||||
Plugin_076_hlw->setPowerMultiplier(hlwMultipliers[2]);
|
||||
if (PLUGIN_076_DEBUG)
|
||||
addLog(LOG_LEVEL_INFO, F("HLW8012: Applied Calibration after INIT"));
|
||||
StoredTaskIndex = event->TaskIndex; // store task index value in order to
|
||||
// use it in the PLUGIN_WRITE routine
|
||||
|
||||
// Library expects an interrupt on both edges
|
||||
attachInterrupt(CF1_PIN, p076_hlw8012_cf1_interrupt, CHANGE);
|
||||
attachInterrupt(CF_PIN, p076_hlw8012_cf_interrupt, CHANGE);
|
||||
attachInterrupt(CF1_PIN, p076_hlw8012_cf1_interrupt, cf1_trigger);
|
||||
attachInterrupt(CF_PIN, p076_hlw8012_cf_interrupt, cf_trigger);
|
||||
}
|
||||
success = true;
|
||||
break;
|
||||
@@ -269,14 +399,11 @@ boolean Plugin_076(byte function, struct EventStruct *event, String &string) {
|
||||
if (Plugin_076_hlw) {
|
||||
String tmpString = string;
|
||||
int argIndex = tmpString.indexOf(',');
|
||||
if (argIndex)
|
||||
if (argIndex){
|
||||
tmpString = tmpString.substring(0, argIndex);
|
||||
|
||||
}
|
||||
if (tmpString.equalsIgnoreCase(F("hlwreset"))) {
|
||||
Plugin_076_hlw->resetMultipliers();
|
||||
Plugin076_SaveMultipliers();
|
||||
if (PLUGIN_076_DEBUG)
|
||||
addLog(LOG_LEVEL_INFO, F("HLW8012: Reset Multipliers to DEFAULT"));
|
||||
Plugin076_ResetMultipliers();
|
||||
success = true;
|
||||
}
|
||||
|
||||
@@ -299,9 +426,9 @@ boolean Plugin_076(byte function, struct EventStruct *event, String &string) {
|
||||
CalibCurr = atof(tmpStr.substring(comma2 + 1, comma3).c_str());
|
||||
CalibAcPwr = tmpStr.substring(comma3 + 1).toInt();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (PLUGIN_076_DEBUG) {
|
||||
String log = F("HLW8012: Calibration to values");
|
||||
String log = F("P076: Calibration to values");
|
||||
log += F(" - Expected-V=");
|
||||
log += CalibVolt;
|
||||
log += F(" - Expected-A=");
|
||||
@@ -310,18 +437,22 @@ boolean Plugin_076(byte function, struct EventStruct *event, String &string) {
|
||||
log += CalibAcPwr;
|
||||
addLog(LOG_LEVEL_INFO, log);
|
||||
}
|
||||
bool changed = false;
|
||||
if (CalibVolt != 0) {
|
||||
Plugin_076_hlw->expectedVoltage(CalibVolt);
|
||||
changed = true;
|
||||
}
|
||||
if (CalibCurr != 0) {
|
||||
if (CalibCurr > 0.0) {
|
||||
Plugin_076_hlw->expectedCurrent(CalibCurr);
|
||||
changed = true;
|
||||
}
|
||||
if (CalibAcPwr != 0) {
|
||||
Plugin_076_hlw->expectedActivePower(CalibAcPwr);
|
||||
changed = true;
|
||||
}
|
||||
// if at least one calibration value has been provided then save the new
|
||||
// multipliers //
|
||||
if ((CalibVolt + CalibCurr + CalibAcPwr) != 0) {
|
||||
if (changed) {
|
||||
Plugin076_SaveMultipliers();
|
||||
}
|
||||
success = true;
|
||||
@@ -333,15 +464,65 @@ boolean Plugin_076(byte function, struct EventStruct *event, String &string) {
|
||||
return success;
|
||||
}
|
||||
|
||||
void Plugin076_ResetMultipliers() {
|
||||
if (Plugin_076_hlw) {
|
||||
Plugin_076_hlw->resetMultipliers();
|
||||
Plugin076_SaveMultipliers();
|
||||
if (PLUGIN_076_DEBUG){
|
||||
addLog(LOG_LEVEL_INFO, F("P076: Reset Multipliers to DEFAULT"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Plugin076_SaveMultipliers() {
|
||||
double hlwMultipliers[3];
|
||||
hlwMultipliers[0] = Plugin_076_hlw->getCurrentMultiplier();
|
||||
hlwMultipliers[1] = Plugin_076_hlw->getVoltageMultiplier();
|
||||
hlwMultipliers[2] = Plugin_076_hlw->getPowerMultiplier();
|
||||
Plugin076_ReadMultipliers(hlwMultipliers[0], hlwMultipliers[1], hlwMultipliers[2]);
|
||||
SaveCustomTaskSettings(StoredTaskIndex, (byte *)&hlwMultipliers,
|
||||
sizeof(hlwMultipliers));
|
||||
}
|
||||
|
||||
void Plugin076_ReadMultipliers(double& current, double& voltage, double& power) {
|
||||
current = 0.0;
|
||||
voltage = 0.0;
|
||||
power = 0.0;
|
||||
if (Plugin_076_hlw) {
|
||||
current = Plugin_076_hlw->getCurrentMultiplier();
|
||||
voltage = Plugin_076_hlw->getVoltageMultiplier();
|
||||
power = Plugin_076_hlw->getPowerMultiplier();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Plugin076_LoadMultipliers(byte TaskIndex, double& current, double& voltage, double& power) {
|
||||
// If multipliers are empty load default ones and save all of them as
|
||||
// "CustomTaskSettings"
|
||||
Plugin076_ReadMultipliers(current, voltage, power);
|
||||
double hlwMultipliers[3];
|
||||
LoadCustomTaskSettings(TaskIndex, (byte *)&hlwMultipliers,
|
||||
sizeof(hlwMultipliers));
|
||||
if (hlwMultipliers[0] > 1.0) {
|
||||
current = hlwMultipliers[0];
|
||||
}
|
||||
if (hlwMultipliers[1] > 1.0) {
|
||||
voltage = hlwMultipliers[1];
|
||||
}
|
||||
if (hlwMultipliers[2] > 1.0) {
|
||||
power = hlwMultipliers[2];
|
||||
}
|
||||
return (current > 1.0) && (voltage > 1.0) && (power > 1.0);
|
||||
}
|
||||
|
||||
void Plugin076_Reset(byte TaskIndex) {
|
||||
if (Plugin_076_hlw) {
|
||||
delete Plugin_076_hlw;
|
||||
Plugin_076_hlw = nullptr;
|
||||
}
|
||||
const byte CF_PIN = Settings.TaskDevicePin3[TaskIndex];
|
||||
const byte CF1_PIN = Settings.TaskDevicePin2[TaskIndex];
|
||||
detachInterrupt(CF_PIN);
|
||||
detachInterrupt(CF1_PIN);
|
||||
}
|
||||
|
||||
// When using interrupts we have to call the library entry point
|
||||
// whenever an interrupt is triggered
|
||||
void ICACHE_RAM_ATTR p076_hlw8012_cf1_interrupt() {
|
||||
|
||||
Reference in New Issue
Block a user