Skip to content

Commit

Permalink
Merged in ToniAr/espurna/sonoff_pow_domoticz_energyincrement (pull re…
Browse files Browse the repository at this point in the history
…quest #11)

Add a separate incremental energy counter into the Domoticz MQTT interface
  • Loading branch information
ToniA authored and xoseperez committed Feb 10, 2017
2 parents 7e94eac + c1bbd6d commit b5e59e9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
6 changes: 4 additions & 2 deletions code/espurna/emon.ino
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ void powerMonitorLoop() {
snprintf(power, 6, "%d", _power);

double energy_inc = (double) _power * EMON_INTERVAL * EMON_MEASUREMENTS / 1000.0 / 3600.0;
char energy_buf[10];
dtostrf(energy_inc, 9, 2, energy_buf);
char energy_buf[11];
dtostrf(energy_inc, 11, 3, energy_buf);
char *e = energy_buf;
while ((unsigned char) *e == ' ') ++e;

Expand All @@ -171,6 +171,8 @@ void powerMonitorLoop() {
char buffer[20];
snprintf(buffer, 20, "%s;%s", power, e);
domoticzSend("dczPowIdx", 0, buffer);
snprintf(buffer, 20, "%s", e);
domoticzSend("dczEnergyIdx", 0, buffer);
snprintf(buffer, 20, "%d", voltage);
domoticzSend("dczVoltIdx", 0, buffer);
snprintf(buffer, 20, "%s", String(current).c_str());
Expand Down
6 changes: 4 additions & 2 deletions code/espurna/pow.ino
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ void powLoop() {
if (factor > 100) factor = 100;

double energy_inc = (double) power * POW_REPORT_EVERY * POW_UPDATE_INTERVAL / 1000.0 / 3600.0;
char energy_buf[10];
dtostrf(energy_inc, 9, 2, energy_buf);
char energy_buf[11];
dtostrf(energy_inc, 11, 3, energy_buf);
char *e = energy_buf;
while ((unsigned char) *e == ' ') ++e;

Expand All @@ -237,6 +237,8 @@ void powLoop() {
char buffer[20];
snprintf(buffer, 20, "%d;%s", power, e);
domoticzSend("dczPowIdx", 0, buffer);
snprintf(buffer, 20, "%s", e);
domoticzSend("dczEnergyIdx", 0, buffer);
snprintf(buffer, 20, "%d", voltage);
domoticzSend("dczVoltIdx", 0, buffer);
snprintf(buffer, 20, "%s", String(current).c_str());
Expand Down
2 changes: 2 additions & 0 deletions code/espurna/web.ino
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,14 @@ void _wsStart(uint32_t client_id) {

#if ENABLE_EMON
root["dczPowIdx"] = getSetting("dczPowIdx").toInt();
root["dczEnergyIdx"] = getSetting("dczEnergyIdx").toInt();
root["dczVoltIdx"] = getSetting("dczVoltIdx").toInt();
root["dczCurrentIdx"] = getSetting("dczCurrentIdx").toInt();
#endif

#if ENABLE_POW
root["dczPowIdx"] = getSetting("dczPowIdx").toInt();
root["dczEnergyIdx"] = getSetting("dczEnergyIdx").toInt();
root["dczVoltIdx"] = getSetting("dczVoltIdx").toInt();
root["dczCurrentIdx"] = getSetting("dczCurrentIdx").toInt();
#endif
Expand Down
10 changes: 8 additions & 2 deletions code/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -409,15 +409,21 @@ <h2>
<div class="pure-u-1 pure-u-sm-5-8 hint center">Set to 0 to disable notifications.</div>
</div>

<div class="pure-g module module-pow module-emon">
<label class="pure-u-1 pure-u-sm-1-4" for="dczEnergyIdx">Energy increment IDX</label>
<div class="pure-u-1 pure-u-sm-1-8"><input class="pure-u-sm-23-24" name="dczEnergyIdx" type="number" min="0" tabindex="36" data="0" /></div>
<div class="pure-u-1 pure-u-sm-5-8 hint center">Set to 0 to disable notifications.</div>
</div>

<div class="pure-g module module-pow module-emon">
<label class="pure-u-1 pure-u-sm-1-4" for="dczVoltIdx">Voltage IDX</label>
<div class="pure-u-1 pure-u-sm-1-8"><input class="pure-u-sm-23-24" name="dczVoltIdx" type="number" min="0" tabindex="36" data="0" /></div>
<div class="pure-u-1 pure-u-sm-1-8"><input class="pure-u-sm-23-24" name="dczVoltIdx" type="number" min="0" tabindex="37" data="0" /></div>
<div class="pure-u-1 pure-u-sm-5-8 hint center">Set to 0 to disable notifications.</div>
</div>

<div class="pure-g module module-pow module-emon">
<label class="pure-u-1 pure-u-sm-1-4" for="dczCurrentIdx">Current IDX</label>
<div class="pure-u-1 pure-u-sm-1-8"><input class="pure-u-sm-23-24" name="dczCurrentIdx" type="number" min="0" tabindex="36" data="0" /></div>
<div class="pure-u-1 pure-u-sm-1-8"><input class="pure-u-sm-23-24" name="dczCurrentIdx" type="number" min="0" tabindex="38" data="0" /></div>
<div class="pure-u-1 pure-u-sm-5-8 hint center">Set to 0 to disable notifications.</div>
</div>

Expand Down

0 comments on commit b5e59e9

Please sign in to comment.