mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-03-11 13:05:31 +00:00
Compare commits
35 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
254e010594 | ||
|
|
4c92e592d6 | ||
|
|
72bdb6e363 | ||
|
|
05bdbaf1f5 | ||
|
|
6cca25788e | ||
|
|
e929f87ea9 | ||
|
|
21a4102553 | ||
|
|
768645fc0a | ||
|
|
c670549dea | ||
|
|
147b2ca33e | ||
|
|
c645b82ed3 | ||
|
|
26bb8a0fea | ||
|
|
507ed13770 | ||
|
|
a0f53a0c52 | ||
|
|
13bbc81b7f | ||
|
|
7412ba2697 | ||
|
|
dce7b7e64b | ||
|
|
7627d6c369 | ||
|
|
9fc9adea1c | ||
|
|
46df07fe40 | ||
|
|
0aeb5555e7 | ||
|
|
181fe3c909 | ||
|
|
867d6a4ef8 | ||
|
|
d52216a73e | ||
|
|
d70b41a454 | ||
|
|
332c366561 | ||
|
|
b572ad97f8 | ||
|
|
aa307f8690 | ||
|
|
19223312b5 | ||
|
|
74bc5aa7a0 | ||
|
|
e66e8a96ff | ||
|
|
ce95360a64 | ||
|
|
7802aeaab1 | ||
|
|
37ce3566bf | ||
|
|
606bac100a |
38
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
38
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Report a bug
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
4. See error
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Hardware information:**
|
||||
- Meter: [e.g. Aidon]
|
||||
- AMS reader: [e.g. Pow-U, ESP32 etc]
|
||||
- M-bus adapter (if applicable):
|
||||
|
||||
**Relevant firmware information:**
|
||||
- Version: [e.g. 1.5.0]
|
||||
- MQTT: [yes/no]
|
||||
- HAN GPIO: [e.g. GPIO5]
|
||||
- Temperature sensors [e.g. 3xDS18B20]
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
22
.github/ISSUE_TEMPLATE/support.md
vendored
Normal file
22
.github/ISSUE_TEMPLATE/support.md
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
---
|
||||
name: Support
|
||||
about: Request support
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe your problem**
|
||||
A clear and concise description of what the problem is.
|
||||
|
||||
**Hardware information:**
|
||||
- Meter: [e.g. Aidon]
|
||||
- AMS reader: [e.g. Pow-U, ESP32 etc]
|
||||
- M-bus adapter (if applicable):
|
||||
|
||||
**Relevant firmware information:**
|
||||
- Version: [e.g. 1.5.0]
|
||||
- MQTT: [yes/no]
|
||||
- HAN GPIO: [e.g. GPIO5]
|
||||
- Temperature sensors [e.g. 3xDS18B20]
|
||||
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@@ -41,7 +41,7 @@ jobs:
|
||||
python -m pip install --upgrade pip
|
||||
pip install -U platformio css_html_js_minify
|
||||
- name: Configure build targets
|
||||
run: echo "[platformio]\ndefault_envs = hw1esp12e, esp12e, esp32" > platformio-user.ini
|
||||
run: echo "[platformio]\ndefault_envs = esp8266, esp32" > platformio-user.ini
|
||||
- name: PlatformIO lib install
|
||||
run: pio lib install
|
||||
- name: PlatformIO run
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -12,3 +12,4 @@ platformio-user.ini
|
||||
/src/AmsToMqttBridge.ino.cpp
|
||||
/test
|
||||
/web/test.html
|
||||
/sdkconfig
|
||||
|
||||
@@ -7,11 +7,8 @@ There is a web interface available on runtime, showing meter data in real time.
|
||||
|
||||
<img src="webui.jpg">
|
||||
|
||||
## Hardware options
|
||||
Look in [hardware section](/hardware) for more details about supported hardware
|
||||
|
||||
## Setting up your device
|
||||
Go to the [WiKi](https://github.com/gskjold/AmsToMqttBridge/wiki) for information on how to set up your own device.
|
||||
Go to the [WiKi](https://github.com/gskjold/AmsToMqttBridge/wiki) for information on how to get your own device!
|
||||
|
||||
## Building this project with PlatformIO
|
||||
To build this project, you need [PlatformIO](https://platformio.org/) installed.
|
||||
|
||||
Binary file not shown.
4
frames/Aidon-TN-3p.raw
Normal file
4
frames/Aidon-TN-3p.raw
Normal file
@@ -0,0 +1,4 @@
|
||||
T FF FF DA SA SA C HC HC LD LS LQ AT AI AI AI AI AD
|
||||
7E A0 2A 41 08 83 13 04 13 E6 E7 00 0F 40 00 00 00 00 01 01 02 03 09 06 01 00 01 07 00 FF 06 00 00 08 64 02 02 0F 00 16 1B E1
|
||||
7E A1 1E 41 08 83 13 EE EE E6 E7 00 0F 40 00 00 00 00 01 0D 02 02 09 06 01 01 00 02 81 FF 0A 0B 41 49 44 4F 4E 5F 56 30 30 30 31 02 02 09 06 00 00 60 01 00 FF 0A 10 37 33 35 39 39 39 32 38 39 30 34 39 37 39 39 37 02 02 09 06 00 00 60 01 07 FF 0A 04 36 35 33 34 02 03 09 06 01 00 01 07 00 FF 06 00 00 08 6C 02 02 0F 00 16 1B 02 03 09 06 01 00 02 07 00 FF 06 00 00 00 00 02 02 0F 00 16 1B 02 03 09 06 01 00 03 07 00 FF 06 00 00 00 00 02 02 0F 00 16 1D 02 03 09 06 01 00 04 07 00 FF 06 00 00 02 09 02 02 0F 00 16 1D 02 03 09 06 01 00 1F 07 00 FF 10 00 41 02 02 0F FF 16 21 02 03 09 06 01 00 33 07 00 FF 10 00 13 02 02 0F FF 16 21 02 03 09 06 01 00 47 07 00 FF 10 00 0E 02 02 0F FF 16 21 02 03 09 06 01 00 20 07 00 FF 12 08 F2 02 02 0F FF 16 23 02 03 09 06 01 00 34 07 00 FF 12 08 D1 02 02 0F FF 16 23 02 03 09 06 01 00 48 07 00 FF 12 08 E8 02 02 0F FF 16 23 8B
|
||||
7E A1 8A 41 08 83 13 EB FD E6 E7 00 0F 40 00 00 00 00 01 12 02 02 09 06 01 01 00 02 81 FF 0A 0B 41 49 44 4F 4E 5F 56 30 30 30 31 02 02 09 06 00 00 60 01 00 FF 0A 10 37 33 35 39 39 39 32 38 39 30 34 39 37 39 39 37 02 02 09 06 00 00 60 01 07 FF 0A 04 36 35 33 34 02 03 09 06 01 00 01 07 00 FF 06 00 00 03 9A 02 02 0F 00 16 1B 02 03 09 06 01 00 02 07 00 FF 06 00 00 00 00 02 02 0F 00 16 1B 02 03 09 06 01 00 03 07 00 FF 06 00 00 00 00 02 02 0F 00 16 1D 02 03 09 06 01 00 04 07 00 FF 06 00 00 02 0E 02 02 0F 00 16 1D 02 03 09 06 01 00 1F 07 00 FF 10 00 11 02 02 0F FF 16 21 02 03 09 06 01 00 33 07 00 FF 10 00 10 02 02 0F FF 16 21 02 03 09 06 01 00 47 07 00 FF 10 00 0E 02 02 0F FF 16 21 02 03 09 06 01 00 20 07 00 FF 12 08 F4 02 02 0F FF 16 23 02 03 09 06 01 00 34 07 00 FF 12 08 CD 02 02 0F FF 16 23 02 03 09 06 01 00 48 07 00 FF 12 08 DC 02 02 0F FF 16 23 02 02 09 06 00 00 01 00 00 FF 09 0C 07 E5 03 18 03 08 00 00 FF 00 00 00 02 03 09 06 01 00 01 08 00 FF 06 00 47 F0 34 02 02 0F 01 16 1E 02 03 09 06 01 00 02 08 00 FF 06 00 00 00 00 02 02 0F 01 16 1E 02 03 09 06 01 00 03 08 00 FF 06 00 00 21 9E 02 02 0F 01 16 20 02 03 09 06 01 00 04 08 00 FF 06 00 08 E0 21 02 02 0F 01 16 20 57
|
||||
26
frames/Kaifa-TN-3p.raw
Normal file
26
frames/Kaifa-TN-3p.raw
Normal file
@@ -0,0 +1,26 @@
|
||||
T FF FF DA SA SA C HC HC LD LS LQ AT AI AI AI AI AD
|
||||
7E A0 27 01 02 01 10 5A 87 E6 E7 00 0F 40 00 00 00 09 0C 07 E5 03 17 02 13 1A 3A FF 80 00 00
|
||||
02 01 // Frame type and size
|
||||
06 00 00 0B F3 // Active power
|
||||
5B 05 7E // CRC and end tag
|
||||
|
||||
T FF FF DA SA SA C HC HC LD LS LQ AT AI AI AI AI AD
|
||||
7E A0 78 01 02 01 10 C4 98 E6 E7 00 0F 40 00 00 00 09 0C 07 E5 03 17 02 13 1B 00 FF 80 00 00
|
||||
02 0D // Frame type and size
|
||||
09 07 4B 46 4D 5F 30 30 31 // List version
|
||||
09 10 XX XX XX XX XX XX XX XX XX XX 35 33 34 34 39 33 // Meter ID
|
||||
09 07 4D 41 33 30 34 48 34 // Meter type
|
||||
06 00 00 0C 21 // Active import
|
||||
06 00 00 00 00 // Active export
|
||||
06 00 00 00 00 // Reactive import
|
||||
06 00 00 01 9F // Reactive export
|
||||
06 00 00 0B F3 // I1
|
||||
06 00 00 05 0B // I2
|
||||
06 00 00 25 11 // I3
|
||||
06 00 00 09 44 // U1
|
||||
06 00 00 09 49 // U2
|
||||
06 00 00 09 39 // U3
|
||||
C9 95 7E // CRC and end tag
|
||||
|
||||
|
||||
7E A0 9A 01 02 01 10 AA A5 E6 E7 00 0F 40 00 00 00 09 0C 07 E5 03 17 02 13 00 0A FF 80 00 00 02 12 09 07 4B 46 4D 5F 30 30 31 09 10 XX XX XX XX XX XX XX XX XX XX 35 33 34 34 39 33 09 07 4D 41 33 30 34 48 34 06 00 00 09 99 06 00 00 00 00 06 00 00 00 00 06 00 00 01 67 06 00 00 03 BF 06 00 00 05 05 06 00 00 24 34 06 00 00 09 45 06 00 00 09 4F 06 00 00 09 3B 09 0C 07 E5 03 17 02 13 00 0A FF 80 00 00 06 01 34 3B 5D 06 00 00 00 00 06 00 00 09 36 06 00 3C 7A 98 DA 15 7E
|
||||
32
frames/decoding.txt
Normal file
32
frames/decoding.txt
Normal file
@@ -0,0 +1,32 @@
|
||||
T = Tag
|
||||
FF = Frame format (4 bit type, 1 bit segmentation, 11 bit frame length)
|
||||
DA = Destination Address (1-4 bytes, LSB=1 terminates)
|
||||
SA = Source address (1-4 bytes, LSB=1 terminates)
|
||||
C = Control (1 byte)
|
||||
HC = HCS (2 bytes)
|
||||
|
||||
LD = LLC Destination
|
||||
LS = LLC Remote
|
||||
LQ = LLC Quality
|
||||
|
||||
AT = Tag (0x0F = unencrypted, 0xDB = encrypted) Not really documented that well...
|
||||
AI = Invoke ID and priority (4 bytes)
|
||||
AD = Date and time
|
||||
AS = System title
|
||||
CT = Cipher frame tag ? Undocumented
|
||||
CL = Lenght of Cipher frame. Length of payload will be this number - 5 (control and counter in start) - 12 (GCM tag appended after payload)
|
||||
CC = Security control
|
||||
CO = Invocation counter
|
||||
|
||||
Security control bits
|
||||
01234567
|
||||
00110000 (0x30)
|
||||
0 = read acces
|
||||
1 = write access
|
||||
2 = Authenticated req
|
||||
3 = Encrypted req
|
||||
4 = Digitally signed req
|
||||
5 = Authenticated res
|
||||
6 = Encrypted res
|
||||
7 = Digitally signed res
|
||||
|
||||
@@ -1,45 +1 @@
|
||||
# Hardware options
|
||||
|
||||
There are currently two possible hardware options for this project, both in need of external power supply. A self powered board is under development by a member of the community and is currently being tested.
|
||||
|
||||
## Hardware v1 by [@roarfred](https://github.com/roarfred)
|
||||
Composed from a ESP12E (or F) chip, this ESP8266 based board is designed specifically for this project with an on board M-bus chip.
|
||||
|
||||
Building this project will require some skills in ordering and assembling electronic circuits as well as programming. No detailed instructions are available.
|
||||
|
||||

|
||||
|
||||
*The completed board mounted in a [3D printed enclosure](/Enclosure)*
|
||||
|
||||
## HAN reader 2.0 by [@dakarym](https://github.com/dakarym)
|
||||
A board that does not require external power source. This have only been successfully tested on Aidon as far as I know. It draws too much power for Kamstrup, but it may work with Kaifa. The design is almost
|
||||
completely built with SMD components, so advanced soldering skills are required to make this one.
|
||||
|
||||
[View his design here](https://github.com/dakarym/AmsToMqttBridge/tree/master/PCB)
|
||||
|
||||
## Assembly of readily available modules
|
||||
You can also use a ESP based development board and combine this with a M-Bus module. Here are a few boards that have been tested, each one has a dedicated firmware file in the releases section.
|
||||
|
||||
### ESP8266 based boards
|
||||
|
||||
[Wemos D1 mini](https://docs.wemos.cc/en/latest/d1/d1_mini.html)
|
||||
- M-Bus connected to GPIO5 (D1)
|
||||
- Jump GPIO4 (D2) to GND to force AP mode during boot
|
||||
- Dallas temp sensor connected to GPIO14 (D5)
|
||||
|
||||
### ESP32 based boards
|
||||
|
||||
[Wemos Lolin D32](https://docs.wemos.cc/en/latest/d32/d32.html)
|
||||
- M-Bus connected to GPIO16
|
||||
- Jump GPIO4 to GND to force AP mode during boot
|
||||
- Dallas temp sensor connected to GPIO14
|
||||
|
||||
[Adafruit HUZZAH32](https://www.adafruit.com/product/3405)
|
||||
- M-Bus connected to GPIO16
|
||||
|
||||
|
||||
Combine one of above board with an M-Bus module. Connect 3.3v and GND together between the boards and connect the TX pin from the M-Bus board to the dedicated M-Bus pin on the ESP board.
|
||||
|
||||
[TSS721 M-BUS module board](https://www.aliexpress.com/item/TSS721/32751482255.html)
|
||||
|
||||

|
||||
[See Hardware page in Wiki](https://github.com/gskjold/AmsToMqttBridge/wiki)
|
||||
|
||||
BIN
hardware/img/pow-k-kamstrup.jpg
Normal file
BIN
hardware/img/pow-k-kamstrup.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 MiB |
BIN
hardware/img/pow-u-universal.jpg
Normal file
BIN
hardware/img/pow-u-universal.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 91 KiB |
@@ -175,6 +175,14 @@ byte* DlmsReader::getBuffer() {
|
||||
return buffer + (3 + destinationAddressLength + sourceAddressLength + 2 + 1);
|
||||
}
|
||||
|
||||
byte* DlmsReader::getFullBuffer() {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
int DlmsReader::getFullBufferLength() {
|
||||
return dataLength;
|
||||
}
|
||||
|
||||
int DlmsReader::GetAddress(int addressPosition, byte* addressBuffer, int start, int length)
|
||||
{
|
||||
int addressBufferPos = start;
|
||||
|
||||
@@ -20,6 +20,8 @@ class DlmsReader
|
||||
int GetRawData(byte *buffer, int start, int length);
|
||||
int getBytesRead();
|
||||
byte* getBuffer();
|
||||
byte* getFullBuffer();
|
||||
int getFullBufferLength();
|
||||
|
||||
protected:
|
||||
Crc16Class Crc16;
|
||||
|
||||
@@ -40,7 +40,10 @@ bool HanReader::read(byte data) {
|
||||
if (debugger->isActive(RemoteDebug::INFO)) {
|
||||
printI("Got valid DLMS data (%d bytes)", bytesRead);
|
||||
if (debugger->isActive(RemoteDebug::DEBUG)) {
|
||||
debugPrint(buffer, 0, bytesRead);
|
||||
byte* full = reader.getFullBuffer();
|
||||
int size = reader.getFullBufferLength();
|
||||
printI("Full DLMS frame (%d bytes)", size);
|
||||
debugPrint(full, 0, size);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -296,10 +299,10 @@ time_t HanReader::getTime(byte *buffer, int start, int length, bool respectTimez
|
||||
tm.Second = second;
|
||||
|
||||
time_t time = makeTime(tm);
|
||||
if(respectTimezone && tzMinutes != 0x8000) {
|
||||
if(respectTimezone && (tzMinutes | 0x8000) != 0x8000 && tzMinutes <= 720 && tzMinutes >= -720) {
|
||||
time -= tzMinutes * 60;
|
||||
if(respectDsc && dsc)
|
||||
time -= 3600;
|
||||
time += 3600;
|
||||
} else {
|
||||
if(respectDsc && dsc)
|
||||
time += 3600;
|
||||
|
||||
@@ -7,4 +7,4 @@ paragraph=The primary aim of the Timezone library is to convert Universal Coordi
|
||||
category=Timing
|
||||
url=https://github.com/JChristensen/Timezone
|
||||
architectures=*
|
||||
depends=Time
|
||||
depends=Time (=1.6.0)
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
[platformio]
|
||||
extra_configs = platformio-user.ini
|
||||
|
||||
|
||||
[common]
|
||||
framework = arduino
|
||||
lib_deps = file://lib/HanReader, file://lib/Timezone, MQTT@2.4.8, DallasTemperature@3.9.1, EspSoftwareSerial@6.9.0, RemoteDebug@3.0.5, Time@1.6
|
||||
lib_deps = file://lib/HanReader, file://lib/Timezone, MQTT@2.5.0, DallasTemperature@3.9.1, EspSoftwareSerial@6.9.0, RemoteDebug@3.0.5, Time@1.6.0
|
||||
|
||||
[env:esp8266]
|
||||
platform = espressif8266@2.6.2
|
||||
board = esp12e
|
||||
board_build.ldscript = eagle.flash.4m2m.ld
|
||||
framework = ${common.framework}
|
||||
framework = arduino
|
||||
lib_deps = ${common.lib_deps}
|
||||
extra_scripts =
|
||||
pre:scripts/addversion.py
|
||||
@@ -20,7 +18,7 @@ extra_scripts =
|
||||
platform = espressif32@2.1.0
|
||||
board = esp32dev
|
||||
board_build.partitions = no_ota.csv
|
||||
framework = ${common.framework}
|
||||
framework = arduino
|
||||
lib_deps = ${common.lib_deps}
|
||||
extra_scripts =
|
||||
pre:scripts/addversion.py
|
||||
|
||||
@@ -220,6 +220,7 @@ bool AmsConfiguration::getDebugConfig(DebugConfig& config) {
|
||||
EEPROM.end();
|
||||
return true;
|
||||
} else {
|
||||
clearDebug(config);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -232,6 +233,12 @@ bool AmsConfiguration::setDebugConfig(DebugConfig& config) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
void AmsConfiguration::clearDebug(DebugConfig& config) {
|
||||
config.level = 5;
|
||||
config.telnet = false;
|
||||
config.serial = false;
|
||||
}
|
||||
|
||||
bool AmsConfiguration::getDomoticzConfig(DomoticzConfig& config) {
|
||||
if(hasConfig()) {
|
||||
EEPROM.begin(EEPROM_SIZE);
|
||||
@@ -496,11 +503,11 @@ void AmsConfiguration::clear() {
|
||||
|
||||
NtpConfig ntp;
|
||||
clearNtp(ntp);
|
||||
EEPROM.put(CONFIG_NTP_START, domo);
|
||||
EEPROM.put(CONFIG_NTP_START, ntp);
|
||||
|
||||
EntsoeConfig entsoe;
|
||||
clearEntsoe(entsoe);
|
||||
EEPROM.put(CONFIG_ENTSOE_START, domo);
|
||||
EEPROM.put(CONFIG_ENTSOE_START, entsoe);
|
||||
|
||||
EEPROM.put(EEPROM_CONFIG_ADDRESS, -1);
|
||||
EEPROM.commit();
|
||||
@@ -534,6 +541,17 @@ bool AmsConfiguration::hasConfig() {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 86:
|
||||
configVersion = -1; // Prevent loop
|
||||
if(relocateConfig86()) {
|
||||
configVersion = EEPROM_CHECK_SUM;
|
||||
return true;
|
||||
} else {
|
||||
configVersion = 0;
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case EEPROM_CHECK_SUM:
|
||||
return true;
|
||||
default:
|
||||
@@ -552,7 +570,7 @@ void AmsConfiguration::loadTempSensors() {
|
||||
int address = EEPROM_TEMP_CONFIG_ADDRESS;
|
||||
int c = 0;
|
||||
int storedCount = EEPROM.read(address++);
|
||||
Serial.print("SEnsors: ");
|
||||
Serial.print("Sensors: ");
|
||||
Serial.println(storedCount);
|
||||
if(storedCount > 0 && storedCount <= 32) {
|
||||
for(int i = 0; i < storedCount; i++) {
|
||||
@@ -792,6 +810,26 @@ bool AmsConfiguration::loadConfig83(int address) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool AmsConfiguration::relocateConfig86() {
|
||||
MqttConfig86 mqtt86;
|
||||
MqttConfig mqtt;
|
||||
EEPROM.begin(EEPROM_SIZE);
|
||||
EEPROM.get(CONFIG_MQTT_START_86, mqtt86);
|
||||
strcpy(mqtt.host, mqtt86.host);
|
||||
mqtt.port = mqtt86.port;
|
||||
strcpy(mqtt.clientId, mqtt86.clientId);
|
||||
strcpy(mqtt.publishTopic, mqtt86.publishTopic);
|
||||
strcpy(mqtt.subscribeTopic, mqtt86.subscribeTopic);
|
||||
strcpy(mqtt.username, mqtt86.username);
|
||||
strcpy(mqtt.password, mqtt86.password);
|
||||
mqtt.payloadFormat = mqtt86.payloadFormat;
|
||||
mqtt.ssl = mqtt86.ssl;
|
||||
EEPROM.put(CONFIG_MQTT_START, mqtt);
|
||||
bool ret = EEPROM.commit();
|
||||
EEPROM.end();
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool AmsConfiguration::save() {
|
||||
EEPROM.begin(EEPROM_SIZE);
|
||||
EEPROM.put(EEPROM_CONFIG_ADDRESS, EEPROM_CHECK_SUM);
|
||||
|
||||
@@ -4,13 +4,12 @@
|
||||
#include "Arduino.h"
|
||||
|
||||
#define EEPROM_SIZE 1024 * 3
|
||||
#define EEPROM_CHECK_SUM 86 // Used to check if config is stored. Change if structure changes
|
||||
#define EEPROM_CHECK_SUM 87 // Used to check if config is stored. Change if structure changes
|
||||
#define EEPROM_CONFIG_ADDRESS 0
|
||||
#define EEPROM_TEMP_CONFIG_ADDRESS 2048
|
||||
|
||||
#define CONFIG_SYSTEM_START 8
|
||||
#define CONFIG_WIFI_START 16
|
||||
#define CONFIG_MQTT_START 224
|
||||
#define CONFIG_WEB_START 648
|
||||
#define CONFIG_METER_START 784
|
||||
#define CONFIG_DEBUG_START 824
|
||||
@@ -18,6 +17,10 @@
|
||||
#define CONFIG_DOMOTICZ_START 856
|
||||
#define CONFIG_NTP_START 872
|
||||
#define CONFIG_ENTSOE_START 944
|
||||
#define CONFIG_MQTT_START 1004
|
||||
|
||||
#define CONFIG_MQTT_START_86 224
|
||||
|
||||
|
||||
struct SystemConfig {
|
||||
uint8_t boardType;
|
||||
@@ -35,7 +38,7 @@ struct WiFiConfig {
|
||||
bool mdns;
|
||||
}; // 204
|
||||
|
||||
struct MqttConfig {
|
||||
struct MqttConfig86 {
|
||||
char host[128];
|
||||
uint16_t port;
|
||||
char clientId[32];
|
||||
@@ -47,6 +50,18 @@ struct MqttConfig {
|
||||
bool ssl;
|
||||
}; // 420
|
||||
|
||||
struct MqttConfig {
|
||||
char host[128];
|
||||
uint16_t port;
|
||||
char clientId[32];
|
||||
char publishTopic[64];
|
||||
char subscribeTopic[64];
|
||||
char username[128];
|
||||
char password[256];
|
||||
uint8_t payloadFormat;
|
||||
bool ssl;
|
||||
}; // 676
|
||||
|
||||
struct WebConfig {
|
||||
uint8_t security;
|
||||
char username[64];
|
||||
@@ -271,6 +286,7 @@ public:
|
||||
|
||||
bool getDebugConfig(DebugConfig&);
|
||||
bool setDebugConfig(DebugConfig&);
|
||||
void clearDebug(DebugConfig&);
|
||||
|
||||
bool pinUsed(uint8_t, GpioConfig&);
|
||||
|
||||
@@ -320,6 +336,7 @@ private:
|
||||
|
||||
bool loadConfig82(int address);
|
||||
bool loadConfig83(int address);
|
||||
bool relocateConfig86();
|
||||
|
||||
int readString(int pAddress, char* pString[]);
|
||||
int readInt(int pAddress, int *pValue);
|
||||
|
||||
@@ -16,15 +16,23 @@ AmsData::AmsData(uint8_t meterType, bool substituteMissing, HanReader& hanReader
|
||||
extractFromKaifa(hanReader, listSize);
|
||||
break;
|
||||
case METER_TYPE_AIDON:
|
||||
extractFromAidon(hanReader, listSize, substituteMissing);
|
||||
extractFromAidon(hanReader, listSize);
|
||||
break;
|
||||
case METER_TYPE_KAMSTRUP:
|
||||
extractFromKamstrup(hanReader, listSize, substituteMissing);
|
||||
extractFromKamstrup(hanReader, listSize);
|
||||
break;
|
||||
case METER_TYPE_OMNIPOWER:
|
||||
extractFromOmnipower(hanReader, listSize);
|
||||
break;
|
||||
}
|
||||
threePhase = l1voltage > 0 && l2voltage > 0 && l3voltage > 0;
|
||||
twoPhase = (l1voltage > 0 && l2voltage > 0) || (l2voltage > 0 && l3voltage > 0) || (l3voltage > 0 && l1voltage > 0);
|
||||
|
||||
if(threePhase) {
|
||||
if(substituteMissing) {
|
||||
l2current = (((activeImportPower - activeExportPower) * sqrt(3)) - (l1voltage * l1current) - (l3voltage * l3current)) / l2voltage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AmsData::extractFromKaifa(HanReader& hanReader, uint8_t listSize) {
|
||||
@@ -90,7 +98,7 @@ void AmsData::extractFromKaifa(HanReader& hanReader, uint8_t listSize) {
|
||||
}
|
||||
}
|
||||
|
||||
void AmsData::extractFromAidon(HanReader& hanReader, uint8_t listSize, bool substituteMissing) {
|
||||
void AmsData::extractFromAidon(HanReader& hanReader, uint8_t listSize) {
|
||||
switch(listSize) {
|
||||
case (uint8_t)Aidon::List1:
|
||||
listType = 1;
|
||||
@@ -171,15 +179,12 @@ void AmsData::extractFromAidon(HanReader& hanReader, uint8_t listSize, bool subs
|
||||
l1voltage = ((float) hanReader.getInt( (uint8_t)Aidon_List3PhaseIT::VoltageL1)) / 10;
|
||||
l2voltage = ((float) hanReader.getInt( (uint8_t)Aidon_List3PhaseIT::VoltageL2)) / 10;
|
||||
l3voltage = ((float) hanReader.getInt( (uint8_t)Aidon_List3PhaseIT::VoltageL3)) / 10;
|
||||
if(substituteMissing) {
|
||||
l2current = (((activeImportPower - activeExportPower) * sqrt(3)) - (l1voltage * l1current) - (l3voltage * l3current)) / l2voltage;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AmsData::extractFromKamstrup(HanReader& hanReader, uint8_t listSize, bool substituteMissing) {
|
||||
void AmsData::extractFromKamstrup(HanReader& hanReader, uint8_t listSize) {
|
||||
switch(listSize) {
|
||||
case (uint8_t)Kamstrup::List3PhaseITShort:
|
||||
case (uint8_t)Kamstrup::List3PhaseShort:
|
||||
@@ -254,15 +259,20 @@ void AmsData::extractFromKamstrup(HanReader& hanReader, uint8_t listSize, bool s
|
||||
l1voltage = hanReader.getInt( (uint8_t)Kamstrup_List3Phase::VoltageL1);
|
||||
l2voltage = hanReader.getInt( (uint8_t)Kamstrup_List3Phase::VoltageL2);
|
||||
l3voltage = hanReader.getInt( (uint8_t)Kamstrup_List3Phase::VoltageL3);
|
||||
if(substituteMissing) {
|
||||
l2current = (((activeImportPower - activeExportPower) * sqrt(3)) - (l1voltage * l1current) - (l3voltage * l3current)) / l2voltage;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void AmsData::extractFromOmnipower(HanReader& hanReader, uint8_t listSize) {
|
||||
switch(listSize) {
|
||||
case (uint8_t)Kamstrup::List3PhaseITShort:
|
||||
case (uint8_t)Kamstrup::List3PhaseShort:
|
||||
case (uint8_t)Kamstrup::List1PhaseShort:
|
||||
case (uint8_t)Kamstrup::List3PhaseITLong:
|
||||
case (uint8_t)Kamstrup::List3PhaseLong:
|
||||
case (uint8_t)Kamstrup::List1PhaseLong:
|
||||
extractFromKamstrup(hanReader, listSize);
|
||||
break;
|
||||
case (uint8_t)Omnipower::DLMS:
|
||||
meterTimestamp = hanReader.getTime( (uint8_t)Omnipower_DLMS::MeterClock, true, true);
|
||||
activeImportCounter = ((float) hanReader.getInt((uint8_t)Omnipower_DLMS::CumulativeActiveImportEnergy)) / 100;
|
||||
@@ -332,6 +342,7 @@ void AmsData::apply(AmsData& other) {
|
||||
this->l2voltage = other.getL2Voltage();
|
||||
this->l3voltage = other.getL3Voltage();
|
||||
this->threePhase = other.isThreePhase();
|
||||
this->twoPhase = other.isTwoPhase();
|
||||
case 1:
|
||||
this->activeImportPower = other.getActiveImportPower();
|
||||
}
|
||||
@@ -424,3 +435,7 @@ float AmsData::getReactiveExportCounter() {
|
||||
bool AmsData::isThreePhase() {
|
||||
return this->threePhase;
|
||||
}
|
||||
|
||||
bool AmsData::isTwoPhase() {
|
||||
return this->twoPhase;
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ public:
|
||||
float getReactiveExportCounter();
|
||||
|
||||
bool isThreePhase();
|
||||
bool isTwoPhase();
|
||||
|
||||
private:
|
||||
unsigned long lastUpdateMillis = 0;
|
||||
@@ -58,11 +59,11 @@ private:
|
||||
uint16_t activeImportPower = 0, reactiveImportPower = 0, activeExportPower = 0, reactiveExportPower = 0;
|
||||
float l1voltage = 0, l2voltage = 0, l3voltage = 0, l1current = 0, l2current = 0, l3current = 0;
|
||||
float activeImportCounter = 0, reactiveImportCounter = 0, activeExportCounter = 0, reactiveExportCounter = 0;
|
||||
bool threePhase = false, counterEstimated = false;
|
||||
bool threePhase = false, twoPhase = false, counterEstimated = false;
|
||||
|
||||
void extractFromKaifa(HanReader& hanReader, uint8_t listSize);
|
||||
void extractFromAidon(HanReader& hanReader, uint8_t listSize, bool substituteMissing);
|
||||
void extractFromKamstrup(HanReader& hanReader, uint8_t listSize, bool substituteMissing);
|
||||
void extractFromAidon(HanReader& hanReader, uint8_t listSize);
|
||||
void extractFromKamstrup(HanReader& hanReader, uint8_t listSize);
|
||||
void extractFromOmnipower(HanReader& hanReader, uint8_t listSize);
|
||||
};
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
#include "AmsToMqttBridge.h"
|
||||
#include "AmsStorage.h"
|
||||
#define ARDUINOJSON_POSITIVE_EXPONENTIATION_THRESHOLD 1e9
|
||||
#include <MQTT.h>
|
||||
#include <DNSServer.h>
|
||||
#include <lwip/apps/sntp.h>
|
||||
@@ -69,6 +68,7 @@ AmsMqttHandler* mqttHandler = NULL;
|
||||
HanReader hanReader;
|
||||
|
||||
Stream *hanSerial;
|
||||
SoftwareSerial *swSerial = NULL;
|
||||
|
||||
GpioConfig gpioConfig;
|
||||
MeterConfig meterConfig;
|
||||
@@ -141,21 +141,11 @@ void setup() {
|
||||
|
||||
bool shared = false;
|
||||
config.getMeterConfig(meterConfig);
|
||||
Serial.flush();
|
||||
Serial.end();
|
||||
if(gpioConfig.hanPin == 3) {
|
||||
shared = true;
|
||||
switch(meterConfig.type) {
|
||||
case METER_TYPE_KAMSTRUP:
|
||||
case METER_TYPE_OMNIPOWER:
|
||||
Serial.begin(2400, SERIAL_8N1);
|
||||
break;
|
||||
default:
|
||||
Serial.begin(2400, SERIAL_8E1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!shared) {
|
||||
Serial.begin(115200);
|
||||
setupHanPort(gpioConfig.hanPin, meterConfig.type);
|
||||
}
|
||||
|
||||
DebugConfig debug;
|
||||
@@ -460,9 +450,11 @@ void setupHanPort(int pin, int newMeterType) {
|
||||
debugI("Setting up HAN on pin %d for meter type %d", pin, newMeterType);
|
||||
|
||||
HardwareSerial *hwSerial = NULL;
|
||||
if(pin == 3) {
|
||||
if(pin == 3 || pin == 113) {
|
||||
hwSerial = &Serial;
|
||||
}
|
||||
|
||||
|
||||
#if defined(ESP32)
|
||||
if(pin == 9) {
|
||||
hwSerial = &Serial1;
|
||||
@@ -479,7 +471,9 @@ void setupHanPort(int pin, int newMeterType) {
|
||||
|
||||
if(hwSerial != NULL) {
|
||||
debugD("Hardware serial");
|
||||
Serial.flush();
|
||||
hwSerial->flush();
|
||||
hwSerial->end();
|
||||
|
||||
switch(newMeterType) {
|
||||
case METER_TYPE_KAMSTRUP:
|
||||
case METER_TYPE_OMNIPOWER:
|
||||
@@ -489,11 +483,27 @@ void setupHanPort(int pin, int newMeterType) {
|
||||
hwSerial->begin(2400, SERIAL_8E1);
|
||||
break;
|
||||
}
|
||||
|
||||
#if defined(ESP8266)
|
||||
if(pin == 3) {
|
||||
debugI("Switching UART0 to pin 1 & 3");
|
||||
Serial.pins(1,3);
|
||||
} else if(pin == 113) {
|
||||
debugI("Switching UART0 to pin 15 & 13");
|
||||
Serial.pins(15,13);
|
||||
}
|
||||
#endif
|
||||
|
||||
hanSerial = hwSerial;
|
||||
} else {
|
||||
debugD("Software serial");
|
||||
Serial.flush();
|
||||
SoftwareSerial *swSerial = new SoftwareSerial(pin);
|
||||
|
||||
if(swSerial != NULL) {
|
||||
swSerial->end();
|
||||
delete swSerial;
|
||||
}
|
||||
swSerial = new SoftwareSerial(pin);
|
||||
|
||||
switch(newMeterType) {
|
||||
case METER_TYPE_KAMSTRUP:
|
||||
@@ -506,6 +516,7 @@ void setupHanPort(int pin, int newMeterType) {
|
||||
}
|
||||
hanSerial = swSerial;
|
||||
|
||||
Serial.end();
|
||||
Serial.begin(115200);
|
||||
}
|
||||
|
||||
|
||||
@@ -129,15 +129,17 @@ bool HwTools::updateTemperatures() {
|
||||
delay(10);
|
||||
}
|
||||
} else {
|
||||
sensorApi->requestTemperatures();
|
||||
if(sensorCount > 0) {
|
||||
sensorApi->requestTemperatures();
|
||||
|
||||
for(int x = 0; x < sensorCount; x++) {
|
||||
TempSensorData *data = tempSensors[x];
|
||||
float t = sensorApi->getTempC(data->address);
|
||||
data->lastRead = t;
|
||||
if(t > -85) {
|
||||
data->changed = data->lastValidRead != t;
|
||||
data->lastValidRead = t;
|
||||
for(int x = 0; x < sensorCount; x++) {
|
||||
TempSensorData *data = tempSensors[x];
|
||||
float t = sensorApi->getTempC(data->address);
|
||||
data->lastRead = t;
|
||||
if(t > -85) {
|
||||
data->changed = data->lastValidRead != t;
|
||||
data->lastValidRead = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,15 +6,15 @@ float DnbCurrParser::getValue() {
|
||||
}
|
||||
|
||||
int DnbCurrParser::available() {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DnbCurrParser::read() {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DnbCurrParser::peek() {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DnbCurrParser::flush() {
|
||||
|
||||
@@ -18,15 +18,15 @@ float EntsoeA44Parser::getPoint(uint8_t position) {
|
||||
}
|
||||
|
||||
int EntsoeA44Parser::available() {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int EntsoeA44Parser::read() {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int EntsoeA44Parser::peek() {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void EntsoeA44Parser::flush() {
|
||||
|
||||
@@ -23,55 +23,47 @@ bool DomoticzMqttHandler::publish(AmsData* data, AmsData* previousState) {
|
||||
return ret;
|
||||
|
||||
if (config.vl1idx > 0){
|
||||
if (data->getL1Voltage() > 0.1){
|
||||
char val[16];
|
||||
snprintf(val, 16, "%.2f", data->getL1Voltage());
|
||||
char json[192];
|
||||
snprintf_P(json, sizeof(json), DOMOTICZ_JSON,
|
||||
config.vl1idx,
|
||||
val
|
||||
);
|
||||
ret |= mqtt->publish("domoticz/in", json);
|
||||
}
|
||||
char val[16];
|
||||
snprintf(val, 16, "%.2f", data->getL1Voltage());
|
||||
char json[192];
|
||||
snprintf_P(json, sizeof(json), DOMOTICZ_JSON,
|
||||
config.vl1idx,
|
||||
val
|
||||
);
|
||||
ret |= mqtt->publish("domoticz/in", json);
|
||||
}
|
||||
|
||||
if (config.vl2idx > 0){
|
||||
if (data->getL2Voltage() > 0.1){
|
||||
char val[16];
|
||||
snprintf(val, 16, "%.2f", data->getL2Voltage());
|
||||
char json[192];
|
||||
snprintf_P(json, sizeof(json), DOMOTICZ_JSON,
|
||||
config.vl2idx,
|
||||
val
|
||||
);
|
||||
ret |= mqtt->publish("domoticz/in", json);
|
||||
}
|
||||
char val[16];
|
||||
snprintf(val, 16, "%.2f", data->getL2Voltage());
|
||||
char json[192];
|
||||
snprintf_P(json, sizeof(json), DOMOTICZ_JSON,
|
||||
config.vl2idx,
|
||||
val
|
||||
);
|
||||
ret |= mqtt->publish("domoticz/in", json);
|
||||
}
|
||||
|
||||
if (config.vl3idx > 0){
|
||||
if (data->getL3Voltage() > 0.1){
|
||||
char val[16];
|
||||
snprintf(val, 16, "%.2f", data->getL3Voltage());
|
||||
char json[192];
|
||||
snprintf_P(json, sizeof(json), DOMOTICZ_JSON,
|
||||
config.vl3idx,
|
||||
val
|
||||
);
|
||||
ret |= mqtt->publish("domoticz/in", json);
|
||||
}
|
||||
char val[16];
|
||||
snprintf(val, 16, "%.2f", data->getL3Voltage());
|
||||
char json[192];
|
||||
snprintf_P(json, sizeof(json), DOMOTICZ_JSON,
|
||||
config.vl3idx,
|
||||
val
|
||||
);
|
||||
ret |= mqtt->publish("domoticz/in", json);
|
||||
}
|
||||
|
||||
if (config.cl1idx > 0){
|
||||
if(data->getL1Current() > 0.0) {
|
||||
char val[16];
|
||||
snprintf(val, 16, "%.1f;%.1f;%.1f", data->getL1Current(), data->getL2Current(), data->getL3Current());
|
||||
char json[192];
|
||||
snprintf_P(json, sizeof(json), DOMOTICZ_JSON,
|
||||
config.cl1idx,
|
||||
val
|
||||
);
|
||||
ret |= mqtt->publish("domoticz/in", json);
|
||||
}
|
||||
char val[16];
|
||||
snprintf(val, 16, "%.1f;%.1f;%.1f", data->getL1Current(), data->getL2Current(), data->getL3Current());
|
||||
char json[192];
|
||||
snprintf_P(json, sizeof(json), DOMOTICZ_JSON,
|
||||
config.cl1idx,
|
||||
val
|
||||
);
|
||||
ret |= mqtt->publish("domoticz/in", json);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -117,9 +117,11 @@ void AmsWebServer::loop() {
|
||||
server.handleClient();
|
||||
|
||||
if(maxPwr == 0 && meterState->getListType() > 1 && meterConfig->mainFuse > 0 && meterConfig->distributionSystem > 0) {
|
||||
int voltage = meterConfig->distributionSystem == 2 ? 400 : 230;
|
||||
if(meterState->isThreePhase()) {
|
||||
int voltage = meterConfig->distributionSystem == 2 ? 400 : 230;
|
||||
maxPwr = meterConfig->mainFuse * sqrt(3) * voltage;
|
||||
} else if(meterState->isTwoPhase()) {
|
||||
maxPwr = meterConfig->mainFuse * voltage;
|
||||
} else {
|
||||
maxPwr = meterConfig->mainFuse * 230;
|
||||
}
|
||||
@@ -134,7 +136,15 @@ bool AmsWebServer::checkSecurity(byte level) {
|
||||
String providedPwd = server.header("Authorization");
|
||||
providedPwd.replace("Basic ", "");
|
||||
|
||||
#if defined(ESP8266)
|
||||
String expectedBase64 = base64::encode(expectedAuth, false);
|
||||
#elif defined(ESP32)
|
||||
String expectedBase64 = base64::encode(expectedAuth);
|
||||
#endif
|
||||
|
||||
debugger->printf("Expected auth: %s\n", expectedBase64.c_str());
|
||||
debugger->printf("Provided auth: %s\n", providedPwd.c_str());
|
||||
|
||||
access = providedPwd.equals(expectedBase64);
|
||||
}
|
||||
|
||||
@@ -181,7 +191,7 @@ void AmsWebServer::temperaturePost() {
|
||||
delay(1);
|
||||
}
|
||||
|
||||
if (debugger->isActive(RemoteDebug::DEBUG)) config->print(debugger);
|
||||
//if (debugger->isActive(RemoteDebug::DEBUG)) config->print(debugger);
|
||||
if(config->save()) {
|
||||
printD("Successfully saved temperature sensors");
|
||||
server.sendHeader("Location", String("/temperature"), true);
|
||||
@@ -352,7 +362,7 @@ void AmsWebServer::indexHtml() {
|
||||
html.replace("{temp}", temp > 0 ? String(temp, 1) : "");
|
||||
|
||||
int rssi = hw->getWifiRssi();
|
||||
html.replace("{rssi}", vcc > 0 ? String(rssi) : "");
|
||||
html.replace("{rssi}", String(rssi));
|
||||
|
||||
html.replace("{cs}", String((uint32_t)(millis64()/1000), 10));
|
||||
|
||||
@@ -685,7 +695,7 @@ void AmsWebServer::dataJson() {
|
||||
mqttStatus = 3;
|
||||
}
|
||||
|
||||
char json[280];
|
||||
char json[290];
|
||||
snprintf_P(json, sizeof(json), DATA_JSON,
|
||||
maxPwr == 0 ? meterState->isThreePhase() ? 20000 : 10000 : maxPwr,
|
||||
meterConfig->productionCapacity,
|
||||
@@ -695,7 +705,7 @@ void AmsWebServer::dataJson() {
|
||||
meterState->getReactiveImportPower(),
|
||||
meterState->getReactiveExportPower(),
|
||||
meterState->getActiveImportCounter(),
|
||||
meterState->getReactiveExportCounter(),
|
||||
meterState->getActiveExportCounter(),
|
||||
meterState->getReactiveImportCounter(),
|
||||
meterState->getReactiveExportCounter(),
|
||||
meterState->getL1Voltage(),
|
||||
@@ -733,6 +743,9 @@ void AmsWebServer::handleSetup() {
|
||||
} else {
|
||||
SystemConfig sys { server.arg("board").toInt() };
|
||||
|
||||
DebugConfig debugConfig;
|
||||
config->getDebugConfig(debugConfig);
|
||||
|
||||
config->clear();
|
||||
|
||||
config->clearGpio(*gpioConfig);
|
||||
@@ -751,7 +764,6 @@ void AmsWebServer::handleSetup() {
|
||||
gpioConfig->apPin = 0;
|
||||
gpioConfig->ledPin = 2;
|
||||
gpioConfig->ledInverted = true;
|
||||
gpioConfig->tempSensorPin = 5;
|
||||
gpioConfig->ledPinRed = 13;
|
||||
gpioConfig->ledPinGreen = 14;
|
||||
gpioConfig->ledRgbInverted = true;
|
||||
@@ -764,12 +776,29 @@ void AmsWebServer::handleSetup() {
|
||||
gpioConfig->tempSensorPin = 5;
|
||||
gpioConfig->vccBootLimit = 33;
|
||||
break;
|
||||
case 3: // Pow UART0
|
||||
gpioConfig->hanPin = 3;
|
||||
gpioConfig->apPin = 0;
|
||||
gpioConfig->ledPin = 2;
|
||||
gpioConfig->ledInverted = true;
|
||||
gpioConfig->ledPinRed = 13;
|
||||
gpioConfig->ledPinGreen = 14;
|
||||
gpioConfig->ledRgbInverted = true;
|
||||
break;
|
||||
case 4: // Pow GPIO12
|
||||
gpioConfig->hanPin = 12;
|
||||
gpioConfig->apPin = 0;
|
||||
gpioConfig->ledPin = 2;
|
||||
gpioConfig->ledInverted = true;
|
||||
gpioConfig->ledPinRed = 13;
|
||||
gpioConfig->ledPinGreen = 14;
|
||||
gpioConfig->ledRgbInverted = true;
|
||||
break;
|
||||
case 101: // D1
|
||||
gpioConfig->hanPin = 5;
|
||||
gpioConfig->apPin = 4;
|
||||
gpioConfig->ledPin = 2;
|
||||
gpioConfig->ledInverted = true;
|
||||
gpioConfig->tempSensorPin = 14;
|
||||
gpioConfig->vccMultiplier = 1100;
|
||||
break;
|
||||
case 100: // ESP8266
|
||||
@@ -782,13 +811,11 @@ void AmsWebServer::handleSetup() {
|
||||
gpioConfig->apPin = 4;
|
||||
gpioConfig->ledPin = 5;
|
||||
gpioConfig->ledInverted = true;
|
||||
gpioConfig->tempSensorPin = 14;
|
||||
break;
|
||||
case 202: // Feather
|
||||
gpioConfig->hanPin = 16;
|
||||
gpioConfig->ledPin = 2;
|
||||
gpioConfig->ledInverted = false;
|
||||
gpioConfig->tempSensorPin = 14;
|
||||
break;
|
||||
case 203: // DevKitC
|
||||
gpioConfig->hanPin = 16;
|
||||
@@ -800,7 +827,6 @@ void AmsWebServer::handleSetup() {
|
||||
gpioConfig->apPin = 0;
|
||||
gpioConfig->ledPin = 2;
|
||||
gpioConfig->ledInverted = false;
|
||||
gpioConfig->tempSensorPin = 14;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -861,6 +887,8 @@ void AmsWebServer::handleSetup() {
|
||||
success = false;
|
||||
}
|
||||
|
||||
config->setDebugConfig(debugConfig);
|
||||
|
||||
if(success && config->save()) {
|
||||
performRestart = true;
|
||||
server.sendHeader("Location","/restart-wait");
|
||||
@@ -898,7 +926,7 @@ void AmsWebServer::handleSave() {
|
||||
authenticationKeyHex.replace("0x", "");
|
||||
fromHex(meterConfig->authenticationKey, authenticationKeyHex, 16);
|
||||
}
|
||||
meterConfig->substituteMissing = server.hasArg("s") && server.arg("substituteMissing") == "true";
|
||||
meterConfig->substituteMissing = server.hasArg("s") && server.arg("s") == "true";
|
||||
config->setMeterConfig(*meterConfig);
|
||||
}
|
||||
|
||||
@@ -1040,7 +1068,7 @@ void AmsWebServer::handleSave() {
|
||||
|
||||
printI("Saving configuration now...");
|
||||
|
||||
if (debugger->isActive(RemoteDebug::DEBUG)) config->print(debugger);
|
||||
//if (debugger->isActive(RemoteDebug::DEBUG)) config->print(debugger);
|
||||
if (config->save()) {
|
||||
printI("Successfully saved.");
|
||||
if(config->isWifiChanged()) {
|
||||
@@ -1163,26 +1191,31 @@ void AmsWebServer::configDebugHtml() {
|
||||
String AmsWebServer::getSerialSelectOptions(int selected) {
|
||||
String gpioOptions;
|
||||
if(selected == 3) {
|
||||
gpioOptions += "<option value=\"3\" selected>UART0</option>";
|
||||
gpioOptions += "<option value=\"3\" selected>UART0 (GPIO3)</option>";
|
||||
} else {
|
||||
gpioOptions += "<option value=\"3\">UART0</option>";
|
||||
gpioOptions += "<option value=\"3\">UART0 (GPIO3)</option>";
|
||||
}
|
||||
#if defined(ESP32)
|
||||
int numGpio = 24;
|
||||
int gpios[] = {4,5,6,7,8,10,11,12,13,14,15,17,18,19,21,22,23,25,32,33,34,35,36,39};
|
||||
if(selected == 9) {
|
||||
gpioOptions += "<option value=\"9\" selected>UART1</option>";
|
||||
gpioOptions += "<option value=\"9\" selected>UART1 (GPIO9)</option>";
|
||||
} else {
|
||||
gpioOptions += "<option value=\"9\">UART1</option>";
|
||||
gpioOptions += "<option value=\"9\">UART1 (GPIO9)</option>";
|
||||
}
|
||||
if(selected == 16) {
|
||||
gpioOptions += "<option value=\"16\" selected>UART2</option>";
|
||||
gpioOptions += "<option value=\"16\" selected>UART2 (GPIO16)</option>";
|
||||
} else {
|
||||
gpioOptions += "<option value=\"16\">UART2</option>";
|
||||
gpioOptions += "<option value=\"16\">UART2 (GPIO16)</option>";
|
||||
}
|
||||
#elif defined(ESP8266)
|
||||
int numGpio = 9;
|
||||
int gpios[] = {4,5,9,10,12,13,14,15,16};
|
||||
if(selected == 113) {
|
||||
gpioOptions += "<option value=\"113\" selected>UART2 (GPIO13)</option>";
|
||||
} else {
|
||||
gpioOptions += "<option value=\"113\">UART2 (GPIO13)</option>";
|
||||
}
|
||||
#endif
|
||||
|
||||
for(int i = 0; i < numGpio; i++) {
|
||||
@@ -1251,7 +1284,7 @@ void AmsWebServer::firmwareHtml() {
|
||||
if(!checkSecurity(1))
|
||||
return;
|
||||
|
||||
uploadHtml("CA file", "/firmware", "mqtt");
|
||||
uploadHtml("Firmware", "/firmware", "system");
|
||||
}
|
||||
|
||||
void AmsWebServer::firmwareUpload() {
|
||||
|
||||
@@ -147,6 +147,7 @@ $(function() {
|
||||
case '/gpio':
|
||||
case '/debugging':
|
||||
case '/firmware':
|
||||
$('#firmware-warn').show();
|
||||
case '/reset':
|
||||
$('#system-link').addClass('active');
|
||||
break;
|
||||
@@ -307,11 +308,22 @@ var fetch = function() {
|
||||
});
|
||||
}
|
||||
|
||||
if(vm && vm.gaugeMeter && json.u1) {
|
||||
var v = parseFloat(json.u1);
|
||||
if(json.u2) {
|
||||
v = (v+parseFloat(json.u2)+parseFloat(json.u3)) / 3;
|
||||
if(vm && vm.gaugeMeter) {
|
||||
var c = 0;
|
||||
var t = 0;
|
||||
if(json.u1) {
|
||||
t += parseFloat(json.u1);
|
||||
c++;
|
||||
}
|
||||
if(json.u2) {
|
||||
t += parseFloat(json.u2);
|
||||
c++;
|
||||
}
|
||||
if(json.u3) {
|
||||
t += parseFloat(json.u3);
|
||||
c++;
|
||||
}
|
||||
v = t/c;
|
||||
var pct = (Math.max(v-207, 1)*100/46);
|
||||
vm.gaugeMeter({
|
||||
percent: pct,
|
||||
@@ -319,18 +331,21 @@ var fetch = function() {
|
||||
});
|
||||
}
|
||||
|
||||
if(am && am.gaugeMeter && json.i1 && json.mf) {
|
||||
var v = parseFloat(json.i1);
|
||||
if(am && am.gaugeMeter && json.mf) {
|
||||
var a = 0;
|
||||
if(json.i1) {
|
||||
a = Math.max(a, parseFloat(json.i1));
|
||||
}
|
||||
if(json.i2) {
|
||||
v = Math.max(v, parseFloat(json.i2));
|
||||
a = Math.max(a, parseFloat(json.i2));
|
||||
}
|
||||
if(json.i3) {
|
||||
v = Math.max(v, parseFloat(json.i3));
|
||||
a = Math.max(a, parseFloat(json.i3));
|
||||
}
|
||||
var pct = (v*100)/parseInt(json.mf);
|
||||
var pct = (a*100)/parseInt(json.mf);
|
||||
am.gaugeMeter({
|
||||
percent: pct,
|
||||
text: v.toFixed(1)
|
||||
text: a.toFixed(1)
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -6,19 +6,19 @@
|
||||
"e" : %d,
|
||||
"ri" : %d,
|
||||
"re" : %d,
|
||||
"ic" : %.1f,
|
||||
"ec" : %.1f,
|
||||
"ric" : %.1f,
|
||||
"rec" : %.1f,
|
||||
"u1" : %.1f,
|
||||
"u2" : %.1f,
|
||||
"u3" : %.1f,
|
||||
"ic" : %.2f,
|
||||
"ec" : %.2f,
|
||||
"ric" : %.2f,
|
||||
"rec" : %.2f,
|
||||
"u1" : %.2f,
|
||||
"u2" : %.2f,
|
||||
"u3" : %.2f,
|
||||
"i1" : %.2f,
|
||||
"i2" : %.2f,
|
||||
"i3" : %.2f,
|
||||
"v" : %.2f,
|
||||
"v" : %.3f,
|
||||
"r" : %d,
|
||||
"t" : %.1f,
|
||||
"t" : %.2f,
|
||||
"u" : %lu,
|
||||
"m" : %lu,
|
||||
"em" : %d,
|
||||
|
||||
@@ -20,10 +20,10 @@
|
||||
"U1" : %.2f,
|
||||
"U2" : %.2f,
|
||||
"U3" : %.2f,
|
||||
"tPI" : %.1f,
|
||||
"tPO" : %.1f,
|
||||
"tQI" : %.1f,
|
||||
"tQO" : %.1f,
|
||||
"tPI" : %.2f,
|
||||
"tPO" : %.2f,
|
||||
"tQI" : %.2f,
|
||||
"tQO" : %.2f,
|
||||
"rtc" : %lu
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
<option value="0" {m0}>Autodetect</option>
|
||||
<option value="1" {m1}>Kaifa</option>
|
||||
<option value="2" {m2}>Aidon</option>
|
||||
<option value="3" {m3}>Kamstrup</option>
|
||||
<option value="4" {m4}>Kamstrup (Omnipower)</option>
|
||||
<option value="3" {m3}>Kamstrup non-encrypted</option>
|
||||
<option value="4" {m4}>Kamstrup encrypted</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text">Host</span>
|
||||
</div>
|
||||
<input type="text" class="form-control mc" name="h" value="{h}" maxlength="128"/>
|
||||
<input type="text" class="form-control mc" name="h" value="{h}" maxlength="127"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xl-2 col-lg-3 col-md-3 col-sm-4">
|
||||
@@ -25,7 +25,7 @@
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text">Client ID</span>
|
||||
</div>
|
||||
<input type="text" class="form-control mc" name="i" value="{i}" maxlength="32"/>
|
||||
<input type="text" class="form-control mc" name="i" value="{i}" maxlength="31"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xl-3 col-lg-4 col-md-6">
|
||||
@@ -33,7 +33,7 @@
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text">Publish topic</span>
|
||||
</div>
|
||||
<input type="text" class="form-control mc" name="t" value="{t}" maxlength="64"/>
|
||||
<input type="text" class="form-control mc" name="t" value="{t}" maxlength="63"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xl-3 col-lg-4 col-md-6 col-sm-6">
|
||||
@@ -41,7 +41,7 @@
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text">Username</span>
|
||||
</div>
|
||||
<input type="text" class="form-control mc" name="u" value="{u}" maxlength="64"/>
|
||||
<input type="text" class="form-control mc" name="u" value="{u}" maxlength="127"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xl-3 col-lg-4 col-md-6 col-sm-6">
|
||||
@@ -49,7 +49,7 @@
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text">Password</span>
|
||||
</div>
|
||||
<input type="password" class="form-control mc" name="pw" value="{pw}" maxlength="64"/>
|
||||
<input type="password" class="form-control mc" name="pw" value="{pw}" maxlength="255"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-3 col-md-4 col-sm-6">
|
||||
|
||||
@@ -25,9 +25,11 @@
|
||||
<h5>Hardware</h5>
|
||||
<select name="board" class="form-control">
|
||||
<optgroup label="Custom hardware">
|
||||
<option value="0" ${config.boardType0}>Custom hardware by Roar Fredriksen</option>
|
||||
<option value="1" ${config.boardType1}>Kamstrup module by Egil Opsahl</option>
|
||||
<option value="4" ${config.boardType2}>Pow-U or Pow-K from amsleser.no (GPIO12)</option>
|
||||
<option value="3" ${config.boardType2}>Pow-U or Pow-K from amsleser.no (UART0)</option>
|
||||
<option value="2" ${config.boardType2}>HAN Reader 2.0 by Max Spencer</option>
|
||||
<option value="1" ${config.boardType1}>Kamstrup module by Egil Opsahl</option>
|
||||
<option value="0" ${config.boardType0}>Custom hardware by Roar Fredriksen</option>
|
||||
</optgroup>
|
||||
<optgroup label="ESP8266">
|
||||
<option value="101" ${config.boardType101}>Wemos D1</option>
|
||||
@@ -41,16 +43,6 @@
|
||||
</optgroup>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-xl-2 col-md-3">
|
||||
<h5>Meter</h5>
|
||||
<select name="meterType" class="form-control">
|
||||
<option value="0" ${config.meterType0}>Autodetect</option>
|
||||
<option value="1" ${config.meterType1}>Kaifa</option>
|
||||
<option value="2" ${config.meterType2}>Aidon</option>
|
||||
<option value="3" ${config.meterType3}>Kamstrup</option>
|
||||
<option value="4" ${config.meterType4}>Kamstrup (Omnipower)</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="my-3 p-3 bg-white rounded shadow">
|
||||
|
||||
@@ -13,6 +13,12 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="firmware-warn" style="display: none;">
|
||||
<br/>
|
||||
<div class="alert alert-danger">
|
||||
WARNING: Units powered over M-bus must be connected to an external power supply during firmware upload. Failure to do so may cause power-down during upload resulting in non-functioning unit.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<hr/>
|
||||
<div class="row form-group">
|
||||
|
||||
Reference in New Issue
Block a user