diff --git a/Code/Arduino/HanReader/HanReader.vcxitems b/Code/Arduino/HanReader/HanReader.vcxitems
index 2ed4df93..8f11f984 100644
--- a/Code/Arduino/HanReader/HanReader.vcxitems
+++ b/Code/Arduino/HanReader/HanReader.vcxitems
@@ -19,15 +19,15 @@
+
-
+
-
\ No newline at end of file
diff --git a/Code/Arduino/HanReader/HanReader.vcxitems.filters b/Code/Arduino/HanReader/HanReader.vcxitems.filters
index f6e8b99b..a2897a11 100644
--- a/Code/Arduino/HanReader/HanReader.vcxitems.filters
+++ b/Code/Arduino/HanReader/HanReader.vcxitems.filters
@@ -20,9 +20,6 @@
Source Files
-
- Source Files
-
@@ -38,7 +35,10 @@
Header Files
-
+
+ Header Files
+
+
Header Files
diff --git a/Code/Arduino/HanReader/src/HanReader.cpp b/Code/Arduino/HanReader/src/HanReader.cpp
index 848b5eae..cbb7c7a6 100644
--- a/Code/Arduino/HanReader/src/HanReader.cpp
+++ b/Code/Arduino/HanReader/src/HanReader.cpp
@@ -8,11 +8,14 @@ HanReader::HanReader()
void HanReader::setup(HardwareSerial *hanPort, unsigned long baudrate, SerialConfig config, Stream *debugPort)
{
// Initialize H/W serial port for MBus communication
- hanPort->begin(baudrate, config);
- while (!hanPort) {}
- bytesRead = 0;
+ if (hanPort != NULL)
+ {
+ hanPort->begin(baudrate, config);
+ while (!hanPort) {}
+ }
+
han = hanPort;
-
+ bytesRead = 0;
debug = debugPort;
if (debug) debug->println("MBUS serial setup complete");
}
@@ -27,44 +30,174 @@ void HanReader::setup(HardwareSerial *hanPort, Stream *debugPort)
setup(hanPort, 2400, SERIAL_8E1, debugPort);
}
-bool HanReader::read()
+bool HanReader::read(byte data)
{
- if (han->available())
- {
- byte newByte = han->read();
- if (reader.Read(newByte))
- {
- bytesRead = reader.GetRawData(buffer, 0, 512);
- list = (List)kaifa.GetListID(buffer, 0, bytesRead);
- return true;
- }
- }
-
- return false;
+ if (reader.Read(data))
+ {
+ bytesRead = reader.GetRawData(buffer, 0, 512);
+ list = getInt(1, buffer, 0, bytesRead);
+ return true;
+ }
}
-List HanReader::getList()
+bool HanReader::read()
+{
+ if (han->available())
+ {
+ byte newByte = han->read();
+ return read(newByte);
+ }
+ return false;
+}
+
+int HanReader::getList()
{
return list;
}
time_t HanReader::getPackageTime()
{
- return kaifa.GetPackageTime(buffer, 0, bytesRead);
+ return getTime(0);
+}
+
+time_t HanReader::getTime(int objectId)
+{
+ return getTime(objectId, buffer, 0, bytesRead);
}
-int HanReader::getInt(List1_ObisObjects objectId) { return getInt((int)objectId); }
-int HanReader::getInt(List2_ObisObjects objectId) { return getInt((int)objectId); }
-int HanReader::getInt(List3_ObisObjects objectId) { return getInt((int)objectId); }
int HanReader::getInt(int objectId)
{
- return kaifa.GetInt(objectId, buffer, 0, bytesRead);
+ return getInt(objectId, buffer, 0, bytesRead);
}
-String HanReader::getString(List1_ObisObjects objectId) { return getString((int)objectId); }
-String HanReader::getString(List2_ObisObjects objectId) { return getString((int)objectId); }
-String HanReader::getString(List3_ObisObjects objectId) { return getString((int)objectId); }
String HanReader::getString(int objectId)
{
- return kaifa.GetString(objectId, buffer, 0, bytesRead);
+ return getString(objectId, buffer, 0, bytesRead);
}
+
+
+int HanReader::findValuePosition(int dataPosition, byte *buffer, int start, int length)
+{
+ for (int i = start + dataHeader; iprint("Unknown data type found: 0x");
+ debug->println(buffer[i], HEX);
+ }
+ return 0; // unknown data type found
+ }
+ }
+
+ if (debug)
+ {
+ debug->print("Passed the end of the data. Length was: ");
+ debug->println(length);
+ }
+
+ return 0;
+}
+
+
+time_t HanReader::getTime(int dataPosition, byte *buffer, int start, int length)
+{
+ int timeStart = findValuePosition(dataPosition, buffer, start, length);
+ int year = buffer[start + timeStart] << 8 |
+ buffer[start + timeStart + 1];
+
+ int month = buffer[start + timeStart + 2];
+ int day = buffer[start + timeStart + 3];
+ int hour = buffer[start + timeStart + 5];
+ int minute = buffer[start + timeStart + 6];
+ int second = buffer[start + timeStart + 7];
+
+ return toUnixTime(year, month, day, hour, minute, second);
+}
+
+int HanReader::getInt(int dataPosition, byte *buffer, int start, int length)
+{
+ int valuePosition = findValuePosition(dataPosition, buffer, start, length);
+
+ if (valuePosition > 0)
+ {
+ int value = 0;
+ int bytes = 0;
+ switch (buffer[valuePosition++])
+ {
+ case 0x12:
+ bytes = 2;
+ break;
+ case 0x06:
+ bytes = 4;
+ break;
+ case 0x02:
+ bytes = 1;
+ break;
+ }
+
+ for (int i = valuePosition; i < valuePosition + bytes; i++)
+ {
+ value = value << 8 | buffer[i];
+ }
+
+ debug->println(value);
+ return value;
+ }
+ return 0;
+}
+
+String HanReader::getString(int dataPosition, byte *buffer, int start, int length)
+{
+ int valuePosition = findValuePosition(dataPosition, buffer, start, length);
+ if (valuePosition > 0)
+ {
+ String value = String("");
+ for (int i = valuePosition + 2; i < valuePosition + buffer[valuePosition + 1]; i++)
+ {
+ value += String((char)buffer[i]);
+ }
+ return value;
+ }
+ return String("");
+}
+
+time_t HanReader::toUnixTime(int year, int month, int day, int hour, int minute, int second)
+{
+ byte daysInMonth[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
+ long secondsPerMinute = 60;
+ long secondsPerHour = secondsPerMinute * 60;
+ long secondsPerDay = secondsPerHour * 24;
+
+ long time = (year - 1970) * secondsPerDay * 365L;
+
+ for (int yearCounter = 1970; yearCounter 2 && (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)))
+ time += secondsPerDay;
+
+ for (int monthCounter = 1; monthCounter 23)
- {
- byte list = buffer[start + 23];
- if (list == (byte)List::List1) return (byte)List::List1;
- if (list == (byte)List::List2) return (byte)List::List2;
- if (list == (byte)List::List3) return (byte)List::List3;
- }
- return (byte)List::ListUnknown;
-}
-
-long KaifaHan::GetPackageTime(byte *buffer, int start, int length)
-{
- const int timeStart = 10;
- int year = buffer[start + timeStart] << 8 |
- buffer[start + timeStart + 1];
-
- int month = buffer[start + timeStart + 2];
- int day = buffer[start + timeStart + 3];
- int hour = buffer[start + timeStart + 5];
- int minute = buffer[start + timeStart + 6];
- int second = buffer[start + timeStart + 7];
-
- return toUnixTime(year, month, day, hour, minute, second);
-}
-
-int KaifaHan::GetInt(int dataPosition, byte *buffer, int start, int length)
-{
- int valuePosition = findValuePosition(dataPosition, buffer, start, length);
- if (valuePosition > 0)
- {
- int value = 0;
- for (int i = valuePosition + 1; i < valuePosition + 5; i++)
- {
- value = value << 8 | buffer[i];
- }
- return value;
- }
- return 0;
-}
-
-int KaifaHan::findValuePosition(int dataPosition, byte *buffer, int start, int length)
-{
- const int dataStart = 24;
- for (int i=start + dataStart; i 0)
- {
- String value = String("");
- for (int i = valuePosition + 2; i < valuePosition + buffer[valuePosition + 1]; i++)
- {
- value += String((char)buffer[i]);
- }
- return value;
- }
- return String("");
-}
-
-time_t KaifaHan::toUnixTime(int year, int month, int day, int hour, int minute, int second)
-{
- byte daysInMonth[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
- long secondsPerMinute = 60;
- long secondsPerHour = secondsPerMinute * 60;
- long secondsPerDay = secondsPerHour * 24;
-
- long time = (year - 1970) * secondsPerDay * 365L;
-
- for (int yearCounter = 1970; yearCounter 2 && (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)))
- time += secondsPerDay;
-
- for (int monthCounter = 1; monthCounter= 100
- #include "arduino.h"
-#else
- #include "WProgram.h"
-#endif
-
-class KaifaHan
-{
- public:
- byte GetListID(byte *buffer, int start, int length);
- long GetPackageTime(byte *buffer, int start, int length);
- int GetInt(int dataPosition, byte *buffer, int start, int length);
- String GetString(int dataPosition, byte *buffer, int start, int length);
- protected:
-
- private:
- int findValuePosition(int dataPosition, byte *buffer, int start, int length);
- time_t toUnixTime(int year, int month, int day, int hour, int minute, int second);
-};
-
-enum class List : byte {
- ListUnknown = 0x00,
- List1 = 0x01,
- List2 = 0x0D,
- List3 = 0x12
-};
-
-
-enum class List1_ObisObjects {
- ActivePowerImported
-};
-
-enum class List2_ObisObjects {
- ObisListVersionIdentifier,
- MeterID,
- MeterType,
- ActivePowerImported,
- ActivePowerExported,
- ReactivePowerImported,
- ReactivePowerExported,
- CurrentPhaseL1,
- CurrentPhaseL2,
- CurrentPhaseL3,
- VoltagePhaseL1,
- VoltagePhaseL2,
- VoltagePhaseL3
-};
-
-enum class List3_ObisObjects {
- ObisListVersionIdentifier,
- MeterID,
- MeterType,
- ActivePowerImported,
- ActivePowerExported,
- ReactivePowerImported,
- ReactivePowerExported,
- CurrentPhaseL1,
- CurrentPhaseL2,
- CurrentPhaseL3,
- VoltagePhaseL1,
- VoltagePhaseL2,
- VoltagePhaseL3,
- ClockAndDate,
- TotalActiveEnergyImported,
- TotalActiveEnergyExported,
- TotalReactiveEnergyImported,
- TotalReactiveEnergyExported
-};
-
-#endif
diff --git a/Code/Arduino/HanReader/src/Kamstrup.h b/Code/Arduino/HanReader/src/Kamstrup.h
new file mode 100644
index 00000000..f368921a
--- /dev/null
+++ b/Code/Arduino/HanReader/src/Kamstrup.h
@@ -0,0 +1,45 @@
+// Kamstrup.h
+
+#ifndef _KAMSTRUP_h
+#define _KAMSTRUP_h
+
+
+enum class Kamstrup
+{
+ List1 = 0x19
+};
+
+enum class Kamstrup_List1
+{
+ Kamstrup_List1_Time,
+ Kamstrup_List1_ListID,
+ Kamstrup_List1_ListVersionIdentifier,
+ Kamstrup_List1_MeterID_OBIS,
+ Kamstrup_List1_MeterID,
+ Kamstrup_List1_MeterType_OBIS,
+ Kamstrup_List1_MeterType,
+ Kamstrup_List1_ActivePowerPos_OBIS,
+ Kamstrup_List1_ActivePowerPos,
+ Kamstrup_List1_ActivePowerNeg_OBIS,
+ Kamstrup_List1_ActivePowerNeg,
+ Kamstrup_List1_ReactivePowerPos_OBIS,
+ Kamstrup_List1_ReactivePowerPos,
+ Kamstrup_List1_ReactivePowerNeg_OBIS,
+ Kamstrup_List1_ReactivePowerNeg,
+ Kamstrup_List1_CurrentL1_OBIS,
+ Kamstrup_List1_CurrentL1,
+ Kamstrup_List1_CurrentL2_OBIS,
+ Kamstrup_List1_CurrentL2,
+ Kamstrup_List1_CurrentL3_OBIS,
+ Kamstrup_List1_CurrentL3,
+ Kamstrup_List1_VoltageL1_OBIS,
+ Kamstrup_List1_VoltageL1,
+ Kamstrup_List1_VoltageL2_OBIS,
+ Kamstrup_List1_VoltageL2,
+ Kamstrup_List1_VoltageL3_OBIS,
+ Kamstrup_List1_VoltageL3
+};
+
+
+#endif
+
diff --git a/Code/Arduino/KamstrupTest/.vs/KamstrupTest/v15/.suo b/Code/Arduino/KamstrupTest/.vs/KamstrupTest/v15/.suo
index 155bbb9c..00f88cd8 100644
Binary files a/Code/Arduino/KamstrupTest/.vs/KamstrupTest/v15/.suo and b/Code/Arduino/KamstrupTest/.vs/KamstrupTest/v15/.suo differ
diff --git a/Code/Arduino/KamstrupTest/.vs/KamstrupTest/v15/Solution.VC.db b/Code/Arduino/KamstrupTest/.vs/KamstrupTest/v15/Solution.VC.db
index e46997bb..1b2a3632 100644
Binary files a/Code/Arduino/KamstrupTest/.vs/KamstrupTest/v15/Solution.VC.db and b/Code/Arduino/KamstrupTest/.vs/KamstrupTest/v15/Solution.VC.db differ
diff --git a/Code/Arduino/KamstrupTest/.vs/KamstrupTest/v15/Solution.VC.db-shm b/Code/Arduino/KamstrupTest/.vs/KamstrupTest/v15/Solution.VC.db-shm
index 60f9c15a..d75da59d 100644
Binary files a/Code/Arduino/KamstrupTest/.vs/KamstrupTest/v15/Solution.VC.db-shm and b/Code/Arduino/KamstrupTest/.vs/KamstrupTest/v15/Solution.VC.db-shm differ
diff --git a/Code/Arduino/KamstrupTest/.vs/KamstrupTest/v15/Solution.VC.db-wal b/Code/Arduino/KamstrupTest/.vs/KamstrupTest/v15/Solution.VC.db-wal
index 123b73c1..b0f88779 100644
Binary files a/Code/Arduino/KamstrupTest/.vs/KamstrupTest/v15/Solution.VC.db-wal and b/Code/Arduino/KamstrupTest/.vs/KamstrupTest/v15/Solution.VC.db-wal differ
diff --git a/Code/Arduino/KamstrupTest/Debug/KamstrupTest.bin b/Code/Arduino/KamstrupTest/Debug/KamstrupTest.bin
index 4c78f242..dc32acdf 100644
Binary files a/Code/Arduino/KamstrupTest/Debug/KamstrupTest.bin and b/Code/Arduino/KamstrupTest/Debug/KamstrupTest.bin differ
diff --git a/Code/Arduino/KamstrupTest/Debug/KamstrupTest.cpp.d b/Code/Arduino/KamstrupTest/Debug/KamstrupTest.cpp.d
index ff3cfd68..e400b558 100644
--- a/Code/Arduino/KamstrupTest/Debug/KamstrupTest.cpp.d
+++ b/Code/Arduino/KamstrupTest/Debug/KamstrupTest.cpp.d
@@ -32,8 +32,8 @@ C:\Users\roarf\AppData\Local\Temp\VMBuilds\KamstrupTest\esp8266_generic\Debug\Ka
C:\Users\roarf\AppData\Local\arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/debug.h \
C:\Users\roarf\AppData\Local\arduino15\packages\esp8266\hardware\esp8266\2.3.0\variants\generic/pins_arduino.h \
C:\Users\roarf\AppData\Local\arduino15\packages\esp8266\hardware\esp8266\2.3.0\variants\generic/common.h \
- C:\Users\roarf\OneDrive\Documents\GitHub\AmsToMqttBridge\Code\Arduino\HanReader\src/hanreader.h \
+ C:\Users\roarf\OneDrive\Documents\GitHub\AmsToMqttBridge\Code\Arduino\HanReader\src/HanReader.h \
C:\Users\roarf\AppData\Local\arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/arduino.h \
- C:\Users\roarf\OneDrive\Documents\GitHub\AmsToMqttBridge\Code\Arduino\HanReader\src/KaifaHan.h \
C:\Users\roarf\OneDrive\Documents\GitHub\AmsToMqttBridge\Code\Arduino\HanReader\src/DlmsReader.h \
- C:\Users\roarf\OneDrive\Documents\GitHub\AmsToMqttBridge\Code\Arduino\HanReader\src/Crc16.h
+ C:\Users\roarf\OneDrive\Documents\GitHub\AmsToMqttBridge\Code\Arduino\HanReader\src/Crc16.h \
+ C:\Users\roarf\OneDrive\Documents\GitHub\AmsToMqttBridge\Code\Arduino\HanReader\src/Kamstrup.h
diff --git a/Code/Arduino/KamstrupTest/Debug/KamstrupTest.cpp.o b/Code/Arduino/KamstrupTest/Debug/KamstrupTest.cpp.o
index a08ad039..67fcd6a7 100644
Binary files a/Code/Arduino/KamstrupTest/Debug/KamstrupTest.cpp.o and b/Code/Arduino/KamstrupTest/Debug/KamstrupTest.cpp.o differ
diff --git a/Code/Arduino/KamstrupTest/Debug/KamstrupTest.elf b/Code/Arduino/KamstrupTest/Debug/KamstrupTest.elf
index 58518542..3ab331d8 100644
Binary files a/Code/Arduino/KamstrupTest/Debug/KamstrupTest.elf and b/Code/Arduino/KamstrupTest/Debug/KamstrupTest.elf differ
diff --git a/Code/Arduino/KamstrupTest/Debug/KamstrupTest.ino.bin b/Code/Arduino/KamstrupTest/Debug/KamstrupTest.ino.bin
index 4c78f242..dc32acdf 100644
Binary files a/Code/Arduino/KamstrupTest/Debug/KamstrupTest.ino.bin and b/Code/Arduino/KamstrupTest/Debug/KamstrupTest.ino.bin differ
diff --git a/Code/Arduino/KamstrupTest/Debug/KamstrupTest.ino.elf b/Code/Arduino/KamstrupTest/Debug/KamstrupTest.ino.elf
index 58518542..3ab331d8 100644
Binary files a/Code/Arduino/KamstrupTest/Debug/KamstrupTest.ino.elf and b/Code/Arduino/KamstrupTest/Debug/KamstrupTest.ino.elf differ
diff --git a/Code/Arduino/KamstrupTest/Debug/board.buildinfo b/Code/Arduino/KamstrupTest/Debug/board.buildinfo
index 1724a3f7..cfb6f136 100644
--- a/Code/Arduino/KamstrupTest/Debug/board.buildinfo
+++ b/Code/Arduino/KamstrupTest/Debug/board.buildinfo
@@ -334,16 +334,13 @@ build.spiffs_start=0x300000
build.spiffs_end=0x3FB000
build.spiffs_blocksize=8192
build.flash_freq=40
+vm.runtime.compiler.shared_library_paths=C:\Users\roarf\OneDrive\Documents\GitHub\AmsToMqttBridge\Code\Arduino\HanReader
builder.noino=false
build.architecture=1.20.0-26-gb404fb9-2
vmresolved.compiler.path=C:\Users\roarf\AppData\Local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2\bin\
vmresolved.tools.path=C:\Users\roarf\AppData\Local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2
build.variant.vmresolved.name=generic
build.variant.vmresolved.full_path=C:\Users\roarf\AppData\Local\arduino15\packages\esp8266\hardware\esp8266\2.3.0\variants\generic
-build.path=C:\Users\roarf\AppData\Local\Temp\VMBuilds\KamstrupTest\esp8266_generic\Debug
-build.project_name=KamstrupTest.ino
-build.project_path=C:\Users\roarf\OneDrive\Documents\GitHub\AmsToMqttBridge\Code\Arduino\KamstrupTest
-ProjectDir=C:\Users\roarf\OneDrive\Documents\GitHub\AmsToMqttBridge\Code\Arduino\KamstrupTest\
vm.runtime.compiler.showwarnings=false
vm.runtime.upload.verbose=false
vm.runtime.upload.verify=false
@@ -372,7 +369,10 @@ serial.vid=0x0403
serial.pid=0x6001
serial.iserial=0000
serial.port.iserial=0000
-vm.runtime.compiler.shared_library_paths=C:\Users\roarf\OneDrive\Documents\GitHub\AmsToMqttBridge\Code\Arduino\HanReader
+build.path=C:\Users\roarf\AppData\Local\Temp\VMBuilds\KamstrupTest\esp8266_generic\Debug
+build.project_name=KamstrupTest.ino
+build.project_path=C:\Users\roarf\OneDrive\Documents\GitHub\AmsToMqttBridge\Code\Arduino\KamstrupTest
+ProjectDir=C:\Users\roarf\OneDrive\Documents\GitHub\AmsToMqttBridge\Code\Arduino\KamstrupTest\
vm.runtime.compiler.auto_discover_includes=true
vm.runtime.compiler.auto_discover_includes_cache=true
build.vm.build.vmdebug=0
@@ -382,14 +382,70 @@ vm.last.buildpath=C:\Users\roarf\AppData\Local\Temp\VMBuilds\KamstrupTest\esp826
vm.build.verbose_build_properties=false
build.source.path=C:\Users\roarf\OneDrive\Documents\GitHub\AmsToMqttBridge\Code\Arduino\KamstrupTest\KamstrupTest.ino
PreProcessor.HeaderCount=1
-PreProcessor.PrototypeCount=4
+PreProcessor.PrototypeCount=5
vm.last.preproc.file.0.file=KamstrupTest.ino
vm.last.preproc.file.0.offset=1
-vm.last.preproc.file.0.length=140
-vm.last.preproc.file.0.linecount=16
+vm.last.preproc.file.0.length=2924
+vm.last.preproc.file.0.linecount=82
vm.last.preproc.file.0.linestart=0
-vm.last.preproc.file.0.lineend=16
+vm.last.preproc.file.0.lineend=82
vm.last.preproc.file.0.prefix_lines=0
+vm.last.preproc.file.1.file=Crc16.cpp
+vm.last.preproc.file.1.offset=0
+vm.last.preproc.file.1.length=815
+vm.last.preproc.file.1.linecount=38
+vm.last.preproc.file.1.linestart=82
+vm.last.preproc.file.1.lineend=120
+vm.last.preproc.file.1.prefix_lines=0
+vm.last.preproc.file.2.file=Crc16.h
+vm.last.preproc.file.2.offset=0
+vm.last.preproc.file.2.length=368
+vm.last.preproc.file.2.linecount=24
+vm.last.preproc.file.2.linestart=120
+vm.last.preproc.file.2.lineend=144
+vm.last.preproc.file.2.prefix_lines=0
+vm.last.preproc.file.3.file=DlmsReader.cpp
+vm.last.preproc.file.3.offset=0
+vm.last.preproc.file.3.length=4622
+vm.last.preproc.file.3.linecount=155
+vm.last.preproc.file.3.linestart=144
+vm.last.preproc.file.3.lineend=299
+vm.last.preproc.file.3.prefix_lines=0
+vm.last.preproc.file.4.file=DlmsReader.h
+vm.last.preproc.file.4.offset=0
+vm.last.preproc.file.4.length=949
+vm.last.preproc.file.4.linecount=43
+vm.last.preproc.file.4.linestart=299
+vm.last.preproc.file.4.lineend=342
+vm.last.preproc.file.4.prefix_lines=0
+vm.last.preproc.file.5.file=HanReader.cpp
+vm.last.preproc.file.5.offset=0
+vm.last.preproc.file.5.length=4486
+vm.last.preproc.file.5.linecount=203
+vm.last.preproc.file.5.linestart=342
+vm.last.preproc.file.5.lineend=545
+vm.last.preproc.file.5.prefix_lines=0
+vm.last.preproc.file.6.file=HanReader.h
+vm.last.preproc.file.6.offset=0
+vm.last.preproc.file.6.length=1111
+vm.last.preproc.file.6.linecount=50
+vm.last.preproc.file.6.linestart=545
+vm.last.preproc.file.6.lineend=595
+vm.last.preproc.file.6.prefix_lines=0
+vm.last.preproc.file.7.file=Kaifa.h
+vm.last.preproc.file.7.offset=0
+vm.last.preproc.file.7.length=914
+vm.last.preproc.file.7.linecount=56
+vm.last.preproc.file.7.linestart=595
+vm.last.preproc.file.7.lineend=651
+vm.last.preproc.file.7.prefix_lines=0
+vm.last.preproc.file.8.file=Kamstrup.h
+vm.last.preproc.file.8.offset=0
+vm.last.preproc.file.8.length=1019
+vm.last.preproc.file.8.linecount=46
+vm.last.preproc.file.8.linestart=651
+vm.last.preproc.file.8.lineend=697
+vm.last.preproc.file.8.prefix_lines=0
sketch_path=C:\Users\roarf\OneDrive\Documents\GitHub\AmsToMqttBridge\Code\Arduino\KamstrupTest
vm.sketch_source_path=C:\Users\roarf\AppData\Local\Temp\VMBuilds\KamstrupTest\esp8266_generic\Debug
vm.build_use_temp=1
@@ -397,7 +453,7 @@ runtime.vm.ide.platforms.path=C:\Program Files (x86)\Microsoft Visual Studio\201
build.variant.path=C:\Users\roarf\AppData\Local\arduino15\packages\esp8266\hardware\esp8266\2.3.0\variants\generic
archive_file=core.a
archive_file_path=C:\Users\roarf\AppData\Local\Temp\VMBuilds\KamstrupTest\esp8266_generic\Debug\core.a
-extra.time.local=58337955
+extra.time.local=72039249
tools.ctags.path={runtime.tools.ctags.path}
tools.ctags.cmd.path={path}/ctags
tools.ctags.pattern="{cmd.path}" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "{source_file}"
@@ -413,4 +469,4 @@ build.path_core=C:\Users\roarf\AppData\Local\Temp\VMBuilds\KamstrupTest\esp8266_
build.path_libraries=C:\Users\roarf\AppData\Local\Temp\VMBuilds\KamstrupTest\esp8266_generic\Debug
object_file=C:\Users\roarf\AppData\Local\Temp\VMBuilds\KamstrupTest\esp8266_generic\Debug\KamstrupTest.cpp.o
source_file=C:\Users\roarf\AppData\Local\Temp\VMBuilds\KamstrupTest\esp8266_generic\Debug\KamstrupTest.cpp
-object_files= "C:\Users\roarf\AppData\Local\Temp\VMBuilds\KamstrupTest\esp8266_generic\Debug\KamstrupTest.cpp.o" "C:\Users\roarf\AppData\Local\Temp\VMBuilds\KamstrupTest\esp8266_generic\Debug\HanReader\Crc16.cpp.o" "C:\Users\roarf\AppData\Local\Temp\VMBuilds\KamstrupTest\esp8266_generic\Debug\HanReader\DlmsReader.cpp.o" "C:\Users\roarf\AppData\Local\Temp\VMBuilds\KamstrupTest\esp8266_generic\Debug\HanReader\HanReader.cpp.o" "C:\Users\roarf\AppData\Local\Temp\VMBuilds\KamstrupTest\esp8266_generic\Debug\HanReader\KaifaHan.cpp.o"
+object_files= "C:\Users\roarf\AppData\Local\Temp\VMBuilds\KamstrupTest\esp8266_generic\Debug\KamstrupTest.cpp.o" "C:\Users\roarf\AppData\Local\Temp\VMBuilds\KamstrupTest\esp8266_generic\Debug\HanReader\Crc16.cpp.o" "C:\Users\roarf\AppData\Local\Temp\VMBuilds\KamstrupTest\esp8266_generic\Debug\HanReader\DlmsReader.cpp.o" "C:\Users\roarf\AppData\Local\Temp\VMBuilds\KamstrupTest\esp8266_generic\Debug\HanReader\HanReader.cpp.o"
diff --git a/Code/Arduino/KamstrupTest/KamstrupTest.ino b/Code/Arduino/KamstrupTest/KamstrupTest.ino
index 3c49c562..fefa32e1 100644
--- a/Code/Arduino/KamstrupTest/KamstrupTest.ino
+++ b/Code/Arduino/KamstrupTest/KamstrupTest.ino
@@ -1,15 +1,82 @@
-#include
+/*
+* Simple sketch to simulate reading data from a Kamstrup
+* AMS Meter.
+*
+* Created 24. October 2017 by Roar Fredriksen
+*/
-void setup()
+#include
+#include
+
+// 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;
- /* add setup code here */
+void setup() {
+ setupDebugPort();
+ // initialize the HanReader
+ // (passing Serial as the HAN port and Serial1 for debugging)
+ hanReader.setup(NULL, &Serial);
}
-void loop()
+void setupDebugPort()
{
-
- /* add main program code here */
-
+ // 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;
+ }
+}
\ No newline at end of file
diff --git a/Code/Arduino/KamstrupTest/KamstrupTest.sln b/Code/Arduino/KamstrupTest/KamstrupTest.sln
index 6f6f6868..b777296b 100644
--- a/Code/Arduino/KamstrupTest/KamstrupTest.sln
+++ b/Code/Arduino/KamstrupTest/KamstrupTest.sln
@@ -8,6 +8,10 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HanReader", "..\HanReader\HanReader.vcxitems", "{CD0F5364-923B-49E4-8BE5-EA7D8A60DF80}"
EndProject
Global
+ GlobalSection(SharedMSBuildProjectFiles) = preSolution
+ ..\HanReader\HanReader.vcxitems*{c5f80730-f44f-4478-bdae-6634efc2ca88}*SharedItemsImports = 4
+ ..\HanReader\HanReader.vcxitems*{cd0f5364-923b-49e4-8be5-ea7d8a60df80}*SharedItemsImports = 9
+ EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
diff --git a/Code/Arduino/KamstrupTest/KamstrupTest.vcxproj b/Code/Arduino/KamstrupTest/KamstrupTest.vcxproj
index 1b0186d9..d698c986 100644
--- a/Code/Arduino/KamstrupTest/KamstrupTest.vcxproj
+++ b/Code/Arduino/KamstrupTest/KamstrupTest.vcxproj
@@ -35,6 +35,9 @@
+
+
+
@@ -48,7 +51,7 @@
Level3
Disabled
true
- $(ProjectDir)..\KamstrupTest;$(ProjectDir)..\..\..\..\..\..\..\..\..\Program Files (x86)\Arduino\libraries;$(ProjectDir)..\..\..\..\..\..\..\AppData\Local\arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries;$(ProjectDir)..\..\..\..\..\..\..\Google Drive\Private\Elektronikk\Arduino\libraries;$(ProjectDir)..\..\..\..\..\..\..\AppData\Local\arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266;$(ProjectDir)..\..\..\..\..\..\..\AppData\Local\arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266\libb64;$(ProjectDir)..\..\..\..\..\..\..\AppData\Local\arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266\spiffs;$(ProjectDir)..\..\..\..\..\..\..\AppData\Local\arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266\umm_malloc;$(ProjectDir)..\..\..\..\..\..\..\AppData\Local\arduino15\packages\esp8266\hardware\esp8266\2.3.0\variants\generic;$(ProjectDir)..\..\..\..\..\..\..\AppData\Local\arduino15\packages\esp8266\hardware\esp8266\2.3.0\tools\sdk\include;$(ProjectDir)..\..\..\..\..\..\..\AppData\Local\arduino15\packages\esp8266\hardware\esp8266\2.3.0\tools\sdk\lwip\include;$(ProjectDir)..\..\..\..\..\..\..\AppData\Local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2\xtensa-lx106-elf\include\c++\4.8.2;$(ProjectDir)..\..\..\..\..\..\..\AppData\Local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2\xtensa-lx106-elf\include\c++\4.8.2\xtensa-lx106-elf;$(ProjectDir)..\..\..\..\..\..\..\AppData\Local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2\xtensa-lx106-elf\include;$(ProjectDir)..\..\..\..\..\..\..\AppData\Local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2\lib\gcc\xtensa-lx106-elf\4.8.2\include;$(ProjectDir)..\..\..\..\..\..\..\AppData\Local\arduino15\packages\esp8266\hardware\esp8266\2.3.0\tools\sdk\include;%(AdditionalIncludeDirectories)
+ $(ProjectDir)..\KamstrupTest;$(ProjectDir)..\HanReader\src;$(ProjectDir)..\..\..\..\..\..\..\..\..\Program Files (x86)\Arduino\libraries;$(ProjectDir)..\..\..\..\..\..\..\AppData\Local\arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries;$(ProjectDir)..\..\..\..\..\..\..\Google Drive\Private\Elektronikk\Arduino\libraries;$(ProjectDir)..\..\..\..\..\..\..\AppData\Local\arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266;$(ProjectDir)..\..\..\..\..\..\..\AppData\Local\arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266\libb64;$(ProjectDir)..\..\..\..\..\..\..\AppData\Local\arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266\spiffs;$(ProjectDir)..\..\..\..\..\..\..\AppData\Local\arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266\umm_malloc;$(ProjectDir)..\..\..\..\..\..\..\AppData\Local\arduino15\packages\esp8266\hardware\esp8266\2.3.0\variants\generic;$(ProjectDir)..\..\..\..\..\..\..\AppData\Local\arduino15\packages\esp8266\hardware\esp8266\2.3.0\tools\sdk\include;$(ProjectDir)..\..\..\..\..\..\..\AppData\Local\arduino15\packages\esp8266\hardware\esp8266\2.3.0\tools\sdk\lwip\include;$(ProjectDir)..\..\..\..\..\..\..\AppData\Local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2\xtensa-lx106-elf\include\c++\4.8.2;$(ProjectDir)..\..\..\..\..\..\..\AppData\Local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2\xtensa-lx106-elf\include\c++\4.8.2\xtensa-lx106-elf;$(ProjectDir)..\..\..\..\..\..\..\AppData\Local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2\xtensa-lx106-elf\include;$(ProjectDir)..\..\..\..\..\..\..\AppData\Local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2\lib\gcc\xtensa-lx106-elf\4.8.2\include;$(ProjectDir)..\..\..\..\..\..\..\AppData\Local\arduino15\packages\esp8266\hardware\esp8266\2.3.0\tools\sdk\include;%(AdditionalIncludeDirectories)
$(ProjectDir)__vm\.KamstrupTest.vsarduino.h;%(ForcedIncludeFiles)
false
__ESP8266_ESp8266__;__ESP8266_ESP8266__;__ets__;ICACHE_FLASH;F_CPU=80000000L;LWIP_OPEN_SRC;ARDUINO=106012;ARDUINO_ESP8266_ESP01;ARDUINO_ARCH_ESP8266;ESP8266;__cplusplus=201103L;_VMICRO_INTELLISENSE;%(PreprocessorDefinitions)
@@ -88,4 +91,9 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/Code/Arduino/KamstrupTest/__vm/Compile.vmps.xml b/Code/Arduino/KamstrupTest/__vm/Compile.vmps.xml
index 99611582..d3cefbc5 100644
--- a/Code/Arduino/KamstrupTest/__vm/Compile.vmps.xml
+++ b/Code/Arduino/KamstrupTest/__vm/Compile.vmps.xml
@@ -2,7 +2,7 @@
-
+
diff --git a/Code/Arduino/KamstrupTest/__vm/Configuration.Debug.vmps.xml b/Code/Arduino/KamstrupTest/__vm/Configuration.Debug.vmps.xml
index 3a6ff91d..c6dd389d 100644
--- a/Code/Arduino/KamstrupTest/__vm/Configuration.Debug.vmps.xml
+++ b/Code/Arduino/KamstrupTest/__vm/Configuration.Debug.vmps.xml
@@ -2,7 +2,7 @@
-
+
diff --git a/Code/Arduino/KamstrupTest/__vm/Upload.vmps.xml b/Code/Arduino/KamstrupTest/__vm/Upload.vmps.xml
new file mode 100644
index 00000000..d3cefbc5
--- /dev/null
+++ b/Code/Arduino/KamstrupTest/__vm/Upload.vmps.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file