mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-01-14 07:49:01 +00:00
Some adjustments
This commit is contained in:
parent
4cd6013d64
commit
f0461a7cdb
@ -157,13 +157,13 @@ bool JsonMqttHandler::publishTemperatures(AmsConfiguration* config, HwTools* hw)
|
||||
return false;
|
||||
}
|
||||
|
||||
snprintf(json, 24, "{\"temperatures\":{");
|
||||
snprintf_P(json, 24, PSTR("{\"temperatures\":{"));
|
||||
|
||||
for(int i = 0; i < count; i++) {
|
||||
TempSensorData* data = hw->getTempSensorData(i);
|
||||
if(data != NULL) {
|
||||
char* pos = json+strlen(json);
|
||||
snprintf(pos, 26, "\"%s\":%.2f,",
|
||||
snprintf_P(pos, 26, PSTR("\"%s\":%.2f,"),
|
||||
toHex(data->address, 8).c_str(),
|
||||
data->lastRead
|
||||
);
|
||||
@ -172,7 +172,7 @@ bool JsonMqttHandler::publishTemperatures(AmsConfiguration* config, HwTools* hw)
|
||||
}
|
||||
}
|
||||
char* pos = json+strlen(json);
|
||||
snprintf(count == 0 ? pos : pos-1, 8, "}}");
|
||||
snprintf_P(count == 0 ? pos : pos-1, 8, PSTR("}}"));
|
||||
bool ret = mqtt->publish(topic, json);
|
||||
mqtt->loop();
|
||||
delay(10);
|
||||
@ -243,7 +243,7 @@ bool JsonMqttHandler::publishPrices(EntsoeApi* eapi) {
|
||||
time_t ts = now + (SECS_PER_HOUR * min1hrIdx);
|
||||
tmElements_t tm;
|
||||
breakTime(ts, tm);
|
||||
sprintf(ts1hr, "%04d-%02d-%02dT%02d:00:00Z", tm.Year+1970, tm.Month, tm.Day, tm.Hour);
|
||||
sprintf_P(ts1hr, PSTR("%04d-%02d-%02dT%02d:00:00Z"), tm.Year+1970, tm.Month, tm.Day, tm.Hour);
|
||||
}
|
||||
char ts3hr[24];
|
||||
memset(ts3hr, 0, 24);
|
||||
@ -251,7 +251,7 @@ bool JsonMqttHandler::publishPrices(EntsoeApi* eapi) {
|
||||
time_t ts = now + (SECS_PER_HOUR * min3hrIdx);
|
||||
tmElements_t tm;
|
||||
breakTime(ts, tm);
|
||||
sprintf(ts3hr, "%04d-%02d-%02dT%02d:00:00Z", tm.Year+1970, tm.Month, tm.Day, tm.Hour);
|
||||
sprintf_P(ts3hr, PSTR("%04d-%02d-%02dT%02d:00:00Z"), tm.Year+1970, tm.Month, tm.Day, tm.Hour);
|
||||
}
|
||||
char ts6hr[24];
|
||||
memset(ts6hr, 0, 24);
|
||||
@ -259,7 +259,7 @@ bool JsonMqttHandler::publishPrices(EntsoeApi* eapi) {
|
||||
time_t ts = now + (SECS_PER_HOUR * min6hrIdx);
|
||||
tmElements_t tm;
|
||||
breakTime(ts, tm);
|
||||
sprintf(ts6hr, "%04d-%02d-%02dT%02d:00:00Z", tm.Year+1970, tm.Month, tm.Day, tm.Hour);
|
||||
sprintf_P(ts6hr, PSTR("%04d-%02d-%02dT%02d:00:00Z"), tm.Year+1970, tm.Month, tm.Day, tm.Hour);
|
||||
}
|
||||
|
||||
snprintf_P(json, BufferSize, JSONPRICES_JSON,
|
||||
|
||||
@ -417,7 +417,7 @@ void AmsWebServer::dataJson() {
|
||||
mqttStatus = 3;
|
||||
}
|
||||
|
||||
float price = ea->getPriceForHour(0);
|
||||
double price = ea->getPriceForHour(0);
|
||||
|
||||
String peaks = "";
|
||||
for(uint8_t i = 1; i <= ea->getConfig()->hours; i++) {
|
||||
|
||||
@ -100,7 +100,7 @@ AmsMqttHandler* mqttHandler = NULL;
|
||||
Stream *hanSerial;
|
||||
SoftwareSerial *swSerial = NULL;
|
||||
HardwareSerial *hwSerial = NULL;
|
||||
size_t rxBufferSize = 64;
|
||||
size_t rxBufferSize = 128;
|
||||
|
||||
GpioConfig gpioConfig;
|
||||
MeterConfig meterConfig;
|
||||
@ -752,6 +752,7 @@ void setupHanPort(GpioConfig& gpioConfig, uint32_t baud, uint8_t parityOrdinal,
|
||||
serialConfig = SERIAL_8E1;
|
||||
break;
|
||||
}
|
||||
if(rxBufferSize < 256) rxBufferSize = 256; // 64 is default for software serial, 256 for hardware
|
||||
|
||||
hwSerial->setRxBufferSize(rxBufferSize);
|
||||
#if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3)
|
||||
@ -777,14 +778,19 @@ void setupHanPort(GpioConfig& gpioConfig, uint32_t baud, uint8_t parityOrdinal,
|
||||
hwSerial->onReceiveError(rxerr);
|
||||
#endif
|
||||
hanSerial = hwSerial;
|
||||
swSerial = NULL;
|
||||
if(swSerial != NULL) {
|
||||
swSerial->end();
|
||||
delete swSerial;
|
||||
swSerial = NULL;
|
||||
}
|
||||
} else {
|
||||
debugD("Software serial");
|
||||
Serial.flush();
|
||||
|
||||
if(swSerial != NULL) {
|
||||
if(swSerial == NULL) {
|
||||
swSerial = new SoftwareSerial(pin, -1, invert);
|
||||
} else {
|
||||
swSerial->end();
|
||||
delete swSerial;
|
||||
}
|
||||
|
||||
SoftwareSerialConfig serialConfig;
|
||||
@ -803,7 +809,6 @@ void setupHanPort(GpioConfig& gpioConfig, uint32_t baud, uint8_t parityOrdinal,
|
||||
break;
|
||||
}
|
||||
|
||||
swSerial = new SoftwareSerial(pin, -1, invert);
|
||||
swSerial->begin(baud, serialConfig, pin, -1, invert, rxBufferSize);
|
||||
hanSerial = swSerial;
|
||||
|
||||
@ -814,6 +819,7 @@ void setupHanPort(GpioConfig& gpioConfig, uint32_t baud, uint8_t parityOrdinal,
|
||||
|
||||
// The library automatically sets the pullup in Serial.begin()
|
||||
if(!gpioConfig.hanPinPullup) {
|
||||
debugI("HAN pin pullup disabled");
|
||||
pinMode(gpioConfig.hanPin, INPUT);
|
||||
}
|
||||
|
||||
@ -1415,7 +1421,7 @@ void MQTT_connect() {
|
||||
}
|
||||
yield();
|
||||
} else {
|
||||
mqtt = new MQTTClient(1500);
|
||||
mqtt = new MQTTClient(1024);
|
||||
ws.setMqtt(mqtt);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user