mirror of
https://github.com/lumapu/ahoy.git
synced 2025-05-10 23:46:37 +02:00
first poc set power limit via mqtt
This commit is contained in:
parent
6dba1d7577
commit
d41c26a3ce
3 changed files with 53 additions and 6 deletions
|
@ -81,8 +81,8 @@ void app::setup(uint32_t timeout) {
|
|||
if(0ULL != invSerial) {
|
||||
iv = mSys->addInverter(name, invSerial, modPwr);
|
||||
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);
|
||||
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++) {
|
||||
mEep->read(ADDR_INV_CH_NAME + (i * 4 * MAX_NAME_LENGTH) + j * MAX_NAME_LENGTH, iv->chName[j], MAX_NAME_LENGTH);
|
||||
}
|
||||
|
@ -148,6 +148,7 @@ void app::setup(uint32_t timeout) {
|
|||
mqttPort = 1883;
|
||||
|
||||
mMqtt.setup(mqttAddr, mqttTopic, mqttUser, mqttPwd, mqttPort);
|
||||
mMqtt.mClient->setCallback(std::bind(&app::cbMqtt, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
|
||||
mMqttTicker = 0;
|
||||
|
||||
mSerialTicker = 0;
|
||||
|
@ -229,7 +230,7 @@ void app::loop(void) {
|
|||
|
||||
if(0 != len) {
|
||||
Inverter<> *iv = mSys->findInverter(&p->packet[1]);
|
||||
if(NULL != iv) {
|
||||
if(NULL != iv && p->packet[0] == 0x95) {
|
||||
uint8_t *pid = &p->packet[9];
|
||||
if((*pid & 0x7F) < 5) {
|
||||
memcpy(mPayload[iv->id].data[(*pid & 0x7F) - 1], &p->packet[10], len-11);
|
||||
|
@ -349,10 +350,17 @@ void app::loop(void) {
|
|||
yield();
|
||||
if(mSerialDebug)
|
||||
DPRINTLN(DBG_INFO, F("Requesting Inverter SN ") + String(iv->serial.u64, HEX));
|
||||
if(iv->powerLimitChange){
|
||||
if(mSerialDebug)
|
||||
DPRINTLN(DBG_INFO, F("Requesting Inverter to change power limit to ") + String(iv->powerLimit));
|
||||
mSys->Radio.sendControlPacket(iv->radioId.u64, uint16_t(iv->powerLimit*10));
|
||||
iv->powerLimitChange = false;
|
||||
} else {
|
||||
mSys->Radio.sendTimePacket(iv->radioId.u64, mPayload[iv->id].ts);
|
||||
mRxTicker = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(mSerialDebug)
|
||||
DPRINTLN(DBG_WARN, F("time not set, can't request inverter!"));
|
||||
yield();
|
||||
|
@ -600,6 +608,22 @@ void app::showErase() {
|
|||
showReboot();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void app::cbMqtt(const char* topic, byte* payload, unsigned int length) {
|
||||
DPRINTLN(DBG_INFO, F("app::cbMqtt"));
|
||||
// DPRINTLN(DBG_INFO, topic);
|
||||
// ToDo check topic !
|
||||
int inverterId = 0; // ToDo get inverter id from topic
|
||||
Inverter<> *iv = this->mSys->getInverterByPos(inverterId);
|
||||
if(NULL != iv) {
|
||||
iv->powerLimit = std::stoi((char*)payload);
|
||||
iv->powerLimitChange = true;
|
||||
mEep->write(ADDR_INV_PWR_LIM + inverterId * 2,iv->powerLimit);
|
||||
DPRINTLN(DBG_INFO, F("Power limit for inverter ") + String(iv->id) + F(" set to ") + String(iv->powerLimit) + F("W") );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void app::showStatistics(void) {
|
||||
|
@ -690,7 +714,7 @@ void app::showLiveData(void) {
|
|||
}
|
||||
|
||||
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};
|
||||
|
||||
for(uint8_t fld = 0; fld < 10; fld++) {
|
||||
|
|
|
@ -51,6 +51,7 @@ class app : public Main {
|
|||
void setup(uint32_t timeout);
|
||||
void loop(void);
|
||||
void handleIntr(void);
|
||||
void cbMqtt(const char* topic, byte* payload, unsigned int length);
|
||||
|
||||
uint8_t app_loops;
|
||||
uint8_t getIrqPin(void) {
|
||||
|
|
|
@ -166,6 +166,28 @@ class HmRadio {
|
|||
return mTxChLst[mTxChIdx];
|
||||
}*/
|
||||
|
||||
void sendControlPacket(uint64_t invId, uint16_t data) {
|
||||
DPRINTLN(DBG_VERBOSE, F("hmRadio.h:sendControlPacket"));
|
||||
sendCmdPacket(invId, 0x51, 0x80, false);
|
||||
mTxBuf[10] = 0x0b; // control type --> 0x0b => Type_ActivePowerContr
|
||||
mTxBuf[11] = 0x00;
|
||||
// 4 bytes control data
|
||||
// Power Limit fix point 10 eg. 30 W --> 0d300 = 0x012c
|
||||
mTxBuf[12] = (data >> 8) & 0xff; // 0x01
|
||||
mTxBuf[13] = (data ) & 0xff; // 0x2c
|
||||
//
|
||||
mTxBuf[14] = 0x00;
|
||||
mTxBuf[15] = 0x00;
|
||||
// crc control data
|
||||
uint16_t crc = crc16(&mTxBuf[10], 6);
|
||||
mTxBuf[16] = (crc >> 8) & 0xff;
|
||||
mTxBuf[17] = (crc ) & 0xff;
|
||||
// crc over all
|
||||
mTxBuf[18] = crc8(mTxBuf, 18);
|
||||
|
||||
sendPacket(invId, mTxBuf, 19, true);
|
||||
}
|
||||
|
||||
void sendTimePacket(uint64_t invId, uint32_t ts) {
|
||||
//DPRINTLN(DBG_VERBOSE, F("hmRadio.h:sendTimePacket"));
|
||||
sendCmdPacket(invId, 0x15, 0x80, false);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue