mirror of
https://github.com/lumapu/ahoy.git
synced 2025-05-15 18:06:39 +02:00
Merge branch 'main' into main
This commit is contained in:
commit
6256c7a178
9 changed files with 197 additions and 15 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -17,3 +17,4 @@ tools/esp8266/binaries
|
||||||
*.db
|
*.db
|
||||||
*.suo
|
*.suo
|
||||||
*.ipch
|
*.ipch
|
||||||
|
tools/esp8266/.vscode/extensions.json
|
||||||
|
|
|
@ -62,6 +62,7 @@ void app::setup(uint32_t timeout) {
|
||||||
mWeb->on("/hoymiles", std::bind(&app::showHoymiles, this));
|
mWeb->on("/hoymiles", std::bind(&app::showHoymiles, this));
|
||||||
mWeb->on("/livedata", std::bind(&app::showLiveData, this));
|
mWeb->on("/livedata", std::bind(&app::showLiveData, this));
|
||||||
mWeb->on("/json", std::bind(&app::showJSON, this));
|
mWeb->on("/json", std::bind(&app::showJSON, this));
|
||||||
|
mWeb->on("/devcontrol", std::bind(&app::devControl, this));
|
||||||
|
|
||||||
if(mSettingsValid) {
|
if(mSettingsValid) {
|
||||||
mEep->read(ADDR_INV_INTERVAL, &mSendInterval);
|
mEep->read(ADDR_INV_INTERVAL, &mSendInterval);
|
||||||
|
@ -81,8 +82,10 @@ void app::setup(uint32_t timeout) {
|
||||||
if(0ULL != invSerial) {
|
if(0ULL != invSerial) {
|
||||||
iv = mSys->addInverter(name, invSerial, modPwr);
|
iv = mSys->addInverter(name, invSerial, modPwr);
|
||||||
if(NULL != iv) {
|
if(NULL != iv) {
|
||||||
DPRINTLN(DBG_INFO, F("add inverter: ") + String(name) + ", SN: " + String(invSerial, HEX));
|
mEep->read(ADDR_INV_PWR_LIM + (i * 2),&iv->powerLimit);
|
||||||
|
iv->devControlCmd = 11; // set active power limit
|
||||||
|
iv->devControlRequest = true; // set to true to update the active power limit from setup html page
|
||||||
|
DPRINTLN(DBG_INFO, F("add inverter: ") + String(name) + ", SN: " + String(invSerial, HEX) + ", Power Limit: " + String(iv->powerLimit));
|
||||||
for(uint8_t j = 0; j < 4; j++) {
|
for(uint8_t j = 0; j < 4; j++) {
|
||||||
mEep->read(ADDR_INV_CH_NAME + (i * 4 * MAX_NAME_LENGTH) + j * MAX_NAME_LENGTH, iv->chName[j], MAX_NAME_LENGTH);
|
mEep->read(ADDR_INV_CH_NAME + (i * 4 * MAX_NAME_LENGTH) + j * MAX_NAME_LENGTH, iv->chName[j], MAX_NAME_LENGTH);
|
||||||
}
|
}
|
||||||
|
@ -155,6 +158,7 @@ void app::setup(uint32_t timeout) {
|
||||||
mqttPort = 1883;
|
mqttPort = 1883;
|
||||||
|
|
||||||
mMqtt.setup(mqttAddr, mqttTopic, mqttUser, mqttPwd, mqttDevName, mqttPort);
|
mMqtt.setup(mqttAddr, mqttTopic, mqttUser, mqttPwd, mqttDevName, mqttPort);
|
||||||
|
mMqtt.mClient->setCallback(std::bind(&app::cbMqtt, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
|
||||||
mMqttTicker = 0;
|
mMqttTicker = 0;
|
||||||
|
|
||||||
mSerialTicker = 0;
|
mSerialTicker = 0;
|
||||||
|
@ -211,7 +215,7 @@ void app::setup(uint32_t timeout) {
|
||||||
void app::loop(void) {
|
void app::loop(void) {
|
||||||
DPRINTLN(DBG_VERBOSE, F("app::loop"));
|
DPRINTLN(DBG_VERBOSE, F("app::loop"));
|
||||||
Main::loop();
|
Main::loop();
|
||||||
|
|
||||||
mSys->Radio.loop();
|
mSys->Radio.loop();
|
||||||
|
|
||||||
yield();
|
yield();
|
||||||
|
@ -238,7 +242,7 @@ void app::loop(void) {
|
||||||
|
|
||||||
if(0 != len) {
|
if(0 != len) {
|
||||||
Inverter<> *iv = mSys->findInverter(&p->packet[1]);
|
Inverter<> *iv = mSys->findInverter(&p->packet[1]);
|
||||||
if(NULL != iv) {
|
if(NULL != iv && p->packet[0] == (0x15 + 0x80)) { // response from get all information command
|
||||||
uint8_t *pid = &p->packet[9];
|
uint8_t *pid = &p->packet[9];
|
||||||
if (*pid == 0x00) {
|
if (*pid == 0x00) {
|
||||||
DPRINT(DBG_DEBUG, "fragment number zero received and ignored");
|
DPRINT(DBG_DEBUG, "fragment number zero received and ignored");
|
||||||
|
@ -257,6 +261,23 @@ void app::loop(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(NULL != iv && p->packet[0] == (0x51 + 0x80)) { // response from dev control command
|
||||||
|
DPRINTLN(DBG_INFO, F("Response from devcontrol received"));
|
||||||
|
iv->devControlRequest = false;
|
||||||
|
if (p->packet[12] != 11 && iv->devControlCmd == 11){
|
||||||
|
// set back to last accpted limit
|
||||||
|
mEep->read(ADDR_INV_PWR_LIM + iv->id * 2, &iv->powerLimit);
|
||||||
|
DPRINTLN(DBG_INFO, F("Inverter has not accepted power limit set point"));
|
||||||
|
}
|
||||||
|
if (p->packet[12] == 11 && iv->devControlCmd == 11){ // ok inverter accepted the set point copy it to dtu eeprom
|
||||||
|
// on every reboot the dtu sets the power limit acc to the value in eeprom
|
||||||
|
mEep->write(ADDR_INV_PWR_LIM + iv->id * 2,iv->powerLimit);
|
||||||
|
updateCrc();
|
||||||
|
mEep->commit();
|
||||||
|
DPRINTLN(DBG_INFO, F("Inverter has accepted power limit set point, written to dtu eeprom"));
|
||||||
|
iv->devControlCmd = 0xff; // set to none known command.
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -365,8 +386,14 @@ void app::loop(void) {
|
||||||
if(mSerialDebug)
|
if(mSerialDebug)
|
||||||
DPRINTLN(DBG_DEBUG, F("app:loop WiFi WiFi.status ") + String(WiFi.status()) );
|
DPRINTLN(DBG_DEBUG, F("app:loop WiFi WiFi.status ") + String(WiFi.status()) );
|
||||||
DPRINTLN(DBG_INFO, F("Requesting Inverter SN ") + String(iv->serial.u64, HEX));
|
DPRINTLN(DBG_INFO, F("Requesting Inverter SN ") + String(iv->serial.u64, HEX));
|
||||||
mSys->Radio.sendTimePacket(iv->radioId.u64, mPayload[iv->id].ts);
|
if(iv->devControlRequest){
|
||||||
mRxTicker = 0;
|
if(mSerialDebug)
|
||||||
|
DPRINTLN(DBG_INFO, F("Devcontrol request ") + String(iv->devControlCmd) + F(" power limit ") + String(iv->powerLimit));
|
||||||
|
mSys->Radio.sendControlPacket(iv->radioId.u64,iv->devControlCmd ,uint16_t(iv->powerLimit));
|
||||||
|
} else {
|
||||||
|
mSys->Radio.sendTimePacket(iv->radioId.u64, mPayload[iv->id].ts);
|
||||||
|
mRxTicker = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(mSerialDebug)
|
else if(mSerialDebug)
|
||||||
|
@ -508,10 +535,12 @@ void app::showSetup(void) {
|
||||||
uint64_t invSerial;
|
uint64_t invSerial;
|
||||||
char name[MAX_NAME_LENGTH + 1] = {0};
|
char name[MAX_NAME_LENGTH + 1] = {0};
|
||||||
uint16_t modPwr[4];
|
uint16_t modPwr[4];
|
||||||
|
uint16_t invActivePowerLimit = -1;
|
||||||
for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i ++) {
|
for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i ++) {
|
||||||
mEep->read(ADDR_INV_ADDR + (i * 8), &invSerial);
|
mEep->read(ADDR_INV_ADDR + (i * 8), &invSerial);
|
||||||
mEep->read(ADDR_INV_NAME + (i * MAX_NAME_LENGTH), name, MAX_NAME_LENGTH);
|
mEep->read(ADDR_INV_NAME + (i * MAX_NAME_LENGTH), name, MAX_NAME_LENGTH);
|
||||||
mEep->read(ADDR_INV_CH_PWR + (i * 2 * 4), modPwr, 4);
|
mEep->read(ADDR_INV_CH_PWR + (i * 2 * 4), modPwr, 4);
|
||||||
|
mEep->read(ADDR_INV_PWR_LIM + (i * 2),&invActivePowerLimit);
|
||||||
inv += F("<p class=\"subdes\">Inverter ") + String(i) + "</p>";
|
inv += F("<p class=\"subdes\">Inverter ") + String(i) + "</p>";
|
||||||
|
|
||||||
inv += F("<label for=\"inv") + String(i) + F("Addr\">Address</label>");
|
inv += F("<label for=\"inv") + String(i) + F("Addr\">Address</label>");
|
||||||
|
@ -525,6 +554,12 @@ void app::showSetup(void) {
|
||||||
inv += String(name);
|
inv += String(name);
|
||||||
inv += F("\"/ maxlength=\"") + String(MAX_NAME_LENGTH) + "\">";
|
inv += F("\"/ maxlength=\"") + String(MAX_NAME_LENGTH) + "\">";
|
||||||
|
|
||||||
|
inv += F("<label for=\"inv") + String(i) + F("ActivePowerLimit\">Active Power Limit (W)</label>");
|
||||||
|
inv += F("<input type=\"text\" class=\"text\" name=\"inv") + String(i) + F("ActivePowerLimit\" value=\"");
|
||||||
|
inv += String(invActivePowerLimit);
|
||||||
|
inv += F("\"/ maxlength=\"") + String(6) + "\">";
|
||||||
|
|
||||||
|
|
||||||
inv += F("<label for=\"inv") + String(i) + F("ModPwr0\" name=\"lbl") + String(i);
|
inv += F("<label for=\"inv") + String(i) + F("ModPwr0\" name=\"lbl") + String(i);
|
||||||
inv += F("ModPwr\">Max Module Power (Wp)</label>");
|
inv += F("ModPwr\">Max Module Power (Wp)</label>");
|
||||||
for(uint8_t j = 0; j < 4; j++) {
|
for(uint8_t j = 0; j < 4; j++) {
|
||||||
|
@ -623,6 +658,77 @@ void app::showErase() {
|
||||||
showReboot();
|
showReboot();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void app::cbMqtt(char* topic, byte* payload, unsigned int length) {
|
||||||
|
// callback handling on subscribed devcontrol topic
|
||||||
|
DPRINTLN(DBG_INFO, F("app::cbMqtt"));
|
||||||
|
// subcribed topics are mTopic + "/devcontrol/#" where # is <inverter_id>/<subcmd in dec>
|
||||||
|
// eg. mypvsolar/devcontrol/1/11 with payload "400" --> inverter 1 active power limit 400 Watt
|
||||||
|
const char *token = strtok(topic, "/");
|
||||||
|
while (token != NULL)
|
||||||
|
{
|
||||||
|
if (std::strcmp(token,"devcontrol")==0){
|
||||||
|
token = strtok(NULL, "/");
|
||||||
|
uint8_t iv_id = std::stoi(token);
|
||||||
|
if (iv_id >= 0 && iv_id <= MAX_NUM_INVERTERS){
|
||||||
|
Inverter<> *iv = this->mSys->getInverterByPos(iv_id);
|
||||||
|
if(NULL != iv) {
|
||||||
|
if (!iv->devControlRequest) { // still pending
|
||||||
|
token = strtok(NULL, "/");
|
||||||
|
uint8_t subcmd = std::stoi(token);
|
||||||
|
switch ( subcmd ){
|
||||||
|
case 11: // Active Power Control
|
||||||
|
if (true){ // if (std::stoi((char*)payload) > 0) error handling powerlimit needed?
|
||||||
|
iv->devControlCmd = 11;
|
||||||
|
iv->powerLimit = std::stoi((char*)payload);
|
||||||
|
DPRINTLN(DBG_INFO, F("Power limit for inverter ") + String(iv->id) + F(" set to ") + String(iv->powerLimit) + F("W") );
|
||||||
|
}
|
||||||
|
iv->devControlRequest = true;
|
||||||
|
break;
|
||||||
|
case 0: // Turn On
|
||||||
|
iv->devControlCmd = 0;
|
||||||
|
DPRINTLN(DBG_INFO, F("Turn on inverter ") + String(iv->id) );
|
||||||
|
iv->devControlRequest = true;
|
||||||
|
break;
|
||||||
|
case 1: // Turn Off
|
||||||
|
iv->devControlCmd = 1;
|
||||||
|
DPRINTLN(DBG_INFO, F("Turn off inverter ") + String(iv->id) );
|
||||||
|
iv->devControlRequest = true;
|
||||||
|
break;
|
||||||
|
case 2: // Restart
|
||||||
|
iv->devControlCmd = 2;
|
||||||
|
DPRINTLN(DBG_INFO, F("Restart inverter ") + String(iv->id) );
|
||||||
|
iv->devControlRequest = true;
|
||||||
|
break;
|
||||||
|
case 12: // Reactive Power Control
|
||||||
|
// iv->devControlCmd = 12;
|
||||||
|
// uint16_t reactive_power = std::stoi(strtok(NULL, "/"));
|
||||||
|
// .../devcontrol/<inverter_id>/<subcmd in dec>/<value in dec>
|
||||||
|
// ^^^
|
||||||
|
DPRINTLN(DBG_INFO, F("Reactive Power Control not implemented for inverter ") + String(iv->id) );
|
||||||
|
break;
|
||||||
|
case 13: // Set Power Factor
|
||||||
|
// iv->devControlCmd = 13;
|
||||||
|
// uint16_t power_factor = std::stoi(strtok(NULL, "/"));
|
||||||
|
// .../devcontrol/<inverter_id>/<subcmd in dec>/<value in dec>
|
||||||
|
// ^^^
|
||||||
|
DPRINTLN(DBG_INFO, F("Set Power Factor not implemented for inverter ") + String(iv->id) );
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
DPRINTLN(DBG_INFO, "Not implemented");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
token = strtok(NULL, "/");
|
||||||
|
}
|
||||||
|
DPRINTLN(DBG_INFO, F("app::cbMqtt finished"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void app::showStatistics(void) {
|
void app::showStatistics(void) {
|
||||||
|
@ -674,6 +780,19 @@ void app::showStatistics(void) {
|
||||||
mWeb->send(200, F("text/plain"), content);
|
mWeb->send(200, F("text/plain"), content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void app::devControl(void) { // ToDo
|
||||||
|
DPRINTLN(DBG_VERBOSE, F("app::devControl"));
|
||||||
|
if(mWeb->args() > 0) {
|
||||||
|
//mWeb->arg("ivid").toChar...
|
||||||
|
// get iv
|
||||||
|
// set devControl on/off/power limt --> integrate buttons in app::showLiveData
|
||||||
|
// ...
|
||||||
|
mWeb->send(200, F("text/html"), F("<!doctype html><html><head><title>Command sent</title><meta http-equiv=\"refresh\" content=\"2; URL=/hoymiles\"></head><body>"
|
||||||
|
"<p>sent</p></body></html>"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void app::showHoymiles(void) {
|
void app::showHoymiles(void) {
|
||||||
|
@ -713,7 +832,7 @@ void app::showLiveData(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
modHtml += F("<div class=\"iv\">"
|
modHtml += F("<div class=\"iv\">"
|
||||||
"<div class=\"ch-iv\"><span class=\"head\">") + String(iv->name) + F("</span>");
|
"<div class=\"ch-iv\"><span class=\"head\">") + String(iv->name) + F(" Limit ") + String(iv->powerLimit) + F(" W</span>");
|
||||||
uint8_t list[] = {FLD_UAC, FLD_IAC, FLD_PAC, FLD_F, FLD_PCT, FLD_T, FLD_YT, FLD_YD, FLD_PDC, FLD_EFF};
|
uint8_t list[] = {FLD_UAC, FLD_IAC, FLD_PAC, FLD_F, FLD_PCT, FLD_T, FLD_YT, FLD_YD, FLD_PDC, FLD_EFF};
|
||||||
|
|
||||||
for(uint8_t fld = 0; fld < 10; fld++) {
|
for(uint8_t fld = 0; fld < 10; fld++) {
|
||||||
|
@ -808,6 +927,7 @@ void app::saveValues(bool webSend = true) {
|
||||||
char buf[20] = {0};
|
char buf[20] = {0};
|
||||||
uint8_t i = 0;
|
uint8_t i = 0;
|
||||||
uint16_t interval;
|
uint16_t interval;
|
||||||
|
uint16_t activepowerlimit=-1;
|
||||||
|
|
||||||
// inverter
|
// inverter
|
||||||
serial_u addr;
|
serial_u addr;
|
||||||
|
@ -819,6 +939,10 @@ void app::saveValues(bool webSend = true) {
|
||||||
addr.u64 = Serial2u64(buf);
|
addr.u64 = Serial2u64(buf);
|
||||||
mEep->write(ADDR_INV_ADDR + (i * 8), addr.u64);
|
mEep->write(ADDR_INV_ADDR + (i * 8), addr.u64);
|
||||||
|
|
||||||
|
// active power limit
|
||||||
|
activepowerlimit = mWeb->arg("inv" + String(i) + "ActivePowerLimit").toInt();
|
||||||
|
mEep->write(ADDR_INV_PWR_LIM + i * 2,activepowerlimit);
|
||||||
|
|
||||||
// name
|
// name
|
||||||
mWeb->arg("inv" + String(i) + "Name").toCharArray(buf, 20);
|
mWeb->arg("inv" + String(i) + "Name").toCharArray(buf, 20);
|
||||||
mEep->write(ADDR_INV_NAME + (i * MAX_NAME_LENGTH), buf, MAX_NAME_LENGTH);
|
mEep->write(ADDR_INV_NAME + (i * MAX_NAME_LENGTH), buf, MAX_NAME_LENGTH);
|
||||||
|
|
|
@ -51,6 +51,7 @@ class app : public Main {
|
||||||
void setup(uint32_t timeout);
|
void setup(uint32_t timeout);
|
||||||
void loop(void);
|
void loop(void);
|
||||||
void handleIntr(void);
|
void handleIntr(void);
|
||||||
|
void cbMqtt(char* topic, byte* payload, unsigned int length);
|
||||||
|
|
||||||
uint8_t app_loops;
|
uint8_t app_loops;
|
||||||
uint8_t getIrqPin(void) {
|
uint8_t getIrqPin(void) {
|
||||||
|
@ -70,6 +71,7 @@ class app : public Main {
|
||||||
void showHoymiles(void);
|
void showHoymiles(void);
|
||||||
void showLiveData(void);
|
void showLiveData(void);
|
||||||
void showJSON(void);
|
void showJSON(void);
|
||||||
|
void devControl(void);
|
||||||
|
|
||||||
|
|
||||||
void saveValues(bool webSend);
|
void saveValues(bool webSend);
|
||||||
|
|
|
@ -20,8 +20,8 @@
|
||||||
// VERSION
|
// VERSION
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
#define VERSION_MAJOR 0
|
#define VERSION_MAJOR 0
|
||||||
#define VERSION_MINOR 4
|
#define VERSION_MINOR 5
|
||||||
#define VERSION_PATCH 25
|
#define VERSION_PATCH 1
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
@ -92,6 +93,7 @@ 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_NTP_ADDR ADDR_INV_MAX_RTRY + INV_MAX_RTRY_LEN
|
#define ADDR_NTP_ADDR ADDR_INV_MAX_RTRY + INV_MAX_RTRY_LEN
|
||||||
#define ADDR_NTP_PORT ADDR_NTP_ADDR + NTP_ADDR_LEN
|
#define ADDR_NTP_PORT ADDR_NTP_ADDR + NTP_ADDR_LEN
|
||||||
|
|
|
@ -69,6 +69,9 @@ 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
|
||||||
|
uint8_t devControlCmd; // carries the requested cmd
|
||||||
|
bool devControlRequest; // 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 +82,9 @@ class Inverter {
|
||||||
|
|
||||||
Inverter() {
|
Inverter() {
|
||||||
ts = 0;
|
ts = 0;
|
||||||
|
powerLimit = -1; // 65535 W Limit -> unlimited
|
||||||
|
devControlRequest = false;
|
||||||
|
devControlCmd = 0xff;
|
||||||
}
|
}
|
||||||
|
|
||||||
~Inverter() {
|
~Inverter() {
|
||||||
|
|
|
@ -159,6 +159,39 @@ class HmRadio {
|
||||||
return mRfChLst[mTxChIdx];
|
return mRfChLst[mTxChIdx];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sendControlPacket(uint64_t invId, uint8_t cmd, uint16_t data) {
|
||||||
|
DPRINTLN(DBG_VERBOSE, F("hmRadio.h:sendControlPacket"));
|
||||||
|
// sendCmdPacket(invId, 0x51, 0x80, false); // 0x80 implementation as original DTU code
|
||||||
|
sendCmdPacket(invId, 0x51, 0x81, false);
|
||||||
|
int cnt = 0;
|
||||||
|
mTxBuf[10] = cmd; // cmd --> 0x0b => Type_ActivePowerContr, 0 on, 1 off, 2 restart, 12 reactive power, 13 power factor
|
||||||
|
mTxBuf[10 + (++cnt)] = 0x00;
|
||||||
|
if (cmd == 11){
|
||||||
|
// 4 bytes control data
|
||||||
|
// Power Limit fix point 10 eg. 30 W --> 0d300 = 0x012c
|
||||||
|
// -1 = 0xffff --> no limit
|
||||||
|
if (data == 0xffff){
|
||||||
|
data &= 0xffff; // ToDo: unlimit value is needed and is inverter specific! --> get it via RF from inverter or via user interface
|
||||||
|
} else {
|
||||||
|
data*= 10;
|
||||||
|
}
|
||||||
|
mTxBuf[10 + (++cnt)] = (data >> 8) & 0xff; // 0x01
|
||||||
|
mTxBuf[10 + (++cnt)] = (data ) & 0xff; // 0x2c
|
||||||
|
// mTxBuf[10 + (++cnt)] = 0x00; // not persistent
|
||||||
|
mTxBuf[10 + (++cnt)] = 0x01; // persistent
|
||||||
|
mTxBuf[10 + (++cnt)] = 0x00;
|
||||||
|
}
|
||||||
|
// crc control data
|
||||||
|
uint16_t crc = crc16(&mTxBuf[10], cnt+1);
|
||||||
|
mTxBuf[10 + (++cnt)] = (crc >> 8) & 0xff;
|
||||||
|
mTxBuf[10 + (++cnt)] = (crc ) & 0xff;
|
||||||
|
// crc over all
|
||||||
|
cnt +=1;
|
||||||
|
mTxBuf[10 + cnt] = crc8(mTxBuf, 10 + cnt);
|
||||||
|
|
||||||
|
sendPacket(invId, mTxBuf, 10 + (++cnt), true);
|
||||||
|
}
|
||||||
|
|
||||||
void sendTimePacket(uint64_t invId, uint32_t ts) {
|
void sendTimePacket(uint64_t invId, uint32_t ts) {
|
||||||
//DPRINTLN(DBG_VERBOSE, F("hmRadio.h:sendTimePacket"));
|
//DPRINTLN(DBG_VERBOSE, F("hmRadio.h:sendTimePacket"));
|
||||||
sendCmdPacket(invId, 0x15, 0x80, false);
|
sendCmdPacket(invId, 0x15, 0x80, false);
|
||||||
|
|
|
@ -71,6 +71,7 @@ void Main::setup(uint32_t timeout) {
|
||||||
|
|
||||||
mUpdater->setup(mWeb);
|
mUpdater->setup(mWeb);
|
||||||
mApActive = startAp;
|
mApActive = startAp;
|
||||||
|
mStActive = !startAp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -121,6 +122,10 @@ void Main::loop(void) {
|
||||||
stats();
|
stats();
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
if (WiFi.status() != WL_CONNECTED) {
|
||||||
|
DPRINTLN(DBG_INFO, "[WiFi]: Connection Lost");
|
||||||
|
mStActive = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -118,6 +118,7 @@ class Main {
|
||||||
bool mWifiSettingsValid;
|
bool mWifiSettingsValid;
|
||||||
bool mSettingsValid;
|
bool mSettingsValid;
|
||||||
bool mApActive;
|
bool mApActive;
|
||||||
|
bool mStActive;
|
||||||
ESP8266WebServer *mWeb;
|
ESP8266WebServer *mWeb;
|
||||||
char mVersion[9];
|
char mVersion[9];
|
||||||
char mDeviceName[DEVNAME_LEN];
|
char mDeviceName[DEVNAME_LEN];
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -40,6 +42,10 @@ class mqtt {
|
||||||
mClient->setBufferSize(MQTT_MAX_PACKET_SIZE);
|
mClient->setBufferSize(MQTT_MAX_PACKET_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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];
|
||||||
|
@ -94,8 +100,8 @@ class mqtt {
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
//DPRINT(F("m"));
|
//DPRINT(F("m"));
|
||||||
//if(!mClient->connected())
|
if(!mClient->connected())
|
||||||
// reconnect();
|
reconnect();
|
||||||
mClient->loop();
|
mClient->loop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,13 +122,15 @@ class mqtt {
|
||||||
mClient->connect(mDevName);
|
mClient->connect(mDevName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DPRINTLN(DBG_DEBUG, F("MQTT mClient->_state ") + String(mClient->state()) );
|
char topic[MQTT_TOPIC_LEN + 13 ]; // "/devcontrol/#" --> + 6 byte
|
||||||
DPRINTLN(DBG_DEBUG, F("WIFI mEspClient.status ") + String(mEspClient.status()) );
|
// ToDo: "/devcontrol/#" is hardcoded
|
||||||
|
snprintf(topic, MQTT_TOPIC_LEN + 13, "%s/devcontrol/#", mTopic);
|
||||||
|
DPRINTLN(DBG_INFO, F("subscribe to ") + String(topic));
|
||||||
|
mClient->subscribe(topic); // subscribe to mTopic + "/devcontrol/#"
|
||||||
}
|
}
|
||||||
|
|
||||||
WiFiClient mEspClient;
|
WiFiClient mEspClient;
|
||||||
PubSubClient *mClient;
|
|
||||||
|
|
||||||
bool mAddressSet;
|
bool mAddressSet;
|
||||||
uint16_t mPort;
|
uint16_t mPort;
|
||||||
char mBroker[MQTT_ADDR_LEN];
|
char mBroker[MQTT_ADDR_LEN];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue