Merge pull request #2727 from gtortone/development

SDM120 power meter - new metrics
This commit is contained in:
Theo Arends 2018-05-14 21:50:40 +02:00 committed by GitHub
commit f637339fd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 118 additions and 13 deletions

2
.gitignore vendored
View File

@ -8,5 +8,5 @@
.piolibdeps
.clang_complete
.gcc-flags.json
.vscode
sonoff/user_config_override.h
build

View File

@ -88,6 +88,9 @@
#define D_JSON_PERIOD "Period"
#define D_JSON_POWERFACTOR "Factor"
#define D_JSON_POWERUSAGE "Power"
#define D_JSON_ACTIVE_POWERUSAGE "ActivePower"
#define D_JSON_APPARENT_POWERUSAGE "ApparentPower"
#define D_JSON_REACTIVE_POWERUSAGE "ReactivePower"
#define D_JSON_PRESSURE "Pressure"
#define D_JSON_PRESSUREATSEALEVEL "SeaPressure"
#define D_JSON_PROGRAMFLASHSIZE "ProgramFlashSize"

View File

@ -121,6 +121,9 @@
#define D_PORT "Порт"
#define D_POWER_FACTOR "Фактор на мощността"
#define D_POWERUSAGE "Мощност"
#define D_POWERUSAGE_ACTIVE "Active Power"
#define D_POWERUSAGE_APPARENT "Apparent Power"
#define D_POWERUSAGE_REACTIVE "Reactive Power"
#define D_PRESSURE "Налягане"
#define D_PRESSUREATSEALEVEL "Налягане на морското ниво"
#define D_PROGRAM_FLASH_SIZE "Размер на флаш паметта за програми"
@ -479,6 +482,8 @@
#define D_UNIT_PRESSURE "хПа"
#define D_UNIT_SECOND "сек"
#define D_UNIT_SECTORS "сектори"
#define D_UNIT_VA "VA"
#define D_UNIT_VAR "VAr"
#define D_UNIT_VOLT "В"
#define D_UNIT_WATT "Вт"
#define D_UNIT_WATTHOUR "Вт/ч"

View File

@ -121,6 +121,9 @@
#define D_PORT "Port"
#define D_POWER_FACTOR "Účiník"
#define D_POWERUSAGE "Příkon"
#define D_POWERUSAGE_ACTIVE "Active Power"
#define D_POWERUSAGE_APPARENT "Apparent Power"
#define D_POWERUSAGE_REACTIVE "Reactive Power"
#define D_PRESSURE "Tlak"
#define D_PRESSUREATSEALEVEL "Tlak na úrovni hladiny moře"
#define D_PROGRAM_FLASH_SIZE "Velikost paměti flash"
@ -479,6 +482,8 @@
#define D_UNIT_PRESSURE "hPa"
#define D_UNIT_SECOND "sec"
#define D_UNIT_SECTORS "sektory"
#define D_UNIT_VA "VA"
#define D_UNIT_VAR "VAr"
#define D_UNIT_VOLT "V"
#define D_UNIT_WATT "W"
#define D_UNIT_WATTHOUR "Wh"

View File

@ -121,6 +121,9 @@
#define D_PORT "Port"
#define D_POWER_FACTOR "Leistungsfaktor"
#define D_POWERUSAGE "Leistung"
#define D_POWERUSAGE_ACTIVE "Active Power"
#define D_POWERUSAGE_APPARENT "Apparent Power"
#define D_POWERUSAGE_REACTIVE "Reactive Power"
#define D_PRESSURE "Luftdruck"
#define D_PRESSUREATSEALEVEL "Luftdruck auf Meereshöhe"
#define D_PROGRAM_FLASH_SIZE "Ges. Flash Speicher"
@ -479,6 +482,8 @@
#define D_UNIT_PRESSURE "hPa"
#define D_UNIT_SECOND "sek"
#define D_UNIT_SECTORS "Sektoren"
#define D_UNIT_VA "VA"
#define D_UNIT_VAR "VAr"
#define D_UNIT_VOLT "V"
#define D_UNIT_WATT "W"
#define D_UNIT_WATTHOUR "Wh"

