From 6637b51962c1f0f35f950d756424e501ee9d22dd Mon Sep 17 00:00:00 2001 From: Softwarecrash Date: Mon, 4 Sep 2023 11:19:46 +0200 Subject: [PATCH] add debug for qe and ql --- src/PI_Serial/QPIGS.h | 150 +++++++++++++++++++++++------------------- src/main.cpp | 15 +++-- 2 files changed, 92 insertions(+), 73 deletions(-) diff --git a/src/PI_Serial/QPIGS.h b/src/PI_Serial/QPIGS.h index 0458aad..3d7d5fb 100644 --- a/src/PI_Serial/QPIGS.h +++ b/src/PI_Serial/QPIGS.h @@ -95,92 +95,104 @@ static const char *const qallList[] = { bool PI_Serial::PIXX_QPIGS() { - byte protocolNum = 0; // for future use - - - String commandAnswerQALL = this->requestData("QALL"); - get.raw.qall = commandAnswerQALL; - if (commandAnswerQALL == "ERCRC") + if (protocol == PI30) { - return false; - } - // - String commandAnswerQPIGS = this->requestData("QPIGS"); - get.raw.qpigs = commandAnswerQPIGS; - if (commandAnswerQPIGS == "NAK") - return true; - if (commandAnswerQPIGS == "ERCRC") - return false; - byte commandAnswerLength = commandAnswerQPIGS.length(); - - // calculate the length with https://elmar-eigner.de/text-zeichen-laenge.html - if (commandAnswerLength >= 60 && commandAnswerLength <= 140) - { - if (commandAnswerLength <= 116) - { - protocolNum = 0; - } - else if (commandAnswerLength > 131) + byte protocolNum = 0; // for future use + String commandAnswerQALL = this->requestData("QALL"); + get.raw.qall = commandAnswerQALL; + if (commandAnswerQALL == "ERCRC") { - protocolNum = 1; + return false; } + // + String commandAnswerQPIGS = this->requestData("QPIGS"); + get.raw.qpigs = commandAnswerQPIGS; + if (commandAnswerQPIGS == "NAK") + return true; + if (commandAnswerQPIGS == "ERCRC") + return false; + byte commandAnswerLength = commandAnswerQPIGS.length(); - // Split the string into substrings - String strs[30]; // buffer for string splitting - int StringCount = 0; - while (commandAnswerQPIGS.length() > 0) + // calculate the length with https://elmar-eigner.de/text-zeichen-laenge.html + if (commandAnswerLength >= 60 && commandAnswerLength <= 140) { - int index = commandAnswerQPIGS.indexOf(delimiter); - if (index == -1) // No space found + if (commandAnswerLength <= 116) { - strs[StringCount++] = commandAnswerQPIGS; - break; + protocolNum = 0; } - else + else if (commandAnswerLength > 131) { - strs[StringCount++] = commandAnswerQPIGS.substring(0, index); - commandAnswerQPIGS = commandAnswerQPIGS.substring(index + 1); + protocolNum = 1; } - } - - for (unsigned int i = 0; i < sizeof qpigsList[protocolNum] / sizeof qpigsList[protocolNum][0]; i++) - { - if (!strs[i].isEmpty() && strcmp(qpigsList[protocolNum][i], "") != 0) - liveData[qpigsList[protocolNum][i]] = (int)(strs[i].toFloat() * 100 + 0.5) / 100.0; - } - // make some things pretty - liveData["Battery_Load"] = (liveData["Battery_Charge_Current"].as() - liveData["Battery_Discharge_Current"].as()); - liveData["PV_Input_Power"] = (liveData["PV_Input_Voltage"].as() * liveData["PV_Input_Current"].as()); - } - if (get.raw.qall != "NAK" || get.raw.qall != "ERCRC") - { - String strsQALL[30]; - // Split the string into substrings - int StringCountQALL = 0; - while (commandAnswerQALL.length() > 0) - { - int index = commandAnswerQALL.indexOf(delimiter); - if (index == -1) // No space found + // Split the string into substrings + String strs[30]; // buffer for string splitting + int StringCount = 0; + while (commandAnswerQPIGS.length() > 0) { - strsQALL[StringCountQALL++] = commandAnswerQALL; - break; + int index = commandAnswerQPIGS.indexOf(delimiter); + if (index == -1) // No space found + { + strs[StringCount++] = commandAnswerQPIGS; + break; + } + else + { + strs[StringCount++] = commandAnswerQPIGS.substring(0, index); + commandAnswerQPIGS = commandAnswerQPIGS.substring(index + 1); + } } - else + + for (unsigned int i = 0; i < sizeof qpigsList[protocolNum] / sizeof qpigsList[protocolNum][0]; i++) { - strsQALL[StringCountQALL++] = commandAnswerQALL.substring(0, index); - commandAnswerQALL = commandAnswerQALL.substring(index + 1); + if (!strs[i].isEmpty() && strcmp(qpigsList[protocolNum][i], "") != 0) + liveData[qpigsList[protocolNum][i]] = (int)(strs[i].toFloat() * 100 + 0.5) / 100.0; } + // make some things pretty + liveData["Battery_Load"] = (liveData["Battery_Charge_Current"].as() - liveData["Battery_Discharge_Current"].as()); + liveData["PV_Input_Power"] = (liveData["PV_Input_Voltage"].as() * liveData["PV_Input_Current"].as()); } - for (unsigned int i = 0; i < sizeof qallList / sizeof qallList[0]; i++) + if (get.raw.qall != "NAK" || get.raw.qall != "ERCRC") { - if (!strsQALL[i].isEmpty() && strcmp(qallList[i], "") != 0) - liveData[qallList[i]] = (int)(strsQALL[i].toFloat() * 100 + 0.5) / 100.0; + String strsQALL[30]; + // Split the string into substrings + int StringCountQALL = 0; + while (commandAnswerQALL.length() > 0) + { + int index = commandAnswerQALL.indexOf(delimiter); + if (index == -1) // No space found + { + strsQALL[StringCountQALL++] = commandAnswerQALL; + break; + } + else + { + strsQALL[StringCountQALL++] = commandAnswerQALL.substring(0, index); + commandAnswerQALL = commandAnswerQALL.substring(index + 1); + } + } + + for (unsigned int i = 0; i < sizeof qallList / sizeof qallList[0]; i++) + { + if (!strsQALL[i].isEmpty() && strcmp(qallList[i], "") != 0) + liveData[qallList[i]] = (int)(strsQALL[i].toFloat() * 100 + 0.5) / 100.0; + } + liveData["Inverter_Operation_Mode"] = getModeDesc((char)liveData["Inverter_Operation_Mode"].as().charAt(0)); + liveData["Battery_Load"] = (liveData["Battery_Charge_Current"].as() - liveData["Battery_Discharge_Current"].as()); } - liveData["Inverter_Operation_Mode"] = getModeDesc((char)liveData["Inverter_Operation_Mode"].as().charAt(0)); - liveData["Battery_Load"] = (liveData["Battery_Charge_Current"].as() - liveData["Battery_Discharge_Current"].as()); + return true; + } + else if (protocol == PI18) + { + return true; + } + else if (protocol == NoD) + { + return false; + } + else + { + return false; } - - return true; } \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 2210816..f8b58d9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -429,8 +429,8 @@ void setup() // #endif server.begin(); - //mppClient.setProtocol(100); // manual set the protocol - mppClient.Init(); // init the PI_serial Library + // mppClient.setProtocol(100); // manual set the protocol + mppClient.Init(); // init the PI_serial Library mppClient.callback(prozessData); mqtttimer = (settings.data.mqttRefresh * 1000) * (-1); @@ -450,13 +450,12 @@ void loop() getJsonData(); mppClient.loop(); // Call the PI Serial Library loop mqttclient.loop(); // Check if we have something to read from MQTT - + if (millis() - mqtttimer > (settings.data.mqttRefresh * 1000)) { sendtoMQTT(); // Update data to MQTT server if we should mqtttimer = millis(); } - } if (restartNow && millis() >= (RestartTimer + 500)) { @@ -606,7 +605,15 @@ bool sendtoMQTT() mqttclient.publish(topicBuilder(buff, "RAW/QPIGS"), (mppClient.get.raw.qpigs).c_str()); mqttclient.publish(topicBuilder(buff, "RAW/QPIGS2"), (mppClient.get.raw.qpigs2).c_str()); mqttclient.publish(topicBuilder(buff, "RAW/QPIRI"), (mppClient.get.raw.qpiri).c_str()); + mqttclient.publish(topicBuilder(buff, "RAW/QT"), (mppClient.get.raw.qt).c_str()); mqttclient.publish(topicBuilder(buff, "RAW/QET"), (mppClient.get.raw.qet).c_str()); + mqttclient.publish(topicBuilder(buff, "RAW/QEY"), (mppClient.get.raw.qey).c_str()); + mqttclient.publish(topicBuilder(buff, "RAW/QEM"), (mppClient.get.raw.qem).c_str()); + mqttclient.publish(topicBuilder(buff, "RAW/QED"), (mppClient.get.raw.qed).c_str()); + mqttclient.publish(topicBuilder(buff, "RAW/QLT"), (mppClient.get.raw.qt).c_str()); + mqttclient.publish(topicBuilder(buff, "RAW/QLY"), (mppClient.get.raw.qly).c_str()); + mqttclient.publish(topicBuilder(buff, "RAW/QLM"), (mppClient.get.raw.qlm).c_str()); + mqttclient.publish(topicBuilder(buff, "RAW/QLD"), (mppClient.get.raw.qld).c_str()); mqttclient.publish(topicBuilder(buff, "RAW/QPI"), (mppClient.get.raw.qpi).c_str()); mqttclient.publish(topicBuilder(buff, "RAW/QMOD"), (mppClient.get.raw.qmod).c_str()); mqttclient.publish(topicBuilder(buff, "RAW/QALL"), (mppClient.get.raw.qall).c_str());