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. 14
      tools/esp8266/mqtt.h
  5. 1
      tools/esp8266/platformio.ini

1
.gitignore

@ -17,3 +17,4 @@ tools/esp8266/binaries
*.db
*.suo
*.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_INTERVAL_LEN 2 // uint16_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
@ -89,8 +90,9 @@ typedef struct {
#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_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_PWD ADDR_MQTT_USER + MQTT_USER_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
byteAssign_t* assign; // type of inverter
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 radioId; // id converted to modbus
uint8_t channels; // number of PV channels (1-4)
@ -79,6 +81,8 @@ class Inverter {
Inverter() {
ts = 0;
powerLimit = -1; // 65535 W Limit -> unlimited
powerLimitChange = false;
}
~Inverter() {

14
tools/esp8266/mqtt.h

@ -12,6 +12,8 @@
class mqtt {
public:
PubSubClient *mClient;
mqtt() {
mClient = new PubSubClient(mEspClient);
mAddressSet = false;
@ -35,6 +37,10 @@ class mqtt {
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) {
//DPRINTLN(DBG_VERBOSE, F("mqtt.h:sendMsg"));
char top[64];
@ -79,24 +85,24 @@ class mqtt {
void loop() {
//DPRINT(F("m"));
//if(!mClient->connected())
// reconnect();
if(!mClient->connected())
reconnect();
mClient->loop();
}
private:
void reconnect(void) {
//DPRINTLN(DBG_VERBOSE, F("mqtt.h:reconnect"));
DPRINTLN(DBG_INFO, F("mqtt.h:reconnect"));
if(!mClient->connected()) {
if((strlen(mUser) > 0) && (strlen(mPwd) > 0))
mClient->connect(DEF_DEVICE_NAME, mUser, mPwd);
else
mClient->connect(DEF_DEVICE_NAME);
}
mClient->subscribe("home/huette/powerset");
}
WiFiClient mEspClient;
PubSubClient *mClient;
bool mAddressSet;
uint16_t mPort;

1
tools/esp8266/platformio.ini

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

Loading…
Cancel
Save