mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-01-31 14:11:58 +00:00
82 lines
2.8 KiB
C++
82 lines
2.8 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]
|
|
{
|
|
0x7E, 0xA0, 0xE3, 0x2B, 0x21, 0x13, 0x98, 0x86, 0xE6, 0xE7, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x00,
|
|
0x09, 0x0C, 0x07, 0xE1, 0x0A, 0x14, 0x05, 0x03, 0x2B, 0x1E, 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, 0x05, 0xBC, 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, 0x00, 0x09, 0x06, 0x01,
|
|
0x01, 0x04, 0x07, 0x00, 0xFF, 0x06, 0x00, 0x00, 0x01, 0xCE, 0x09, 0x06, 0x01, 0x01, 0x1F, 0x07,
|
|
0x00, 0xFF, 0x06, 0x00, 0x00, 0x02, 0x34, 0x09, 0x06, 0x01, 0x01, 0x33, 0x07, 0x00, 0xFF, 0x06,
|
|
0x00, 0x00, 0x00, 0xCA, 0x09, 0x06, 0x01, 0x01, 0x47, 0x07, 0x00, 0xFF, 0x06, 0x00, 0x00, 0x01,
|
|
0xFF, 0x09, 0x06, 0x01, 0x01, 0x20, 0x07, 0x00, 0xFF, 0x12, 0x00, 0xE8, 0x09, 0x06, 0x01, 0x01,
|
|
0x34, 0x07, 0x00, 0xFF, 0x12, 0x00, 0xE4, 0x09, 0x06, 0x01, 0x01, 0x48, 0x07, 0x00, 0xFF, 0x12,
|
|
0x00, 0xE9, 0xA1, 0xA5, 0x7E
|
|
};
|
|
int sampleIndex = 0;
|
|
|
|
void setup() {
|
|
setupDebugPort();
|
|
|
|
// initialize the HanReader
|
|
// (passing Serial as the HAN port and Serial1 for debugging)
|
|
hanReader.setup(NULL, &Serial);
|
|
}
|
|
|
|
void setupDebugPort()
|
|
{
|
|
// Initialize the Serial1 port for debugging
|
|
// (This port is fixed to Pin2 of the ESP8266)
|
|
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 list = hanReader.getList();
|
|
|
|
Serial.println("");
|
|
Serial.print("List #");
|
|
Serial.print((byte)list, HEX);
|
|
Serial.print(": ");
|
|
|
|
// Only care for the ACtive Power Imported, which is found in the first list
|
|
if (list == (int)Kamstrup::List1)
|
|
{
|
|
int power = hanReader.getInt((int)Kamstrup_List1::Kamstrup_List1_ActivePowerPos);
|
|
Serial.print("Power consumtion is right now: ");
|
|
Serial.print(power);
|
|
Serial.println(" W");
|
|
}
|
|
}
|
|
|
|
delay(10);
|
|
if (sampleIndex >= sizeof(samples))
|
|
{
|
|
delay(2000);
|
|
sampleIndex = 0;
|
|
}
|
|
} |