Browse Source

Support for BL0937 power monitoring chip with unmodified HLW8012 library (#737)

rfm69
Xose Pérez 6 years ago
parent
commit
cb63e2659b
6 changed files with 98 additions and 5 deletions
  1. +1
    -0
      code/espurna/config/arduino.h
  2. +46
    -0
      code/espurna/config/hardware.h
  3. +20
    -0
      code/espurna/config/sensors.h
  4. +3
    -3
      code/espurna/sensor.ino
  5. +2
    -2
      code/espurna/sensors/HLW8012Sensor.h
  6. +26
    -0
      code/platformio.ini

+ 1
- 0
code/espurna/config/arduino.h View File

@ -85,6 +85,7 @@
//#define NEO_COOLCAM_POWER_PLUG_WIFI
//#define ESTINK_WIFI_POWER_STRIP
//#define PILOTAK_ESP_DIN_V1
//#define BLITZWOLF_BWSHP2
//--------------------------------------------------------------------------------
// Features (values below are non-default values)


+ 46
- 0
code/espurna/config/hardware.h View File

@ -2240,6 +2240,52 @@
#define LED3_RELAY 3
#define LED4_RELAY 4
// -----------------------------------------------------------------------------
// Several boards under different names uing a power chip labelled BL0937 or HJL-01
// * Blitzwolf (https://www.amazon.es/Inteligente-Temporización-Dispositivos-Cualquier-BlitzWolf/dp/B07BMQP142)
// * HomeCube (https://www.amazon.de/Steckdose-Homecube-intelligente-Verbrauchsanzeige-funktioniert/dp/B076Q2LKHG)
// * Coosa (https://www.amazon.com/COOSA-Monitoring-Function-Campatible-Assiatant/dp/B0788W9TDR)
// * Goosund (http://www.gosund.com/?m=content&c=index&a=show&catid=6&id=5)
// -----------------------------------------------------------------------------
#elif defined(BLITZWOLF_BWSHP2)
// Info
#define MANUFACTURER "BLITZWOLF"
#define DEVICE "BWSHP2"
// Buttons
#define BUTTON1_PIN 13
#define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
#define BUTTON1_RELAY 1
// Relays
#define RELAY1_PIN 15
#define RELAY1_TYPE RELAY_TYPE_NORMAL
// LEDs
#define LED1_PIN 2
#define LED1_PIN_INVERSE 1
#define LED2_PIN 0
#define LED2_PIN_INVERSE 1
#define LED2_MODE LED_MODE_FINDME
#define LED2_RELAY 1
// HJL01 / BL0937
#ifndef HLW8012_SUPPORT
#define HLW8012_SUPPORT 1
#endif
#define HLW8012_SEL_PIN 12
#define HLW8012_CF1_PIN 14
#define HLW8012_CF_PIN 5
#define HLW8012_SEL_CURRENT LOW
#define HLW8012_CURRENT_RATIO 25740
#define HLW8012_VOLTAGE_RATIO 313400
#define HLW8012_POWER_RATIO 3414290
#define HLW8012_INTERRUPT_ON FALLING
// -----------------------------------------------------------------------------
// TEST boards (do not use!!)
// -----------------------------------------------------------------------------


+ 20
- 0
code/espurna/config/sensors.h View File

@ -383,7 +383,27 @@
#define HLW8012_VOLTAGE_R_DOWN ( 1000 ) // Downstream voltage resistor
#endif
#ifndef HLW8012_CURRENT_RATIO
#define HLW8012_CURRENT_RATIO 0 // Set to 0 to use factory defaults
#endif
#ifndef HLW8012_VOLTAGE_RATIO
#define HLW8012_VOLTAGE_RATIO 0 // Set to 0 to use factory defaults
#endif
#ifndef HLW8012_POWER_RATIO
#define HLW8012_POWER_RATIO 0 // Set to 0 to use factory defaults
#endif
#ifndef HLW8012_USE_INTERRUPTS
#define HLW8012_USE_INTERRUPTS 1 // Use interrupts to trap HLW8012 signals
#endif
#ifndef HLW8012_INTERRUPT_ON
#define HLW8012_INTERRUPT_ON CHANGE // When to trigger the interrupt
// Use CHANGE for HLW8012
// Use FALLING for BL0937 / HJL0
#endif
//------------------------------------------------------------------------------
// MHZ19 CO2 sensor


+ 3
- 3
code/espurna/sensor.ino View File

@ -644,13 +644,13 @@ void _sensorInit() {
double value;
value = getSetting("pwrRatioC", 0).toFloat();
value = getSetting("pwrRatioC", HLW8012_CURRENT_RATIO).toFloat();
if (value > 0) sensor->setCurrentRatio(value);
value = getSetting("pwrRatioV", 0).toFloat();
value = getSetting("pwrRatioV", HLW8012_VOLTAGE_RATIO).toFloat();
if (value > 0) sensor->setVoltageRatio(value);
value = getSetting("pwrRatioP", 0).toFloat();
value = getSetting("pwrRatioP", HLW8012_POWER_RATIO).toFloat();
if (value > 0) sensor->setPowerRatio(value);
}


+ 2
- 2
code/espurna/sensors/HLW8012Sensor.h View File

@ -234,13 +234,13 @@ class HLW8012Sensor : public BaseSensor {
if (_interrupt_cf != _cf) {
if (_interrupt_cf != GPIO_NONE) _detach(_interrupt_cf);
_attach(this, _cf, CHANGE);
_attach(this, _cf, HLW8012_INTERRUPT_ON);
_interrupt_cf = _cf;
}
if (_interrupt_cf1 != _cf1) {
if (_interrupt_cf1 != GPIO_NONE) _detach(_interrupt_cf1);
_attach(this, _cf1, CHANGE);
_attach(this, _cf1, HLW8012_INTERRUPT_ON);
_interrupt_cf1 = _cf1;
}


+ 26
- 0
code/platformio.ini View File

@ -2423,3 +2423,29 @@ upload_port = "${env.ESPURNA_IP}"
upload_flags = --auth=${env.ESPURNA_AUTH} --port 8266
extra_scripts = ${common.extra_scripts}
modules = ${common.modules} sensor
[env:blitzwolf-bwshp2]
platform = ${common.platform}
framework = arduino
board = esp01_1m
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m0m} -DBLITZWOLF_BWSHP2
upload_speed = 115200
monitor_speed = 115200
extra_scripts = ${common.extra_scripts}
modules = ${common.modules} sensor
[env:blitzwolf-bwshp2-ota]
platform = ${common.platform}
framework = arduino
board = esp01_1m
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m0m} -DBLITZWOLF_BWSHP2
upload_speed = 115200
monitor_speed = 115200
upload_port = "${env.ESPURNA_IP}"
upload_flags = --auth=${env.ESPURNA_AUTH} --port 8266
extra_scripts = ${common.extra_scripts}
modules = ${common.modules} sensor

Loading…
Cancel
Save