View File

@ -121,6 +121,9 @@
#define D_PORT "Πόρτα"
#define D_POWER_FACTOR "Παράγοντας ισχύος"
#define D_POWERUSAGE "Ισχύης"
#define D_POWERUSAGE_ACTIVE "Active Power"
#define D_POWERUSAGE_APPARENT "Apparent Power"
#define D_POWERUSAGE_REACTIVE "Reactive Power"
#define D_PRESSURE "Πίεση"
#define D_PRESSUREATSEALEVEL "Πίεση στην επιφάνεια της Θάλασσας"
#define D_PROGRAM_FLASH_SIZE "Μέγεθος Προγράμματος Flash"
@ -479,6 +482,8 @@
#define D_UNIT_PRESSURE "hPa"
#define D_UNIT_SECOND "sec"
#define D_UNIT_SECTORS "sectors"
#define D_UNIT_VA "VA"
#define D_UNIT_VAR "VAr"
#define D_UNIT_VOLT "V"
#define D_UNIT_WATT "W"
#define D_UNIT_WATTHOUR "Wh"

View File

@ -121,6 +121,9 @@
#define D_PORT "Port"
#define D_POWER_FACTOR "Power Factor"
#define D_POWERUSAGE "Power"
#define D_POWERUSAGE_ACTIVE "Active Power"
#define D_POWERUSAGE_APPARENT "Apparent Power"
#define D_POWERUSAGE_REACTIVE "Reactive Power"
#define D_PRESSURE "Pressure"
#define D_PRESSUREATSEALEVEL "SeaPressure"
#define D_PROGRAM_FLASH_SIZE "Program Flash Size"
@ -478,6 +481,8 @@
#define D_UNIT_PRESSURE "hPa"
#define D_UNIT_SECOND "sec"
#define D_UNIT_SECTORS "sectors"
#define D_UNIT_VA "VA"
#define D_UNIT_VAR "VAr"
#define D_UNIT_VOLT "V"
#define D_UNIT_WATT "W"
#define D_UNIT_WATTHOUR "Wh"

View File

@ -121,6 +121,9 @@
#define D_PORT "Puerto"
#define D_POWER_FACTOR "Factor de Potencia"
#define D_POWERUSAGE "Potencia"
#define D_POWERUSAGE_ACTIVE "Active Power"
#define D_POWERUSAGE_APPARENT "Apparent Power"
#define D_POWERUSAGE_REACTIVE "Reactive Power"
#define D_PRESSURE "Presión"
#define D_PRESSUREATSEALEVEL "Presión al nivel del mar"
#define D_PROGRAM_FLASH_SIZE "Tamaño de Flash de Programa"
@ -479,6 +482,8 @@
#define D_UNIT_PRESSURE "hPa"
#define D_UNIT_SECOND "seg"
#define D_UNIT_SECTORS "sectores"
#define D_UNIT_VA "VA"
#define D_UNIT_VAR "VAr"
#define D_UNIT_VOLT "V"
#define D_UNIT_WATT "W"
#define D_UNIT_WATTHOUR "Wh"

View File

@ -121,6 +121,9 @@
#define D_PORT "Port"
#define D_POWER_FACTOR "Facteur de puissance"
#define D_POWERUSAGE "Puissance"
#define D_POWERUSAGE_ACTIVE "Active Power"
#define D_POWERUSAGE_APPARENT "Apparent Power"
#define D_POWERUSAGE_REACTIVE "Reactive Power"
#define D_PRESSURE "Pression"
#define D_PRESSUREATSEALEVEL "PressionMer"
#define D_PROGRAM_FLASH_SIZE "Taille Flash Programme"
@ -479,6 +482,8 @@
#define D_UNIT_PRESSURE "hPa"
#define D_UNIT_SECOND "sec"
#define D_UNIT_SECTORS "secteurs"
#define D_UNIT_VA "VA"
#define D_UNIT_VAR "VAr"
#define D_UNIT_VOLT "V"
#define D_UNIT_WATT "W"
#define D_UNIT_WATTHOUR "Wh"

