mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-04-13 08:14:11 +00:00
Changed buffer size defaults and some null terminator issues on json mqtt
This commit is contained in:
@@ -96,7 +96,8 @@ bool JsonMqttHandler::publishList1(AmsData* data, EnergyAccounting* ea) {
|
||||
}
|
||||
pos += snprintf_P(json+pos, BufferSize-pos, PSTR("\"P\":%d"), data->getActiveImportPower());
|
||||
pos += appendJsonFooter(ea, pos);
|
||||
json[pos] = '}';
|
||||
json[pos++] = '}';
|
||||
json[pos] = '\0';
|
||||
if(mqttConfig.payloadFormat == 5) {
|
||||
char topic[192];
|
||||
snprintf_P(topic, 192, PSTR("%s/list1"), mqttConfig.publishTopic);
|
||||
@@ -127,7 +128,8 @@ bool JsonMqttHandler::publishList2(AmsData* data, EnergyAccounting* ea) {
|
||||
data->getL3Voltage()
|
||||
);
|
||||
pos += appendJsonFooter(ea, pos);
|
||||
json[pos] = '}';
|
||||
json[pos++] = '}';
|
||||
json[pos] = '\0';
|
||||
if(mqttConfig.payloadFormat == 5) {
|
||||
char topic[192];
|
||||
snprintf_P(topic, 192, PSTR("%s/list2"), mqttConfig.publishTopic);
|
||||
@@ -163,7 +165,8 @@ bool JsonMqttHandler::publishList3(AmsData* data, EnergyAccounting* ea) {
|
||||
data->getMeterTimestamp()
|
||||
);
|
||||
pos += appendJsonFooter(ea, pos);
|
||||
json[pos] = '}';
|
||||
json[pos++] = '}';
|
||||
json[pos] = '\0';
|
||||
if(mqttConfig.payloadFormat == 5) {
|
||||
char topic[192];
|
||||
snprintf_P(topic, 192, PSTR("%s/list3"), mqttConfig.publishTopic);
|
||||
@@ -215,7 +218,8 @@ bool JsonMqttHandler::publishList4(AmsData* data, EnergyAccounting* ea) {
|
||||
data->getMeterTimestamp()
|
||||
);
|
||||
pos += appendJsonFooter(ea, pos);
|
||||
json[pos] = '}';
|
||||
json[pos++] = '}';
|
||||
json[pos] = '\0';
|
||||
if(mqttConfig.payloadFormat == 5) {
|
||||
char topic[192];
|
||||
snprintf_P(topic, 192, PSTR("%s/list4"), mqttConfig.publishTopic);
|
||||
@@ -256,7 +260,8 @@ bool JsonMqttHandler::publishTemperatures(AmsConfiguration* config, HwTools* hw)
|
||||
bool ret = false;
|
||||
json[pos-1] = '}';
|
||||
if(mqttConfig.payloadFormat != 6) {
|
||||
json[pos] = '}';
|
||||
json[pos++] = '}';
|
||||
json[pos] = '\0';
|
||||
}
|
||||
if(mqttConfig.payloadFormat == 5) {
|
||||
char topic[192];
|
||||
@@ -382,7 +387,8 @@ bool JsonMqttHandler::publishPrices(PriceService* ps) {
|
||||
ts6hr
|
||||
);
|
||||
if(mqttConfig.payloadFormat != 6) {
|
||||
json[pos] = '}';
|
||||
json[pos++] = '}';
|
||||
json[pos] = '\0';
|
||||
}
|
||||
bool ret = false;
|
||||
if(mqttConfig.payloadFormat == 5) {
|
||||
|
||||
@@ -1181,6 +1181,7 @@ void AmsWebServer::handleSave() {
|
||||
case 6: // Pow-P1
|
||||
meterConfig.baud = 115200;
|
||||
meterConfig.parity = 3; // 8N1
|
||||
meterConfig.bufferSize = 8;
|
||||
break;
|
||||
case 3: // Pow-K UART0
|
||||
case 5: // Pow-K+
|
||||
@@ -1200,6 +1201,9 @@ void AmsWebServer::handleSave() {
|
||||
network.sleep = 2; // Light sleep
|
||||
break;
|
||||
}
|
||||
#if defined(ESP8266)
|
||||
meterConfig.bufferSize = 1;
|
||||
#endif
|
||||
config->setNetworkConfig(network);
|
||||
config->setMeterConfig(meterConfig);
|
||||
|
||||
|
||||
@@ -172,26 +172,6 @@ bool PassiveMeterCommunicator::loop() {
|
||||
dataAvailable = true;
|
||||
lastError = DATA_PARSE_OK;
|
||||
|
||||
// After one hour, adjust buffer size to match the largest payload
|
||||
if(!maxDetectPayloadDetectDone && now > 3600000) {
|
||||
if(maxDetectedPayloadSize * 1.25 > meterConfig.bufferSize * 64) {
|
||||
int bufferSize = min((double) 64, ceil((maxDetectedPayloadSize * 1.25) / 64));
|
||||
#if defined(ESP8266)
|
||||
if(meterConfig.rxPin != 3 && meterConfig.rxPin != 113) {
|
||||
bufferSize = min(bufferSize, 2);
|
||||
} else {
|
||||
bufferSize = min(bufferSize, 8);
|
||||
}
|
||||
#endif
|
||||
if(bufferSize != meterConfig.bufferSize) {
|
||||
if (debugger->isActive(RemoteDebug::INFO)) debugger->printf_P(PSTR("Increasing RX buffer to %d bytes\n"), meterConfig.bufferSize * 64);
|
||||
meterConfig.bufferSize = bufferSize;
|
||||
configChanged = true;
|
||||
}
|
||||
}
|
||||
maxDetectPayloadDetectDone = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -671,7 +651,7 @@ void PassiveMeterCommunicator::rxerr(int err) {
|
||||
case 2:
|
||||
if (debugger->isActive(RemoteDebug::ERROR)) debugger->printf_P(PSTR("Serial buffer overflow\n"));
|
||||
rxBufferErrors++;
|
||||
if(rxBufferErrors > 3 && meterConfig.bufferSize < 64) {
|
||||
if(rxBufferErrors > 1 && meterConfig.bufferSize < 8) {
|
||||
meterConfig.bufferSize += 2;
|
||||
if (debugger->isActive(RemoteDebug::INFO)) debugger->printf_P(PSTR("Increasing RX buffer to %d bytes\n"), meterConfig.bufferSize * 64);
|
||||
configChanged = true;
|
||||
|
||||
Reference in New Issue
Block a user