Skip to content

Commit

Permalink
add debug for qe and ql
Browse files Browse the repository at this point in the history
  • Loading branch information
softwarecrash committed Sep 4, 2023
1 parent d067696 commit 6637b51
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 73 deletions.
150 changes: 81 additions & 69 deletions src/PI_Serial/QPIGS.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned short>() - liveData["Battery_Discharge_Current"].as<unsigned short>());
liveData["PV_Input_Power"] = (liveData["PV_Input_Voltage"].as<unsigned short>() * liveData["PV_Input_Current"].as<unsigned short>());
}

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<unsigned short>() - liveData["Battery_Discharge_Current"].as<unsigned short>());
liveData["PV_Input_Power"] = (liveData["PV_Input_Voltage"].as<unsigned short>() * liveData["PV_Input_Current"].as<unsigned short>());
}

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<String>().charAt(0));
liveData["Battery_Load"] = (liveData["Battery_Charge_Current"].as<unsigned short>() - liveData["Battery_Discharge_Current"].as<unsigned short>());
}
liveData["Inverter_Operation_Mode"] = getModeDesc((char)liveData["Inverter_Operation_Mode"].as<String>().charAt(0));
liveData["Battery_Load"] = (liveData["Battery_Charge_Current"].as<unsigned short>() - liveData["Battery_Discharge_Current"].as<unsigned short>());
return true;
}
else if (protocol == PI18)
{
return true;
}
else if (protocol == NoD)
{
return false;
}
else
{
return false;
}

return true;
}
15 changes: 11 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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))
{
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 6637b51

Please sign in to comment.