View File

@ -121,6 +121,9 @@
#define D_PORT "Port"
#define D_POWER_FACTOR "Teljesítmény tényező"
#define D_POWERUSAGE "Energiafelhasználás"
#define D_POWERUSAGE_ACTIVE "Active Power"
#define D_POWERUSAGE_APPARENT "Apparent Power"
#define D_POWERUSAGE_REACTIVE "Reactive Power"
#define D_PRESSURE "Nyomás"
#define D_PRESSUREATSEALEVEL "Tengerszinti nyomás"
#define D_PROGRAM_FLASH_SIZE "Program Flash Méret"
@ -479,6 +482,8 @@
#define D_UNIT_PRESSURE "hPa"
#define D_UNIT_SECOND "m"
#define D_UNIT_SECTORS "szektorok"
#define D_UNIT_VA "VA"
#define D_UNIT_VAR "VAr"
#define D_UNIT_VOLT "V"
#define D_UNIT_WATT "W"
#define D_UNIT_WATTHOUR "Wh"

View File

@ -121,6 +121,9 @@
#define D_PORT "Porta"
#define D_POWER_FACTOR "Fattore di potenza"
#define D_POWERUSAGE "Potenza"
#define D_POWERUSAGE_ACTIVE "Potenza Attiva"
#define D_POWERUSAGE_APPARENT "Potenza Apparente"
#define D_POWERUSAGE_REACTIVE "Potenza Reattiva"
#define D_PRESSURE "Pressione"
#define D_PRESSUREATSEALEVEL "Pressione al livello del mare"
#define D_PROGRAM_FLASH_SIZE "Dimensione Flash Programma"
@ -479,6 +482,8 @@
#define D_UNIT_PRESSURE "hPa"
#define D_UNIT_SECOND "sec"
#define D_UNIT_SECTORS "settori"
#define D_UNIT_VA "VA"
#define D_UNIT_VAR "VAr"
#define D_UNIT_VOLT "V"
#define D_UNIT_WATT "W"
#define D_UNIT_WATTHOUR "Wh"

View File

@ -121,6 +121,9 @@
#define D_PORT "Poort"
#define D_POWER_FACTOR "Arbeidsfactor"
#define D_POWERUSAGE "Vermogen"
#define D_POWERUSAGE_ACTIVE "Active Power"
#define D_POWERUSAGE_APPARENT "Apparent Power"
#define D_POWERUSAGE_REACTIVE "Reactive Power"
#define D_PRESSURE "Luchtdruk"
#define D_PRESSUREATSEALEVEL "ZeeLuchtdruk"
#define D_PROGRAM_FLASH_SIZE "Programma Flash Grootte"
@ -479,6 +482,8 @@
#define D_UNIT_PRESSURE "hPa"
#define D_UNIT_SECOND "sec"
#define D_UNIT_SECTORS "sectoren"
#define D_UNIT_VA "VA"
#define D_UNIT_VAR "VAr"
#define D_UNIT_VOLT "V"
#define D_UNIT_WATT "W"
#define D_UNIT_WATTHOUR "Wh"

View File

@ -121,6 +121,9 @@
#define D_PORT "Port"
#define D_POWER_FACTOR "Współczynik mocy"
#define D_POWERUSAGE "Moc"
#define D_POWERUSAGE_ACTIVE "Active Power"
#define D_POWERUSAGE_APPARENT "Apparent Power"
#define D_POWERUSAGE_REACTIVE "Reactive Power"
#define D_PRESSURE "Ciśnienie"
#define D_PRESSUREATSEALEVEL "Ciśnienie na poziomie morza"
#define D_PROGRAM_FLASH_SIZE "Wielkość programu flash"
@ -479,6 +482,8 @@
#define D_UNIT_PRESSURE "hPa"
#define D_UNIT_SECOND "sec"
#define D_UNIT_SECTORS "sektory"
#define D_UNIT_VA "VA"
#define D_UNIT_VAR "VAr"
#define D_UNIT_VOLT "V"
#define D_UNIT_WATT "W"
#define D_UNIT_WATTHOUR "Wh"

