diff --git a/platformio.ini b/platformio.ini index c140edb..3e31204 100644 --- a/platformio.ini +++ b/platformio.ini @@ -12,7 +12,7 @@ platform = espressif8266@4.2.1 framework = arduino monitor_speed = 115200 -custom_prog_version = 1.2.1 +custom_prog_version = 1.2.2 build_flags = -DVERSION=${this.custom_prog_version} -DPIO_SRC_NAM="Solar2MQTT" diff --git a/src/PI_Serial/PI_Serial.cpp b/src/PI_Serial/PI_Serial.cpp index 55fb3ed..3720e89 100644 --- a/src/PI_Serial/PI_Serial.cpp +++ b/src/PI_Serial/PI_Serial.cpp @@ -15,6 +15,7 @@ CRC16 crc; #include "QPIGS2.h" #include "QMOD.h" #include "QEX.h" +#include "QPIWS.h" extern void writeLog(const char *format, ...); //---------------------------------------------------------------------- // Public Functions @@ -85,6 +86,7 @@ bool PI_Serial::loop() break; } break; + case false: switch (requestCounter) { @@ -104,6 +106,9 @@ bool PI_Serial::loop() requestCounter = PIXX_QEX() ? (requestCounter + 1) : 0; break; case 5: + requestCounter = PIXX_QPIWS() ? (requestCounter + 1) : 0; + break; + case 6: requestCallback(); requestCounter = 0; break; diff --git a/src/PI_Serial/PI_Serial.h b/src/PI_Serial/PI_Serial.h index b1b9444..df9aaf1 100644 --- a/src/PI_Serial/PI_Serial.h +++ b/src/PI_Serial/PI_Serial.h @@ -1,7 +1,7 @@ #include "SoftwareSerial.h" #ifndef PI_SERIAL_H #define PI_SERIAL_H - +#include "vector" #include #include extern JsonObject deviceJson; @@ -41,6 +41,7 @@ class PI_Serial String qlm; String qld; String commandAnswer; + String qpiws; } raw; } get; @@ -147,6 +148,7 @@ class PI_Serial bool PIXX_QPIGS2(); bool PIXX_QMOD(); bool PIXX_QEX(); + bool PIXX_QPIWS(); // static reqeuests bool PIXX_QPIRI(); bool PIXX_QPI(); diff --git a/src/PI_Serial/QPIWS.h b/src/PI_Serial/QPIWS.h new file mode 100644 index 0000000..d3d9416 --- /dev/null +++ b/src/PI_Serial/QPIWS.h @@ -0,0 +1,73 @@ +bool PI_Serial::PIXX_QPIWS() +{ + if (protocol == PI30) + { + String commandAnswer = this->requestData("QPIWS"); + //String commandAnswer = "10000000001010000000000000000000"; + get.raw.qpiws = commandAnswer; + byte commandAnswerLength = commandAnswer.length(); + if (commandAnswer == "NAK") + { + return true; + } + if (commandAnswer == "ERCRC") + { + return false; + } + if (commandAnswerLength == 32) + { + std::vector qpiwsStrings; + if ((char)commandAnswer.charAt(1) == '1') qpiwsStrings.emplace_back("Inverter fault"); // 2 + if ((char)commandAnswer.charAt(2) == '1') qpiwsStrings.emplace_back("Bus over fault"); // 3 + if ((char)commandAnswer.charAt(3) == '1') qpiwsStrings.emplace_back("Bus under fault"); // 4 + if ((char)commandAnswer.charAt(4) == '1') qpiwsStrings.emplace_back("Bus soft fail fault"); // 5 + if ((char)commandAnswer.charAt(5) == '1') qpiwsStrings.emplace_back("Line fail warning"); // 6 + if ((char)commandAnswer.charAt(6) == '1') qpiwsStrings.emplace_back("OPV short warning"); // 7 + if ((char)commandAnswer.charAt(7) == '1') qpiwsStrings.emplace_back("Inverter voltage too low fault"); // 8 + if ((char)commandAnswer.charAt(8) == '1') qpiwsStrings.emplace_back("Inverter voltage too high fault"); // 9 + if ((char)commandAnswer.charAt(9) == '1') qpiwsStrings.emplace_back("Over temperature fault"); // 10 + if ((char)commandAnswer.charAt(10) == '1') qpiwsStrings.emplace_back("Fan locked fault"); // 11 + if ((char)commandAnswer.charAt(11) == '1') qpiwsStrings.emplace_back("Battery voltage too high fault"); // 12 + if ((char)commandAnswer.charAt(12) == '1') qpiwsStrings.emplace_back("Battery low alarm warning"); // 13 + if ((char)commandAnswer.charAt(14) == '1') qpiwsStrings.emplace_back("Battery under shutdown warning"); // 15 + if ((char)commandAnswer.charAt(16) == '1') qpiwsStrings.emplace_back("Overload fault"); // 17 + if ((char)commandAnswer.charAt(17) == '1') qpiwsStrings.emplace_back("EEPROM fault"); // 18 + if ((char)commandAnswer.charAt(18) == '1') qpiwsStrings.emplace_back("Inverter over current fault"); // 19 + if ((char)commandAnswer.charAt(19) == '1') qpiwsStrings.emplace_back("Inverter soft fail fault"); // 20 + if ((char)commandAnswer.charAt(20) == '1') qpiwsStrings.emplace_back("Self test fail fault"); // 21 + if ((char)commandAnswer.charAt(21) == '1') qpiwsStrings.emplace_back("OP DC voltage over fault"); // 22 + if ((char)commandAnswer.charAt(22) == '1') qpiwsStrings.emplace_back("Battery open fault"); // 23 + if ((char)commandAnswer.charAt(23) == '1') qpiwsStrings.emplace_back("Current sensor fail fault"); // 24 + if ((char)commandAnswer.charAt(24) == '1') qpiwsStrings.emplace_back("Battery short fault"); // 25 + if ((char)commandAnswer.charAt(25) == '1') qpiwsStrings.emplace_back("Power limit warning"); // 26 + if ((char)commandAnswer.charAt(26) == '1') qpiwsStrings.emplace_back("PV voltage high warning"); // 27 + if ((char)commandAnswer.charAt(27) == '1') qpiwsStrings.emplace_back("MPPT overload fault"); // 28 + if ((char)commandAnswer.charAt(28) == '1') qpiwsStrings.emplace_back("MPPT overload warning"); // 29 + if ((char)commandAnswer.charAt(29) == '1') qpiwsStrings.emplace_back("Battery too low to charge warning"); // 30 + if (!qpiwsStrings.empty()) + { + String qpiwsStr = ""; + for (size_t i = 0; i < qpiwsStrings.size(); i++) { + qpiwsStr += qpiwsStrings[i]; + if (i < qpiwsStrings.size() - 1) { + qpiwsStr += "; "; + } + } + liveData["Fault_or_Warning"] = qpiwsStr; + } + else + { + liveData["Fault_or_Warning"] = "None"; + } + } + return true; + } + else if (protocol == NoD) + { + return false; + } + else + { + return false; + } +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 60b2a15..fa3c495 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -578,6 +578,7 @@ bool sendtoMQTT() mqttclient.publish(topicBuilder(buff, "RAW/QMOD"), (mppClient.get.raw.qmod).c_str()); mqttclient.publish(topicBuilder(buff, "RAW/QALL"), (mppClient.get.raw.qall).c_str()); mqttclient.publish(topicBuilder(buff, "RAW/QMN"), (mppClient.get.raw.qmn).c_str()); + mqttclient.publish(topicBuilder(buff, "RAW/QPIWS"), (mppClient.get.raw.qpiws).c_str()); } else {