mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-01-14 15:54:47 +00:00
Support for Aidon meter
This commit is contained in:
parent
8191476256
commit
0471e61ba5
@ -193,9 +193,79 @@ void readHanPort()
|
||||
|
||||
void readHanPort_Aidon(int listSize)
|
||||
{
|
||||
if (debugger)
|
||||
debugger->println("Meter type Aidon is not yet implemented");
|
||||
delay(10000);
|
||||
if (listSize == (int)Aidon::List1 || listSize == (int)Aidon::List2 || listSize == (int)Aidon::List3)
|
||||
{
|
||||
if (listSize == (int)Aidon::List1)
|
||||
{
|
||||
if (debugger) debugger->println(" (list #1 has no ID)");
|
||||
}
|
||||
else
|
||||
{
|
||||
String id = hanReader.getString((int)Aidon_List2::ListVersionIdentifier);
|
||||
if (debugger) debugger->println(id);
|
||||
}
|
||||
|
||||
// Get the timestamp (as unix time) from the package
|
||||
time_t time = hanReader.getPackageTime();
|
||||
if (debugger) debugger->print("Time of the package is: ");
|
||||
if (debugger) debugger->println(time);
|
||||
|
||||
// Define a json object to keep the data
|
||||
//StaticJsonBuffer<500> jsonBuffer;
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
JsonObject& root = jsonBuffer.createObject();
|
||||
|
||||
// Any generic useful info here
|
||||
root["id"] = WiFi.macAddress();
|
||||
root["up"] = millis();
|
||||
root["t"] = time;
|
||||
|
||||
// Add a sub-structure to the json object,
|
||||
// to keep the data from the meter itself
|
||||
JsonObject& data = root.createNestedObject("data");
|
||||
|
||||
// Get the temperature too
|
||||
tempSensor.requestTemperatures();
|
||||
float temperature = tempSensor.getTempCByIndex(0);
|
||||
data["temp"] = String(temperature);
|
||||
|
||||
// Based on the list number, get all details
|
||||
// according to OBIS specifications for the meter
|
||||
if (listSize == (int)Aidon::List1)
|
||||
{
|
||||
data["P"] = hanReader.getInt((int)Aidon_List1::ActivePowerImported);
|
||||
}
|
||||
else if (listSize == (int)Aidon::List2)
|
||||
{
|
||||
data["lv"] = hanReader.getString((int)Aidon_List2::ListVersionIdentifier);
|
||||
data["id"] = hanReader.getString((int)Aidon_List2::MeterID);
|
||||
data["type"] = hanReader.getString((int)Aidon_List2::MeterType);
|
||||
data["P"] = hanReader.getInt((int)Aidon_List2::ActiveImportPower);
|
||||
data["Q"] = hanReader.getInt((int)Aidon_List2::ReactiveImportPower);
|
||||
data["I1"] = hanReader.getInt((int)Aidon_List2::CurrentL1);
|
||||
data["I2"] = hanReader.getInt((int)Aidon_List2::CurrentL2);
|
||||
data["I3"] = hanReader.getInt((int)Aidon_List2::CurrentL3);
|
||||
data["U1"] = hanReader.getInt((int)Aidon_List2::VoltageL1);
|
||||
data["U2"] = hanReader.getInt((int)Aidon_List2::VoltageL2);
|
||||
data["U3"] = hanReader.getInt((int)Aidon_List2::VoltageL3);
|
||||
}
|
||||
|
||||
// Write the json to the debug port
|
||||
if (debugger) {
|
||||
debugger->print("Sending data to MQTT: ");
|
||||
root.printTo(*debugger);
|
||||
debugger->println();
|
||||
}
|
||||
|
||||
// Make sure we have configured a publish topic
|
||||
if (ap.config.mqttPublishTopic == 0 || strlen(ap.config.mqttPublishTopic) == 0)
|
||||
return;
|
||||
|
||||
// Publish the json to the MQTT server
|
||||
char msg[1024];
|
||||
root.printTo(msg, 1024);
|
||||
mqtt.publish(ap.config.mqttPublishTopic, msg);
|
||||
}
|
||||
}
|
||||
|
||||
void readHanPort_Kamstrup(int listSize)
|
||||
|
||||
@ -28,71 +28,72 @@ enum class Aidon_List2
|
||||
IGN_0,
|
||||
ListVersionIdentifier_OBIS,
|
||||
ListVersionIdentifier,
|
||||
IGN_0,
|
||||
IGN_1,
|
||||
MeterID_OBIS,
|
||||
MeterID,
|
||||
IGN_0,
|
||||
IGN_2,
|
||||
MeterType_OBIS,
|
||||
MeterType,
|
||||
IGN_0,
|
||||
IGN_3,
|
||||
ActiveImportPower_OBIS,
|
||||
ActiveImportPower,
|
||||
IGN_0,
|
||||
IGN_4,
|
||||
ActiveImportPowerInt8,
|
||||
ActiveImportPowerEnum,
|
||||
IGN_0,
|
||||
IGN_5,
|
||||
ActiveExportPower_OBIS,
|
||||
ActiveExportPower,
|
||||
IGN_0,
|
||||
IGN_6,
|
||||
ActiveExportPowerInt8,
|
||||
ActiveExportPowerEnum,
|
||||
IGN_0,
|
||||
IGN_7,
|
||||
ReactiveImportPower_OBIS,
|
||||
ReactiveImportPower,
|
||||
IGN_0,
|
||||
IGN_8,
|
||||
ReactiveImportPowerInt8,
|
||||
ReactiveImportPowerEnum,
|
||||
IGN_0,
|
||||
IGN_9,
|
||||
ReactiveExportPower_OBIS,
|
||||
ReactiveExportPower,
|
||||
IGN_0,
|
||||
IGN_10,
|
||||
ReactiveExportPowerInt8,
|
||||
ReactiveExportPowerEnum,
|
||||
IGN_0,
|
||||
IGN_11,
|
||||
CurrentL1_OBIS,
|
||||
CurrentL1,
|
||||
IGN_0,
|
||||
IGN_12,
|
||||
CurrentL1Int8,
|
||||
CurrentL1Enum,
|
||||
IGN_0,
|
||||
IGN_13,
|
||||
CurrentL2_OBIS,
|
||||
CurrentL2,
|
||||
IGN_0,
|
||||
IGN_14,
|
||||
CurrentL2Int8,
|
||||
CurrentL2Enum,
|
||||
IGN_0,
|
||||
IGN_15,
|
||||
CurrentL3_OBIS,
|
||||
CurrentL3,
|
||||
IGN_0,
|
||||
IGN_16,
|
||||
CurrentL3Int8,
|
||||
CurrentL3Enum,
|
||||
IGN_0,
|
||||
IGN_17,
|
||||
VoltageL1_OBIS,
|
||||
VoltageL1,
|
||||
IGN_18,
|
||||
VoltageL1Int8,
|
||||
VoltageL1Enum,
|
||||
IGN_19,
|
||||
VoltageL2_OBIS,
|
||||
VoltageL2,
|
||||
IGN_20,
|
||||
VoltageL2Int8,
|
||||
VoltageL2Enum,
|
||||
IGN_21,
|
||||
VoltageL3_OBIS,
|
||||
VoltageL3,
|
||||
MeterClock_OBIS,
|
||||
MeterClock,
|
||||
CumulativeActiveImportEnergy_OBIS,
|
||||
CumulativeActiveImportEnergy,
|
||||
CumulativeActiveExportEnergy_OBIS,
|
||||
CumulativeActiveExportEnergy,
|
||||
CumulativeReactiveImportEnergy_OBIS,
|
||||
CumulativeReactiveImportEnergy,
|
||||
CumulativeReactiveExportEnergy_OBIS,
|
||||
CumulativeReactiveExportEnergy
|
||||
IGN_22,
|
||||
VoltageL3Int8,
|
||||
VoltageL3Enum
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -137,16 +137,26 @@ int HanReader::findValuePosition(int dataPosition, byte *buffer, int start, int
|
||||
{
|
||||
if (dataPosition-- == 0)
|
||||
return i;
|
||||
else if (buffer[i] == 0x0A) // OBIS code value
|
||||
else if (buffer[i] == 0x00) // null
|
||||
i += 0;
|
||||
else if (buffer[i] == 0x0A) // String
|
||||
i += buffer[i + 1] + 1;
|
||||
else if (buffer[i] == 0x09) // string value
|
||||
else if (buffer[i] == 0x09) // byte array
|
||||
i += buffer[i + 1] + 1;
|
||||
else if (buffer[i] == 0x02) // byte value (1 byte)
|
||||
else if (buffer[i] == 0x01) // array (1 byte for reading size)
|
||||
i += 1;
|
||||
else if (buffer[i] == 0x12) // integer value (2 bytes)
|
||||
else if (buffer[i] == 0x02) // struct (1 byte for reading size)
|
||||
i += 1;
|
||||
else if (buffer[i] == 0x10) // int16 value (2 bytes)
|
||||
i += 2;
|
||||
else if (buffer[i] == 0x06) // integer value (4 bytes)
|
||||
else if (buffer[i] == 0x12) // uint16 value (2 bytes)
|
||||
i += 2;
|
||||
else if (buffer[i] == 0x06) // uint32 value (4 bytes)
|
||||
i += 4;
|
||||
else if (buffer[i] == 0x0F) // int8 value (1 bytes)
|
||||
i += 1;
|
||||
else if (buffer[i] == 0x16) // enum (1 bytes)
|
||||
i += 1;
|
||||
else
|
||||
{
|
||||
if (debug)
|
||||
@ -211,6 +221,9 @@ int HanReader::getInt(int dataPosition, byte *buffer, int start, int length)
|
||||
int bytes = 0;
|
||||
switch (buffer[valuePosition++])
|
||||
{
|
||||
case 0x10:
|
||||
bytes = 2;
|
||||
break;
|
||||
case 0x12:
|
||||
bytes = 2;
|
||||
break;
|
||||
@ -220,6 +233,15 @@ int HanReader::getInt(int dataPosition, byte *buffer, int start, int length)
|
||||
case 0x02:
|
||||
bytes = 1;
|
||||
break;
|
||||
case 0x01:
|
||||
bytes = 1;
|
||||
break;
|
||||
case 0x0F:
|
||||
bytes = 1;
|
||||
break;
|
||||
case 0x16:
|
||||
bytes = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = valuePosition; i < valuePosition + bytes; i++)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user