View File

@ -121,6 +121,9 @@
#define D_PORT "Porta"
#define D_POWER_FACTOR "Fator de potência"
#define D_POWERUSAGE "Potência"
#define D_POWERUSAGE_ACTIVE "Active Power"
#define D_POWERUSAGE_APPARENT "Apparent Power"
#define D_POWERUSAGE_REACTIVE "Reactive Power"
#define D_PRESSURE "Pressão"
#define D_PRESSUREATSEALEVEL "Pressão ao nível do mar"
#define D_PROGRAM_FLASH_SIZE "Tamanho do programa na memória"
@ -479,6 +482,8 @@
#define D_UNIT_PRESSURE "hPa"
#define D_UNIT_SECOND "s"
#define D_UNIT_SECTORS "setores"
#define D_UNIT_VA "VA"
#define D_UNIT_VAR "VAr"
#define D_UNIT_VOLT "V"
#define D_UNIT_WATT "W"
#define D_UNIT_WATTHOUR "W/h"

View File

@ -121,6 +121,9 @@
#define D_PORT "Porta"
#define D_POWER_FACTOR "Factor de Potência"
#define D_POWERUSAGE "Potência"
#define D_POWERUSAGE_ACTIVE "Active Power"
#define D_POWERUSAGE_APPARENT "Apparent Power"
#define D_POWERUSAGE_REACTIVE "Reactive Power"
#define D_PRESSURE "Pressão"
#define D_PRESSUREATSEALEVEL "Pressão ao nível do Mar"
#define D_PROGRAM_FLASH_SIZE "Tamanho do Programa na Flash"
@ -479,6 +482,8 @@
#define D_UNIT_PRESSURE "hPa"
#define D_UNIT_SECOND "sec"
#define D_UNIT_SECTORS "sectors"
#define D_UNIT_VA "VA"
#define D_UNIT_VAR "VAr"
#define D_UNIT_VOLT "V"
#define D_UNIT_WATT "W"
#define D_UNIT_WATTHOUR "Wh"

View File

@ -121,6 +121,9 @@
#define D_PORT "Порт"
#define D_POWER_FACTOR "Коэффициент Мощности"
#define D_POWERUSAGE "Мощность"
#define D_POWERUSAGE_ACTIVE "Active Power"
#define D_POWERUSAGE_APPARENT "Apparent Power"
#define D_POWERUSAGE_REACTIVE "Reactive Power"
#define D_PRESSURE "Давление"
#define D_PRESSUREATSEALEVEL "Давление на уровне моря"
#define D_PROGRAM_FLASH_SIZE "Размер Flash для программ"
@ -479,6 +482,8 @@
#define D_UNIT_PRESSURE "гПа"
#define D_UNIT_SECOND "сек"
#define D_UNIT_SECTORS "секторов"
#define D_UNIT_VA "VA"
#define D_UNIT_VAR "VAr"
#define D_UNIT_VOLT "В"
#define D_UNIT_WATT "Вт"
#define D_UNIT_WATTHOUR "ВтЧ"

View File

@ -121,6 +121,9 @@
#define D_PORT "端口"
#define D_POWER_FACTOR "功率因数"
#define D_POWERUSAGE "功率"
#define D_POWERUSAGE_ACTIVE "Active Power"
#define D_POWERUSAGE_APPARENT "Apparent Power"
#define D_POWERUSAGE_REACTIVE "Reactive Power"
#define D_PRESSURE "气压"
#define D_PRESSUREATSEALEVEL "海平面气压"
#define D_PROGRAM_FLASH_SIZE "固件 Flash 大小"
@ -479,6 +482,8 @@
#define D_UNIT_PRESSURE "百帕"
#define D_UNIT_SECOND "秒"
#define D_UNIT_SECTORS "扇区"
#define D_UNIT_VA "VA"
#define D_UNIT_VAR "VAr"
#define D_UNIT_VOLT "伏"
#define D_UNIT_WATT "瓦"
#define D_UNIT_WATTHOUR "瓦时"

