mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-04-27 12:39:40 +00:00
Some changes during testing
This commit is contained in:
@@ -239,30 +239,22 @@ String HanReader::getString(int dataPosition, byte *buffer, int start, int lengt
|
|||||||
return String("");
|
return String("");
|
||||||
}
|
}
|
||||||
|
|
||||||
void HanReader::printD(String fmt, ...) {
|
void HanReader::printD(String fmt, int arg) {
|
||||||
va_list args;
|
if(debugger->isActive(RemoteDebug::DEBUG)) debugger->printf(String("(HanReader)" + fmt + "\n").c_str(), arg);
|
||||||
va_start(args, fmt);
|
|
||||||
if(debugger->isActive(RemoteDebug::DEBUG)) debugger->printf(String("(HanReader)" + fmt + "\n").c_str(), args);
|
|
||||||
va_end(args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HanReader::printI(String fmt, ...) {
|
void HanReader::printI(String fmt, int arg) {
|
||||||
va_list args;
|
if(debugger->isActive(RemoteDebug::INFO)) debugger->printf(String("(HanReader)" + fmt + "\n").c_str(), arg);
|
||||||
va_start(args, fmt);
|
|
||||||
if(debugger->isActive(RemoteDebug::INFO)) debugger->printf(String("(HanReader)" + fmt + "\n").c_str(), args);
|
|
||||||
va_end(args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HanReader::printW(String fmt, ...) {
|
void HanReader::printW(String fmt, int arg) {
|
||||||
va_list args;
|
if(debugger->isActive(RemoteDebug::WARNING)) debugger->printf(String("(HanReader)" + fmt + "\n").c_str(), arg);
|
||||||
va_start(args, fmt);
|
|
||||||
if(debugger->isActive(RemoteDebug::WARNING)) debugger->printf(String("(HanReader)" + fmt + "\n").c_str(), args);
|
|
||||||
va_end(args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HanReader::printE(String fmt, ...) {
|
void HanReader::printW(String fmt, const char* arg) {
|
||||||
va_list args;
|
if(debugger->isActive(RemoteDebug::WARNING)) debugger->printf(String("(HanReader)" + fmt + "\n").c_str(), arg);
|
||||||
va_start(args, fmt);
|
}
|
||||||
if(debugger->isActive(RemoteDebug::ERROR)) debugger->printf(String("(HanReader)" + fmt + "\n").c_str(), args);
|
|
||||||
va_end(args);
|
void HanReader::printE(String fmt, int arg) {
|
||||||
|
if(debugger->isActive(RemoteDebug::ERROR)) debugger->printf(String("(HanReader)" + fmt + "\n").c_str(), arg);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,10 +49,11 @@ private:
|
|||||||
|
|
||||||
void debugPrint(byte *buffer, int start, int length);
|
void debugPrint(byte *buffer, int start, int length);
|
||||||
|
|
||||||
void printD(String fmt, ...);
|
void printD(String fmt, int arg=0);
|
||||||
void printI(String fmt, ...);
|
void printI(String fmt, int arg=0);
|
||||||
void printW(String fmt, ...);
|
void printW(String fmt, int arg=0);
|
||||||
void printE(String fmt, ...);
|
void printW(String fmt, const char* arg);
|
||||||
|
void printE(String fmt, int arg=0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -789,7 +789,7 @@ void AmsConfiguration::print(Print* debugger)
|
|||||||
debugger->printf("authPass: %s\r\n", this->getAuthPassword().c_str());
|
debugger->printf("authPass: %s\r\n", this->getAuthPassword().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
debugger->printf("meterType: %i\r\n", this->getMeterType());
|
debugger->printf("meterType: %i\r\n", this->getMeterType());
|
||||||
debugger->printf("distSys: %i\r\n", this->getDistributionSystem());
|
debugger->printf("distSys: %i\r\n", this->getDistributionSystem());
|
||||||
debugger->printf("fuseSize: %i\r\n", this->getMainFuse());
|
debugger->printf("fuseSize: %i\r\n", this->getMainFuse());
|
||||||
debugger->printf("productionCapacity: %i\r\n", this->getProductionCapacity());
|
debugger->printf("productionCapacity: %i\r\n", this->getProductionCapacity());
|
||||||
|
|||||||
@@ -433,78 +433,80 @@ void readHanPort() {
|
|||||||
rgb_led(RGB_GREEN, 2);
|
rgb_led(RGB_GREEN, 2);
|
||||||
|
|
||||||
AmsData data(config.getMeterType(), hanReader);
|
AmsData data(config.getMeterType(), hanReader);
|
||||||
ws.setData(data);
|
if(data.getListType() > 0) {
|
||||||
|
ws.setData(data);
|
||||||
|
|
||||||
if(!config.getMqttHost().isEmpty() && !config.getMqttPublishTopic().isEmpty()) {
|
if(!config.getMqttHost().isEmpty() && !config.getMqttPublishTopic().isEmpty()) {
|
||||||
if(config.getMqttPayloadFormat() == 0) {
|
if(config.getMqttPayloadFormat() == 0) {
|
||||||
StaticJsonDocument<512> json;
|
StaticJsonDocument<512> json;
|
||||||
hanToJson(json, data, hw, temperature);
|
hanToJson(json, data, hw, temperature);
|
||||||
if (Debug.isActive(RemoteDebug::INFO)) {
|
if (Debug.isActive(RemoteDebug::INFO)) {
|
||||||
debugI("Sending data to MQTT");
|
debugI("Sending data to MQTT");
|
||||||
if (Debug.isActive(RemoteDebug::DEBUG)) {
|
if (Debug.isActive(RemoteDebug::DEBUG)) {
|
||||||
serializeJsonPretty(json, Debug);
|
serializeJsonPretty(json, Debug);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String msg;
|
||||||
|
serializeJson(json, msg);
|
||||||
|
mqtt.publish(config.getMqttPublishTopic(), msg.c_str());
|
||||||
|
} else if(config.getMqttPayloadFormat() == 1) {
|
||||||
|
mqtt.publish(config.getMqttPublishTopic() + "/meter/dlms/timestamp", String(data.getPackageTimestamp()));
|
||||||
|
switch(data.getListType()) {
|
||||||
|
case 3:
|
||||||
|
// ID and type belongs to List 2, but I see no need to send that every 10s
|
||||||
|
mqtt.publish(config.getMqttPublishTopic() + "/meter/id", data.getMeterId());
|
||||||
|
mqtt.publish(config.getMqttPublishTopic() + "/meter/type", data.getMeterType());
|
||||||
|
mqtt.publish(config.getMqttPublishTopic() + "/meter/clock", String(data.getMeterTimestamp()));
|
||||||
|
mqtt.publish(config.getMqttPublishTopic() + "/meter/import/reactive/accumulated", String(data.getReactiveImportCounter(), 2));
|
||||||
|
mqtt.publish(config.getMqttPublishTopic() + "/meter/import/active/accumulated", String(data.getActiveImportCounter(), 2));
|
||||||
|
mqtt.publish(config.getMqttPublishTopic() + "/meter/export/reactive/accumulated", String(data.getReactiveExportCounter(), 2));
|
||||||
|
mqtt.publish(config.getMqttPublishTopic() + "/meter/export/active/accumulated", String(data.getActiveExportCounter(), 2));
|
||||||
|
case 2:
|
||||||
|
// Only send data if changed. ID and Type is sent on the 10s interval only if changed
|
||||||
|
if(lastMqttData.getMeterId() != data.getMeterId()) {
|
||||||
|
mqtt.publish(config.getMqttPublishTopic() + "/meter/id", data.getMeterId());
|
||||||
|
}
|
||||||
|
if(lastMqttData.getMeterType() != data.getMeterType()) {
|
||||||
|
mqtt.publish(config.getMqttPublishTopic() + "/meter/type", data.getMeterType());
|
||||||
|
}
|
||||||
|
if(lastMqttData.getL1Current() != data.getL1Current()) {
|
||||||
|
mqtt.publish(config.getMqttPublishTopic() + "/meter/l1/current", String(data.getL1Current(), 2));
|
||||||
|
}
|
||||||
|
if(lastMqttData.getL1Voltage() != data.getL1Voltage()) {
|
||||||
|
mqtt.publish(config.getMqttPublishTopic() + "/meter/l1/voltage", String(data.getL1Voltage(), 2));
|
||||||
|
}
|
||||||
|
if(lastMqttData.getL2Current() != data.getL2Current()) {
|
||||||
|
mqtt.publish(config.getMqttPublishTopic() + "/meter/l2/current", String(data.getL2Current(), 2));
|
||||||
|
}
|
||||||
|
if(lastMqttData.getL2Voltage() != data.getL2Voltage()) {
|
||||||
|
mqtt.publish(config.getMqttPublishTopic() + "/meter/l2/voltage", String(data.getL2Voltage(), 2));
|
||||||
|
}
|
||||||
|
if(lastMqttData.getL3Current() != data.getL3Current()) {
|
||||||
|
mqtt.publish(config.getMqttPublishTopic() + "/meter/l3/current", String(data.getL3Current(), 2));
|
||||||
|
}
|
||||||
|
if(lastMqttData.getL3Voltage() != data.getL3Voltage()) {
|
||||||
|
mqtt.publish(config.getMqttPublishTopic() + "/meter/l3/voltage", String(data.getL3Voltage(), 2));
|
||||||
|
}
|
||||||
|
if(lastMqttData.getReactiveExportPower() != data.getReactiveExportPower()) {
|
||||||
|
mqtt.publish(config.getMqttPublishTopic() + "/meter/export/reactive", String(data.getReactiveExportPower()));
|
||||||
|
}
|
||||||
|
if(lastMqttData.getActiveExportPower() != data.getActiveExportPower()) {
|
||||||
|
mqtt.publish(config.getMqttPublishTopic() + "/meter/export/active", String(data.getActiveExportPower()));
|
||||||
|
}
|
||||||
|
if(lastMqttData.getReactiveImportPower() != data.getReactiveImportPower()) {
|
||||||
|
mqtt.publish(config.getMqttPublishTopic() + "/meter/import/reactive", String(data.getReactiveImportPower()));
|
||||||
|
}
|
||||||
|
case 1:
|
||||||
|
if(lastMqttData.getActiveImportPower() != data.getActiveImportPower()) {
|
||||||
|
mqtt.publish(config.getMqttPublishTopic() + "/meter/import/active", String(data.getActiveImportPower()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
lastMqttData.apply(data);
|
||||||
String msg;
|
mqtt.loop();
|
||||||
serializeJson(json, msg);
|
delay(10);
|
||||||
mqtt.publish(config.getMqttPublishTopic(), msg.c_str());
|
|
||||||
} else if(config.getMqttPayloadFormat() == 1) {
|
|
||||||
mqtt.publish(config.getMqttPublishTopic() + "/meter/dlms/timestamp", String(data.getPackageTimestamp()));
|
|
||||||
switch(data.getListType()) {
|
|
||||||
case 3:
|
|
||||||
// ID and type belongs to List 2, but I see no need to send that every 10s
|
|
||||||
mqtt.publish(config.getMqttPublishTopic() + "/meter/id", data.getMeterId());
|
|
||||||
mqtt.publish(config.getMqttPublishTopic() + "/meter/type", data.getMeterType());
|
|
||||||
mqtt.publish(config.getMqttPublishTopic() + "/meter/clock", String(data.getMeterTimestamp()));
|
|
||||||
mqtt.publish(config.getMqttPublishTopic() + "/meter/import/reactive/accumulated", String(data.getReactiveImportCounter(), 2));
|
|
||||||
mqtt.publish(config.getMqttPublishTopic() + "/meter/import/active/accumulated", String(data.getActiveImportCounter(), 2));
|
|
||||||
mqtt.publish(config.getMqttPublishTopic() + "/meter/export/reactive/accumulated", String(data.getReactiveExportCounter(), 2));
|
|
||||||
mqtt.publish(config.getMqttPublishTopic() + "/meter/export/active/accumulated", String(data.getActiveExportCounter(), 2));
|
|
||||||
case 2:
|
|
||||||
// Only send data if changed. ID and Type is sent on the 10s interval only if changed
|
|
||||||
if(lastMqttData.getMeterId() != data.getMeterId()) {
|
|
||||||
mqtt.publish(config.getMqttPublishTopic() + "/meter/id", data.getMeterId());
|
|
||||||
}
|
|
||||||
if(lastMqttData.getMeterType() != data.getMeterType()) {
|
|
||||||
mqtt.publish(config.getMqttPublishTopic() + "/meter/type", data.getMeterType());
|
|
||||||
}
|
|
||||||
if(lastMqttData.getL1Current() != data.getL1Current()) {
|
|
||||||
mqtt.publish(config.getMqttPublishTopic() + "/meter/l1/current", String(data.getL1Current(), 2));
|
|
||||||
}
|
|
||||||
if(lastMqttData.getL1Voltage() != data.getL1Voltage()) {
|
|
||||||
mqtt.publish(config.getMqttPublishTopic() + "/meter/l1/voltage", String(data.getL1Voltage(), 2));
|
|
||||||
}
|
|
||||||
if(lastMqttData.getL2Current() != data.getL2Current()) {
|
|
||||||
mqtt.publish(config.getMqttPublishTopic() + "/meter/l2/current", String(data.getL2Current(), 2));
|
|
||||||
}
|
|
||||||
if(lastMqttData.getL2Voltage() != data.getL2Voltage()) {
|
|
||||||
mqtt.publish(config.getMqttPublishTopic() + "/meter/l2/voltage", String(data.getL2Voltage(), 2));
|
|
||||||
}
|
|
||||||
if(lastMqttData.getL3Current() != data.getL3Current()) {
|
|
||||||
mqtt.publish(config.getMqttPublishTopic() + "/meter/l3/current", String(data.getL3Current(), 2));
|
|
||||||
}
|
|
||||||
if(lastMqttData.getL3Voltage() != data.getL3Voltage()) {
|
|
||||||
mqtt.publish(config.getMqttPublishTopic() + "/meter/l3/voltage", String(data.getL3Voltage(), 2));
|
|
||||||
}
|
|
||||||
if(lastMqttData.getReactiveExportPower() != data.getReactiveExportPower()) {
|
|
||||||
mqtt.publish(config.getMqttPublishTopic() + "/meter/export/reactive", String(data.getReactiveExportPower()));
|
|
||||||
}
|
|
||||||
if(lastMqttData.getActiveExportPower() != data.getActiveExportPower()) {
|
|
||||||
mqtt.publish(config.getMqttPublishTopic() + "/meter/export/active", String(data.getActiveExportPower()));
|
|
||||||
}
|
|
||||||
if(lastMqttData.getReactiveImportPower() != data.getReactiveImportPower()) {
|
|
||||||
mqtt.publish(config.getMqttPublishTopic() + "/meter/import/reactive", String(data.getReactiveImportPower()));
|
|
||||||
}
|
|
||||||
case 1:
|
|
||||||
if(lastMqttData.getActiveImportPower() != data.getActiveImportPower()) {
|
|
||||||
mqtt.publish(config.getMqttPublishTopic() + "/meter/import/active", String(data.getActiveImportPower()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
lastMqttData.apply(data);
|
|
||||||
mqtt.loop();
|
|
||||||
delay(10);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Auto detect meter if not set
|
// Auto detect meter if not set
|
||||||
|
|||||||
Reference in New Issue
Block a user