Skip to content

Commit

Permalink
Migrate HLW8012 sensor to new sensor module, remove old code
Browse files Browse the repository at this point in the history
  • Loading branch information
xoseperez committed Dec 21, 2017
1 parent f3c494d commit 1ac4a61
Show file tree
Hide file tree
Showing 18 changed files with 3,454 additions and 4,555 deletions.
114 changes: 0 additions & 114 deletions code/espurna/config/general.h
Original file line number Diff line number Diff line change
Expand Up @@ -553,120 +553,6 @@ PROGMEM const char* const custom_reset_string[] = {
#define LIGHT_TRANSITION_STEP 10 // Time in millis between each transtion step
#define LIGHT_TRANSITION_STEPS 50 // Number of steps to acomplish transition

// -----------------------------------------------------------------------------
// POWER METERING
// -----------------------------------------------------------------------------

// Available power-metering providers (do not change this)
#define POWER_PROVIDER_NONE 0x00
#define POWER_PROVIDER_EMON_ANALOG 0x10
#define POWER_PROVIDER_EMON_ADC121 0x11
#define POWER_PROVIDER_HLW8012 0x20
#define POWER_PROVIDER_V9261F 0x30
#define POWER_PROVIDER_ECH1560 0x40

// Available magnitudes (do not change this)
#define POWER_MAGNITUDE_CURRENT 1
#define POWER_MAGNITUDE_VOLTAGE 2
#define POWER_MAGNITUDE_ACTIVE 4
#define POWER_MAGNITUDE_APPARENT 8
#define POWER_MAGNITUDE_REACTIVE 16
#define POWER_MAGNITUDE_POWER_FACTOR 32
#define POWER_MAGNITUDE_ALL 63

// No power provider defined (do not change this)
#ifndef POWER_PROVIDER
#define POWER_PROVIDER POWER_PROVIDER_NONE
#endif

// Identify available magnitudes (do not change this)
#if (POWER_PROVIDER == POWER_PROVIDER_HLW8012) || (POWER_PROVIDER == POWER_PROVIDER_V9261F)
#define POWER_HAS_ACTIVE 1
#else
#define POWER_HAS_ACTIVE 0
#endif

#if (POWER_PROVIDER == POWER_PROVIDER_HLW8012)
#define POWER_HAS_ENERGY 1
#else
#define POWER_HAS_ENERGY 0
#endif

#define POWER_VOLTAGE 230 // Default voltage
#define POWER_MIN_READ_INTERVAL 2000 // Minimum read interval
#define POWER_READ_INTERVAL 6000 // Default reading interval (6 seconds)
#define POWER_REPORT_INTERVAL 60000 // Default report interval (1 minute)
#define POWER_CURRENT_DECIMALS 2 // Decimals for current values
#define POWER_VOLTAGE_DECIMALS 0 // Decimals for voltage values
#define POWER_POWER_DECIMALS 0 // Decimals for power values
#define POWER_ENERGY_DECIMALS 3 // Decimals for energy values
#define POWER_ENERGY_DECIMALS_KWH 6 // Decimals for energy values
#define POWER_ENERGY_FACTOR 1 // Watt * seconds == Joule (Ws == J)
#define POWER_ENERGY_FACTOR_KWH (1. / 1000. / 3600.) // kWh

#if POWER_PROVIDER == POWER_PROVIDER_EMON_ANALOG
#define EMON_CURRENT_RATIO 30 // Current ratio in the clamp (30V/1A)
#define EMON_SAMPLES 1000 // Number of samples to get for each reading
#define EMON_ADC_BITS 10 // ADC depth
#define EMON_REFERENCE_VOLTAGE 1.0 // Reference voltage of the ADC
#define EMON_CURRENT_OFFSET 0.25 // Current offset (error)
#undef ADC_VCC_ENABLED
#define ADC_VCC_ENABLED 0 // Disable internal battery measurement
#endif

#if POWER_PROVIDER == POWER_PROVIDER_EMON_ADC121
#define EMON_CURRENT_RATIO 30 // Current ratio in the clamp (30V/1A)
#define EMON_SAMPLES 1000 // Number of samples to get for each reading
#define EMON_ADC_BITS 12 // ADC depth
#define EMON_REFERENCE_VOLTAGE 3.3 // Reference voltage of the ADC
#define EMON_CURRENT_OFFSET 0.10 // Current offset (error)
#define ADC121_I2C_ADDRESS 0x50 // I2C address of the ADC121
#undef I2C_SUPPORT
#define I2C_SUPPORT 1 // Enabled I2C support
#endif

#if POWER_PROVIDER == POWER_PROVIDER_HLW8012
#define HLW8012_USE_INTERRUPTS 1 // Use interrupts to trap HLW8012 signals
#define HLW8012_SEL_CURRENT HIGH // SEL pin to HIGH to measure current
#define HLW8012_CURRENT_R 0.001 // Current resistor
#define HLW8012_VOLTAGE_R_UP ( 5 * 470000 ) // Upstream voltage resistor
#define HLW8012_VOLTAGE_R_DOWN ( 1000 ) // Downstream voltage resistor
#endif

#if POWER_PROVIDER == POWER_PROVIDER_V9261F

#ifndef V9261F_PIN
#define V9261F_PIN 2 // TX pin from the V9261F
#endif
#ifndef V9261F_PIN_INVERSE
#define V9261F_PIN_INVERSE 1 // Signal is inverted
#endif

#define V9261F_SYNC_INTERVAL 600 // Sync signal length (ms)
#define V9261F_BAUDRATE 4800 // UART baudrate

// Default ratios
#define V9261F_CURRENT_FACTOR 79371434.0
#define V9261F_VOLTAGE_FACTOR 4160651.0
#define V9261F_POWER_FACTOR 153699.0
#define V9261F_RPOWER_FACTOR V9261F_CURRENT_FACTOR

#endif

#if POWER_PROVIDER == POWER_PROVIDER_ECH1560

#ifndef ECH1560_CLK_PIN
#define ECH1560_CLK_PIN 4 // Default CLK pin
#endif
#ifndef ECH1560_MISO_PIN
#define ECH1560_MISO_PIN 5 // Default MISO pin
#endif
#ifndef ECH1560_INVERTED
#define ECH1560_INVERTED 0 // Power signal is inverted
#endif

#endif

// -----------------------------------------------------------------------------
// DOMOTICZ
// -----------------------------------------------------------------------------
Expand Down
12 changes: 4 additions & 8 deletions code/espurna/config/hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@
#define LED1_PIN_INVERSE 1

// HLW8012
#ifndef POWER_PROVIDER
#define POWER_PROVIDER POWER_PROVIDER_HLW8012
#endif
#define HLW8012_SUPPORT 1
#define HLW8012_SEL_PIN 2
#define HLW8012_CF1_PIN 13
#define HLW8012_CF_PIN 14
Expand Down Expand Up @@ -148,9 +146,7 @@
#define LED1_PIN_INVERSE 0

// HLW8012
#ifndef POWER_PROVIDER
#define POWER_PROVIDER POWER_PROVIDER_HLW8012
#endif
#define HLW8012_SUPPORT 1
#define HLW8012_SEL_PIN 5
#define HLW8012_CF1_PIN 13
#define HLW8012_CF_PIN 14
Expand Down Expand Up @@ -322,7 +318,7 @@
#define LED1_PIN_INVERSE 0

// HLW8012
#define POWER_PROVIDER POWER_PROVIDER_HLW8012
#define HLW8012_SUPPORT 1
#define HLW8012_SEL_PIN 5
#define HLW8012_CF1_PIN 13
#define HLW8012_CF_PIN 14
Expand Down Expand Up @@ -1042,7 +1038,7 @@
#define ALEXA_SUPPORT 0

// ECH1560
#define POWER_PROVIDER POWER_PROVIDER_ECH1560
#define ECH1560_SUPPORT 1
#define ECH1560_CLK_PIN 4
#define ECH1560_MISO_PIN 5
#define ECH1560_INVERTED 0
Expand Down
21 changes: 20 additions & 1 deletion code/espurna/config/sensors.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@
//------------------------------------------------------------------------------

#ifndef ECH1560_SUPPORT
#define ECH1560_SUPPORT 1
#define ECH1560_SUPPORT 0
#endif

#ifndef ECH1560_CLK_PIN
Expand Down Expand Up @@ -301,6 +301,24 @@
#define HLW8012_SUPPORT 0
#endif

#ifndef HLW8012_SEL_PIN
#define HLW8012_SEL_PIN 5
#endif

#ifndef HLW8012_CF1_PIN
#define HLW8012_CF1_PIN 13
#endif

#ifndef HLW8012_CF_PIN
#define HLW8012_CF_PIN 14
#endif

#define HLW8012_USE_INTERRUPTS 1 // Use interrupts to trap HLW8012 signals
#define HLW8012_SEL_CURRENT HIGH // SEL pin to HIGH to measure current
#define HLW8012_CURRENT_R 0.001 // Current resistor
#define HLW8012_VOLTAGE_R_UP ( 5 * 470000 ) // Upstream voltage resistor
#define HLW8012_VOLTAGE_R_DOWN ( 1000 ) // Downstream voltage resistor

//------------------------------------------------------------------------------
// MHZ19 CO2 sensor
// Enable support by passing MHZ19_SUPPORT=1 build flag
Expand Down Expand Up @@ -476,6 +494,7 @@
#endif

#if HLW8012_SUPPORT
#include <HLW8012.h>
#include "sensors/HLW8012Sensor.h"
#endif

Expand Down
Binary file modified code/espurna/data/index.html.gz
Binary file not shown.
Loading

0 comments on commit 1ac4a61

Please sign in to comment.