View File

@ -121,6 +121,9 @@
#define D_PORT "端口"
#define D_POWER_FACTOR "功率因數"
#define D_POWERUSAGE "功率"
#define D_POWERUSAGE_ACTIVE "Active Power"
#define D_POWERUSAGE_APPARENT "Apparent Power"
#define D_POWERUSAGE_REACTIVE "Reactive Power"
#define D_PRESSURE "氣壓"
#define D_PRESSUREATSEALEVEL "海平面氣壓"
#define D_PROGRAM_FLASH_SIZE "韌體 Flash 大小"
@ -479,6 +482,8 @@
#define D_UNIT_PRESSURE "百帕"
#define D_UNIT_SECOND "秒"
#define D_UNIT_SECTORS "扇區"
#define D_UNIT_VA "VA"
#define D_UNIT_VAR "VAr"
#define D_UNIT_VOLT "伏"
#define D_UNIT_WATT "瓦"
#define D_UNIT_WATTHOUR "瓦時"

View File

@ -292,6 +292,7 @@
#define USE_PZEM004T // Add support for PZEM004T Energy monitor (+2k code)
#define USE_SERIAL_BRIDGE // Add support for software Serial Bridge (+0k8 code)
#define USE_SDM120 // Add support for Eastron SDM120-Modbus energy meter (+1k2 code)
#define SDM120_SPEED 9600 // SDM120-Modbus RS485 serial speed (default: 2400 baud)
// -- Low level interface devices -----------------
#define USE_IR_REMOTE // Send IR remote commands using library IRremoteESP8266 and ArduinoJson (+4k code, 0k3 mem, 48 iram)

View File

