Browse Source

first poc for power set via mqtt

pull/109/head
Andreas Schiffler 3 years ago
parent
commit
dccd04ab42
  1. 1
      .gitignore
  2. 4
      tools/esp8266/defines.h
  3. 4
      tools/esp8266/hmInverter.h
  4. 16
      tools/esp8266/mqtt.h
  5. 1
      tools/esp8266/platformio.ini

1
.gitignore

@ -17,3 +17,4 @@ tools/esp8266/binaries
*.db *.db
*.suo *.suo
*.ipch *.ipch
tools/esp8266/.vscode/extensions.json

4
tools/esp8266/defines.h

@ -53,6 +53,7 @@ typedef struct {
#define INV_CH_CH_NAME_LEN MAX_NUM_INVERTERS * MAX_NAME_LENGTH * 4 // (4 channels) #define INV_CH_CH_NAME_LEN MAX_NUM_INVERTERS * MAX_NAME_LENGTH * 4 // (4 channels)
#define INV_INTERVAL_LEN 2 // uint16_t #define INV_INTERVAL_LEN 2 // uint16_t
#define INV_MAX_RTRY_LEN 1 // uint8_t #define INV_MAX_RTRY_LEN 1 // uint8_t
#define INV_PWR_LIM_LEN MAX_NUM_INVERTERS * 2 // uint16_t
#define PINOUT_LEN 3 // 3 pins: CS, CE, IRQ #define PINOUT_LEN 3 // 3 pins: CS, CE, IRQ
@ -89,8 +90,9 @@ typedef struct {
#define ADDR_INV_CH_NAME ADDR_INV_CH_PWR + INV_CH_CH_PWR_LEN #define ADDR_INV_CH_NAME ADDR_INV_CH_PWR + INV_CH_CH_PWR_LEN
#define ADDR_INV_INTERVAL ADDR_INV_CH_NAME + INV_CH_CH_NAME_LEN #define ADDR_INV_INTERVAL ADDR_INV_CH_NAME + INV_CH_CH_NAME_LEN
#define ADDR_INV_MAX_RTRY ADDR_INV_INTERVAL + INV_INTERVAL_LEN #define ADDR_INV_MAX_RTRY ADDR_INV_INTERVAL + INV_INTERVAL_LEN
#define ADDR_INV_PWR_LIM ADDR_INV_MAX_RTRY + INV_MAX_RTRY_LEN
#define ADDR_MQTT_ADDR ADDR_INV_MAX_RTRY + INV_MAX_RTRY_LEN #define ADDR_MQTT_ADDR ADDR_INV_PWR_LIM + INV_PWR_LIM_LEN
#define ADDR_MQTT_USER ADDR_MQTT_ADDR + MQTT_ADDR_LEN #define ADDR_MQTT_USER ADDR_MQTT_ADDR + MQTT_ADDR_LEN
#define ADDR_MQTT_PWD ADDR_MQTT_USER + MQTT_USER_LEN #define ADDR_MQTT_PWD ADDR_MQTT_USER + MQTT_USER_LEN
#define ADDR_MQTT_TOPIC ADDR_MQTT_PWD + MQTT_PWD_LEN #define ADDR_MQTT_TOPIC ADDR_MQTT_PWD + MQTT_PWD_LEN

4
tools/esp8266/hmInverter.h

@ -69,6 +69,8 @@ class Inverter {
uint8_t type; // integer which refers to inverter type uint8_t type; // integer which refers to inverter type
byteAssign_t* assign; // type of inverter byteAssign_t* assign; // type of inverter
uint8_t listLen; // length of assignments uint8_t listLen; // length of assignments
uint16_t powerLimit; // limit power output
bool powerLimitChange; // true if change needed
serial_u serial; // serial number as on barcode serial_u serial; // serial number as on barcode
serial_u radioId; // id converted to modbus serial_u radioId; // id converted to modbus
uint8_t channels; // number of PV channels (1-4) uint8_t channels; // number of PV channels (1-4)
@ -79,6 +81,8 @@ class Inverter {
Inverter() { Inverter() {
ts = 0; ts = 0;
powerLimit = -1; // 65535 W Limit -> unlimited
powerLimitChange = false;
} }
~Inverter() { ~Inverter() {

16
tools/esp8266/mqtt.h

@ -12,6 +12,8 @@
class mqtt { class mqtt {
public: public:
PubSubClient *mClient;
mqtt() { mqtt() {
mClient = new PubSubClient(mEspClient); mClient = new PubSubClient(mEspClient);
mAddressSet = false; mAddressSet = false;
@ -35,6 +37,10 @@ class mqtt {
snprintf(mTopic, MQTT_TOPIC_LEN, "%s", topic); snprintf(mTopic, MQTT_TOPIC_LEN, "%s", topic);
} }
void setCallback(void (*func)(const char* topic, byte* payload, unsigned int length)){
mClient->setCallback(func);
}
void sendMsg(const char *topic, const char *msg) { void sendMsg(const char *topic, const char *msg) {
//DPRINTLN(DBG_VERBOSE, F("mqtt.h:sendMsg")); //DPRINTLN(DBG_VERBOSE, F("mqtt.h:sendMsg"));
char top[64]; char top[64];
@ -79,25 +85,25 @@ class mqtt {
void loop() { void loop() {
//DPRINT(F("m")); //DPRINT(F("m"));
//if(!mClient->connected()) if(!mClient->connected())
// reconnect(); reconnect();
mClient->loop(); mClient->loop();
} }
private: private:
void reconnect(void) { void reconnect(void) {
//DPRINTLN(DBG_VERBOSE, F("mqtt.h:reconnect")); DPRINTLN(DBG_INFO, F("mqtt.h:reconnect"));
if(!mClient->connected()) { if(!mClient->connected()) {
if((strlen(mUser) > 0) && (strlen(mPwd) > 0)) if((strlen(mUser) > 0) && (strlen(mPwd) > 0))
mClient->connect(DEF_DEVICE_NAME, mUser, mPwd); mClient->connect(DEF_DEVICE_NAME, mUser, mPwd);
else else
mClient->connect(DEF_DEVICE_NAME); mClient->connect(DEF_DEVICE_NAME);
} }
mClient->subscribe("home/huette/powerset");
} }
WiFiClient mEspClient; WiFiClient mEspClient;
PubSubClient *mClient;
bool mAddressSet; bool mAddressSet;
uint16_t mPort; uint16_t mPort;
char mUser[MQTT_USER_LEN]; char mUser[MQTT_USER_LEN];

1
tools/esp8266/platformio.ini

@ -28,7 +28,6 @@ framework = arduino
board = nodemcuv2 board = nodemcuv2
monitor_speed = 115200 monitor_speed = 115200
board_build.f_cpu = 80000000L board_build.f_cpu = 80000000L
upload_port = /dev/ttyUSB0
lib_deps = lib_deps =
nrf24/RF24@1.4.2 nrf24/RF24@1.4.2

Loading…
Cancel
Save