mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-01-15 08:22:10 +00:00
128 lines
5.7 KiB
C++
128 lines
5.7 KiB
C++
/*
|
|
* Simple sketch to simulate reading data from a Kamstrup
|
|
* AMS Meter.
|
|
*
|
|
* Created 24. October 2017 by Roar Fredriksen
|
|
*/
|
|
|
|
#include <HanReader.h>
|
|
#include <Kamstrup.h>
|
|
|
|
// The HAN Port reader
|
|
HanReader hanReader;
|
|
|
|
byte samples[] =
|
|
// [2017-10-20 04.43.32.368 - Received 229 (0xE5) bytes]
|
|
{
|
|
// List #1
|
|
0x7E, 0xA0, 0xE2, 0x2B, 0x21, 0x13, 0x23, 0x9A, 0xE6, 0xE7, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x07, 0xE2, 0x03, 0x04, 0x07, 0x14, 0x3B,
|
|
0x32, 0xFF, 0x80, 0x00, 0x00, 0x02, 0x19, 0x0A, 0x0E, 0x4B, 0x61, 0x6D, 0x73, 0x74, 0x72, 0x75, 0x70, 0x5F, 0x56, 0x30, 0x30, 0x30, 0x31, 0x09,
|
|
0x06, 0x01, 0x01, 0x00, 0x00, 0x05, 0xFF, 0x0A, 0x10, 0x35, 0x37, 0x30, 0x36, 0x35, 0x36, 0x37, 0x32, 0x37, 0x34, 0x33, 0x38, 0x39, 0x37, 0x30,
|
|
0x32, 0x09, 0x06, 0x01, 0x01, 0x60, 0x01, 0x01, 0xFF, 0x0A, 0x12, 0x36, 0x38, 0x34, 0x31, 0x31, 0x32, 0x31, 0x42, 0x4E, 0x32, 0x34, 0x33, 0x31,
|
|
0x30, 0x31, 0x30, 0x34, 0x30, 0x09, 0x06, 0x01, 0x01, 0x01, 0x07, 0x00, 0xFF, 0x06, 0x00, 0x00, 0x11, 0x28, 0x09, 0x06, 0x01, 0x01, 0x02, 0x07,
|
|
0x00, 0xFF, 0x06, 0x00, 0x00, 0x00, 0x00, 0x09, 0x06, 0x01, 0x01, 0x03, 0x07, 0x00, 0xFF, 0x06, 0x00, 0x00, 0x00, 0x84, 0x09, 0x06, 0x01, 0x01,
|
|
0x04, 0x07, 0x00, 0xFF, 0x06, 0x00, 0x00, 0x00, 0x00, 0x09, 0x06, 0x01, 0x01, 0x1F, 0x07, 0x00, 0xFF, 0x06, 0x00, 0x00, 0x05, 0x66, 0x09, 0x06,
|
|
0x01, 0x01, 0x33, 0x07, 0x00, 0xFF, 0x06, 0x00, 0x00, 0x03, 0x0C, 0x09, 0x06, 0x01, 0x01, 0x47, 0x07, 0x00, 0xFF, 0x06, 0x00, 0x00, 0x05, 0x5A,
|
|
0x09, 0x06, 0x01, 0x01, 0x20, 0x07, 0x00, 0xFF, 0x12, 0x00, 0xE0, 0x09, 0x06, 0x01, 0x01, 0x34, 0x07, 0x00, 0xFF, 0x12, 0x00, 0xDF, 0x09, 0x06,
|
|
0x01, 0x01, 0x48, 0x07, 0x00, 0xFF, 0x12, 0x00, 0xDF, 0xA1, 0xD8, 0x7E,
|
|
|
|
// List #2
|
|
0x7E, 0xA1, 0x2C, 0x2B, 0x21, 0x13, 0xFC, 0x04, 0xE6, 0xE7, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x07, 0xE2, 0x03, 0x04, 0x07, 0x15, 0x00,
|
|
0x05, 0xFF, 0x80, 0x00, 0x00, 0x02, 0x23, 0x0A, 0x0E, 0x4B, 0x61, 0x6D, 0x73, 0x74, 0x72, 0x75, 0x70, 0x5F, 0x56, 0x30, 0x30, 0x30, 0x31, 0x09,
|
|
0x06, 0x01, 0x01, 0x00, 0x00, 0x05, 0xFF, 0x0A, 0x10, 0x35, 0x37, 0x30, 0x36, 0x35, 0x36, 0x37, 0x32, 0x37, 0x34, 0x33, 0x38, 0x39, 0x37, 0x30,
|
|
0x32, 0x09, 0x06, 0x01, 0x01, 0x60, 0x01, 0x01, 0xFF, 0x0A, 0x12, 0x36, 0x38, 0x34, 0x31, 0x31, 0x32, 0x31, 0x42, 0x4E, 0x32, 0x34, 0x33, 0x31,
|
|
0x30, 0x31, 0x30, 0x34, 0x30, 0x09, 0x06, 0x01, 0x01, 0x01, 0x07, 0x00, 0xFF, 0x06, 0x00, 0x00, 0x0E, 0x3B, 0x09, 0x06, 0x01, 0x01, 0x02, 0x07,
|
|
0x00, 0xFF, 0x06, 0x00, 0x00, 0x00, 0x00, 0x09, 0x06, 0x01, 0x01, 0x03, 0x07, 0x00, 0xFF, 0x06, 0x00, 0x00, 0x00, 0x86, 0x09, 0x06, 0x01, 0x01,
|
|
0x04, 0x07, 0x00, 0xFF, 0x06, 0x00, 0x00, 0x00, 0x00, 0x09, 0x06, 0x01, 0x01, 0x1F, 0x07, 0x00, 0xFF, 0x06, 0x00, 0x00, 0x04, 0x21, 0x09, 0x06,
|
|
0x01, 0x01, 0x33, 0x07, 0x00, 0xFF, 0x06, 0x00, 0x00, 0x03, 0x0C, 0x09, 0x06, 0x01, 0x01, 0x47, 0x07, 0x00, 0xFF, 0x06, 0x00, 0x00, 0x04, 0x1C,
|
|
0x09, 0x06, 0x01, 0x01, 0x20, 0x07, 0x00, 0xFF, 0x12, 0x00, 0xE2, 0x09, 0x06, 0x01, 0x01, 0x34, 0x07, 0x00, 0xFF, 0x12, 0x00, 0xE0, 0x09, 0x06,
|
|
0x01, 0x01, 0x48, 0x07, 0x00, 0xFF, 0x12, 0x00, 0xDF, 0x09, 0x06, 0x00, 0x01, 0x01, 0x00, 0x00, 0xFF, 0x09, 0x0C, 0x07, 0xE2, 0x03, 0x04, 0x07,
|
|
0x15, 0x00, 0x05, 0xFF, 0x80, 0x00, 0x00, 0x09, 0x06, 0x01, 0x01, 0x01, 0x08, 0x00, 0xFF, 0x06, 0x00, 0x1A, 0x40, 0x49, 0x09, 0x06, 0x01, 0x01,
|
|
0x02, 0x08, 0x00, 0xFF, 0x06, 0x00, 0x00, 0x00, 0x00, 0x09, 0x06, 0x01, 0x01, 0x03, 0x08, 0x00, 0xFF, 0x06, 0x00, 0x00, 0x05, 0x64, 0x09, 0x06,
|
|
0x01, 0x01, 0x04, 0x08, 0x00, 0xFF, 0x06, 0x00, 0x02, 0x7B, 0x21, 0x20, 0x92, 0x7E
|
|
};
|
|
|
|
int sampleIndex = 0;
|
|
|
|
void setup() {
|
|
setupDebugPort();
|
|
|
|
// initialize the HanReader
|
|
// (passing no han port, as we are feeding data manually, but provide Serial for debugging)
|
|
hanReader.setup(NULL, &Serial);
|
|
}
|
|
|
|
void setupDebugPort()
|
|
{
|
|
// Initialize the Serial port for debugging
|
|
Serial.begin(115200);
|
|
while (!Serial) {}
|
|
Serial.setDebugOutput(true);
|
|
Serial.println("Serial1");
|
|
Serial.println("Serial debugging port initialized");
|
|
}
|
|
|
|
void loop() {
|
|
// Read one byte from the "port", and see if we got a full package
|
|
if (hanReader.read(samples[sampleIndex++]))
|
|
{
|
|
// Get the list identifier
|
|
int listSize = hanReader.getListSize();
|
|
|
|
Serial.println("");
|
|
Serial.print("List size: ");
|
|
Serial.print(listSize);
|
|
Serial.print(": ");
|
|
|
|
// Only care for the ACtive Power Imported, which is found in the first list
|
|
if (listSize == (int)Kamstrup::List1 || listSize == (int)Kamstrup::List2)
|
|
{
|
|
String id = hanReader.getString((int)Kamstrup_List1::ListVersionIdentifier);
|
|
Serial.println(id);
|
|
|
|
time_t time = hanReader.getPackageTime();
|
|
Serial.print("Time of the package is: ");
|
|
Serial.println(time);
|
|
|
|
int power = hanReader.getInt((int)Kamstrup_List1::ActiveImportPower);
|
|
Serial.print("Power consumtion is right now: ");
|
|
Serial.print(power);
|
|
Serial.println(" W");
|
|
|
|
float current[3];
|
|
current[0] = (float)hanReader.getInt((int)Kamstrup_List1::CurrentL1) / 100.0;
|
|
current[1] = (float)hanReader.getInt((int)Kamstrup_List1::CurrentL2) / 100.0;
|
|
current[2] = (float)hanReader.getInt((int)Kamstrup_List1::CurrentL3) / 100.0;
|
|
|
|
int voltage[3];
|
|
voltage[0] = hanReader.getInt((int)Kamstrup_List1::VoltageL1);
|
|
voltage[1] = hanReader.getInt((int)Kamstrup_List1::VoltageL2);
|
|
voltage[2] = hanReader.getInt((int)Kamstrup_List1::VoltageL3);
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
{
|
|
Serial.print("L");
|
|
Serial.print(i + 1);
|
|
Serial.print(" is ");
|
|
Serial.print(voltage[i]);
|
|
Serial.print(" V (");
|
|
Serial.print(current[i]);
|
|
Serial.println(" A)");
|
|
}
|
|
|
|
if (listSize == (int)Kamstrup::List2)
|
|
{
|
|
time_t clock = hanReader.getTime((int)Kamstrup_List2::MeterClock);
|
|
Serial.print("Clock is: ");
|
|
Serial.println(clock);
|
|
}
|
|
}
|
|
}
|
|
|
|
delay(10);
|
|
if (sampleIndex >= sizeof(samples))
|
|
{
|
|
delay(2000);
|
|
sampleIndex = 0;
|
|
}
|
|
} |