@ -34,7 +34,9 @@ uint8_t sdm120_state = 0;
float sdm120_voltage = 0;
float sdm120_current = 0;
float sdm120_power = 0;
float sdm120_active_power = 0;
float sdm120_apparent_power = 0;
float sdm120_reactive_power = 0;
float sdm120_power_factor = 0;
float sdm120_frequency = 0;
float sdm120_energy_total = 0;
@ -123,8 +125,8 @@ const uint16_t sdm_start_addresses[] {
0x0000, // SDM120C_VOLTAGE [V]
0x0006, // SDM120C_CURRENT [A]
0x000C, // SDM120C_POWER [W]
0x0012, // SDM120C_ACTIVE_APPARENT_POWER [VA]
0x0018, // SDM120C_REACTIVE_APPARENT_POWER [VAR]
0x0012, // SDM120C_APPARENT_POWER [VA]
0x0018, // SDM120C_REACTIVE_POWER [VAR]
0x001E, // SDM120C_POWER_FACTOR
0x0046, // SDM120C_FREQUENCY [Hz]
0x0048, // SDM120C_IMPORT_ACTIVE_ENERGY [Wh]
@ -160,7 +162,15 @@ void SDM12050ms() // Every 50 mSec
break;
case 2:
sdm120_power = value;
sdm120_active_power = value;
break;
case 3:
sdm120_apparent_power = value;
break;
case 4:
sdm120_reactive_power = value;
break;
case 5:
@ -198,7 +208,11 @@ void SDM120Init()
sdm120_type = 0;
if ((pin[GPIO_SDM120_RX] < 99) && (pin[GPIO_SDM120_TX] < 99)) {
SDM120Serial = new TasmotaSerial(pin[GPIO_SDM120_RX], pin[GPIO_SDM120_TX], 1);
if (SDM120Serial->begin(9600)) {
#ifdef SDM120_SPEED
if (SDM120Serial->begin(SDM120_SPEED)) {
#else
if (SDM120Serial->begin(2400)) {
#endif
if (SDM120Serial->hardwareSerial()) { ClaimSerial(); }
sdm120_type = 1;
}
@ -209,7 +223,9 @@ void SDM120Init()
const char HTTP_SNS_SDM120_DATA[] PROGMEM = "%s"
"{s}SDM120 " D_VOLTAGE "{m}%s " D_UNIT_VOLT "{e}"
"{s}SDM120 " D_CURRENT "{m}%s " D_UNIT_AMPERE "{e}"
"{s}SDM120 " D_POWERUSAGE "{m}%s " D_UNIT_WATT "{e}"
"{s}SDM120 " D_POWERUSAGE_ACTIVE "{m}%s " D_UNIT_WATT "{e}"
"{s}SDM120 " D_POWERUSAGE_APPARENT "{m}%s " D_UNIT_VA "{e}"
"{s}SDM120 " D_POWERUSAGE_REACTIVE "{m}%s " D_UNIT_VAR "{e}"
"{s}SDM120 " D_POWER_FACTOR "{m}%s{e}"
"{s}SDM120 " D_FREQUENCY "{m}%s " D_UNIT_HERTZ "{e}"
"{s}SDM120 " D_ENERGY_TOTAL "{m}%s " D_UNIT_KILOWATTHOUR "{e}";
@ -219,31 +235,35 @@ void SDM120Show(boolean json)
{
char voltage[10];
char current[10];
char power[10];
char active_power[10];
char apparent_power[10];
char reactive_power[10];
char power_factor[10];
char frequency[10];
char energy_total[10];
dtostrfd(sdm120_voltage, Settings.flag2.voltage_resolution, voltage);
dtostrfd(sdm120_current, Settings.flag2.current_resolution, current);
dtostrfd(sdm120_power, Settings.flag2.wattage_resolution, power);
dtostrfd(sdm120_active_power, Settings.flag2.wattage_resolution, active_power);
dtostrfd(sdm120_apparent_power, Settings.flag2.wattage_resolution, apparent_power);
dtostrfd(sdm120_reactive_power, Settings.flag2.wattage_resolution, reactive_power);
dtostrfd(sdm120_power_factor, 2, power_factor);
dtostrfd(sdm120_frequency, 2, frequency);
dtostrfd(sdm120_energy_total, Settings.flag2.energy_resolution, energy_total);
if (json) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_RSLT_ENERGY "\":{\"" D_JSON_TOTAL "\":%s,\"" D_JSON_POWERUSAGE "\":%s,\"" D_JSON_FREQUENCY "\":%s,\"" D_JSON_POWERFACTOR "\":%s,\"" D_JSON_VOLTAGE "\":%s,\"" D_JSON_CURRENT "\":%s}"),
mqtt_data, energy_total, power, frequency, power_factor, voltage, current);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_RSLT_ENERGY "\":{\"" D_JSON_TOTAL "\":%s,\"" D_JSON_ACTIVE_POWERUSAGE "\":%s,\"" D_JSON_APPARENT_POWERUSAGE "\":%s,\"" D_JSON_REACTIVE_POWERUSAGE "\":%s,\"" D_JSON_FREQUENCY "\":%s,\"" D_JSON_POWERFACTOR "\":%s,\"" D_JSON_VOLTAGE "\":%s,\"" D_JSON_CURRENT "\":%s}"),
mqtt_data, energy_total, active_power, apparent_power, reactive_power, frequency, power_factor, voltage, current);
#ifdef USE_DOMOTICZ
if (0 == tele_period) {
DomoticzSensor(DZ_VOLTAGE, voltage);
DomoticzSensor(DZ_CURRENT, current);
DomoticzSensorPowerEnergy((uint16_t)sdm120_power, energy_total);
DomoticzSensorPowerEnergy((uint16_t)sdm120_active_power, energy_total);
}
#endif // USE_DOMOTICZ
#ifdef USE_WEBSERVER
} else {
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_SDM120_DATA, mqtt_data, voltage, current, power, power_factor, frequency, energy_total);
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_SDM120_DATA, mqtt_data, voltage, current, active_power, apparent_power, reactive_power, power_factor, frequency, energy_total);
}
#endif // USE_WEBSERVER
}
@ -280,3 +300,4 @@ boolean Xsns23(byte function)
}
#endif // USE_SDM120