diff --git a/code/espurna/config/arduino.h b/code/espurna/config/arduino.h index f737a677..e6e3f395 100644 --- a/code/espurna/config/arduino.h +++ b/code/espurna/config/arduino.h @@ -116,6 +116,7 @@ //#define GOSUND_WS1 //#define ARILUX_AL_LC02_V14 //#define BLITZWOLF_BWSHPX_V23 +//#define DIGOO_NX_SP202 //-------------------------------------------------------------------------------- // Features (values below are non-default values) diff --git a/code/espurna/config/hardware.h b/code/espurna/config/hardware.h index 4d7b5635..4e6e9fb9 100644 --- a/code/espurna/config/hardware.h +++ b/code/espurna/config/hardware.h @@ -3393,6 +3393,51 @@ #define LED1_PIN 4 #define LED1_PIN_INVERSE 1 +// ----------------------------------------------------------------------------- +// Oxaoxe NX-SP202 +// Digoo NX-SP202 (not tested) +// Digoo DG-SP202 (not tested) +// https://github.com/xoseperez/espurna/issues/1502 +// ----------------------------------------------------------------------------- + +#elif defined(DIGOO_NX_SP202) + + // Info + #define MANUFACTURER "DIGOO" + #define DEVICE "NX_SP202" + + // Buttons + #define BUTTON1_PIN 0 + #define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH + #define BUTTON1_RELAY 1 + #define BUTTON2_PIN 16 + #define BUTTON2_MODE BUTTON_PUSHBUTTON | BUTTON_SET_PULLUP | BUTTON_DEFAULT_HIGH + #define BUTTON2_RELAY 2 + + // Relays + #define RELAY1_PIN 15 + #define RELAY1_TYPE RELAY_TYPE_NORMAL + #define RELAY2_PIN 14 + #define RELAY2_TYPE RELAY_TYPE_NORMAL + + // LEDs + #define LED1_PIN 13 + #define LED1_PIN_INVERSE 1 + + // HJL01 / BL0937 + #ifndef HLW8012_SUPPORT + #define HLW8012_SUPPORT 1 + #endif + #define HLW8012_SEL_PIN 12 + #define HLW8012_CF1_PIN 5 + #define HLW8012_CF_PIN 4 + + #define HLW8012_SEL_CURRENT LOW + #define HLW8012_CURRENT_RATIO 23296 + #define HLW8012_VOLTAGE_RATIO 310085 + #define HLW8012_POWER_RATIO 3368471 + #define HLW8012_INTERRUPT_ON FALLING + // ----------------------------------------------------------------------------- // TEST boards (do not use!!) // ----------------------------------------------------------------------------- diff --git a/code/espurna/migrate.ino b/code/espurna/migrate.ino index 40f93995..43254537 100644 --- a/code/espurna/migrate.ino +++ b/code/espurna/migrate.ino @@ -1268,6 +1268,27 @@ void migrate() { setSetting("relayGPIO", 1, 15); // Left outlet setSetting("relayType", 1, RELAY_TYPE_NORMAL); + #elif defined(DIGOO_NX_SP202) + + setSetting("board", 95); + setSetting("ledGPIO", 0, 13); + setSetting("ledLogic", 0, 1); + setSetting("btnGPIO", 0, 0); + setSetting("btnRelay", 0, 0); + setSetting("btnGPIO", 1, 16); + setSetting("btnRelay", 1, 1); + setSetting("relayGPIO", 0, 15); + setSetting("relayType", 0, RELAY_TYPE_NORMAL); + setSetting("relayGPIO", 1, 14); + setSetting("relayType", 1, RELAY_TYPE_NORMAL); + setSetting("selGPIO", 12); + setSetting("cf1GPIO", 5); + setSetting("cfGPIO", 4); + setSetting("pwrRatioC", 23296); + setSetting("pwrRatioV", 310085); + setSetting("pwrRatioP", 3368471); + setSetting("hlwSelC", LOW); + setSetting("hlwIntM", FALLING); #else diff --git a/code/espurna/sensor.ino b/code/espurna/sensor.ino index 82f271b9..8c2571d4 100644 --- a/code/espurna/sensor.ino +++ b/code/espurna/sensor.ino @@ -1404,7 +1404,7 @@ void sensorLoop() { // Get the first relay state #if SENSOR_POWER_CHECK_STATUS - bool relay_off = (relayCount() > 0) && (relayStatus(0) == 0); + bool relay_off = (relayCount() == 1) && (relayStatus(0) == 0); #endif // Get readings diff --git a/code/platformio.ini b/code/platformio.ini index 656e33f1..2a318889 100644 --- a/code/platformio.ini +++ b/code/platformio.ini @@ -2902,6 +2902,32 @@ upload_port = ${common.upload_port} upload_flags = ${common.upload_flags} extra_scripts = ${common.extra_scripts} +[env:digoo-nx-sp202] +platform = ${common.platform} +framework = ${common.framework} +board = ${common.board_1m} +board_build.flash_mode = ${common.flash_mode} +lib_deps = ${common.lib_deps} +lib_ignore = ${common.lib_ignore} +build_flags = ${common.build_flags_1m0m} -DDIGOO_NX_SP202 +upload_speed = ${common.upload_speed} +monitor_speed = ${common.monitor_speed} +extra_scripts = ${common.extra_scripts} + +[env:digoo-nx-sp202-ota] +platform = ${common.platform} +framework = ${common.framework} +board = ${common.board_1m} +board_build.flash_mode = ${common.flash_mode} +lib_deps = ${common.lib_deps} +lib_ignore = ${common.lib_ignore} +build_flags = ${common.build_flags_1m0m} -DDIGOO_NX_SP202 +upload_speed = ${common.upload_speed} +monitor_speed = ${common.monitor_speed} +upload_port = ${common.upload_port} +upload_flags = ${common.upload_flags} +extra_scripts = ${common.extra_scripts} + [env:homecube-16a] platform = ${common.platform} framework = ${common.framework}