Skip to content

Commit

Permalink
Generic SML based power meters support (#146)
Browse files Browse the repository at this point in the history
* add support for energy & power readings on SML based power meters, taking OBIS 16.7.1 for power (using mod. SML Parser lib. by olliiiver)

* switched SML read to use software serial

* made total power meter response controled by meter source to obtain either the sum of phase powers or explicit total power provided by meter

* made mqtt subscriptions to power meter topics meter source dependend

* simplified SML read loop and OBIS handler registration, + minor refactoring

* minor cleanup/style changes and optim. PowerMeter

* fixed build, add SOURCE_SML == 4

* removed optional usage of HW serial for SML power meter

* switched to usage of _powerMeter1Power for SML power reading to allign better with existing code

---------

Co-authored-by: helgeerbe <helge@erbehome.de>
  • Loading branch information
qubeck and helgeerbe committed Apr 7, 2023
1 parent fd94a69 commit 00def1d
Show file tree
Hide file tree
Showing 9 changed files with 637 additions and 16 deletions.
24 changes: 21 additions & 3 deletions include/PowerMeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <Hoymiles.h>
#include <memory>
#include "SDM.h"
#include "sml.h"

#ifndef SDM_RX_PIN
#define SDM_RX_PIN 13
Expand All @@ -16,13 +17,24 @@
#define SDM_TX_PIN 32
#endif

#ifndef SML_RX_PIN
#define SML_RX_PIN 35
#endif

typedef struct {
const unsigned char OBIS[6];
void (*Fn)(double&);
float* Arg;
} OBISHandler;

class PowerMeterClass {
public:
enum SOURCE {
SOURCE_MQTT = 0,
SOURCE_SDM1PH = 1,
SOURCE_SDM3PH = 2,
SOURCE_HTTP = 3,
SOURCE_SML = 4
};
void init();
void mqtt();
Expand All @@ -40,14 +52,20 @@ class PowerMeterClass {
float _powerMeter1Power = 0.0;
float _powerMeter2Power = 0.0;
float _powerMeter3Power = 0.0;
float _powerMeterTotalPower = 0.0;
float _powerMeter1Voltage = 0.0;
float _powerMeter2Voltage = 0.0;
float _powerMeter3Voltage = 0.0;
float _PowerMeterImport = 0.0;
float _PowerMeterExport = 0.0;
float _powerMeterImport = 0.0;
float _powerMeterExport = 0.0;

bool mqttInitDone = false;

bool smlReadLoop();
const std::list<OBISHandler> smlHandlerList{
{{0x01, 0x00, 0x10, 0x07, 0x00, 0xff}, &smlOBISW, &_powerMeter1Power},
{{0x01, 0x00, 0x01, 0x08, 0x00, 0xff}, &smlOBISWh, &_powerMeterImport},
{{0x01, 0x00, 0x02, 0x08, 0x00, 0xff}, &smlOBISWh, &_powerMeterExport}
};
};

extern PowerMeterClass PowerMeter;
Loading

0 comments on commit 00def1d

Please sign in to comment.