mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-03-11 13:05:31 +00:00
Compare commits
52 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ed523bda24 | ||
|
|
e3a1a242d2 | ||
|
|
ddfade65d8 | ||
|
|
0ef8390df0 | ||
|
|
f43fe5f864 | ||
|
|
f9ddd7533a | ||
|
|
f9f18bc106 | ||
|
|
280dd8605b | ||
|
|
41324cf590 | ||
|
|
64132d5ce3 | ||
|
|
0e75732022 | ||
|
|
6975714922 | ||
|
|
7f3e0e6089 | ||
|
|
6ff5518738 | ||
|
|
be29daee77 | ||
|
|
a90ed40aee | ||
|
|
32ba6c31f0 | ||
|
|
caf00f99e3 | ||
|
|
aaa318e511 | ||
|
|
648cac0b06 | ||
|
|
a5d1a2c0ee | ||
|
|
55f1b4b129 | ||
|
|
b805363c60 | ||
|
|
846b166ae9 | ||
|
|
4e039c2cc9 | ||
|
|
e5556fe80b | ||
|
|
c5aa65a780 | ||
|
|
30cf1435da | ||
|
|
fca46a3f54 | ||
|
|
0dca85d67b | ||
|
|
d9a5a21fe0 | ||
|
|
68eaa7d39b | ||
|
|
3231d0747e | ||
|
|
2617956b38 | ||
|
|
07614226b3 | ||
|
|
cddb170f24 | ||
|
|
ba7915ca7c | ||
|
|
ee12db4f51 | ||
|
|
f01fbfca53 | ||
|
|
fab637cf60 | ||
|
|
b2e144efcf | ||
|
|
10308ce738 | ||
|
|
70f5b0f912 | ||
|
|
d724a90085 | ||
|
|
1ab529785a | ||
|
|
3a81e62bbe | ||
|
|
4882916b5c | ||
|
|
1f7e43256a | ||
|
|
a0d3632fd7 | ||
|
|
b25564a89f | ||
|
|
191d9fa562 | ||
|
|
e009b4e54e |
5
.github/ISSUE_TEMPLATE/bug_report.md
vendored
5
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@@ -24,16 +24,19 @@ A clear description of what you expected to happen.
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Hardware information:**
|
||||
- Country: [e.g. Norway]
|
||||
- Meter: [e.g. Aidon]
|
||||
- Encryption enabled [yes/no]
|
||||
- AMS reader: [e.g. Pow-U, ESP32 etc]
|
||||
- M-bus adapter (if applicable):
|
||||
|
||||
**Relevant firmware information:**
|
||||
- Version: [e.g. 1.5.0]
|
||||
- Version: [e.g. 2.1.0]
|
||||
- MQTT: [yes/no]
|
||||
- HAN GPIO: [e.g. GPIO5]
|
||||
- HAN baud and parity: [e.g. 2400 8E1]
|
||||
- Temperature sensors [e.g. 3xDS18B20]
|
||||
- ENTSO-E API enabled: [yes/no]
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
|
||||
6
.github/ISSUE_TEMPLATE/support.md
vendored
6
.github/ISSUE_TEMPLATE/support.md
vendored
@@ -11,12 +11,16 @@ assignees: ''
|
||||
A clear and concise description of what the problem is.
|
||||
|
||||
**Hardware information:**
|
||||
- Country: [e.g. Norway]
|
||||
- Meter: [e.g. Aidon]
|
||||
- Encryption enabled [yes/no]
|
||||
- AMS reader: [e.g. Pow-U, ESP32 etc]
|
||||
- M-bus adapter (if applicable):
|
||||
|
||||
**Relevant firmware information:**
|
||||
- Version: [e.g. 1.5.0]
|
||||
- Version: [e.g. 2.1.0]
|
||||
- MQTT: [yes/no]
|
||||
- HAN GPIO: [e.g. GPIO5]
|
||||
- HAN baud and parity: [e.g. 2400 8E1]
|
||||
- Temperature sensors [e.g. 3xDS18B20]
|
||||
- ENTSO-E API enabled: [yes/no]
|
||||
|
||||
9
.github/workflows/release.yml
vendored
9
.github/workflows/release.yml
vendored
@@ -104,6 +104,15 @@ jobs:
|
||||
asset_path: .pio/build/esp32/firmware.bin
|
||||
asset_name: ams2mqtt-esp32-${{ steps.release_tag.outputs.tag }}.bin
|
||||
asset_content_type: application/octet-stream
|
||||
- name: Upload esp32solo binary to release
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: .pio/build/esp32solo/firmware.bin
|
||||
asset_name: ams2mqtt-esp32solo-${{ steps.release_tag.outputs.tag }}.bin
|
||||
asset_content_type: application/octet-stream
|
||||
- name: Upload esp32s2 binary to release
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
|
||||
BIN
doc/Switzerland/RWB_SmartMeter_Bedienungsanleitung.pdf
Normal file
BIN
doc/Switzerland/RWB_SmartMeter_Bedienungsanleitung.pdf
Normal file
Binary file not shown.
@@ -6,7 +6,7 @@ DB // Encrypted
|
||||
08 4B 41 4D 45 01 AC 4D 6E // System title
|
||||
82 // Prefix for 2-byte length
|
||||
01 D0 // Length 464
|
||||
30 // Security tag 0011 0000, 0=Compression off, 0=Unicast, 1=Encryption, 0=Authentication, 0000= Security Suite ID
|
||||
30 // Security tag 0011 0000, 0=Compression off, 0=Unicast, 1=Encryption, 1=Authentication, 0000= Security Suite ID
|
||||
00 00 A3 2F // Frame counter
|
||||
|
||||
// Decrypted frame below
|
||||
|
||||
45
frames/lng.raw
Normal file
45
frames/lng.raw
Normal file
@@ -0,0 +1,45 @@
|
||||
7E // Flag
|
||||
A08B
|
||||
CEFF03
|
||||
13
|
||||
EEE1
|
||||
E6E700
|
||||
E0 // GBT (Green book 9.4.6.13)
|
||||
40 // Block control 0100 0000, last block=no, streaming=yes, remainig=window
|
||||
0001 // Block sequence
|
||||
0000 // Block sequence ack
|
||||
77 // How many bytes in this block
|
||||
|
||||
0F 00000DB7 // APDU tag, Invoke ID and priority
|
||||
|
||||
0C07E604020607220FFF800000 // Date and time
|
||||
0205 // Structure with 5 items
|
||||
0105 // Array with 5 items
|
||||
020412002809060008190900FF0F02120000 // Structure with 4 items, uint16, OBIS, int8, uint16 (0-8:25.9.0;2)
|
||||
020412002809060008190900FF0F01120000 // Structure with 4 items, uint16, OBIS, int8, uint16 (0-8:25.9.0;1)
|
||||
020412000109060000600101FF0F02120000 // Structure with 4 items, uint16, OBIS, int8, uint16 (96.1.1 - Meter model)
|
||||
020412000309060100010700FF0F02120000 // Structure with 4 items, uint16, OBIS, int8, uint16 (1.7.0 Active import)
|
||||
020412000309060100020700FF0F02120000 // Structure with 4 items, uint16, OBIS, int8, uint16 (2.7.0 Active export)
|
||||
09060008190900 // OBIS 0-8:25.9.0 Object list push settings consumer information 1
|
||||
ABA6
|
||||
7E
|
||||
|
||||
|
||||
|
||||
7E
|
||||
A024
|
||||
CEFF03
|
||||
13
|
||||
D661
|
||||
E0 // GBT
|
||||
C0 // Block control 0100 0000, last block=yes, streaming=yes, remainig=window
|
||||
0002 // Block sequence
|
||||
0000 // Block sequence ack
|
||||
13 // How many bytes in this block
|
||||
|
||||
FF // Last byte of OBIS in previous block
|
||||
0906363031313039 // Device ID
|
||||
0600000028 // Accumulated import
|
||||
0600000000 // Accumulated export
|
||||
8BA4
|
||||
7E
|
||||
34
hardware/wemos_mbus_shield/README.md
Normal file
34
hardware/wemos_mbus_shield/README.md
Normal file
@@ -0,0 +1,34 @@
|
||||
## Wemos shield
|
||||
|
||||
Fits D1 mini and S2 mini.
|
||||
|
||||
<img src="img1.jpg"/>
|
||||
<img src="img2.jpg"/>
|
||||
|
||||
**WARNING** Not properly tested
|
||||
|
||||
**Resistors**
|
||||
- R1: 470 (for U1)
|
||||
- R2: 220 (for U1)
|
||||
- R3: 82k (for U1)
|
||||
- R4: 220 (for U1)
|
||||
- R5: 100k (for U1)
|
||||
- R6: 10k (for AP button)
|
||||
- R7: 4.7k (for DS18B20)
|
||||
- R8-R10: 1k (for RGB LED)
|
||||
|
||||
**Capacitors**
|
||||
- C1: 100n (for U1)
|
||||
- C2: 1u (for U1)
|
||||
- C3: 100n (for U1)
|
||||
|
||||
**Other components**
|
||||
- U1: TSS521 or TSS721
|
||||
- U2: DS18B20 (Digital temperature sensor)
|
||||
- D1: RGB LED
|
||||
- J1: RJ45
|
||||
- SW1: AP button (to D3 GPIO0)
|
||||
|
||||
**Jumper**
|
||||
- JP1 & JP4: Jump these to receive power (5V) via RJ45 on pin 7 (GND) and 8 (+5)
|
||||
- JP2 & JP3: Jump these to attach DS18B20 sensors via RJ45 on pin 4 (Data) and pin 5 (GND)
|
||||
BIN
hardware/wemos_mbus_shield/img1.jpg
Normal file
BIN
hardware/wemos_mbus_shield/img1.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 237 KiB |
BIN
hardware/wemos_mbus_shield/img2.jpg
Normal file
BIN
hardware/wemos_mbus_shield/img2.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 296 KiB |
3
hardware/wemos_mbus_shield/kicad/.gitignore
vendored
Normal file
3
hardware/wemos_mbus_shield/kicad/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
gerber
|
||||
rescue-backup
|
||||
*-bak
|
||||
326
hardware/wemos_mbus_shield/kicad/d1_mini_shield-cache.lib
Normal file
326
hardware/wemos_mbus_shield/kicad/d1_mini_shield-cache.lib
Normal file
@@ -0,0 +1,326 @@
|
||||
EESchema-LIBRARY Version 2.4
|
||||
#encoding utf-8
|
||||
#
|
||||
# Connector_RJ45
|
||||
#
|
||||
DEF Connector_RJ45 J 0 40 Y Y 1 F N
|
||||
F0 "J" -200 550 50 H V R CNN
|
||||
F1 "Connector_RJ45" 100 550 50 H V L CNN
|
||||
F2 "" 0 25 50 V I C CNN
|
||||
F3 "" 0 25 50 V I C CNN
|
||||
ALIAS RJ31 RJ32 RJ33 RJ34 RJ35 RJ41 RJ45 RJ49 RJ61
|
||||
$FPLIST
|
||||
8P8C*
|
||||
RJ31*
|
||||
RJ32*
|
||||
RJ33*
|
||||
RJ34*
|
||||
RJ35*
|
||||
RJ41*
|
||||
RJ45*
|
||||
RJ49*
|
||||
RJ61*
|
||||
$ENDFPLIST
|
||||
DRAW
|
||||
S 300 500 -300 -400 0 1 10 f
|
||||
P 2 0 1 0 -200 175 -250 175 N
|
||||
P 2 0 1 0 -200 225 -250 225 N
|
||||
P 3 0 1 0 -250 -125 -200 -125 -200 -125 N
|
||||
P 3 0 1 0 -250 -75 -200 -75 -200 -75 N
|
||||
P 3 0 1 0 -250 -25 -200 -25 -200 -25 N
|
||||
P 3 0 1 0 -250 25 -200 25 -200 25 N
|
||||
P 3 0 1 0 -250 75 -200 75 -200 75 N
|
||||
P 3 0 1 0 -200 125 -250 125 -250 125 N
|
||||
P 14 0 1 0 -250 -175 -250 275 150 275 150 175 200 175 200 125 250 125 250 -25 200 -25 200 -75 150 -75 150 -175 -250 -175 -250 -175 N
|
||||
X ~ 1 400 -300 100 L 50 50 1 1 P
|
||||
X ~ 2 400 -200 100 L 50 50 1 1 P
|
||||
X ~ 3 400 -100 100 L 50 50 1 1 P
|
||||
X ~ 4 400 0 100 L 50 50 1 1 P
|
||||
X ~ 5 400 100 100 L 50 50 1 1 P
|
||||
X ~ 6 400 200 100 L 50 50 1 1 P
|
||||
X ~ 7 400 300 100 L 50 50 1 1 P
|
||||
X ~ 8 400 400 100 L 50 50 1 1 P
|
||||
ENDDRAW
|
||||
ENDDEF
|
||||
#
|
||||
# Device_C
|
||||
#
|
||||
DEF Device_C C 0 10 N Y 1 F N
|
||||
F0 "C" 25 100 50 H V L CNN
|
||||
F1 "Device_C" 25 -100 50 H V L CNN
|
||||
F2 "" 38 -150 50 H I C CNN
|
||||
F3 "" 0 0 50 H I C CNN
|
||||
$FPLIST
|
||||
C_*
|
||||
$ENDFPLIST
|
||||
DRAW
|
||||
P 2 0 1 20 -80 -30 80 -30 N
|
||||
P 2 0 1 20 -80 30 80 30 N
|
||||
X ~ 1 0 150 110 D 50 50 1 1 P
|
||||
X ~ 2 0 -150 110 U 50 50 1 1 P
|
||||
ENDDRAW
|
||||
ENDDEF
|
||||
#
|
||||
# Device_Jumper
|
||||
#
|
||||
DEF Device_Jumper JP 0 30 Y N 1 F N
|
||||
F0 "JP" 0 150 50 H V C CNN
|
||||
F1 "Device_Jumper" 0 -80 50 H V C CNN
|
||||
F2 "" 0 0 50 H I C CNN
|
||||
F3 "" 0 0 50 H I C CNN
|
||||
$FPLIST
|
||||
SolderJumper*
|
||||
$ENDFPLIST
|
||||
DRAW
|
||||
A 0 -26 125 1426 373 0 1 0 N -98 50 99 50
|
||||
C -100 0 35 0 1 0 N
|
||||
C 100 0 35 0 1 0 N
|
||||
X 1 1 -300 0 165 R 50 50 0 1 P
|
||||
X 2 2 300 0 165 L 50 50 0 1 P
|
||||
ENDDRAW
|
||||
ENDDEF
|
||||
#
|
||||
# Device_LED_RGB
|
||||
#
|
||||
DEF Device_LED_RGB D 0 0 Y N 1 F N
|
||||
F0 "D" 0 370 50 H V C CNN
|
||||
F1 "Device_LED_RGB" 0 -350 50 H V C CNN
|
||||
F2 "" 0 -50 50 H I C CNN
|
||||
F3 "" 0 -50 50 H I C CNN
|
||||
$FPLIST
|
||||
LED*
|
||||
LED_SMD:*
|
||||
LED_THT:*
|
||||
$ENDFPLIST
|
||||
DRAW
|
||||
T 0 -75 -250 50 0 0 0 B Normal 0 C C
|
||||
T 0 -75 -50 50 0 0 0 G Normal 0 C C
|
||||
T 0 -75 150 50 0 0 0 R Normal 0 C C
|
||||
S 50 -50 50 50 0 1 0 N
|
||||
S 50 50 50 50 0 1 0 N
|
||||
S 50 150 50 250 0 1 0 N
|
||||
S 50 250 50 250 0 1 0 N
|
||||
S 110 330 -110 -300 0 1 10 f
|
||||
P 2 0 1 0 -50 -200 -100 -200 N
|
||||
P 2 0 1 0 -50 -200 50 -200 N
|
||||
P 2 0 1 0 -50 -150 -50 -250 N
|
||||
P 2 0 1 8 -50 -150 -50 -250 N
|
||||
P 2 0 1 0 -50 0 -100 0 N
|
||||
P 2 0 1 8 -50 50 -50 -50 N
|
||||
P 2 0 1 0 -50 200 -100 200 N
|
||||
P 2 0 1 0 -50 200 50 200 N
|
||||
P 2 0 1 8 -50 250 -50 150 N
|
||||
P 2 0 1 0 50 -200 100 -200 N
|
||||
P 2 0 1 0 50 0 -50 0 N
|
||||
P 2 0 1 0 50 0 100 0 N
|
||||
P 2 0 1 0 50 200 100 200 N
|
||||
P 3 0 1 0 -50 50 -50 -50 -50 -50 N
|
||||
P 3 0 1 0 -50 250 -50 150 -50 150 N
|
||||
P 4 0 1 8 50 -150 50 -250 -50 -200 50 -150 N
|
||||
P 4 0 1 8 50 50 50 -50 -50 0 50 50 N
|
||||
P 4 0 1 8 50 250 50 150 -50 200 50 250 N
|
||||
P 5 0 1 0 -40 -150 20 -90 -10 -90 20 -90 20 -120 N
|
||||
P 5 0 1 0 -40 50 20 110 -10 110 20 110 20 80 N
|
||||
P 5 0 1 0 -40 250 20 310 -10 310 20 310 20 280 N
|
||||
P 5 0 1 0 0 -150 60 -90 30 -90 60 -90 60 -120 N
|
||||
P 5 0 1 0 0 50 60 110 30 110 60 110 60 80 N
|
||||
P 5 0 1 0 0 250 60 310 30 310 60 310 60 280 N
|
||||
X RK 1 -200 200 100 R 50 50 1 1 P
|
||||
X GK 2 -200 0 100 R 50 50 1 1 P
|
||||
X BK 3 -200 -200 100 R 50 50 1 1 P
|
||||
X BA 4 200 -200 100 L 50 50 1 1 P
|
||||
X GA 5 200 0 100 L 50 50 1 1 P
|
||||
X RA 6 200 200 100 L 50 50 1 1 P
|
||||
ENDDRAW
|
||||
ENDDEF
|
||||
#
|
||||
# Device_R
|
||||
#
|
||||
DEF Device_R R 0 0 N Y 1 F N
|
||||
F0 "R" 80 0 50 V V C CNN
|
||||
F1 "Device_R" 0 0 50 V V C CNN
|
||||
F2 "" -70 0 50 V I C CNN
|
||||
F3 "" 0 0 50 H I C CNN
|
||||
$FPLIST
|
||||
R_*
|
||||
$ENDFPLIST
|
||||
DRAW
|
||||
S -40 -100 40 100 0 1 10 N
|
||||
X ~ 1 0 150 50 D 50 50 1 1 P
|
||||
X ~ 2 0 -150 50 U 50 50 1 1 P
|
||||
ENDDRAW
|
||||
ENDDEF
|
||||
#
|
||||
# Sensor_Temperature_DS18B20
|
||||
#
|
||||
DEF Sensor_Temperature_DS18B20 U 0 40 Y Y 1 F N
|
||||
F0 "U" -150 250 50 H V C CNN
|
||||
F1 "Sensor_Temperature_DS18B20" 250 250 50 H V C CNN
|
||||
F2 "Package_TO_SOT_THT:TO-92_Inline" -1000 -250 50 H I C CNN
|
||||
F3 "" -150 250 50 H I C CNN
|
||||
ALIAS DS1822 DS18B20 DS18S20 DS1821C
|
||||
$FPLIST
|
||||
TO*92*
|
||||
$ENDFPLIST
|
||||
DRAW
|
||||
A -130 125 25 1 1799 0 1 10 N -105 125 -155 125
|
||||
C -130 -100 50 0 1 10 F
|
||||
S -200 200 200 -200 0 1 10 f
|
||||
S -105 -75 -155 0 0 1 10 F
|
||||
P 2 0 1 10 -155 25 -130 25 N
|
||||
P 2 0 1 10 -155 50 -130 50 N
|
||||
P 2 0 1 10 -155 75 -130 75 N
|
||||
P 2 0 1 10 -155 100 -130 100 N
|
||||
P 2 0 1 10 -155 125 -155 0 N
|
||||
P 2 0 1 10 -155 125 -130 125 N
|
||||
P 2 0 1 10 -105 125 -105 0 N
|
||||
X GND 1 0 -300 100 U 50 50 1 1 W
|
||||
X DQ 2 300 0 100 L 50 50 1 1 B
|
||||
X VDD 3 0 300 100 D 50 50 1 1 W
|
||||
ENDDRAW
|
||||
ENDDEF
|
||||
#
|
||||
# Switch_SW_Push
|
||||
#
|
||||
DEF Switch_SW_Push SW 0 40 N N 1 F N
|
||||
F0 "SW" 50 100 50 H V L CNN
|
||||
F1 "Switch_SW_Push" 0 -60 50 H V C CNN
|
||||
F2 "" 0 200 50 H I C CNN
|
||||
F3 "" 0 200 50 H I C CNN
|
||||
DRAW
|
||||
C -80 0 20 0 1 0 N
|
||||
C 80 0 20 0 1 0 N
|
||||
P 2 0 1 0 0 50 0 120 N
|
||||
P 2 0 1 0 100 50 -100 50 N
|
||||
X 1 1 -200 0 100 R 50 50 0 1 P
|
||||
X 2 2 200 0 100 L 50 50 0 1 P
|
||||
ENDDRAW
|
||||
ENDDEF
|
||||
#
|
||||
# d1_mini_shield-rescue_CONN_01X08
|
||||
#
|
||||
DEF d1_mini_shield-rescue_CONN_01X08 P 0 40 Y N 1 F N
|
||||
F0 "P" 0 450 50 H V C CNN
|
||||
F1 "d1_mini_shield-rescue_CONN_01X08" 100 0 50 V V C CNN
|
||||
F2 "" 0 0 60 H V C CNN
|
||||
F3 "" 0 0 60 H V C CNN
|
||||
$FPLIST
|
||||
Pin_Header_Straight_1X08
|
||||
Pin_Header_Angled_1X08
|
||||
Socket_Strip_Straight_1X08
|
||||
Socket_Strip_Angled_1X08
|
||||
$ENDFPLIST
|
||||
DRAW
|
||||
S -50 -400 50 400 0 1 0 N
|
||||
S -50 -345 10 -355 0 1 0 N
|
||||
S -50 -245 10 -255 0 1 0 N
|
||||
S -50 -145 10 -155 0 1 0 N
|
||||
S -50 -45 10 -55 0 1 0 N
|
||||
S -50 55 10 45 0 1 0 N
|
||||
S -50 155 10 145 0 1 0 N
|
||||
S -50 255 10 245 0 1 0 N
|
||||
S -50 355 10 345 0 1 0 N
|
||||
X P1 1 -200 350 150 R 50 50 1 1 P
|
||||
X P2 2 -200 250 150 R 50 50 1 1 P
|
||||
X P3 3 -200 150 150 R 50 50 1 1 P
|
||||
X P4 4 -200 50 150 R 50 50 1 1 P
|
||||
X P5 5 -200 -50 150 R 50 50 1 1 P
|
||||
X P6 6 -200 -150 150 R 50 50 1 1 P
|
||||
X P7 7 -200 -250 150 R 50 50 1 1 P
|
||||
X P8 8 -200 -350 150 R 50 50 1 1 P
|
||||
ENDDRAW
|
||||
ENDDEF
|
||||
#
|
||||
# power_+3.3V
|
||||
#
|
||||
DEF power_+3.3V #PWR 0 0 Y Y 1 F P
|
||||
F0 "#PWR" 0 -150 50 H I C CNN
|
||||
F1 "power_+3.3V" 0 140 50 H V C CNN
|
||||
F2 "" 0 0 50 H I C CNN
|
||||
F3 "" 0 0 50 H I C CNN
|
||||
ALIAS +3.3V
|
||||
DRAW
|
||||
P 2 0 1 0 -30 50 0 100 N
|
||||
P 2 0 1 0 0 0 0 100 N
|
||||
P 2 0 1 0 0 100 30 50 N
|
||||
X +3V3 1 0 0 0 U 50 50 1 1 W N
|
||||
ENDDRAW
|
||||
ENDDEF
|
||||
#
|
||||
# power_+3V3
|
||||
#
|
||||
DEF power_+3V3 #PWR 0 0 Y Y 1 F P
|
||||
F0 "#PWR" 0 -150 50 H I C CNN
|
||||
F1 "power_+3V3" 0 140 50 H V C CNN
|
||||
F2 "" 0 0 50 H I C CNN
|
||||
F3 "" 0 0 50 H I C CNN
|
||||
DRAW
|
||||
P 2 0 1 0 -30 50 0 100 N
|
||||
P 2 0 1 0 0 0 0 100 N
|
||||
P 2 0 1 0 0 100 30 50 N
|
||||
X +3V3 1 0 0 0 U 50 50 1 1 W N
|
||||
ENDDRAW
|
||||
ENDDEF
|
||||
#
|
||||
# power_+5V
|
||||
#
|
||||
DEF power_+5V #PWR 0 0 Y Y 1 F P
|
||||
F0 "#PWR" 0 -150 50 H I C CNN
|
||||
F1 "power_+5V" 0 140 50 H V C CNN
|
||||
F2 "" 0 0 50 H I C CNN
|
||||
F3 "" 0 0 50 H I C CNN
|
||||
DRAW
|
||||
P 2 0 1 0 -30 50 0 100 N
|
||||
P 2 0 1 0 0 0 0 100 N
|
||||
P 2 0 1 0 0 100 30 50 N
|
||||
X +5V 1 0 0 0 U 50 50 1 1 W N
|
||||
ENDDRAW
|
||||
ENDDEF
|
||||
#
|
||||
# power_GND
|
||||
#
|
||||
DEF power_GND #PWR 0 0 Y Y 1 F P
|
||||
F0 "#PWR" 0 -250 50 H I C CNN
|
||||
F1 "power_GND" 0 -150 50 H V C CNN
|
||||
F2 "" 0 0 50 H I C CNN
|
||||
F3 "" 0 0 50 H I C CNN
|
||||
DRAW
|
||||
P 6 0 1 0 0 0 0 -50 50 -50 0 -100 -50 -50 0 -50 N
|
||||
X GND 1 0 0 0 D 50 50 1 1 W N
|
||||
ENDDRAW
|
||||
ENDDEF
|
||||
#
|
||||
# tss721_TSS721
|
||||
#
|
||||
DEF tss721_TSS721 U 0 40 Y Y 1 F N
|
||||
F0 "U" 200 850 50 H V L CNN
|
||||
F1 "tss721_TSS721" 200 750 50 H V L CNN
|
||||
F2 "" 0 -850 50 H V C CIN
|
||||
F3 "" -200 -800 50 H V C CNN
|
||||
ALIAS TSS721A
|
||||
$FPLIST
|
||||
SOIC*3.9x9.9mm*Pitch1.27mm*
|
||||
TSSOP*4.4x5mm*Pitch0.65mm*
|
||||
$ENDFPLIST
|
||||
DRAW
|
||||
S -500 -700 500 700 0 1 10 f
|
||||
X BUSL2 1 -600 400 100 R 50 50 1 1 I
|
||||
X VS 10 -600 0 100 R 50 50 1 1 P
|
||||
X VDD 11 0 800 100 D 50 50 1 1 W
|
||||
X RX 12 600 500 100 L 50 50 1 1 I
|
||||
X RXI 13 600 400 100 L 50 50 1 1 I I
|
||||
X RIS 14 300 -800 100 U 50 50 1 1 I
|
||||
X GND 15 0 -800 100 U 50 50 1 1 W
|
||||
X BUSL1 16 -600 500 100 R 50 50 1 1 I
|
||||
X VB 2 -600 -150 100 R 50 50 1 1 P
|
||||
X STC 3 -600 -500 100 R 50 50 1 1 P
|
||||
X RIDD 4 200 -800 100 U 50 50 1 1 O
|
||||
X PF 5 -600 100 100 R 50 50 1 1 I
|
||||
X SC 6 400 -800 100 U 50 50 1 1 P
|
||||
X TXI 7 600 100 100 L 50 50 1 1 O I
|
||||
X TX 8 600 200 100 L 50 50 1 1 O
|
||||
X BAT 9 -100 800 100 D 50 50 1 1 I
|
||||
ENDDRAW
|
||||
ENDDEF
|
||||
#
|
||||
#End Library
|
||||
38
hardware/wemos_mbus_shield/kicad/d1_mini_shield-rescue.lib
Normal file
38
hardware/wemos_mbus_shield/kicad/d1_mini_shield-rescue.lib
Normal file
@@ -0,0 +1,38 @@
|
||||
EESchema-LIBRARY Version 2.4
|
||||
#encoding utf-8
|
||||
#
|
||||
# CONN_01X08
|
||||
#
|
||||
DEF CONN_01X08 P 0 40 Y N 1 F N
|
||||
F0 "P" 0 450 50 H V C CNN
|
||||
F1 "CONN_01X08" 100 0 50 V V C CNN
|
||||
F2 "" 0 0 60 H V C CNN
|
||||
F3 "" 0 0 60 H V C CNN
|
||||
$FPLIST
|
||||
Pin_Header_Straight_1X08
|
||||
Pin_Header_Angled_1X08
|
||||
Socket_Strip_Straight_1X08
|
||||
Socket_Strip_Angled_1X08
|
||||
$ENDFPLIST
|
||||
DRAW
|
||||
S -50 -400 50 400 0 1 0 N
|
||||
S -50 -345 10 -355 0 1 0 N
|
||||
S -50 -245 10 -255 0 1 0 N
|
||||
S -50 -145 10 -155 0 1 0 N
|
||||
S -50 -45 10 -55 0 1 0 N
|
||||
S -50 55 10 45 0 1 0 N
|
||||
S -50 155 10 145 0 1 0 N
|
||||
S -50 255 10 245 0 1 0 N
|
||||
S -50 355 10 345 0 1 0 N
|
||||
X P1 1 -200 350 150 R 50 50 1 1 P
|
||||
X P2 2 -200 250 150 R 50 50 1 1 P
|
||||
X P3 3 -200 150 150 R 50 50 1 1 P
|
||||
X P4 4 -200 50 150 R 50 50 1 1 P
|
||||
X P5 5 -200 -50 150 R 50 50 1 1 P
|
||||
X P6 6 -200 -150 150 R 50 50 1 1 P
|
||||
X P7 7 -200 -250 150 R 50 50 1 1 P
|
||||
X P8 8 -200 -350 150 R 50 50 1 1 P
|
||||
ENDDRAW
|
||||
ENDDEF
|
||||
#
|
||||
#End Library
|
||||
1852
hardware/wemos_mbus_shield/kicad/d1_mini_shield.kicad_pcb
Normal file
1852
hardware/wemos_mbus_shield/kicad/d1_mini_shield.kicad_pcb
Normal file
File diff suppressed because it is too large
Load Diff
482
hardware/wemos_mbus_shield/kicad/d1_mini_shield.net
Normal file
482
hardware/wemos_mbus_shield/kicad/d1_mini_shield.net
Normal file
@@ -0,0 +1,482 @@
|
||||
(export (version D)
|
||||
(design
|
||||
(source /home/gunnar/src/AmsToMqttBridge/hardware/wemos_mbus_shield/kicad/d1_mini_shield.sch)
|
||||
(date "sø. 26. juni 2022 kl. 12.19 +0200")
|
||||
(tool "Eeschema 5.1.5+dfsg1-2build2")
|
||||
(sheet (number 1) (name /) (tstamps /)
|
||||
(title_block
|
||||
(title)
|
||||
(company)
|
||||
(rev)
|
||||
(date)
|
||||
(source d1_mini_shield.sch)
|
||||
(comment (number 1) (value ""))
|
||||
(comment (number 2) (value ""))
|
||||
(comment (number 3) (value ""))
|
||||
(comment (number 4) (value "")))))
|
||||
(components
|
||||
(comp (ref P1)
|
||||
(value CONN_01X08)
|
||||
(footprint D1_mini:D1_mini_Pin_Header)
|
||||
(libsource (lib d1_mini_shield-rescue) (part CONN_01X08) (description ""))
|
||||
(sheetpath (names /) (tstamps /))
|
||||
(tstamp 5763EB78))
|
||||
(comp (ref P2)
|
||||
(value CONN_01X08)
|
||||
(footprint D1_mini:D1_mini_Pin_Header)
|
||||
(libsource (lib d1_mini_shield-rescue) (part CONN_01X08) (description ""))
|
||||
(sheetpath (names /) (tstamps /))
|
||||
(tstamp 5763EBF2))
|
||||
(comp (ref U1)
|
||||
(value TSS721)
|
||||
(footprint Package_SO:SOIC-16_3.9x9.9mm_P1.27mm)
|
||||
(datasheet http://www.ti.com/lit/ds/symlink/tss721a.pdf)
|
||||
(libsource (lib tss721) (part TSS721) (description "TSS721A Meter Bus Transceiver, SOIC-16/TSSOP-16"))
|
||||
(sheetpath (names /) (tstamps /))
|
||||
(tstamp 62B826D2))
|
||||
(comp (ref J1)
|
||||
(value RJ45)
|
||||
(footprint Connector_RJ:RJ45_Amphenol_54602-x08_Horizontal)
|
||||
(datasheet ~)
|
||||
(libsource (lib Connector) (part RJ45) (description "RJ connector, 8P8C (8 positions 8 connected)"))
|
||||
(sheetpath (names /) (tstamps /))
|
||||
(tstamp 62B8AC34))
|
||||
(comp (ref R4)
|
||||
(value 220)
|
||||
(footprint Resistor_SMD:R_0805_2012Metric_Pad1.15x1.40mm_HandSolder)
|
||||
(datasheet ~)
|
||||
(libsource (lib Device) (part R) (description Resistor))
|
||||
(sheetpath (names /) (tstamps /))
|
||||
(tstamp 62B8CAA8))
|
||||
(comp (ref R2)
|
||||
(value 220)
|
||||
(footprint Resistor_SMD:R_0805_2012Metric_Pad1.15x1.40mm_HandSolder)
|
||||
(datasheet ~)
|
||||
(libsource (lib Device) (part R) (description Resistor))
|
||||
(sheetpath (names /) (tstamps /))
|
||||
(tstamp 62B8DB92))
|
||||
(comp (ref R3)
|
||||
(value 82k)
|
||||
(footprint Resistor_SMD:R_0805_2012Metric_Pad1.15x1.40mm_HandSolder)
|
||||
(datasheet ~)
|
||||
(libsource (lib Device) (part R) (description Resistor))
|
||||
(sheetpath (names /) (tstamps /))
|
||||
(tstamp 62B9F861))
|
||||
(comp (ref R1)
|
||||
(value 470)
|
||||
(footprint Resistor_SMD:R_0805_2012Metric_Pad1.15x1.40mm_HandSolder)
|
||||
(datasheet ~)
|
||||
(libsource (lib Device) (part R) (description Resistor))
|
||||
(sheetpath (names /) (tstamps /))
|
||||
(tstamp 62B9FC37))
|
||||
(comp (ref C2)
|
||||
(value 1u)
|
||||
(footprint Resistor_SMD:R_0805_2012Metric_Pad1.15x1.40mm_HandSolder)
|
||||
(datasheet ~)
|
||||
(libsource (lib Device) (part C) (description "Unpolarized capacitor"))
|
||||
(sheetpath (names /) (tstamps /))
|
||||
(tstamp 62BA06BE))
|
||||
(comp (ref C1)
|
||||
(value 100n)
|
||||
(footprint Resistor_SMD:R_0805_2012Metric_Pad1.15x1.40mm_HandSolder)
|
||||
(datasheet ~)
|
||||
(libsource (lib Device) (part C) (description "Unpolarized capacitor"))
|
||||
(sheetpath (names /) (tstamps /))
|
||||
(tstamp 62BA09E7))
|
||||
(comp (ref R5)
|
||||
(value 100k)
|
||||
(footprint Resistor_SMD:R_0805_2012Metric_Pad1.15x1.40mm_HandSolder)
|
||||
(datasheet ~)
|
||||
(libsource (lib Device) (part R) (description Resistor))
|
||||
(sheetpath (names /) (tstamps /))
|
||||
(tstamp 62BED413))
|
||||
(comp (ref C3)
|
||||
(value 100n)
|
||||
(footprint Resistor_SMD:R_0805_2012Metric_Pad1.15x1.40mm_HandSolder)
|
||||
(datasheet ~)
|
||||
(libsource (lib Device) (part C) (description "Unpolarized capacitor"))
|
||||
(sheetpath (names /) (tstamps /))
|
||||
(tstamp 62BED9ED))
|
||||
(comp (ref JP1)
|
||||
(value Jumper)
|
||||
(footprint Jumper:SolderJumper-2_P1.3mm_Open_RoundedPad1.0x1.5mm)
|
||||
(datasheet ~)
|
||||
(libsource (lib Device) (part Jumper) (description "Jumper, normally closed"))
|
||||
(sheetpath (names /) (tstamps /))
|
||||
(tstamp 62C331C0))
|
||||
(comp (ref JP2)
|
||||
(value Jumper)
|
||||
(footprint Jumper:SolderJumper-2_P1.3mm_Open_RoundedPad1.0x1.5mm)
|
||||
(datasheet ~)
|
||||
(libsource (lib Device) (part Jumper) (description "Jumper, normally closed"))
|
||||
(sheetpath (names /) (tstamps /))
|
||||
(tstamp 62C365CA))
|
||||
(comp (ref JP3)
|
||||
(value Jumper)
|
||||
(footprint Jumper:SolderJumper-2_P1.3mm_Open_RoundedPad1.0x1.5mm)
|
||||
(datasheet ~)
|
||||
(libsource (lib Device) (part Jumper) (description "Jumper, normally closed"))
|
||||
(sheetpath (names /) (tstamps /))
|
||||
(tstamp 62C36C70))
|
||||
(comp (ref D1)
|
||||
(value LED_RGB)
|
||||
(footprint LED_SMD:LED_RGB_PLCC-6)
|
||||
(datasheet ~)
|
||||
(libsource (lib Device) (part LED_RGB) (description "RGB LED, 6 pin package"))
|
||||
(sheetpath (names /) (tstamps /))
|
||||
(tstamp 62C43A7B))
|
||||
(comp (ref R9)
|
||||
(value 1k)
|
||||
(footprint Resistor_SMD:R_0805_2012Metric_Pad1.15x1.40mm_HandSolder)
|
||||
(datasheet ~)
|
||||
(libsource (lib Device) (part R) (description Resistor))
|
||||
(sheetpath (names /) (tstamps /))
|
||||
(tstamp 62C495F7))
|
||||
(comp (ref R8)
|
||||
(value 1k)
|
||||
(footprint Resistor_SMD:R_0805_2012Metric_Pad1.15x1.40mm_HandSolder)
|
||||
(datasheet ~)
|
||||
(libsource (lib Device) (part R) (description Resistor))
|
||||
(sheetpath (names /) (tstamps /))
|
||||
(tstamp 62C4BDE9))
|
||||
(comp (ref R10)
|
||||
(value 1k)
|
||||
(footprint Resistor_SMD:R_0805_2012Metric_Pad1.15x1.40mm_HandSolder)
|
||||
(datasheet ~)
|
||||
(libsource (lib Device) (part R) (description Resistor))
|
||||
(sheetpath (names /) (tstamps /))
|
||||
(tstamp 62C4C336))
|
||||
(comp (ref U2)
|
||||
(value DS18B20)
|
||||
(footprint Package_TO_SOT_THT:TO-92_Inline)
|
||||
(datasheet http://datasheets.maximintegrated.com/en/ds/DS18B20.pdf)
|
||||
(libsource (lib Sensor_Temperature) (part DS18B20) (description "Programmable Resolution 1-Wire Digital Thermometer TO-92"))
|
||||
(sheetpath (names /) (tstamps /))
|
||||
(tstamp 62C6296F))
|
||||
(comp (ref R7)
|
||||
(value 4k7)
|
||||
(footprint Resistor_SMD:R_0805_2012Metric_Pad1.15x1.40mm_HandSolder)
|
||||
(datasheet ~)
|
||||
(libsource (lib Device) (part R) (description Resistor))
|
||||
(sheetpath (names /) (tstamps /))
|
||||
(tstamp 62C6405D))
|
||||
(comp (ref SW1)
|
||||
(value SW_Push)
|
||||
(footprint Button_Switch_SMD:SW_SPST_B3U-3000P)
|
||||
(datasheet ~)
|
||||
(libsource (lib Switch) (part SW_Push) (description "Push button switch, generic, two pins"))
|
||||
(sheetpath (names /) (tstamps /))
|
||||
(tstamp 62C73229))
|
||||
(comp (ref R6)
|
||||
(value 10k)
|
||||
(footprint Resistor_SMD:R_0805_2012Metric_Pad1.15x1.40mm_HandSolder)
|
||||
(datasheet ~)
|
||||
(libsource (lib Device) (part R) (description Resistor))
|
||||
(sheetpath (names /) (tstamps /))
|
||||
(tstamp 62C73CE8))
|
||||
(comp (ref JP4)
|
||||
(value Jumper)
|
||||
(footprint Jumper:SolderJumper-2_P1.3mm_Open_RoundedPad1.0x1.5mm)
|
||||
(datasheet ~)
|
||||
(libsource (lib Device) (part Jumper) (description "Jumper, normally closed"))
|
||||
(sheetpath (names /) (tstamps /))
|
||||
(tstamp 62D1E97A)))
|
||||
(libparts
|
||||
(libpart (lib Connector) (part 8P8C)
|
||||
(aliases
|
||||
(alias RJ31)
|
||||
(alias RJ32)
|
||||
(alias RJ33)
|
||||
(alias RJ34)
|
||||
(alias RJ35)
|
||||
(alias RJ41)
|
||||
(alias RJ45)
|
||||
(alias RJ49)
|
||||
(alias RJ61))
|
||||
(description "RJ connector, 8P8C (8 positions 8 connected), RJ31/RJ32/RJ33/RJ34/RJ35/RJ41/RJ45/RJ49/RJ61")
|
||||
(docs ~)
|
||||
(footprints
|
||||
(fp 8P8C*)
|
||||
(fp RJ31*)
|
||||
(fp RJ32*)
|
||||
(fp RJ33*)
|
||||
(fp RJ34*)
|
||||
(fp RJ35*)
|
||||
(fp RJ41*)
|
||||
(fp RJ45*)
|
||||
(fp RJ49*)
|
||||
(fp RJ61*))
|
||||
(fields
|
||||
(field (name Reference) J)
|
||||
(field (name Value) 8P8C))
|
||||
(pins
|
||||
(pin (num 1) (name ~) (type passive))
|
||||
(pin (num 2) (name ~) (type passive))
|
||||
(pin (num 3) (name ~) (type passive))
|
||||
(pin (num 4) (name ~) (type passive))
|
||||
(pin (num 5) (name ~) (type passive))
|
||||
(pin (num 6) (name ~) (type passive))
|
||||
(pin (num 7) (name ~) (type passive))
|
||||
(pin (num 8) (name ~) (type passive))))
|
||||
(libpart (lib Device) (part C)
|
||||
(description "Unpolarized capacitor")
|
||||
(docs ~)
|
||||
(footprints
|
||||
(fp C_*))
|
||||
(fields
|
||||
(field (name Reference) C)
|
||||
(field (name Value) C))
|
||||
(pins
|
||||
(pin (num 1) (name ~) (type passive))
|
||||
(pin (num 2) (name ~) (type passive))))
|
||||
(libpart (lib Device) (part Jumper)
|
||||
(description "Jumper, normally closed")
|
||||
(docs ~)
|
||||
(footprints
|
||||
(fp SolderJumper*))
|
||||
(fields
|
||||
(field (name Reference) JP)
|
||||
(field (name Value) Jumper))
|
||||
(pins
|
||||
(pin (num 1) (name 1) (type passive))
|
||||
(pin (num 2) (name 2) (type passive))))
|
||||
(libpart (lib Device) (part LED_RGB)
|
||||
(description "RGB LED, 6 pin package")
|
||||
(docs ~)
|
||||
(footprints
|
||||
(fp LED*)
|
||||
(fp LED_SMD:*)
|
||||
(fp LED_THT:*))
|
||||
(fields
|
||||
(field (name Reference) D)
|
||||
(field (name Value) LED_RGB))
|
||||
(pins
|
||||
(pin (num 1) (name RK) (type passive))
|
||||
(pin (num 2) (name GK) (type passive))
|
||||
(pin (num 3) (name BK) (type passive))
|
||||
(pin (num 4) (name BA) (type passive))
|
||||
(pin (num 5) (name GA) (type passive))
|
||||
(pin (num 6) (name RA) (type passive))))
|
||||
(libpart (lib Device) (part R)
|
||||
(description Resistor)
|
||||
(docs ~)
|
||||
(footprints
|
||||
(fp R_*))
|
||||
(fields
|
||||
(field (name Reference) R)
|
||||
(field (name Value) R))
|
||||
(pins
|
||||
(pin (num 1) (name ~) (type passive))
|
||||
(pin (num 2) (name ~) (type passive))))
|
||||
(libpart (lib Sensor_Temperature) (part MAX31820)
|
||||
(aliases
|
||||
(alias DS1822)
|
||||
(alias DS18B20)
|
||||
(alias DS18S20)
|
||||
(alias DS1821C))
|
||||
(description "1-Wire Ambient Temperature Sensor TO-92")
|
||||
(docs http://datasheets.maximintegrated.com/en/ds/MAX31820.pdf)
|
||||
(footprints
|
||||
(fp TO*92*))
|
||||
(fields
|
||||
(field (name Reference) U)
|
||||
(field (name Value) MAX31820)
|
||||
(field (name Footprint) Package_TO_SOT_THT:TO-92_Inline))
|
||||
(pins
|
||||
(pin (num 1) (name GND) (type power_in))
|
||||
(pin (num 2) (name DQ) (type BiDi))
|
||||
(pin (num 3) (name VDD) (type power_in))))
|
||||
(libpart (lib Switch) (part SW_Push)
|
||||
(description "Push button switch, generic, two pins")
|
||||
(docs ~)
|
||||
(fields
|
||||
(field (name Reference) SW)
|
||||
(field (name Value) SW_Push))
|
||||
(pins
|
||||
(pin (num 1) (name 1) (type passive))
|
||||
(pin (num 2) (name 2) (type passive))))
|
||||
(libpart (lib d1_mini_shield-rescue) (part CONN_01X08)
|
||||
(footprints
|
||||
(fp Pin_Header_Straight_1X08)
|
||||
(fp Pin_Header_Angled_1X08)
|
||||
(fp Socket_Strip_Straight_1X08)
|
||||
(fp Socket_Strip_Angled_1X08))
|
||||
(fields
|
||||
(field (name Reference) P)
|
||||
(field (name Value) CONN_01X08))
|
||||
(pins
|
||||
(pin (num 1) (name P1) (type passive))
|
||||
(pin (num 2) (name P2) (type passive))
|
||||
(pin (num 3) (name P3) (type passive))
|
||||
(pin (num 4) (name P4) (type passive))
|
||||
(pin (num 5) (name P5) (type passive))
|
||||
(pin (num 6) (name P6) (type passive))
|
||||
(pin (num 7) (name P7) (type passive))
|
||||
(pin (num 8) (name P8) (type passive))))
|
||||
(libpart (lib tss721) (part TSS721)
|
||||
(aliases
|
||||
(alias TSS721A))
|
||||
(description "TSS721A Meter Bus Transceiver, SOIC-16/TSSOP-16")
|
||||
(docs http://www.ti.com/lit/ds/symlink/tss721a.pdf)
|
||||
(footprints
|
||||
(fp SOIC*3.9x9.9mm*Pitch1.27mm*)
|
||||
(fp TSSOP*4.4x5mm*Pitch0.65mm*))
|
||||
(fields
|
||||
(field (name Reference) U)
|
||||
(field (name Value) TSS721))
|
||||
(pins
|
||||
(pin (num 1) (name BUSL2) (type input))
|
||||
(pin (num 2) (name VB) (type passive))
|
||||
(pin (num 3) (name STC) (type passive))
|
||||
(pin (num 4) (name RIDD) (type output))
|
||||
(pin (num 5) (name PF) (type input))
|
||||
(pin (num 6) (name SC) (type passive))
|
||||
(pin (num 7) (name TXI) (type output))
|
||||
(pin (num 8) (name TX) (type output))
|
||||
(pin (num 9) (name BAT) (type input))
|
||||
(pin (num 10) (name VS) (type passive))
|
||||
(pin (num 11) (name VDD) (type power_in))
|
||||
(pin (num 12) (name RX) (type input))
|
||||
(pin (num 13) (name RXI) (type input))
|
||||
(pin (num 14) (name RIS) (type input))
|
||||
(pin (num 15) (name GND) (type power_in))
|
||||
(pin (num 16) (name BUSL1) (type input)))))
|
||||
(libraries
|
||||
(library (logical Connector)
|
||||
(uri /usr/share/kicad/library/Connector.lib))
|
||||
(library (logical Device)
|
||||
(uri /usr/share/kicad/library/Device.lib))
|
||||
(library (logical Sensor_Temperature)
|
||||
(uri /usr/share/kicad/library/Sensor_Temperature.lib))
|
||||
(library (logical Switch)
|
||||
(uri /usr/share/kicad/library/Switch.lib))
|
||||
(library (logical d1_mini_shield-rescue)
|
||||
(uri /home/gunnar/src/AmsToMqttBridge/hardware/wemos_mbus_shield/kicad/d1_mini_shield-rescue.lib))
|
||||
(library (logical tss721)
|
||||
(uri /home/gunnar/src/AmsToMqttBridge/hardware/wemos_mbus_shield/kicad/tss721.lib)))
|
||||
(nets
|
||||
(net (code 1) (name TEMP)
|
||||
(node (ref R7) (pin 2))
|
||||
(node (ref U2) (pin 2))
|
||||
(node (ref P1) (pin 5))
|
||||
(node (ref JP3) (pin 2)))
|
||||
(net (code 2) (name +3V3)
|
||||
(node (ref R7) (pin 1))
|
||||
(node (ref U1) (pin 9))
|
||||
(node (ref P2) (pin 1))
|
||||
(node (ref R6) (pin 2))
|
||||
(node (ref D1) (pin 4))
|
||||
(node (ref D1) (pin 5))
|
||||
(node (ref D1) (pin 6))
|
||||
(node (ref U2) (pin 3)))
|
||||
(net (code 3) (name "Net-(D1-Pad1)")
|
||||
(node (ref R9) (pin 2))
|
||||
(node (ref D1) (pin 1)))
|
||||
(net (code 4) (name "Net-(D1-Pad2)")
|
||||
(node (ref D1) (pin 2))
|
||||
(node (ref R8) (pin 2)))
|
||||
(net (code 5) (name "Net-(D1-Pad3)")
|
||||
(node (ref D1) (pin 3))
|
||||
(node (ref R10) (pin 2)))
|
||||
(net (code 6) (name MBUS2)
|
||||
(node (ref J1) (pin 2))
|
||||
(node (ref R4) (pin 1)))
|
||||
(net (code 7) (name BTN_AP)
|
||||
(node (ref P1) (pin 4))
|
||||
(node (ref SW1) (pin 1))
|
||||
(node (ref R6) (pin 1)))
|
||||
(net (code 8) (name "Net-(R4-Pad2)")
|
||||
(node (ref U1) (pin 1))
|
||||
(node (ref R4) (pin 2)))
|
||||
(net (code 9) (name "Net-(R2-Pad2)")
|
||||
(node (ref R2) (pin 2))
|
||||
(node (ref U1) (pin 16)))
|
||||
(net (code 10) (name MBUS1)
|
||||
(node (ref J1) (pin 1))
|
||||
(node (ref R2) (pin 1)))
|
||||
(net (code 11) (name LED_R)
|
||||
(node (ref R9) (pin 1))
|
||||
(node (ref P2) (pin 4)))
|
||||
(net (code 12) (name "Net-(J1-Pad8)")
|
||||
(node (ref J1) (pin 8))
|
||||
(node (ref JP1) (pin 1)))
|
||||
(net (code 13) (name "Net-(J1-Pad5)")
|
||||
(node (ref J1) (pin 5))
|
||||
(node (ref JP2) (pin 1)))
|
||||
(net (code 14) (name "Net-(J1-Pad4)")
|
||||
(node (ref J1) (pin 4))
|
||||
(node (ref JP3) (pin 1)))
|
||||
(net (code 15) (name +5V)
|
||||
(node (ref P1) (pin 1))
|
||||
(node (ref JP1) (pin 2)))
|
||||
(net (code 16) (name "Net-(J1-Pad7)")
|
||||
(node (ref J1) (pin 7))
|
||||
(node (ref JP4) (pin 1)))
|
||||
(net (code 17) (name GND)
|
||||
(node (ref P1) (pin 2))
|
||||
(node (ref C3) (pin 2))
|
||||
(node (ref R3) (pin 1))
|
||||
(node (ref R1) (pin 1))
|
||||
(node (ref C2) (pin 1))
|
||||
(node (ref C1) (pin 1))
|
||||
(node (ref R5) (pin 2))
|
||||
(node (ref U1) (pin 15))
|
||||
(node (ref U2) (pin 1))
|
||||
(node (ref SW1) (pin 2))
|
||||
(node (ref JP4) (pin 2))
|
||||
(node (ref JP2) (pin 2)))
|
||||
(net (code 18) (name LED_G)
|
||||
(node (ref R8) (pin 1))
|
||||
(node (ref P2) (pin 5)))
|
||||
(net (code 19) (name "Net-(U1-Pad10)")
|
||||
(node (ref U1) (pin 10)))
|
||||
(net (code 20) (name "Net-(U1-Pad12)")
|
||||
(node (ref U1) (pin 12)))
|
||||
(net (code 21) (name "Net-(U1-Pad13)")
|
||||
(node (ref U1) (pin 13)))
|
||||
(net (code 22) (name "Net-(U1-Pad2)")
|
||||
(node (ref U1) (pin 2)))
|
||||
(net (code 23) (name "Net-(U1-Pad5)")
|
||||
(node (ref U1) (pin 5)))
|
||||
(net (code 24) (name "Net-(U1-Pad7)")
|
||||
(node (ref U1) (pin 7)))
|
||||
(net (code 25) (name "Net-(J1-Pad3)")
|
||||
(node (ref J1) (pin 3)))
|
||||
(net (code 26) (name "Net-(J1-Pad6)")
|
||||
(node (ref J1) (pin 6)))
|
||||
(net (code 27) (name /RST)
|
||||
(node (ref P2) (pin 8)))
|
||||
(net (code 28) (name /D4)
|
||||
(node (ref P1) (pin 3)))
|
||||
(net (code 29) (name /D1)
|
||||
(node (ref P1) (pin 6)))
|
||||
(net (code 30) (name /RX)
|
||||
(node (ref P1) (pin 7)))
|
||||
(net (code 31) (name /TX)
|
||||
(node (ref P1) (pin 8)))
|
||||
(net (code 32) (name /D8)
|
||||
(node (ref P2) (pin 2)))
|
||||
(net (code 33) (name /D0)
|
||||
(node (ref P2) (pin 6)))
|
||||
(net (code 34) (name /A0)
|
||||
(node (ref P2) (pin 7)))
|
||||
(net (code 35) (name "Net-(R3-Pad2)")
|
||||
(node (ref R3) (pin 2))
|
||||
(node (ref U1) (pin 4)))
|
||||
(net (code 36) (name HAN_TX)
|
||||
(node (ref R10) (pin 1))
|
||||
(node (ref U1) (pin 8))
|
||||
(node (ref P2) (pin 3)))
|
||||
(net (code 37) (name "Net-(C3-Pad1)")
|
||||
(node (ref U1) (pin 11))
|
||||
(node (ref C3) (pin 1))
|
||||
(node (ref R5) (pin 1)))
|
||||
(net (code 38) (name "Net-(R1-Pad2)")
|
||||
(node (ref R1) (pin 2))
|
||||
(node (ref U1) (pin 14)))
|
||||
(net (code 39) (name "Net-(C2-Pad2)")
|
||||
(node (ref C2) (pin 2))
|
||||
(node (ref U1) (pin 3)))
|
||||
(net (code 40) (name "Net-(C1-Pad2)")
|
||||
(node (ref U1) (pin 6))
|
||||
(node (ref C1) (pin 2)))))
|
||||
246
hardware/wemos_mbus_shield/kicad/d1_mini_shield.pro
Normal file
246
hardware/wemos_mbus_shield/kicad/d1_mini_shield.pro
Normal file
@@ -0,0 +1,246 @@
|
||||
update=sø. 26. juni 2022 kl. 11.55 +0200
|
||||
version=1
|
||||
last_client=kicad
|
||||
[general]
|
||||
version=1
|
||||
[cvpcb]
|
||||
version=1
|
||||
NetIExt=net
|
||||
[eeschema]
|
||||
version=1
|
||||
LibDir=
|
||||
[schematic_editor]
|
||||
version=1
|
||||
PageLayoutDescrFile=
|
||||
PlotDirectoryName=
|
||||
SubpartIdSeparator=0
|
||||
SubpartFirstId=65
|
||||
NetFmtName=Pcbnew
|
||||
SpiceAjustPassiveValues=0
|
||||
LabSize=50
|
||||
ERC_TestSimilarLabels=1
|
||||
[pcbnew]
|
||||
version=1
|
||||
PageLayoutDescrFile=
|
||||
LastNetListRead=d1_mini_shield.net
|
||||
CopperLayerCount=2
|
||||
BoardThickness=1.6
|
||||
AllowMicroVias=0
|
||||
AllowBlindVias=0
|
||||
RequireCourtyardDefinitions=0
|
||||
ProhibitOverlappingCourtyards=1
|
||||
MinTrackWidth=0.2
|
||||
MinViaDiameter=0.4
|
||||
MinViaDrill=0.3
|
||||
MinMicroViaDiameter=0.2
|
||||
MinMicroViaDrill=0.09999999999999999
|
||||
MinHoleToHole=0.25
|
||||
TrackWidth1=0.25
|
||||
TrackWidth2=0.5
|
||||
ViaDiameter1=0.6
|
||||
ViaDrill1=0.4
|
||||
dPairWidth1=0.2
|
||||
dPairGap1=0.25
|
||||
dPairViaGap1=0.25
|
||||
SilkLineWidth=0.15
|
||||
SilkTextSizeV=1
|
||||
SilkTextSizeH=1
|
||||
SilkTextSizeThickness=0.15
|
||||
SilkTextItalic=0
|
||||
SilkTextUpright=1
|
||||
CopperLineWidth=0.2
|
||||
CopperTextSizeV=1.5
|
||||
CopperTextSizeH=1.5
|
||||
CopperTextThickness=0.3
|
||||
CopperTextItalic=0
|
||||
CopperTextUpright=1
|
||||
EdgeCutLineWidth=0.15
|
||||
CourtyardLineWidth=0.05
|
||||
OthersLineWidth=0.15
|
||||
OthersTextSizeV=1
|
||||
OthersTextSizeH=1
|
||||
OthersTextSizeThickness=0.15
|
||||
OthersTextItalic=0
|
||||
OthersTextUpright=1
|
||||
SolderMaskClearance=0.2
|
||||
SolderMaskMinWidth=0
|
||||
SolderPasteClearance=0
|
||||
SolderPasteRatio=-0
|
||||
[pcbnew/Layer.F.Cu]
|
||||
Name=F.Cu
|
||||
Type=0
|
||||
Enabled=1
|
||||
[pcbnew/Layer.In1.Cu]
|
||||
Name=In1.Cu
|
||||
Type=0
|
||||
Enabled=0
|
||||
[pcbnew/Layer.In2.Cu]
|
||||
Name=In2.Cu
|
||||
Type=0
|
||||
Enabled=0
|
||||
[pcbnew/Layer.In3.Cu]
|
||||
Name=In3.Cu
|
||||
Type=0
|
||||
Enabled=0
|
||||
[pcbnew/Layer.In4.Cu]
|
||||
Name=In4.Cu
|
||||
Type=0
|
||||
Enabled=0
|
||||
[pcbnew/Layer.In5.Cu]
|
||||
Name=In5.Cu
|
||||
Type=0
|
||||
Enabled=0
|
||||
[pcbnew/Layer.In6.Cu]
|
||||
Name=In6.Cu
|
||||
Type=0
|
||||
Enabled=0
|
||||
[pcbnew/Layer.In7.Cu]
|
||||
Name=In7.Cu
|
||||
Type=0
|
||||
Enabled=0
|
||||
[pcbnew/Layer.In8.Cu]
|
||||
Name=In8.Cu
|
||||
Type=0
|
||||
Enabled=0
|
||||
[pcbnew/Layer.In9.Cu]
|
||||
Name=In9.Cu
|
||||
Type=0
|
||||
Enabled=0
|
||||
[pcbnew/Layer.In10.Cu]
|
||||
Name=In10.Cu
|
||||
Type=0
|
||||
Enabled=0
|
||||
[pcbnew/Layer.In11.Cu]
|
||||
Name=In11.Cu
|
||||
Type=0
|
||||
Enabled=0
|
||||
[pcbnew/Layer.In12.Cu]
|
||||
Name=In12.Cu
|
||||
Type=0
|
||||
Enabled=0
|
||||
[pcbnew/Layer.In13.Cu]
|
||||
Name=In13.Cu
|
||||
Type=0
|
||||
Enabled=0
|
||||
[pcbnew/Layer.In14.Cu]
|
||||
Name=In14.Cu
|
||||
Type=0
|
||||
Enabled=0
|
||||
[pcbnew/Layer.In15.Cu]
|
||||
Name=In15.Cu
|
||||
Type=0
|
||||
Enabled=0
|
||||
[pcbnew/Layer.In16.Cu]
|
||||
Name=In16.Cu
|
||||
Type=0
|
||||
Enabled=0
|
||||
[pcbnew/Layer.In17.Cu]
|
||||
Name=In17.Cu
|
||||
Type=0
|
||||
Enabled=0
|
||||
[pcbnew/Layer.In18.Cu]
|
||||
Name=In18.Cu
|
||||
Type=0
|
||||
Enabled=0
|
||||
[pcbnew/Layer.In19.Cu]
|
||||
Name=In19.Cu
|
||||
Type=0
|
||||
Enabled=0
|
||||
[pcbnew/Layer.In20.Cu]
|
||||
Name=In20.Cu
|
||||
Type=0
|
||||
Enabled=0
|
||||
[pcbnew/Layer.In21.Cu]
|
||||
Name=In21.Cu
|
||||
Type=0
|
||||
Enabled=0
|
||||
[pcbnew/Layer.In22.Cu]
|
||||
Name=In22.Cu
|
||||
Type=0
|
||||
Enabled=0
|
||||
[pcbnew/Layer.In23.Cu]
|
||||
Name=In23.Cu
|
||||
Type=0
|
||||
Enabled=0
|
||||
[pcbnew/Layer.In24.Cu]
|
||||
Name=In24.Cu
|
||||
Type=0
|
||||
Enabled=0
|
||||
[pcbnew/Layer.In25.Cu]
|
||||
Name=In25.Cu
|
||||
Type=0
|
||||
Enabled=0
|
||||
[pcbnew/Layer.In26.Cu]
|
||||
Name=In26.Cu
|
||||
Type=0
|
||||
Enabled=0
|
||||
[pcbnew/Layer.In27.Cu]
|
||||
Name=In27.Cu
|
||||
Type=0
|
||||
Enabled=0
|
||||
[pcbnew/Layer.In28.Cu]
|
||||
Name=In28.Cu
|
||||
Type=0
|
||||
Enabled=0
|
||||
[pcbnew/Layer.In29.Cu]
|
||||
Name=In29.Cu
|
||||
Type=0
|
||||
Enabled=0
|
||||
[pcbnew/Layer.In30.Cu]
|
||||
Name=In30.Cu
|
||||
Type=0
|
||||
Enabled=0
|
||||
[pcbnew/Layer.B.Cu]
|
||||
Name=B.Cu
|
||||
Type=0
|
||||
Enabled=1
|
||||
[pcbnew/Layer.B.Adhes]
|
||||
Enabled=1
|
||||
[pcbnew/Layer.F.Adhes]
|
||||
Enabled=1
|
||||
[pcbnew/Layer.B.Paste]
|
||||
Enabled=1
|
||||
[pcbnew/Layer.F.Paste]
|
||||
Enabled=1
|
||||
[pcbnew/Layer.B.SilkS]
|
||||
Enabled=1
|
||||
[pcbnew/Layer.F.SilkS]
|
||||
Enabled=1
|
||||
[pcbnew/Layer.B.Mask]
|
||||
Enabled=1
|
||||
[pcbnew/Layer.F.Mask]
|
||||
Enabled=1
|
||||
[pcbnew/Layer.Dwgs.User]
|
||||
Enabled=1
|
||||
[pcbnew/Layer.Cmts.User]
|
||||
Enabled=1
|
||||
[pcbnew/Layer.Eco1.User]
|
||||
Enabled=1
|
||||
[pcbnew/Layer.Eco2.User]
|
||||
Enabled=1
|
||||
[pcbnew/Layer.Edge.Cuts]
|
||||
Enabled=1
|
||||
[pcbnew/Layer.Margin]
|
||||
Enabled=1
|
||||
[pcbnew/Layer.B.CrtYd]
|
||||
Enabled=1
|
||||
[pcbnew/Layer.F.CrtYd]
|
||||
Enabled=1
|
||||
[pcbnew/Layer.B.Fab]
|
||||
Enabled=1
|
||||
[pcbnew/Layer.F.Fab]
|
||||
Enabled=1
|
||||
[pcbnew/Layer.Rescue]
|
||||
Enabled=0
|
||||
[pcbnew/Netclasses]
|
||||
[pcbnew/Netclasses/Default]
|
||||
Name=Default
|
||||
Clearance=0.2
|
||||
TrackWidth=0.25
|
||||
ViaDiameter=0.6
|
||||
ViaDrill=0.4
|
||||
uViaDiameter=0.3
|
||||
uViaDrill=0.1
|
||||
dPairWidth=0.2
|
||||
dPairGap=0.25
|
||||
dPairViaGap=0.25
|
||||
725
hardware/wemos_mbus_shield/kicad/d1_mini_shield.sch
Normal file
725
hardware/wemos_mbus_shield/kicad/d1_mini_shield.sch
Normal file
@@ -0,0 +1,725 @@
|
||||
EESchema Schematic File Version 4
|
||||
EELAYER 30 0
|
||||
EELAYER END
|
||||
$Descr A4 11693 8268
|
||||
encoding utf-8
|
||||
Sheet 1 1
|
||||
Title ""
|
||||
Date ""
|
||||
Rev ""
|
||||
Comp ""
|
||||
Comment1 ""
|
||||
Comment2 ""
|
||||
Comment3 ""
|
||||
Comment4 ""
|
||||
$EndDescr
|
||||
$Comp
|
||||
L d1_mini_shield-rescue:CONN_01X08 P1
|
||||
U 1 1 5763EB78
|
||||
P 8300 1850
|
||||
F 0 "P1" H 8300 2300 50 0000 C CNN
|
||||
F 1 "CONN_01X08" V 8400 1850 50 0000 C CNN
|
||||
F 2 "D1_mini:D1_mini_Pin_Header" H 8300 1850 50 0001 C CNN
|
||||
F 3 "" H 8300 1850 50 0000 C CNN
|
||||
1 8300 1850
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
$Comp
|
||||
L d1_mini_shield-rescue:CONN_01X08 P2
|
||||
U 1 1 5763EBF2
|
||||
P 9400 1850
|
||||
F 0 "P2" H 9400 2300 50 0000 C CNN
|
||||
F 1 "CONN_01X08" V 9500 1850 50 0000 C CNN
|
||||
F 2 "D1_mini:D1_mini_Pin_Header" H 9400 1850 50 0001 C CNN
|
||||
F 3 "" H 9400 1850 50 0000 C CNN
|
||||
1 9400 1850
|
||||
-1 0 0 -1
|
||||
$EndComp
|
||||
Text Label 8100 1500 2 60 ~ 0
|
||||
+5V
|
||||
Text Label 8100 1600 2 60 ~ 0
|
||||
GND
|
||||
Text Label 8100 1700 2 60 ~ 0
|
||||
D4
|
||||
Text Label 8100 1800 2 60 ~ 0
|
||||
D3
|
||||
Text Label 8100 1900 2 60 ~ 0
|
||||
D2
|
||||
Text Label 8100 2000 2 60 ~ 0
|
||||
D1
|
||||
Text Label 8100 2100 2 60 ~ 0
|
||||
RX
|
||||
Text Label 8100 2200 2 60 ~ 0
|
||||
TX
|
||||
Text Label 9600 1500 0 60 ~ 0
|
||||
+3.3V
|
||||
Text Label 9600 1600 0 60 ~ 0
|
||||
D8
|
||||
Text Label 9600 1700 0 60 ~ 0
|
||||
D7
|
||||
Text Label 9600 1800 0 60 ~ 0
|
||||
D6
|
||||
Text Label 9600 1900 0 60 ~ 0
|
||||
D5
|
||||
Text Label 9600 2000 0 60 ~ 0
|
||||
D0
|
||||
Text Label 9600 2100 0 60 ~ 0
|
||||
A0
|
||||
Text Label 9600 2200 0 60 ~ 0
|
||||
RST
|
||||
Text Notes 8750 1750 2 60 ~ 0
|
||||
GPIO2
|
||||
Text Notes 8750 1850 2 60 ~ 0
|
||||
GPIO0
|
||||
Text Notes 8750 1950 2 60 ~ 0
|
||||
GPIO4
|
||||
Text Notes 8750 2050 2 60 ~ 0
|
||||
GPIO5
|
||||
Text Notes 8900 1650 0 60 ~ 0
|
||||
GPIO15
|
||||
Text Notes 8900 1750 0 60 ~ 0
|
||||
GPIO13
|
||||
Text Notes 8900 1850 0 60 ~ 0
|
||||
GPIO12
|
||||
Text Notes 8900 1950 0 60 ~ 0
|
||||
GPIO14
|
||||
Text Notes 8900 2050 0 60 ~ 0
|
||||
GPIO16
|
||||
Text Notes 7550 1050 0 60 ~ 0
|
||||
D1 Mini Shield
|
||||
$Comp
|
||||
L tss721:TSS721 U1
|
||||
U 1 1 62B826D2
|
||||
P 3650 5550
|
||||
F 0 "U1" H 3650 6621 50 0000 C CNN
|
||||
F 1 "TSS721" H 3650 6530 50 0000 C CNN
|
||||
F 2 "Package_SO:SOIC-16_3.9x9.9mm_P1.27mm" H 3650 4700 50 0001 C CIN
|
||||
F 3 "http://www.ti.com/lit/ds/symlink/tss721a.pdf" H 3650 6439 50 0000 C CNN
|
||||
1 3650 5550
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
$Comp
|
||||
L power:+3.3V #PWR0101
|
||||
U 1 1 62B89C7B
|
||||
P 2850 4750
|
||||
F 0 "#PWR0101" H 2850 4600 50 0001 C CNN
|
||||
F 1 "+3.3V" V 2865 4878 50 0000 L CNN
|
||||
F 2 "" H 2850 4750 50 0001 C CNN
|
||||
F 3 "" H 2850 4750 50 0001 C CNN
|
||||
1 2850 4750
|
||||
0 -1 -1 0
|
||||
$EndComp
|
||||
$Comp
|
||||
L Connector:RJ45 J1
|
||||
U 1 1 62B8AC34
|
||||
P 1950 1850
|
||||
F 0 "J1" H 2007 2517 50 0000 C CNN
|
||||
F 1 "RJ45" H 2007 2426 50 0000 C CNN
|
||||
F 2 "Connector_RJ:RJ45_Amphenol_54602-x08_Horizontal" V 1950 1875 50 0001 C CNN
|
||||
F 3 "~" V 1950 1875 50 0001 C CNN
|
||||
1 1950 1850
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
$Comp
|
||||
L Device:R R4
|
||||
U 1 1 62B8CAA8
|
||||
P 2750 5150
|
||||
F 0 "R4" V 2957 5150 50 0000 C CNN
|
||||
F 1 "220" V 2866 5150 50 0000 C CNN
|
||||
F 2 "Resistor_SMD:R_0805_2012Metric_Pad1.15x1.40mm_HandSolder" V 2680 5150 50 0001 C CNN
|
||||
F 3 "~" H 2750 5150 50 0001 C CNN
|
||||
1 2750 5150
|
||||
0 -1 -1 0
|
||||
$EndComp
|
||||
$Comp
|
||||
L Device:R R2
|
||||
U 1 1 62B8DB92
|
||||
P 2500 5050
|
||||
F 0 "R2" V 2707 5050 50 0000 C CNN
|
||||
F 1 "220" V 2616 5050 50 0000 C CNN
|
||||
F 2 "Resistor_SMD:R_0805_2012Metric_Pad1.15x1.40mm_HandSolder" V 2430 5050 50 0001 C CNN
|
||||
F 3 "~" H 2500 5050 50 0001 C CNN
|
||||
1 2500 5050
|
||||
0 -1 -1 0
|
||||
$EndComp
|
||||
$Comp
|
||||
L power:GND #PWR0102
|
||||
U 1 1 62B9F029
|
||||
P 1850 6050
|
||||
F 0 "#PWR0102" H 1850 5800 50 0001 C CNN
|
||||
F 1 "GND" H 1855 5877 50 0000 C CNN
|
||||
F 2 "" H 1850 6050 50 0001 C CNN
|
||||
F 3 "" H 1850 6050 50 0001 C CNN
|
||||
1 1850 6050
|
||||
-1 0 0 1
|
||||
$EndComp
|
||||
$Comp
|
||||
L Device:R R3
|
||||
U 1 1 62B9F861
|
||||
P 2500 6300
|
||||
F 0 "R3" H 2570 6346 50 0000 L CNN
|
||||
F 1 "82k" H 2570 6255 50 0000 L CNN
|
||||
F 2 "Resistor_SMD:R_0805_2012Metric_Pad1.15x1.40mm_HandSolder" V 2430 6300 50 0001 C CNN
|
||||
F 3 "~" H 2500 6300 50 0001 C CNN
|
||||
1 2500 6300
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
$Comp
|
||||
L Device:R R1
|
||||
U 1 1 62B9FC37
|
||||
P 2250 6300
|
||||
F 0 "R1" H 2320 6346 50 0000 L CNN
|
||||
F 1 "470" H 2320 6255 50 0000 L CNN
|
||||
F 2 "Resistor_SMD:R_0805_2012Metric_Pad1.15x1.40mm_HandSolder" V 2180 6300 50 0001 C CNN
|
||||
F 3 "~" H 2250 6300 50 0001 C CNN
|
||||
1 2250 6300
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
$Comp
|
||||
L Device:C C2
|
||||
U 1 1 62BA06BE
|
||||
P 2850 6050
|
||||
F 0 "C2" V 3102 6050 50 0000 C CNN
|
||||
F 1 "1u" V 3011 6050 50 0000 C CNN
|
||||
F 2 "Resistor_SMD:R_0805_2012Metric_Pad1.15x1.40mm_HandSolder" H 2888 5900 50 0001 C CNN
|
||||
F 3 "~" H 2850 6050 50 0001 C CNN
|
||||
1 2850 6050
|
||||
0 -1 -1 0
|
||||
$EndComp
|
||||
$Comp
|
||||
L Device:C C1
|
||||
U 1 1 62BA09E7
|
||||
P 1850 6300
|
||||
F 0 "C1" H 1965 6346 50 0000 L CNN
|
||||
F 1 "100n" H 1965 6255 50 0000 L CNN
|
||||
F 2 "Resistor_SMD:R_0805_2012Metric_Pad1.15x1.40mm_HandSolder" H 1888 6150 50 0001 C CNN
|
||||
F 3 "~" H 1850 6300 50 0001 C CNN
|
||||
1 1850 6300
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
Wire Wire Line
|
||||
1850 6050 1850 6150
|
||||
Wire Wire Line
|
||||
2250 6050 2250 6150
|
||||
Wire Wire Line
|
||||
2500 6050 2500 6150
|
||||
Connection ~ 1850 6050
|
||||
Connection ~ 2250 6050
|
||||
Wire Wire Line
|
||||
2250 6050 2500 6050
|
||||
Wire Wire Line
|
||||
1850 6050 2250 6050
|
||||
Connection ~ 2500 6050
|
||||
Wire Wire Line
|
||||
3850 6450 3850 6350
|
||||
Wire Wire Line
|
||||
2250 6450 2250 6550
|
||||
Wire Wire Line
|
||||
3950 6550 3950 6350
|
||||
Wire Wire Line
|
||||
1850 6450 1850 6650
|
||||
Wire Wire Line
|
||||
4050 6650 4050 6350
|
||||
Wire Wire Line
|
||||
3050 6050 3000 6050
|
||||
Wire Wire Line
|
||||
2500 6050 2700 6050
|
||||
Wire Wire Line
|
||||
2700 6050 2700 6350
|
||||
Wire Wire Line
|
||||
2700 6350 3650 6350
|
||||
Connection ~ 2700 6050
|
||||
Wire Wire Line
|
||||
3850 6450 2500 6450
|
||||
Wire Wire Line
|
||||
2250 6550 3950 6550
|
||||
Wire Wire Line
|
||||
4050 6650 1850 6650
|
||||
Text GLabel 4350 5350 2 50 Output ~ 0
|
||||
HAN_TX
|
||||
Wire Wire Line
|
||||
4350 5350 4300 5350
|
||||
Wire Wire Line
|
||||
2850 4750 3550 4750
|
||||
$Comp
|
||||
L Device:R R5
|
||||
U 1 1 62BED413
|
||||
P 4650 4550
|
||||
F 0 "R5" V 4857 4550 50 0000 C CNN
|
||||
F 1 "100k" V 4766 4550 50 0000 C CNN
|
||||
F 2 "Resistor_SMD:R_0805_2012Metric_Pad1.15x1.40mm_HandSolder" V 4580 4550 50 0001 C CNN
|
||||
F 3 "~" H 4650 4550 50 0001 C CNN
|
||||
1 4650 4550
|
||||
0 -1 -1 0
|
||||
$EndComp
|
||||
$Comp
|
||||
L Device:C C3
|
||||
U 1 1 62BED9ED
|
||||
P 4650 4900
|
||||
F 0 "C3" V 4902 4900 50 0000 C CNN
|
||||
F 1 "100n" V 4811 4900 50 0000 C CNN
|
||||
F 2 "Resistor_SMD:R_0805_2012Metric_Pad1.15x1.40mm_HandSolder" H 4688 4750 50 0001 C CNN
|
||||
F 3 "~" H 4650 4900 50 0001 C CNN
|
||||
1 4650 4900
|
||||
0 -1 -1 0
|
||||
$EndComp
|
||||
$Comp
|
||||
L power:GND #PWR0103
|
||||
U 1 1 62BF4151
|
||||
P 4800 5050
|
||||
F 0 "#PWR0103" H 4800 4800 50 0001 C CNN
|
||||
F 1 "GND" H 4805 4877 50 0000 C CNN
|
||||
F 2 "" H 4800 5050 50 0001 C CNN
|
||||
F 3 "" H 4800 5050 50 0001 C CNN
|
||||
1 4800 5050
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
Wire Wire Line
|
||||
4800 4550 4800 4900
|
||||
Wire Wire Line
|
||||
4800 4900 4800 5050
|
||||
Connection ~ 4800 4900
|
||||
Wire Wire Line
|
||||
4500 4900 4500 4550
|
||||
Wire Wire Line
|
||||
4500 4550 3650 4550
|
||||
Wire Wire Line
|
||||
3650 4550 3650 4750
|
||||
Connection ~ 4500 4550
|
||||
Wire Notes Line
|
||||
1500 4050 5050 4050
|
||||
Wire Notes Line
|
||||
5050 4050 5050 6850
|
||||
Wire Notes Line
|
||||
5050 6850 1500 6850
|
||||
Wire Notes Line
|
||||
1500 6850 1500 4050
|
||||
Wire Notes Line
|
||||
7550 950 10200 950
|
||||
Wire Notes Line
|
||||
10200 950 10200 2750
|
||||
Wire Notes Line
|
||||
10200 2750 7550 2750
|
||||
Wire Notes Line
|
||||
7550 2750 7550 950
|
||||
Text GLabel 9800 1700 2 50 Input ~ 0
|
||||
HAN_TX
|
||||
Wire Wire Line
|
||||
9800 1700 9600 1700
|
||||
$Comp
|
||||
L power:+3V3 #PWR0104
|
||||
U 1 1 62C0EBC2
|
||||
P 9850 1500
|
||||
F 0 "#PWR0104" H 9850 1350 50 0001 C CNN
|
||||
F 1 "+3V3" V 9865 1628 50 0000 L CNN
|
||||
F 2 "" H 9850 1500 50 0001 C CNN
|
||||
F 3 "" H 9850 1500 50 0001 C CNN
|
||||
1 9850 1500
|
||||
0 1 1 0
|
||||
$EndComp
|
||||
Wire Wire Line
|
||||
9850 1500 9600 1500
|
||||
Text GLabel 9800 1800 2 50 Output ~ 0
|
||||
LED_R
|
||||
Text GLabel 9800 1900 2 50 Output ~ 0
|
||||
LED_G
|
||||
Wire Wire Line
|
||||
9800 1800 9600 1800
|
||||
Wire Wire Line
|
||||
9800 1900 9600 1900
|
||||
$Comp
|
||||
L power:GND #PWR0105
|
||||
U 1 1 62C13452
|
||||
P 7850 1600
|
||||
F 0 "#PWR0105" H 7850 1350 50 0001 C CNN
|
||||
F 1 "GND" V 7855 1472 50 0000 R CNN
|
||||
F 2 "" H 7850 1600 50 0001 C CNN
|
||||
F 3 "" H 7850 1600 50 0001 C CNN
|
||||
1 7850 1600
|
||||
0 1 1 0
|
||||
$EndComp
|
||||
Wire Wire Line
|
||||
8100 1600 7850 1600
|
||||
Text GLabel 7950 1800 0 50 Input ~ 0
|
||||
BTN_AP
|
||||
Wire Wire Line
|
||||
8100 1800 7950 1800
|
||||
Text GLabel 7950 1900 0 50 Input ~ 0
|
||||
TEMP
|
||||
Wire Wire Line
|
||||
8100 1900 7950 1900
|
||||
Wire Wire Line
|
||||
3050 5150 2900 5150
|
||||
Wire Wire Line
|
||||
3050 5050 2650 5050
|
||||
Text GLabel 2200 5050 0 50 Input ~ 0
|
||||
MBUS1
|
||||
Text GLabel 2200 5150 0 50 Input ~ 0
|
||||
MBUS2
|
||||
Wire Wire Line
|
||||
2350 5050 2200 5050
|
||||
Wire Wire Line
|
||||
2600 5150 2200 5150
|
||||
Text GLabel 2500 2150 2 50 Output ~ 0
|
||||
MBUS1
|
||||
Text GLabel 2500 2050 2 50 Output ~ 0
|
||||
MBUS2
|
||||
Wire Wire Line
|
||||
2500 2050 2350 2050
|
||||
Wire Wire Line
|
||||
2350 2150 2500 2150
|
||||
$Comp
|
||||
L Device:Jumper JP1
|
||||
U 1 1 62C331C0
|
||||
P 3300 1250
|
||||
F 0 "JP1" H 3300 1514 50 0000 C CNN
|
||||
F 1 "Jumper" H 3300 1423 50 0000 C CNN
|
||||
F 2 "Jumper:SolderJumper-2_P1.3mm_Open_RoundedPad1.0x1.5mm" H 3300 1250 50 0001 C CNN
|
||||
F 3 "~" H 3300 1250 50 0001 C CNN
|
||||
1 3300 1250
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
$Comp
|
||||
L Device:Jumper JP2
|
||||
U 1 1 62C365CA
|
||||
P 3300 1850
|
||||
F 0 "JP2" H 3300 2114 50 0000 C CNN
|
||||
F 1 "Jumper" H 3300 2023 50 0000 C CNN
|
||||
F 2 "Jumper:SolderJumper-2_P1.3mm_Open_RoundedPad1.0x1.5mm" H 3300 1850 50 0001 C CNN
|
||||
F 3 "~" H 3300 1850 50 0001 C CNN
|
||||
1 3300 1850
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
$Comp
|
||||
L Device:Jumper JP3
|
||||
U 1 1 62C36C70
|
||||
P 3300 2200
|
||||
F 0 "JP3" H 3300 2464 50 0000 C CNN
|
||||
F 1 "Jumper" H 3300 2373 50 0000 C CNN
|
||||
F 2 "Jumper:SolderJumper-2_P1.3mm_Open_RoundedPad1.0x1.5mm" H 3300 2200 50 0001 C CNN
|
||||
F 3 "~" H 3300 2200 50 0001 C CNN
|
||||
1 3300 2200
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
Wire Wire Line
|
||||
3000 1850 2900 1850
|
||||
Wire Wire Line
|
||||
2900 1850 2900 1750
|
||||
Wire Wire Line
|
||||
2350 1750 2900 1750
|
||||
Wire Wire Line
|
||||
2350 1850 2850 1850
|
||||
Wire Wire Line
|
||||
2850 1850 2850 2200
|
||||
Wire Wire Line
|
||||
2850 2200 3000 2200
|
||||
$Comp
|
||||
L power:GND #PWR0107
|
||||
U 1 1 62C3D94F
|
||||
P 3750 1850
|
||||
F 0 "#PWR0107" H 3750 1600 50 0001 C CNN
|
||||
F 1 "GND" V 3755 1722 50 0000 R CNN
|
||||
F 2 "" H 3750 1850 50 0001 C CNN
|
||||
F 3 "" H 3750 1850 50 0001 C CNN
|
||||
1 3750 1850
|
||||
0 -1 -1 0
|
||||
$EndComp
|
||||
Text GLabel 3750 2200 2 50 Output ~ 0
|
||||
TEMP
|
||||
Wire Wire Line
|
||||
3750 1850 3600 1850
|
||||
Wire Wire Line
|
||||
3750 2200 3600 2200
|
||||
Wire Notes Line
|
||||
1450 950 4350 950
|
||||
Wire Notes Line
|
||||
4350 950 4350 2450
|
||||
Wire Notes Line
|
||||
4350 2450 1450 2450
|
||||
Wire Notes Line
|
||||
1450 2450 1450 950
|
||||
$Comp
|
||||
L Device:LED_RGB D1
|
||||
U 1 1 62C43A7B
|
||||
P 9550 4800
|
||||
F 0 "D1" H 9550 5297 50 0000 C CNN
|
||||
F 1 "LED_RGB" H 9550 5206 50 0000 C CNN
|
||||
F 2 "LED_SMD:LED_RGB_PLCC-6" H 9550 4750 50 0001 C CNN
|
||||
F 3 "~" H 9550 4750 50 0001 C CNN
|
||||
1 9550 4800
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
$Comp
|
||||
L power:+3.3V #PWR0108
|
||||
U 1 1 62C44A94
|
||||
P 10000 4800
|
||||
F 0 "#PWR0108" H 10000 4650 50 0001 C CNN
|
||||
F 1 "+3.3V" V 10015 4928 50 0000 L CNN
|
||||
F 2 "" H 10000 4800 50 0001 C CNN
|
||||
F 3 "" H 10000 4800 50 0001 C CNN
|
||||
1 10000 4800
|
||||
0 1 1 0
|
||||
$EndComp
|
||||
Wire Wire Line
|
||||
9750 4800 9900 4800
|
||||
Wire Wire Line
|
||||
9750 4600 9900 4600
|
||||
Wire Wire Line
|
||||
9900 4600 9900 4800
|
||||
Connection ~ 9900 4800
|
||||
Wire Wire Line
|
||||
9900 4800 10000 4800
|
||||
Wire Wire Line
|
||||
9900 4800 9900 5000
|
||||
Wire Wire Line
|
||||
9900 5000 9750 5000
|
||||
$Comp
|
||||
L Device:R R9
|
||||
U 1 1 62C495F7
|
||||
P 9100 4600
|
||||
F 0 "R9" V 9307 4600 50 0000 C CNN
|
||||
F 1 "1k" V 9216 4600 50 0000 C CNN
|
||||
F 2 "Resistor_SMD:R_0805_2012Metric_Pad1.15x1.40mm_HandSolder" V 9030 4600 50 0001 C CNN
|
||||
F 3 "~" H 9100 4600 50 0001 C CNN
|
||||
1 9100 4600
|
||||
0 -1 -1 0
|
||||
$EndComp
|
||||
$Comp
|
||||
L Device:R R8
|
||||
U 1 1 62C4BDE9
|
||||
P 8850 4800
|
||||
F 0 "R8" V 9057 4800 50 0000 C CNN
|
||||
F 1 "1k" V 8966 4800 50 0000 C CNN
|
||||
F 2 "Resistor_SMD:R_0805_2012Metric_Pad1.15x1.40mm_HandSolder" V 8780 4800 50 0001 C CNN
|
||||
F 3 "~" H 8850 4800 50 0001 C CNN
|
||||
1 8850 4800
|
||||
0 -1 -1 0
|
||||
$EndComp
|
||||
$Comp
|
||||
L Device:R R10
|
||||
U 1 1 62C4C336
|
||||
P 9100 5000
|
||||
F 0 "R10" V 9307 5000 50 0000 C CNN
|
||||
F 1 "1k" V 9216 5000 50 0000 C CNN
|
||||
F 2 "Resistor_SMD:R_0805_2012Metric_Pad1.15x1.40mm_HandSolder" V 9030 5000 50 0001 C CNN
|
||||
F 3 "~" H 9100 5000 50 0001 C CNN
|
||||
1 9100 5000
|
||||
0 -1 -1 0
|
||||
$EndComp
|
||||
Wire Wire Line
|
||||
9350 4600 9250 4600
|
||||
Wire Wire Line
|
||||
9350 4800 9000 4800
|
||||
Wire Wire Line
|
||||
9350 5000 9250 5000
|
||||
Text GLabel 8650 4600 0 50 Input ~ 0
|
||||
LED_R
|
||||
Text GLabel 8650 4800 0 50 Input ~ 0
|
||||
LED_G
|
||||
Text GLabel 8650 5000 0 50 Input ~ 0
|
||||
LED_B
|
||||
Wire Wire Line
|
||||
8700 4800 8650 4800
|
||||
Wire Wire Line
|
||||
8950 4600 8650 4600
|
||||
Wire Wire Line
|
||||
8950 5000 8650 5000
|
||||
Wire Notes Line
|
||||
8200 4050 10550 4050
|
||||
Wire Notes Line
|
||||
10550 4050 10550 5400
|
||||
Wire Notes Line
|
||||
10550 5400 8200 5400
|
||||
Wire Notes Line
|
||||
8200 5400 8200 4050
|
||||
$Comp
|
||||
L Sensor_Temperature:DS18B20 U2
|
||||
U 1 1 62C6296F
|
||||
P 6600 4900
|
||||
F 0 "U2" H 6370 4946 50 0000 R CNN
|
||||
F 1 "DS18B20" H 6370 4855 50 0000 R CNN
|
||||
F 2 "Package_TO_SOT_THT:TO-92_Inline" H 5600 4650 50 0001 C CNN
|
||||
F 3 "http://datasheets.maximintegrated.com/en/ds/DS18B20.pdf" H 6450 5150 50 0001 C CNN
|
||||
1 6600 4900
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
$Comp
|
||||
L power:GND #PWR0109
|
||||
U 1 1 62C6373E
|
||||
P 6600 5350
|
||||
F 0 "#PWR0109" H 6600 5100 50 0001 C CNN
|
||||
F 1 "GND" H 6605 5177 50 0000 C CNN
|
||||
F 2 "" H 6600 5350 50 0001 C CNN
|
||||
F 3 "" H 6600 5350 50 0001 C CNN
|
||||
1 6600 5350
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
$Comp
|
||||
L power:+3.3V #PWR0110
|
||||
U 1 1 62C63C02
|
||||
P 6600 4450
|
||||
F 0 "#PWR0110" H 6600 4300 50 0001 C CNN
|
||||
F 1 "+3.3V" H 6615 4623 50 0000 C CNN
|
||||
F 2 "" H 6600 4450 50 0001 C CNN
|
||||
F 3 "" H 6600 4450 50 0001 C CNN
|
||||
1 6600 4450
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
$Comp
|
||||
L Device:R R7
|
||||
U 1 1 62C6405D
|
||||
P 6900 4600
|
||||
F 0 "R7" H 6970 4646 50 0000 L CNN
|
||||
F 1 "4k7" H 6970 4555 50 0000 L CNN
|
||||
F 2 "Resistor_SMD:R_0805_2012Metric_Pad1.15x1.40mm_HandSolder" V 6830 4600 50 0001 C CNN
|
||||
F 3 "~" H 6900 4600 50 0001 C CNN
|
||||
1 6900 4600
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
Wire Wire Line
|
||||
6600 5200 6600 5350
|
||||
Wire Wire Line
|
||||
6600 4600 6600 4450
|
||||
Wire Wire Line
|
||||
6900 4900 6900 4750
|
||||
Wire Wire Line
|
||||
6900 4450 6600 4450
|
||||
Connection ~ 6600 4450
|
||||
Text GLabel 7050 4900 2 50 Output ~ 0
|
||||
TEMP
|
||||
Wire Wire Line
|
||||
7050 4900 6900 4900
|
||||
Connection ~ 6900 4900
|
||||
Wire Notes Line
|
||||
5750 4050 7500 4050
|
||||
Wire Notes Line
|
||||
7500 4050 7500 5750
|
||||
Wire Notes Line
|
||||
7500 5750 5750 5750
|
||||
Wire Notes Line
|
||||
5750 5750 5750 4050
|
||||
$Comp
|
||||
L Switch:SW_Push SW1
|
||||
U 1 1 62C73229
|
||||
P 5950 1400
|
||||
F 0 "SW1" H 5950 1685 50 0000 C CNN
|
||||
F 1 "SW_Push" H 5950 1594 50 0000 C CNN
|
||||
F 2 "Button_Switch_SMD:SW_SPST_B3U-3000P" H 5950 1600 50 0001 C CNN
|
||||
F 3 "~" H 5950 1600 50 0001 C CNN
|
||||
1 5950 1400
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
$Comp
|
||||
L Device:R R6
|
||||
U 1 1 62C73CE8
|
||||
P 5950 1700
|
||||
F 0 "R6" V 6157 1700 50 0000 C CNN
|
||||
F 1 "10k" V 6066 1700 50 0000 C CNN
|
||||
F 2 "Resistor_SMD:R_0805_2012Metric_Pad1.15x1.40mm_HandSolder" V 5880 1700 50 0001 C CNN
|
||||
F 3 "~" H 5950 1700 50 0001 C CNN
|
||||
1 5950 1700
|
||||
0 -1 -1 0
|
||||
$EndComp
|
||||
$Comp
|
||||
L power:GND #PWR0111
|
||||
U 1 1 62C76961
|
||||
P 6350 1400
|
||||
F 0 "#PWR0111" H 6350 1150 50 0001 C CNN
|
||||
F 1 "GND" V 6355 1272 50 0000 R CNN
|
||||
F 2 "" H 6350 1400 50 0001 C CNN
|
||||
F 3 "" H 6350 1400 50 0001 C CNN
|
||||
1 6350 1400
|
||||
0 -1 -1 0
|
||||
$EndComp
|
||||
$Comp
|
||||
L power:+3.3V #PWR0112
|
||||
U 1 1 62C776AD
|
||||
P 6350 1700
|
||||
F 0 "#PWR0112" H 6350 1550 50 0001 C CNN
|
||||
F 1 "+3.3V" V 6365 1828 50 0000 L CNN
|
||||
F 2 "" H 6350 1700 50 0001 C CNN
|
||||
F 3 "" H 6350 1700 50 0001 C CNN
|
||||
1 6350 1700
|
||||
0 1 1 0
|
||||
$EndComp
|
||||
Wire Wire Line
|
||||
6350 1400 6150 1400
|
||||
Wire Wire Line
|
||||
6350 1700 6100 1700
|
||||
Wire Wire Line
|
||||
5750 1400 5550 1400
|
||||
Wire Wire Line
|
||||
5550 1400 5550 1550
|
||||
Wire Wire Line
|
||||
5550 1700 5800 1700
|
||||
Text GLabel 5450 1550 0 50 Output ~ 0
|
||||
BTN_AP
|
||||
Wire Wire Line
|
||||
5450 1550 5550 1550
|
||||
Connection ~ 5550 1550
|
||||
Wire Wire Line
|
||||
5550 1550 5550 1700
|
||||
Wire Notes Line
|
||||
5000 950 6850 950
|
||||
Wire Notes Line
|
||||
6850 950 6850 1950
|
||||
Wire Notes Line
|
||||
6850 1950 5000 1950
|
||||
Wire Notes Line
|
||||
5000 1950 5000 950
|
||||
Text GLabel 4350 5450 2 50 Output ~ 0
|
||||
LED_B
|
||||
Wire Wire Line
|
||||
4350 5450 4300 5450
|
||||
Wire Wire Line
|
||||
4300 5450 4300 5350
|
||||
Connection ~ 4300 5350
|
||||
Wire Wire Line
|
||||
4300 5350 4250 5350
|
||||
$Comp
|
||||
L power:+5V #PWR0106
|
||||
U 1 1 62D05402
|
||||
P 7850 1500
|
||||
F 0 "#PWR0106" H 7850 1350 50 0001 C CNN
|
||||
F 1 "+5V" V 7865 1628 50 0000 L CNN
|
||||
F 2 "" H 7850 1500 50 0001 C CNN
|
||||
F 3 "" H 7850 1500 50 0001 C CNN
|
||||
1 7850 1500
|
||||
0 -1 -1 0
|
||||
$EndComp
|
||||
Wire Wire Line
|
||||
8100 1500 7850 1500
|
||||
$Comp
|
||||
L power:+5V #PWR0113
|
||||
U 1 1 62D0B1E1
|
||||
P 3750 1250
|
||||
F 0 "#PWR0113" H 3750 1100 50 0001 C CNN
|
||||
F 1 "+5V" V 3765 1378 50 0000 L CNN
|
||||
F 2 "" H 3750 1250 50 0001 C CNN
|
||||
F 3 "" H 3750 1250 50 0001 C CNN
|
||||
1 3750 1250
|
||||
0 1 1 0
|
||||
$EndComp
|
||||
$Comp
|
||||
L Device:Jumper JP4
|
||||
U 1 1 62D1E97A
|
||||
P 3300 1550
|
||||
F 0 "JP4" H 3300 1814 50 0000 C CNN
|
||||
F 1 "Jumper" H 3300 1723 50 0000 C CNN
|
||||
F 2 "Jumper:SolderJumper-2_P1.3mm_Open_RoundedPad1.0x1.5mm" H 3300 1550 50 0001 C CNN
|
||||
F 3 "~" H 3300 1550 50 0001 C CNN
|
||||
1 3300 1550
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
Wire Wire Line
|
||||
3000 1250 2350 1250
|
||||
Wire Wire Line
|
||||
2350 1250 2350 1450
|
||||
Wire Wire Line
|
||||
3600 1250 3750 1250
|
||||
Wire Wire Line
|
||||
3600 1550 3600 1850
|
||||
Connection ~ 3600 1850
|
||||
Wire Wire Line
|
||||
2350 1550 3000 1550
|
||||
$EndSCHEMATC
|
||||
75272
hardware/wemos_mbus_shield/kicad/fp-info-cache
Normal file
75272
hardware/wemos_mbus_shield/kicad/fp-info-cache
Normal file
File diff suppressed because it is too large
Load Diff
3
hardware/wemos_mbus_shield/kicad/fp-lib-table
Normal file
3
hardware/wemos_mbus_shield/kicad/fp-lib-table
Normal file
@@ -0,0 +1,3 @@
|
||||
(fp_lib_table
|
||||
(lib (name D1_mini)(type KiCad)(uri "$(KIPRJMOD)/lib/D1_mini.pretty")(options "")(descr ""))
|
||||
)
|
||||
@@ -0,0 +1,27 @@
|
||||
(module Pin_Headers:Pin_Header_Straight_1x08 (layer F.Cu) (tedit 5766A5B6)
|
||||
(descr "Through hole pin header")
|
||||
(tags "pin header")
|
||||
(fp_text reference P1 (at 0.11176 -2.43586) (layer F.SilkS)
|
||||
(effects (font (size 1 1) (thickness 0.15)))
|
||||
)
|
||||
(fp_text value CONN_01X08 (at 0 -3.1) (layer F.Fab) hide
|
||||
(effects (font (size 1 1) (thickness 0.15)))
|
||||
)
|
||||
(fp_line (start -1.75 -1.75) (end -1.75 19.55) (layer F.CrtYd) (width 0.05))
|
||||
(fp_line (start 1.75 -1.75) (end 1.75 19.55) (layer F.CrtYd) (width 0.05))
|
||||
(fp_line (start -1.75 -1.75) (end 1.75 -1.75) (layer F.CrtYd) (width 0.05))
|
||||
(fp_line (start -1.75 19.55) (end 1.75 19.55) (layer F.CrtYd) (width 0.05))
|
||||
(pad 1 thru_hole rect (at 0 0) (size 1.8 1.8) (drill 1.016) (layers *.Cu *.Mask F.SilkS))
|
||||
(pad 2 thru_hole oval (at 0 2.54) (size 1.8 1.8) (drill 1.016) (layers *.Cu *.Mask F.SilkS))
|
||||
(pad 3 thru_hole oval (at 0 5.08) (size 1.8 1.8) (drill 1.016) (layers *.Cu *.Mask F.SilkS))
|
||||
(pad 4 thru_hole oval (at 0 7.62) (size 1.8 1.8) (drill 1.016) (layers *.Cu *.Mask F.SilkS))
|
||||
(pad 5 thru_hole oval (at 0 10.16) (size 1.8 1.8) (drill 1.016) (layers *.Cu *.Mask F.SilkS))
|
||||
(pad 6 thru_hole oval (at 0 12.7) (size 1.8 1.8) (drill 1.016) (layers *.Cu *.Mask F.SilkS))
|
||||
(pad 7 thru_hole oval (at 0 15.24) (size 1.8 1.8) (drill 1.016) (layers *.Cu *.Mask F.SilkS))
|
||||
(pad 8 thru_hole oval (at 0 17.78) (size 1.8 1.8) (drill 1.016) (layers *.Cu *.Mask F.SilkS))
|
||||
(model Pin_Headers.3dshapes/Pin_Header_Straight_1x08.wrl
|
||||
(at (xyz 0 -0.35 0))
|
||||
(scale (xyz 1 1 1))
|
||||
(rotate (xyz 0 0 90))
|
||||
)
|
||||
)
|
||||
@@ -0,0 +1,54 @@
|
||||
(module OSHW (layer F.Cu) (tedit 5766B04E)
|
||||
(descr OSHW)
|
||||
(tags "Symbol, OSHW-Logo, Silk Screen,")
|
||||
(fp_text reference "" (at 0.09906 -4.38912) (layer F.SilkS) hide
|
||||
(effects (font (size 1 1) (thickness 0.15)))
|
||||
)
|
||||
(fp_text value OSHW (at 0 5) (layer F.Fab) hide
|
||||
(effects (font (size 1 1) (thickness 0.15)))
|
||||
)
|
||||
(fp_line (start -1.78054 0.92964) (end -2.03962 1.49098) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start -2.03962 1.49098) (end -1.50114 2.00914) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start -1.50114 2.00914) (end -0.98044 1.7399) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start -0.98044 1.7399) (end -0.70104 1.89992) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start 0.73914 1.8796) (end 1.06934 1.6891) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start 1.06934 1.6891) (end 1.50876 2.0193) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start 1.50876 2.0193) (end 1.9812 1.52908) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start 1.9812 1.52908) (end 1.69926 1.04902) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start 1.69926 1.04902) (end 1.88976 0.57912) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start 1.88976 0.57912) (end 2.49936 0.39116) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start 2.49936 0.39116) (end 2.49936 -0.28956) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start 2.49936 -0.28956) (end 1.94056 -0.42926) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start 1.94056 -0.42926) (end 1.7399 -1.00076) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start 1.7399 -1.00076) (end 2.00914 -1.47066) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start 2.00914 -1.47066) (end 1.53924 -1.9812) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start 1.53924 -1.9812) (end 1.02108 -1.71958) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start 1.02108 -1.71958) (end 0.55118 -1.92024) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start 0.55118 -1.92024) (end 0.381 -2.46126) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start 0.381 -2.46126) (end -0.30988 -2.47904) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start -0.30988 -2.47904) (end -0.5207 -1.9304) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start -0.5207 -1.9304) (end -0.9398 -1.76022) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start -0.9398 -1.76022) (end -1.49098 -2.02946) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start -1.49098 -2.02946) (end -2.00914 -1.50114) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start -2.00914 -1.50114) (end -1.76022 -0.96012) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start -1.76022 -0.96012) (end -1.9304 -0.48006) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start -1.9304 -0.48006) (end -2.47904 -0.381) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start -2.47904 -0.381) (end -2.4892 0.32004) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start -2.4892 0.32004) (end -1.9304 0.5207) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start -1.9304 0.5207) (end -1.7907 0.91948) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start 0.35052 0.89916) (end 0.65024 0.7493) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start 0.65024 0.7493) (end 0.8509 0.55118) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start 0.8509 0.55118) (end 1.00076 0.14986) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start 1.00076 0.14986) (end 1.00076 -0.24892) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start 1.00076 -0.24892) (end 0.8509 -0.59944) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start 0.8509 -0.59944) (end 0.39878 -0.94996) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start 0.39878 -0.94996) (end -0.0508 -1.00076) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start -0.0508 -1.00076) (end -0.44958 -0.89916) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start -0.44958 -0.89916) (end -0.8509 -0.55118) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start -0.8509 -0.55118) (end -1.00076 -0.09906) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start -1.00076 -0.09906) (end -0.94996 0.39878) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start -0.94996 0.39878) (end -0.70104 0.70104) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start -0.70104 0.70104) (end -0.35052 0.89916) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start -0.35052 0.89916) (end -0.70104 1.89992) (layer F.SilkS) (width 0.15))
|
||||
(fp_line (start 0.35052 0.89916) (end 0.7493 1.89992) (layer F.SilkS) (width 0.15))
|
||||
)
|
||||
BIN
hardware/wemos_mbus_shield/kicad/meta/brd.png
Normal file
BIN
hardware/wemos_mbus_shield/kicad/meta/brd.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 198 KiB |
BIN
hardware/wemos_mbus_shield/kicad/meta/icon.png
Normal file
BIN
hardware/wemos_mbus_shield/kicad/meta/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
21
hardware/wemos_mbus_shield/kicad/meta/info.html
Normal file
21
hardware/wemos_mbus_shield/kicad/meta/info.html
Normal file
@@ -0,0 +1,21 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<title>D1Shield</title>
|
||||
</HEAD>
|
||||
<BODY>
|
||||
<P>This project template is the basis of an expansion board for the
|
||||
<A HREF="https://www.wemos.cc/en/latest/d1/d1_mini.html" TARGET="blank">D1 mini board</A>.
|
||||
<BR><BR>This base project includes a PCB edge defined
|
||||
as the same size as the D1 mini PCB with the connectors placed
|
||||
correctly to align the two boards. All IO present on the D1 mini
|
||||
board is connected to the project through the expansion
|
||||
headers. <BR><BR>The board looks like the following:
|
||||
</P>
|
||||
<P><IMG SRC="brd.png">
|
||||
</P>
|
||||
<p><i>Dwgs.User</i> layer show mechanical components of the D1mini board.</p>
|
||||
<P>©2016 Jérôme Labidurie<br/>
|
||||
Licence: <a href="https://creativecommons.org/licenses/by-sa/3.0/">CC:BY-SA 3.0</a><br/>
|
||||
<a href="http://dinask.eu">dinask.eu</a></P>
|
||||
</BODY>
|
||||
</HTML>
|
||||
4
hardware/wemos_mbus_shield/kicad/sym-lib-table
Normal file
4
hardware/wemos_mbus_shield/kicad/sym-lib-table
Normal file
@@ -0,0 +1,4 @@
|
||||
(sym_lib_table
|
||||
(lib (name d1_mini_shield-rescue)(type Legacy)(uri ${KIPRJMOD}/d1_mini_shield-rescue.lib)(options "")(descr ""))
|
||||
(lib (name tss721)(type Legacy)(uri ${KIPRJMOD}/tss721.lib)(options "")(descr ""))
|
||||
)
|
||||
9
hardware/wemos_mbus_shield/kicad/tss721.dcm
Normal file
9
hardware/wemos_mbus_shield/kicad/tss721.dcm
Normal file
@@ -0,0 +1,9 @@
|
||||
EESchema-DOCLIB Version 2.0
|
||||
#
|
||||
$CMP TSS721
|
||||
D TSS721A Meter Bus Transceiver, SOIC-16/TSSOP-16
|
||||
K MBUS Tranciever
|
||||
F http://www.ti.com/lit/ds/symlink/tss721a.pdf
|
||||
$ENDCMP
|
||||
#
|
||||
#End Doc Library
|
||||
37
hardware/wemos_mbus_shield/kicad/tss721.lib
Normal file
37
hardware/wemos_mbus_shield/kicad/tss721.lib
Normal file
@@ -0,0 +1,37 @@
|
||||
EESchema-LIBRARY Version 2.4
|
||||
#encoding utf-8
|
||||
#
|
||||
# TSS721
|
||||
#
|
||||
DEF TSS721 U 0 40 Y Y 1 F N
|
||||
F0 "U" 200 850 50 H V L CNN
|
||||
F1 "TSS721" 200 750 50 H V L CNN
|
||||
F2 "" 0 -850 50 H V C CIN
|
||||
F3 "" -200 -800 50 H V C CNN
|
||||
ALIAS TSS721A
|
||||
$FPLIST
|
||||
SOIC*3.9x9.9mm*Pitch1.27mm*
|
||||
TSSOP*4.4x5mm*Pitch0.65mm*
|
||||
$ENDFPLIST
|
||||
DRAW
|
||||
S -500 -700 500 700 0 1 10 f
|
||||
X BUSL2 1 -600 400 100 R 50 50 1 1 I
|
||||
X VS 10 -600 0 100 R 50 50 1 1 P
|
||||
X VDD 11 0 800 100 D 50 50 1 1 W
|
||||
X RX 12 600 500 100 L 50 50 1 1 I
|
||||
X RXI 13 600 400 100 L 50 50 1 1 I I
|
||||
X RIS 14 300 -800 100 U 50 50 1 1 I
|
||||
X GND 15 0 -800 100 U 50 50 1 1 W
|
||||
X BUSL1 16 -600 500 100 R 50 50 1 1 I
|
||||
X VB 2 -600 -150 100 R 50 50 1 1 P
|
||||
X STC 3 -600 -500 100 R 50 50 1 1 P
|
||||
X RIDD 4 200 -800 100 U 50 50 1 1 O
|
||||
X PF 5 -600 100 100 R 50 50 1 1 I
|
||||
X SC 6 400 -800 100 U 50 50 1 1 P
|
||||
X TXI 7 600 100 100 L 50 50 1 1 O I
|
||||
X TX 8 600 200 100 L 50 50 1 1 O
|
||||
X BAT 9 -100 800 100 D 50 50 1 1 I
|
||||
ENDDRAW
|
||||
ENDDEF
|
||||
#
|
||||
#End Library
|
||||
@@ -17,22 +17,24 @@ extra_scripts =
|
||||
pre:scripts/addversion.py
|
||||
scripts/makeweb.py
|
||||
|
||||
|
||||
[env:esp32]
|
||||
platform = https://github.com/platformio/platform-espressif32.git#feature/arduino-upstream
|
||||
platform = https://github.com/tasmota/platform-espressif32/releases/download/v2.0.4/platform-espressif32-2.0.4.zip
|
||||
framework = arduino
|
||||
board = esp32dev
|
||||
board_build.f_cpu = 160000000L
|
||||
build_flags = -D WEBSOCKET_DISABLED=1
|
||||
build_flags = -D WEBSOCKET_DISABLED=1 -fexceptions
|
||||
lib_deps = ${common.lib_deps}
|
||||
lib_ignore = ${common.lib_ignore}
|
||||
extra_scripts =
|
||||
pre:scripts/addversion.py
|
||||
scripts/makeweb.py
|
||||
|
||||
# Tasmota has pre-built platform for C3, S2, S3 and Solo, more information at:
|
||||
# https://github.com/Jason2866/esp32-arduino-lib-builder
|
||||
|
||||
[env:esp32s2]
|
||||
platform = https://github.com/tasmota/platform-espressif32.git#v2.0.3
|
||||
platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#2.0.2
|
||||
platform = https://github.com/tasmota/platform-espressif32/releases/download/v2.0.4/platform-espressif32-2.0.4.zip
|
||||
platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#2.0.4
|
||||
framework = arduino
|
||||
board = esp32dev
|
||||
board_build.mcu = esp32s2
|
||||
@@ -46,3 +48,15 @@ lib_ignore = ${common.lib_ignore}
|
||||
extra_scripts =
|
||||
pre:scripts/addversion.py
|
||||
scripts/makeweb.py
|
||||
|
||||
[env:esp32solo]
|
||||
platform = https://github.com/tasmota/platform-espressif32/releases/download/v2.0.4/platform-espressif32-solo1-2.0.4.zip
|
||||
framework = arduino
|
||||
board = esp32dev
|
||||
board_build.f_cpu = 160000000L
|
||||
build_flags = -D WEBSOCKET_DISABLED=1 -fexceptions
|
||||
lib_deps = ${common.lib_deps}
|
||||
lib_ignore = ${common.lib_ignore}
|
||||
extra_scripts =
|
||||
pre:scripts/addversion.py
|
||||
scripts/makeweb.py
|
||||
|
||||
40
scripts/esp32solo/flash.sh
Executable file
40
scripts/esp32solo/flash.sh
Executable file
@@ -0,0 +1,40 @@
|
||||
#!/bin/sh
|
||||
|
||||
if [ -z "$1" ];then
|
||||
echo "Usage: "
|
||||
echo " Flashing first time : $0 flash /dev/ttyUSB0"
|
||||
echo " When upgrading to new version : $0 upgrade /dev/ttyUSB0"
|
||||
echo " NOTE: Replace /dev/ttyUSB0 with correct port"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$2" ];then
|
||||
echo "Please specify port"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
esptool=`which esptool`
|
||||
if [ -z "$esptool" ];then
|
||||
esptool=`which esptool.py`
|
||||
fi
|
||||
if [ -z "$esptool" ];then
|
||||
if [ -f esptool.py ];then
|
||||
esptool="esptool.py"
|
||||
fi
|
||||
fi
|
||||
if [ -z "$esptool" ];then
|
||||
echo "esptool.py not available to run following command: "
|
||||
esptool="echo esptool.py"
|
||||
fi
|
||||
|
||||
if [ "$1" = "flash" ];then
|
||||
$esptool --chip esp32 --port $2 --baud 460800 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect \
|
||||
0x1000 bootloader_dio_40m.bin \
|
||||
0x8000 partitions.bin \
|
||||
0xe000 boot_app0.bin \
|
||||
0x10000 firmware.bin
|
||||
exit $?
|
||||
elif [ "$1" = "upgrade" ];then
|
||||
$esptool --chip esp32 --port $2 --baud 460800 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect 0x10000 firmware.bin
|
||||
exit $?
|
||||
fi
|
||||
14
scripts/esp32solo/mkzip.sh
Executable file
14
scripts/esp32solo/mkzip.sh
Executable file
@@ -0,0 +1,14 @@
|
||||
#!/bin/sh
|
||||
|
||||
env="esp32solo"
|
||||
build_dir=".pio/build/$env/"
|
||||
|
||||
if [ ! -d $build_dir ];then
|
||||
echo "No build directory"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cp ~/.platformio/packages/framework-arduinoespressif32/tools/sdk/$env/bin/bootloader_dio_40m.bin $build_dir
|
||||
cp ~/.platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin $build_dir
|
||||
chmod +x scripts/$env/flash.sh
|
||||
zip -j $env.zip $build_dir/*.bin scripts/$env/flash.sh
|
||||
@@ -657,6 +657,14 @@ bool AmsConfiguration::hasConfig() {
|
||||
configVersion = 0;
|
||||
return false;
|
||||
}
|
||||
case 94:
|
||||
configVersion = -1; // Prevent loop
|
||||
if(relocateConfig94()) {
|
||||
configVersion = 95;
|
||||
} else {
|
||||
configVersion = 0;
|
||||
return false;
|
||||
}
|
||||
case EEPROM_CHECK_SUM:
|
||||
return true;
|
||||
default:
|
||||
@@ -822,6 +830,18 @@ bool AmsConfiguration::relocateConfig93() {
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool AmsConfiguration::relocateConfig94() {
|
||||
EnergyAccountingConfig eac;
|
||||
EEPROM.begin(EEPROM_SIZE);
|
||||
EEPROM.get(CONFIG_ENERGYACCOUNTING_START, eac);
|
||||
eac.hours = 1;
|
||||
EEPROM.put(CONFIG_ENERGYACCOUNTING_START, eac);
|
||||
EEPROM.put(EEPROM_CONFIG_ADDRESS, 95);
|
||||
bool ret = EEPROM.commit();
|
||||
EEPROM.end();
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool AmsConfiguration::save() {
|
||||
EEPROM.begin(EEPROM_SIZE);
|
||||
EEPROM.put(EEPROM_CONFIG_ADDRESS, EEPROM_CHECK_SUM);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "Arduino.h"
|
||||
|
||||
#define EEPROM_SIZE 1024*3
|
||||
#define EEPROM_CHECK_SUM 94 // Used to check if config is stored. Change if structure changes
|
||||
#define EEPROM_CHECK_SUM 95 // Used to check if config is stored. Change if structure changes
|
||||
#define EEPROM_CONFIG_ADDRESS 0
|
||||
#define EEPROM_TEMP_CONFIG_ADDRESS 2048
|
||||
|
||||
@@ -99,7 +99,9 @@ struct MeterConfig {
|
||||
uint16_t voltageMultiplier;
|
||||
uint16_t amperageMultiplier;
|
||||
uint16_t accumulatedMultiplier;
|
||||
}; // 49
|
||||
uint8_t source;
|
||||
uint8_t parser;
|
||||
}; // 50
|
||||
|
||||
struct MeterConfig87 {
|
||||
uint8_t type;
|
||||
@@ -161,7 +163,8 @@ struct EntsoeConfig {
|
||||
|
||||
struct EnergyAccountingConfig {
|
||||
uint8_t thresholds[10];
|
||||
}; // 10
|
||||
uint8_t hours;
|
||||
}; // 11
|
||||
|
||||
struct TempSensorConfig {
|
||||
uint8_t address[8];
|
||||
@@ -264,7 +267,8 @@ private:
|
||||
bool relocateConfig90(); // 2.0.0
|
||||
bool relocateConfig91(); // 2.0.2
|
||||
bool relocateConfig92(); // 2.0.3
|
||||
bool relocateConfig93(); // 2.1 beta
|
||||
bool relocateConfig93(); // 2.1.0
|
||||
bool relocateConfig94(); // 2.1.4
|
||||
|
||||
void saveToFs();
|
||||
bool loadFromFs(uint8_t version);
|
||||
|
||||
@@ -383,17 +383,17 @@ bool AmsDataStorage::isDayHappy() {
|
||||
tmElements_t tm, last;
|
||||
|
||||
if(now < day.lastMeterReadTime) {
|
||||
if(debugger->isActive(RemoteDebug::DEBUG)) debugger->printf("(AmsDataStorage) Day %lld < %lld\n", (int64_t) now, (int64_t) day.lastMeterReadTime);
|
||||
if(debugger->isActive(RemoteDebug::VERBOSE)) debugger->printf("(AmsDataStorage) Day %lld < %lld\n", (int64_t) now, (int64_t) day.lastMeterReadTime);
|
||||
return false;
|
||||
}
|
||||
if(now-day.lastMeterReadTime > 3600) {
|
||||
if(debugger->isActive(RemoteDebug::DEBUG)) debugger->printf("(AmsDataStorage) Day %lld - %lld > 3600\n", (int64_t) now, (int64_t) day.lastMeterReadTime);
|
||||
if(debugger->isActive(RemoteDebug::VERBOSE)) debugger->printf("(AmsDataStorage) Day %lld - %lld > 3600\n", (int64_t) now, (int64_t) day.lastMeterReadTime);
|
||||
return false;
|
||||
}
|
||||
breakTime(tz->toLocal(now), tm);
|
||||
breakTime(tz->toLocal(day.lastMeterReadTime), last);
|
||||
if(tm.Hour > last.Hour) {
|
||||
if(debugger->isActive(RemoteDebug::DEBUG)) debugger->printf("(AmsDataStorage) Day %d > %d\n", tm.Hour, last.Hour);
|
||||
if(debugger->isActive(RemoteDebug::VERBOSE)) debugger->printf("(AmsDataStorage) Day %d > %d\n", tm.Hour, last.Hour);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -411,17 +411,17 @@ bool AmsDataStorage::isMonthHappy() {
|
||||
tmElements_t tm, last;
|
||||
|
||||
if(now < month.lastMeterReadTime) {
|
||||
if(debugger->isActive(RemoteDebug::DEBUG)) debugger->printf("(AmsDataStorage) Month %lld < %lld\n", (int64_t) now, (int64_t) month.lastMeterReadTime);
|
||||
if(debugger->isActive(RemoteDebug::VERBOSE)) debugger->printf("(AmsDataStorage) Month %lld < %lld\n", (int64_t) now, (int64_t) month.lastMeterReadTime);
|
||||
return false;
|
||||
}
|
||||
if(now-month.lastMeterReadTime > 86400) {
|
||||
if(debugger->isActive(RemoteDebug::DEBUG)) debugger->printf("(AmsDataStorage) Month %lld - %lld > 3600\n", (int64_t) now, (int64_t) month.lastMeterReadTime);
|
||||
if(debugger->isActive(RemoteDebug::VERBOSE)) debugger->printf("(AmsDataStorage) Month %lld - %lld > 3600\n", (int64_t) now, (int64_t) month.lastMeterReadTime);
|
||||
return false;
|
||||
}
|
||||
breakTime(tz->toLocal(now), tm);
|
||||
breakTime(tz->toLocal(month.lastMeterReadTime), last);
|
||||
if(tm.Day > last.Day) {
|
||||
if(debugger->isActive(RemoteDebug::DEBUG)) debugger->printf("(AmsDataStorage) Month %d > %d\n", tm.Day, last.Day);
|
||||
if(debugger->isActive(RemoteDebug::VERBOSE)) debugger->printf("(AmsDataStorage) Month %d > %d\n", tm.Day, last.Day);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,11 @@
|
||||
|
||||
#define MAX_PEM_SIZE 4096
|
||||
|
||||
#define METER_SOURCE_NONE 0
|
||||
#define METER_SOURCE_SERIAL 1
|
||||
#define METER_SOURCE_MQTT 2
|
||||
#define METER_SOURCE_ESPNOW 3
|
||||
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
#if defined(ESP8266)
|
||||
|
||||
@@ -62,12 +62,12 @@ ADC_MODE(ADC_VCC);
|
||||
|
||||
#define BUF_SIZE_COMMON (2048)
|
||||
#define BUF_SIZE_HAN (1024)
|
||||
#include "ams/hdlc.h"
|
||||
#include "MbusAssembler.h"
|
||||
|
||||
#include "IEC6205621.h"
|
||||
#include "IEC6205675.h"
|
||||
|
||||
#include "ams/DataParsers.h"
|
||||
|
||||
uint8_t commonBuffer[BUF_SIZE_COMMON];
|
||||
uint8_t hanBuffer[BUF_SIZE_HAN];
|
||||
|
||||
@@ -86,13 +86,12 @@ Timezone* tz;
|
||||
AmsWebServer ws(commonBuffer, &Debug, &hw);
|
||||
|
||||
MQTTClient *mqtt = NULL;
|
||||
WiFiClient *mqttClient = new WiFiClient();
|
||||
WiFiClient *mqttClient = NULL;
|
||||
WiFiClientSecure *mqttSecureClient = NULL;
|
||||
AmsMqttHandler* mqttHandler = NULL;
|
||||
|
||||
Stream *hanSerial;
|
||||
SoftwareSerial *swSerial = NULL;
|
||||
HDLCConfig* hc = NULL;
|
||||
|
||||
GpioConfig gpioConfig;
|
||||
MeterConfig meterConfig;
|
||||
@@ -106,6 +105,14 @@ EnergyAccounting ea(&Debug);
|
||||
|
||||
uint8_t wifiReconnectCount = 0;
|
||||
|
||||
HDLCParser *hdlcParser = NULL;
|
||||
MBUSParser *mbusParser = NULL;
|
||||
GBTParser *gbtParser = NULL;
|
||||
GCMParser *gcmParser = NULL;
|
||||
LLCParser *llcParser = NULL;
|
||||
DLMSParser *dlmsParser = NULL;
|
||||
DSMRParser *dsmrParser = NULL;
|
||||
|
||||
void setup() {
|
||||
WiFiConfig wifi;
|
||||
Serial.begin(115200);
|
||||
@@ -370,7 +377,8 @@ void setup() {
|
||||
config.setEnergyAccountingConfig(*eac);
|
||||
config.ackEnergyAccountingChange();
|
||||
}
|
||||
ea.setup(&ds, eapi, eac);
|
||||
ea.setup(&ds, eac);
|
||||
ea.setEapi(eapi);
|
||||
ws.setup(&config, &gpioConfig, &meterConfig, &meterState, &ds, &ea);
|
||||
|
||||
#if defined(ESP32)
|
||||
@@ -516,6 +524,7 @@ void loop() {
|
||||
if(config.getEntsoeConfig(entsoe) && strlen(entsoe.token) > 0) {
|
||||
if(eapi == NULL) {
|
||||
eapi = new EntsoeApi(&Debug);
|
||||
ea.setEapi(eapi);
|
||||
ws.setEntsoeApi(eapi);
|
||||
}
|
||||
eapi->setup(entsoe);
|
||||
@@ -553,14 +562,14 @@ void loop() {
|
||||
config.getMeterConfig(meterConfig);
|
||||
setupHanPort(gpioConfig.hanPin, meterConfig.baud, meterConfig.parity, meterConfig.invert);
|
||||
config.ackMeterChanged();
|
||||
delete hc;
|
||||
hc = NULL;
|
||||
delete gcmParser;
|
||||
gcmParser = NULL;
|
||||
}
|
||||
|
||||
if(config.isEnergyAccountingChanged()) {
|
||||
EnergyAccountingConfig *eac = ea.getConfig();
|
||||
config.getEnergyAccountingConfig(*eac);
|
||||
ea.setup(&ds, eapi, eac);
|
||||
ea.setup(&ds, eac);
|
||||
config.ackEnergyAccountingChange();
|
||||
}
|
||||
|
||||
@@ -607,6 +616,9 @@ void setupHanPort(uint8_t pin, uint32_t baud, uint8_t parityOrdinal, bool invert
|
||||
hwSerial = &Serial2;
|
||||
}
|
||||
#elif defined(CONFIG_IDF_TARGET_ESP32S2)
|
||||
if(pin == 18) {
|
||||
hwSerial = &Serial1;
|
||||
}
|
||||
#elif defined(CONFIG_IDF_TARGET_ESP32C3)
|
||||
#endif
|
||||
#endif
|
||||
@@ -764,162 +776,83 @@ void swapWifiMode() {
|
||||
}
|
||||
|
||||
int len = 0;
|
||||
MbusAssembler* ma = NULL;
|
||||
int currentMeterType = -1;
|
||||
bool serialInit = false;
|
||||
bool readHanPort() {
|
||||
if(!hanSerial->available()) return false;
|
||||
|
||||
if(currentMeterType == -1) {
|
||||
// Before reading, empty serial buffer to increase chance of getting first byte of a data transfer
|
||||
if(!serialInit) {
|
||||
hanSerial->readBytes(hanBuffer, BUF_SIZE_HAN);
|
||||
currentMeterType = 0;
|
||||
serialInit = true;
|
||||
return false;
|
||||
}
|
||||
if(currentMeterType == 0) {
|
||||
uint8_t flag = hanSerial->read();
|
||||
if(flag == 0x7E || flag == 0x68) currentMeterType = 1;
|
||||
else currentMeterType = 2;
|
||||
hanSerial->readBytes(hanBuffer, BUF_SIZE_HAN);
|
||||
return false;
|
||||
}
|
||||
CosemDateTime timestamp = {0};
|
||||
AmsData data;
|
||||
if(currentMeterType == 1) {
|
||||
int pos = HDLC_FRAME_INCOMPLETE;
|
||||
while(hanSerial->available() && pos == HDLC_FRAME_INCOMPLETE) {
|
||||
hanBuffer[len++] = hanSerial->read();
|
||||
pos = HDLC_validate((uint8_t *) hanBuffer, len, hc, ×tamp);
|
||||
}
|
||||
if(len > 0) {
|
||||
if(len >= BUF_SIZE_HAN) {
|
||||
hanSerial->readBytes(hanBuffer, BUF_SIZE_HAN);
|
||||
len = 0;
|
||||
debugI("Buffer overflow, resetting");
|
||||
return false;
|
||||
}
|
||||
if(pos == MBUS_FRAME_INTERMEDIATE_SEGMENT) {
|
||||
debugI("Intermediate segment");
|
||||
if(ma == NULL) {
|
||||
ma = new MbusAssembler();
|
||||
}
|
||||
if(ma->append((uint8_t *) hanBuffer, len) < 0)
|
||||
pos = -77;
|
||||
if(Debug.isActive(RemoteDebug::VERBOSE)) {
|
||||
debugD("Frame dump (%db):", len);
|
||||
debugPrint(hanBuffer, 0, len);
|
||||
}
|
||||
len = 0;
|
||||
return false;
|
||||
} else if(pos == MBUS_FRAME_LAST_SEGMENT) {
|
||||
debugI("Final segment");
|
||||
if(Debug.isActive(RemoteDebug::VERBOSE)) {
|
||||
debugD("Frame dump (%db):", len);
|
||||
debugPrint(hanBuffer, 0, len);
|
||||
}
|
||||
if(ma->append((uint8_t *) hanBuffer, len) >= 0) {
|
||||
len = ma->write((uint8_t *) hanBuffer);
|
||||
pos = HDLC_validate((uint8_t *) hanBuffer, len, hc, ×tamp);
|
||||
} else {
|
||||
pos = -77;
|
||||
}
|
||||
}
|
||||
if(pos == HDLC_FRAME_INCOMPLETE) {
|
||||
return false;
|
||||
}
|
||||
for(int i = len; i<BUF_SIZE_HAN; i++) {
|
||||
hanBuffer[i] = 0x00;
|
||||
}
|
||||
if(pos == HDLC_ENCRYPTION_CONFIG_MISSING) {
|
||||
hc = new HDLCConfig();
|
||||
memcpy(hc->encryption_key, meterConfig.encryptionKey, 16);
|
||||
memcpy(hc->authentication_key, meterConfig.authenticationKey, 16);
|
||||
}
|
||||
if(Debug.isActive(RemoteDebug::VERBOSE)) {
|
||||
debugD("Frame dump (%db):", len);
|
||||
debugPrint(hanBuffer, 0, len);
|
||||
}
|
||||
if(hc != NULL && Debug.isActive(RemoteDebug::VERBOSE)) {
|
||||
debugD("System title:");
|
||||
debugPrint(hc->system_title, 0, 8);
|
||||
debugD("Initialization vector:");
|
||||
debugPrint(hc->initialization_vector, 0, 12);
|
||||
debugD("Additional authenticated data:");
|
||||
debugPrint(hc->additional_authenticated_data, 0, 17);
|
||||
debugD("Authentication tag:");
|
||||
debugPrint(hc->authentication_tag, 0, 12);
|
||||
}
|
||||
if(mqttEnabled && mqtt != NULL && mqttHandler == NULL) {
|
||||
mqtt->publish(topic.c_str(), toHex(hanBuffer, len));
|
||||
}
|
||||
|
||||
DataParserContext ctx = {0};
|
||||
int pos = DATA_PARSE_INCOMPLETE;
|
||||
// For each byte received, check if we have a complete frame we can handle
|
||||
while(hanSerial->available() && pos == DATA_PARSE_INCOMPLETE) {
|
||||
// If buffer was overflowed, reset
|
||||
if(len >= BUF_SIZE_HAN) {
|
||||
hanSerial->readBytes(hanBuffer, BUF_SIZE_HAN);
|
||||
len = 0;
|
||||
if(pos > 0) {
|
||||
debugD("Valid data, start at byte %d", pos);
|
||||
data = IEC6205675(((char *) (hanBuffer)) + pos, meterState.getMeterType(), &meterConfig, timestamp, hc);
|
||||
debugI("Buffer overflow, resetting");
|
||||
return false;
|
||||
}
|
||||
hanBuffer[len++] = hanSerial->read();
|
||||
ctx.length = len;
|
||||
pos = unwrapData((uint8_t *) hanBuffer, ctx);
|
||||
if(pos >= 0) {
|
||||
if(ctx.type == DATA_TAG_DLMS) {
|
||||
debugV("Received valid DLMS at %d", pos);
|
||||
} else if(ctx.type == DATA_TAG_DSMR) {
|
||||
debugV("Received valid DSMR at %d", pos);
|
||||
} else {
|
||||
if(Debug.isActive(RemoteDebug::WARNING)) {
|
||||
switch(pos) {
|
||||
case HDLC_BOUNDRY_FLAG_MISSING:
|
||||
debugW("Boundry flag missing");
|
||||
break;
|
||||
case HDLC_HCS_ERROR:
|
||||
debugW("Header checksum error");
|
||||
break;
|
||||
case HDLC_FCS_ERROR:
|
||||
debugW("Frame checksum error");
|
||||
break;
|
||||
case HDLC_FRAME_INCOMPLETE:
|
||||
debugW("Received frame is incomplete");
|
||||
break;
|
||||
case HDLC_ENCRYPTION_CONFIG_MISSING:
|
||||
debugI("Encryption configuration requested, initializing");
|
||||
break;
|
||||
case HDLC_ENCRYPTION_AUTH_FAILED:
|
||||
debugW("Decrypt authentication failed");
|
||||
break;
|
||||
case HDLC_ENCRYPTION_KEY_FAILED:
|
||||
debugW("Setting decryption key failed");
|
||||
break;
|
||||
case HDLC_ENCRYPTION_DECRYPT_FAILED:
|
||||
debugW("Decryption failed");
|
||||
break;
|
||||
case MBUS_FRAME_LENGTH_NOT_EQUAL:
|
||||
debugW("Frame length mismatch");
|
||||
break;
|
||||
case MBUS_FRAME_INTERMEDIATE_SEGMENT:
|
||||
case MBUS_FRAME_LAST_SEGMENT:
|
||||
debugW("Partial frame dropped");
|
||||
break;
|
||||
case HDLC_TIMESTAMP_UNKNOWN:
|
||||
debugW("Frame timestamp is not correctly formatted");
|
||||
break;
|
||||
case HDLC_UNKNOWN_DATA:
|
||||
debugW("Unknown data format %02X", hanBuffer[0]);
|
||||
currentMeterType = 0;
|
||||
break;
|
||||
default:
|
||||
debugW("Unspecified error while reading data: %d", pos);
|
||||
}
|
||||
}
|
||||
// TODO: Move this so that payload is sent to MQTT
|
||||
debugE("Unknown tag %02X at pos %d", ctx.type, pos);
|
||||
len = 0;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else if(currentMeterType == 2) {
|
||||
String payload = hanSerial->readString();
|
||||
if(mqttEnabled && mqtt != NULL && mqttHandler == NULL) {
|
||||
mqtt->publish(topic.c_str(), payload);
|
||||
}
|
||||
data = IEC6205621(payload);
|
||||
if(data.getListType() == 0) {
|
||||
currentMeterType = 1;
|
||||
return false;
|
||||
} else {
|
||||
if(Debug.isActive(RemoteDebug::DEBUG)) {
|
||||
debugD("Frame dump: %d", payload.length());
|
||||
debugD("%s", payload.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
if(pos == DATA_PARSE_INCOMPLETE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(pos == DATA_PARSE_INTERMEDIATE_SEGMENT) {
|
||||
len = 0;
|
||||
return false;
|
||||
} else if(pos < 0) {
|
||||
printHanReadError(pos);
|
||||
len += hanSerial->readBytes(hanBuffer+len, BUF_SIZE_HAN-len);
|
||||
if(mqttEnabled && mqtt != NULL && mqttHandler == NULL) {
|
||||
mqtt->publish(topic.c_str(), toHex(hanBuffer+pos, len));
|
||||
}
|
||||
while(hanSerial->available()) hanSerial->read(); // Make sure it is all empty, in case we overflowed buffer above
|
||||
len = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Data is valid, clear the rest of the buffer to avoid tainted parsing
|
||||
for(int i = pos+ctx.length; i<BUF_SIZE_HAN; i++) {
|
||||
hanBuffer[i] = 0x00;
|
||||
}
|
||||
|
||||
AmsData data;
|
||||
if(ctx.type == DATA_TAG_DLMS) {
|
||||
// If MQTT bytestream payload is selected (mqttHandler == NULL), send the payload to MQTT
|
||||
if(mqttEnabled && mqtt != NULL && mqttHandler == NULL) {
|
||||
mqtt->publish(topic.c_str(), toHex(hanBuffer+pos, ctx.length));
|
||||
}
|
||||
|
||||
debugV("Using application data:");
|
||||
if(Debug.isActive(RemoteDebug::VERBOSE)) debugPrint(hanBuffer+pos, 0, ctx.length);
|
||||
|
||||
// TODO: Split IEC6205675 into DataParserKaifa and DataParserObis. This way we can add other means of parsing, for those other proprietary formats
|
||||
data = IEC6205675(((char *) (hanBuffer)) + pos, meterState.getMeterType(), &meterConfig, ctx);
|
||||
} else if(ctx.type == DATA_TAG_DSMR) {
|
||||
data = IEC6205621(((char *) (hanBuffer)) + pos);
|
||||
}
|
||||
len = 0;
|
||||
|
||||
if(data.getListType() > 0) {
|
||||
if(!hw.ledBlink(LED_GREEN, 1))
|
||||
@@ -953,14 +886,14 @@ bool readHanPort() {
|
||||
|
||||
bool saveData = false;
|
||||
if(!ds.isHappy() && now > BUILD_EPOCH) {
|
||||
debugD("Its time to update data storage");
|
||||
debugV("Its time to update data storage");
|
||||
tmElements_t tm;
|
||||
breakTime(now, tm);
|
||||
if(tm.Minute == 0) {
|
||||
debugD(" using actual data");
|
||||
debugV(" using actual data");
|
||||
saveData = ds.update(&data);
|
||||
} else if(meterState.getListType() >= 3) {
|
||||
debugD(" using estimated data");
|
||||
debugV(" using estimated data");
|
||||
saveData = ds.update(&meterState);
|
||||
}
|
||||
if(saveData) {
|
||||
@@ -978,6 +911,45 @@ bool readHanPort() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void printHanReadError(int pos) {
|
||||
if(Debug.isActive(RemoteDebug::WARNING)) {
|
||||
switch(pos) {
|
||||
case DATA_PARSE_BOUNDRY_FLAG_MISSING:
|
||||
debugW("Boundry flag missing");
|
||||
break;
|
||||
case DATA_PARSE_HEADER_CHECKSUM_ERROR:
|
||||
debugW("Header checksum error");
|
||||
break;
|
||||
case DATA_PARSE_FOOTER_CHECKSUM_ERROR:
|
||||
debugW("Frame checksum error");
|
||||
break;
|
||||
case DATA_PARSE_INCOMPLETE:
|
||||
debugW("Received frame is incomplete");
|
||||
break;
|
||||
case GCM_AUTH_FAILED:
|
||||
debugW("Decrypt authentication failed");
|
||||
break;
|
||||
case GCM_ENCRYPTION_KEY_FAILED:
|
||||
debugW("Setting decryption key failed");
|
||||
break;
|
||||
case GCM_DECRYPT_FAILED:
|
||||
debugW("Decryption failed");
|
||||
break;
|
||||
case MBUS_FRAME_LENGTH_NOT_EQUAL:
|
||||
debugW("Frame length mismatch");
|
||||
break;
|
||||
case DATA_PARSE_INTERMEDIATE_SEGMENT:
|
||||
debugI("Intermediate segment received");
|
||||
break;
|
||||
case DATA_PARSE_UNKNOWN_DATA:
|
||||
debugW("Unknown data format %02X", hanBuffer[0]);
|
||||
break;
|
||||
default:
|
||||
debugW("Unspecified error while reading data: %d", pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void debugPrint(byte *buffer, int start, int length) {
|
||||
for (int i = start; i < start + length; i++) {
|
||||
if (buffer[i] < 0x10)
|
||||
@@ -1125,6 +1097,128 @@ void WiFi_connect() {
|
||||
}
|
||||
}
|
||||
|
||||
void mqttMessageReceived(String &topic, String &payload) {
|
||||
debugI("Received message for topic %s", topic.c_str() );
|
||||
if(meterConfig.source == METER_SOURCE_MQTT) {
|
||||
DataParserContext ctx = {payload.length()/2};
|
||||
fromHex(hanBuffer, payload, ctx.length);
|
||||
uint16_t pos = unwrapData(hanBuffer, ctx);
|
||||
// TODO: Run through DLMS/DMSR parser and apply AmsData
|
||||
}
|
||||
}
|
||||
|
||||
int16_t unwrapData(uint8_t *buf, DataParserContext &context) {
|
||||
int16_t ret;
|
||||
bool doRet = false;
|
||||
uint16_t end = BUF_SIZE_HAN;
|
||||
uint8_t tag = (*buf);
|
||||
uint8_t lastTag = DATA_TAG_NONE;
|
||||
while(tag != DATA_TAG_NONE) {
|
||||
int16_t curLen = context.length;
|
||||
int8_t res = 0;
|
||||
switch(tag) {
|
||||
case DATA_TAG_HDLC:
|
||||
if(hdlcParser == NULL) hdlcParser = new HDLCParser();
|
||||
res = hdlcParser->parse(buf, context);
|
||||
break;
|
||||
case DATA_TAG_MBUS:
|
||||
if(mbusParser == NULL) mbusParser = new MBUSParser();
|
||||
res = mbusParser->parse(buf, context);
|
||||
break;
|
||||
case DATA_TAG_GBT:
|
||||
if(gbtParser == NULL) gbtParser = new GBTParser();
|
||||
res = gbtParser->parse(buf, context);
|
||||
break;
|
||||
case DATA_TAG_GCM:
|
||||
if(gcmParser == NULL) gcmParser = new GCMParser(meterConfig.encryptionKey, meterConfig.authenticationKey);
|
||||
res = gcmParser->parse(buf, context);
|
||||
break;
|
||||
case DATA_TAG_LLC:
|
||||
if(llcParser == NULL) llcParser = new LLCParser();
|
||||
res = llcParser->parse(buf, context);
|
||||
break;
|
||||
case DATA_TAG_DLMS:
|
||||
if(dlmsParser == NULL) dlmsParser = new DLMSParser();
|
||||
res = dlmsParser->parse(buf, context);
|
||||
if(res >= 0) doRet = true;
|
||||
break;
|
||||
case DATA_TAG_DSMR:
|
||||
if(dsmrParser == NULL) dsmrParser = new DSMRParser();
|
||||
res = dsmrParser->parse(buf, context, lastTag != DATA_TAG_NONE);
|
||||
if(res >= 0) doRet = true;
|
||||
break;
|
||||
default:
|
||||
debugE("Ended up in default case while unwrapping...");
|
||||
return DATA_PARSE_UNKNOWN_DATA;
|
||||
}
|
||||
lastTag = tag;
|
||||
if(res == DATA_PARSE_INCOMPLETE) {
|
||||
return res;
|
||||
}
|
||||
if(context.length > end) return false;
|
||||
if(Debug.isActive(RemoteDebug::VERBOSE)) {
|
||||
switch(tag) {
|
||||
case DATA_TAG_HDLC:
|
||||
debugV("HDLC frame:");
|
||||
// If MQTT bytestream payload is selected (mqttHandler == NULL), send the payload to MQTT
|
||||
if(mqttEnabled && mqtt != NULL && mqttHandler == NULL) {
|
||||
mqtt->publish(topic.c_str(), toHex(buf, curLen));
|
||||
}
|
||||
break;
|
||||
case DATA_TAG_MBUS:
|
||||
debugV("MBUS frame:");
|
||||
// If MQTT bytestream payload is selected (mqttHandler == NULL), send the payload to MQTT
|
||||
if(mqttEnabled && mqtt != NULL && mqttHandler == NULL) {
|
||||
mqtt->publish(topic.c_str(), toHex(buf, curLen));
|
||||
}
|
||||
break;
|
||||
case DATA_TAG_GBT:
|
||||
debugV("GBT frame:");
|
||||
break;
|
||||
case DATA_TAG_GCM:
|
||||
debugV("GCM frame:");
|
||||
break;
|
||||
case DATA_TAG_LLC:
|
||||
debugV("LLC frame:");
|
||||
break;
|
||||
case DATA_TAG_DLMS:
|
||||
debugV("DLMS frame:");
|
||||
break;
|
||||
case DATA_TAG_DSMR:
|
||||
debugV("DSMR frame:");
|
||||
if(mqttEnabled && mqtt != NULL && mqttHandler == NULL) {
|
||||
mqtt->publish(topic.c_str(), (char*) buf);
|
||||
}
|
||||
break;
|
||||
}
|
||||
debugPrint(buf, 0, curLen);
|
||||
}
|
||||
if(res == DATA_PARSE_FINAL_SEGMENT) {
|
||||
if(tag == DATA_TAG_MBUS) {
|
||||
res = mbusParser->write(buf, context);
|
||||
}
|
||||
}
|
||||
|
||||
if(res < 0) {
|
||||
return res;
|
||||
}
|
||||
buf += res;
|
||||
end -= res;
|
||||
ret += res;
|
||||
|
||||
// If we are ready to return, do that
|
||||
if(doRet) {
|
||||
context.type = tag;
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Use start byte of new buffer position as tag for next round in loop
|
||||
tag = (*buf);
|
||||
}
|
||||
debugE("Got to end of unwrap method...");
|
||||
return DATA_PARSE_UNKNOWN_DATA;
|
||||
}
|
||||
|
||||
unsigned long lastMqttRetry = -10000;
|
||||
void MQTT_connect() {
|
||||
MqttConfig mqttConfig;
|
||||
@@ -1149,15 +1243,12 @@ void MQTT_connect() {
|
||||
mqtt->disconnect();
|
||||
yield();
|
||||
} else {
|
||||
uint16_t size = 128;
|
||||
uint16_t size = 256;
|
||||
switch(mqttConfig.payloadFormat) {
|
||||
case 0: // JSON
|
||||
case 4: // Home Assistant
|
||||
size = 768;
|
||||
break;
|
||||
case 3: // Domoticz
|
||||
size = 256;
|
||||
break;
|
||||
case 255: // Raw frame
|
||||
size = 1024;
|
||||
break;
|
||||
@@ -1195,22 +1286,19 @@ void MQTT_connect() {
|
||||
}
|
||||
|
||||
if(mqttConfig.ssl) {
|
||||
debugI("MQTT SSL is configured");
|
||||
debugI("MQTT SSL is configured (%dkb free heap)", ESP.getFreeHeap());
|
||||
if(mqttSecureClient == NULL) {
|
||||
mqttSecureClient = new WiFiClientSecure();
|
||||
}
|
||||
#if defined(ESP8266)
|
||||
mqttSecureClient->setBufferSizes(512, 512);
|
||||
#endif
|
||||
|
||||
|
||||
if(LittleFS.begin()) {
|
||||
char *ca = NULL;
|
||||
char *cert = NULL;
|
||||
char *key = NULL;
|
||||
File file;
|
||||
|
||||
if(LittleFS.exists(FILE_MQTT_CA)) {
|
||||
debugI("Found MQTT CA file");
|
||||
debugI("Found MQTT CA file (%dkb free heap)", ESP.getFreeHeap());
|
||||
file = LittleFS.open(FILE_MQTT_CA, "r");
|
||||
#if defined(ESP8266)
|
||||
BearSSL::X509List *serverTrustedCA = new BearSSL::X509List(file);
|
||||
@@ -1218,26 +1306,37 @@ void MQTT_connect() {
|
||||
#elif defined(ESP32)
|
||||
mqttSecureClient->loadCACert(file, file.size());
|
||||
#endif
|
||||
file.close();
|
||||
}
|
||||
|
||||
if(LittleFS.exists(FILE_MQTT_CERT) && LittleFS.exists(FILE_MQTT_KEY)) {
|
||||
#if defined(ESP8266)
|
||||
debugI("Found MQTT certificate file (%dkb free heap)", ESP.getFreeHeap());
|
||||
file = LittleFS.open(FILE_MQTT_CERT, "r");
|
||||
BearSSL::X509List *serverCertList = new BearSSL::X509List(file);
|
||||
file.close();
|
||||
|
||||
debugI("Found MQTT key file (%dkb free heap)", ESP.getFreeHeap());
|
||||
file = LittleFS.open(FILE_MQTT_KEY, "r");
|
||||
BearSSL::PrivateKey *serverPrivKey = new BearSSL::PrivateKey(file);
|
||||
file.close();
|
||||
|
||||
debugD("Setting client certificates (%dkb free heap)", ESP.getFreeHeap());
|
||||
mqttSecureClient->setClientRSACert(serverCertList, serverPrivKey);
|
||||
#elif defined(ESP32)
|
||||
debugI("Found MQTT certificate file");
|
||||
debugI("Found MQTT certificate file (%dkb free heap)", ESP.getFreeHeap());
|
||||
file = LittleFS.open(FILE_MQTT_CERT, "r");
|
||||
mqttSecureClient->loadCertificate(file, file.size());
|
||||
file.close();
|
||||
|
||||
debugI("Found MQTT key file");
|
||||
debugI("Found MQTT key file (%dkb free heap)", ESP.getFreeHeap());
|
||||
file = LittleFS.open(FILE_MQTT_KEY, "r");
|
||||
mqttSecureClient->loadPrivateKey(file, file.size());
|
||||
file.close();
|
||||
#endif
|
||||
}
|
||||
LittleFS.end();
|
||||
debugD("MQTT SSL setup complete (%dkb free heap)", ESP.getFreeHeap());
|
||||
}
|
||||
mqttClient = mqttSecureClient;
|
||||
} else if(mqttClient == NULL) {
|
||||
@@ -1267,6 +1366,13 @@ void MQTT_connect() {
|
||||
if(mqttHandler != NULL) {
|
||||
mqttHandler->publishSystem(&hw);
|
||||
}
|
||||
|
||||
// Subscribe to the chosen MQTT topic, if set in configuration
|
||||
if (strlen(mqttConfig.subscribeTopic) > 0) {
|
||||
mqtt->onMessage(mqttMessageReceived);
|
||||
mqtt->subscribe(String(mqttConfig.subscribeTopic) + "/#");
|
||||
debugI(" Subscribing to [%s]\r\n", mqttConfig.subscribeTopic);
|
||||
}
|
||||
} else {
|
||||
if (Debug.isActive(RemoteDebug::ERROR)) {
|
||||
debugE("Failed to connect to MQTT: %d", mqtt->lastError());
|
||||
@@ -1302,6 +1408,8 @@ void configFileParse() {
|
||||
bool lNtp = false;
|
||||
bool lEntsoe = false;
|
||||
bool lEac = false;
|
||||
bool sEa = false;
|
||||
bool sDs = false;
|
||||
|
||||
SystemConfig sys;
|
||||
WiFiConfig wifi;
|
||||
@@ -1528,6 +1636,7 @@ void configFileParse() {
|
||||
i++;
|
||||
}
|
||||
ds.setDayData(day);
|
||||
sDs = true;
|
||||
} else if(strncmp(buf, "monthplot ", 10) == 0) {
|
||||
int i = 0;
|
||||
MonthDataPoints month = { 5 }; // Use a version we know the multiplier of the data points
|
||||
@@ -1550,31 +1659,53 @@ void configFileParse() {
|
||||
i++;
|
||||
}
|
||||
ds.setMonthData(month);
|
||||
sDs = true;
|
||||
} else if(strncmp(buf, "energyaccounting ", 17) == 0) {
|
||||
int i = 0;
|
||||
EnergyAccountingData ead = { 1 };
|
||||
uint8_t i = 0;
|
||||
EnergyAccountingData ead = { 4, 0,
|
||||
0, 0, 0,
|
||||
0, 0, // Peak 1
|
||||
0, 0, // Peak 2
|
||||
0, 0, // Peak 3
|
||||
0, 0, // Peak 4
|
||||
0, 0 // Peak 5
|
||||
};
|
||||
char * pch = strtok (buf+17," ");
|
||||
while (pch != NULL) {
|
||||
if(i == 1) {
|
||||
if(i == 0) {
|
||||
// Ignore version
|
||||
} else if(i == 1) {
|
||||
long val = String(pch).toInt();
|
||||
ead.month = val;
|
||||
} else if(i == 2) {
|
||||
double val = String(pch).toDouble();
|
||||
ead.maxHour = val * 100;
|
||||
if(val > 0.0) {
|
||||
ead.peaks[0] = { 1, (uint16_t) (val*100) };
|
||||
}
|
||||
} else if(i == 3) {
|
||||
double val = String(pch).toDouble();
|
||||
ead.costYesterday = val * 100;
|
||||
ead.costYesterday = val * 10;
|
||||
} else if(i == 4) {
|
||||
double val = String(pch).toDouble();
|
||||
ead.costThisMonth = val * 100;
|
||||
ead.costThisMonth = val;
|
||||
} else if(i == 5) {
|
||||
double val = String(pch).toDouble();
|
||||
ead.costLastMonth = val * 100;
|
||||
ead.costLastMonth = val;
|
||||
} else if(i >= 6 && i < 18) {
|
||||
uint8_t hour = i-6;
|
||||
if(hour%2 == 0) {
|
||||
long val = String(pch).toInt();
|
||||
ead.peaks[hour/2].day = val;
|
||||
} else {
|
||||
double val = String(pch).toDouble();
|
||||
ead.peaks[hour/2].value = val * 100;
|
||||
}
|
||||
}
|
||||
pch = strtok (NULL, " ");
|
||||
i++;
|
||||
}
|
||||
ea.setData(ead);
|
||||
sEa = true;
|
||||
}
|
||||
memset(buf, 0, 1024);
|
||||
}
|
||||
@@ -1594,7 +1725,7 @@ void configFileParse() {
|
||||
if(lDomo) config.setDomoticzConfig(domo);
|
||||
if(lNtp) config.setNtpConfig(ntp);
|
||||
if(lEntsoe) config.setEntsoeConfig(entsoe);
|
||||
ds.save();
|
||||
ea.save();
|
||||
if(sDs) ds.save();
|
||||
if(sEa) ea.save();
|
||||
config.save();
|
||||
}
|
||||
|
||||
@@ -8,13 +8,16 @@ EnergyAccounting::EnergyAccounting(RemoteDebug* debugger) {
|
||||
this->debugger = debugger;
|
||||
}
|
||||
|
||||
void EnergyAccounting::setup(AmsDataStorage *ds, EntsoeApi *eapi, EnergyAccountingConfig *config) {
|
||||
void EnergyAccounting::setup(AmsDataStorage *ds, EnergyAccountingConfig *config) {
|
||||
this->ds = ds;
|
||||
this->eapi = eapi;
|
||||
this->config = config;
|
||||
this->currentThresholdIdx = 0;
|
||||
}
|
||||
|
||||
void EnergyAccounting::setEapi(EntsoeApi *eapi) {
|
||||
this->eapi = eapi;
|
||||
}
|
||||
|
||||
EnergyAccountingConfig* EnergyAccounting::getConfig() {
|
||||
return config;
|
||||
}
|
||||
@@ -24,6 +27,7 @@ void EnergyAccounting::setTimezone(Timezone* tz) {
|
||||
}
|
||||
|
||||
bool EnergyAccounting::update(AmsData* amsData) {
|
||||
if(config == NULL) return false;
|
||||
time_t now = time(nullptr);
|
||||
if(now < BUILD_EPOCH) return false;
|
||||
if(tz == NULL) {
|
||||
@@ -38,24 +42,39 @@ bool EnergyAccounting::update(AmsData* amsData) {
|
||||
if(!init) {
|
||||
currentHour = local.Hour;
|
||||
currentDay = local.Day;
|
||||
if(debugger->isActive(RemoteDebug::INFO)) debugger->printf("(EnergyAccounting) Initializing data at %lld\n", (int64_t) now);
|
||||
if(debugger->isActive(RemoteDebug::DEBUG)) debugger->printf("(EnergyAccounting) Initializing data at %lld\n", (int64_t) now);
|
||||
if(!load()) {
|
||||
if(debugger->isActive(RemoteDebug::INFO)) debugger->printf("(EnergyAccounting) Unable to load existing data");
|
||||
data = { 1, local.Month, 0, 0, 0, 0 };
|
||||
if(calcDayUse()) ret = true;
|
||||
if(debugger->isActive(RemoteDebug::INFO)) debugger->printf("(EnergyAccounting) Unable to load existing data\n");
|
||||
data = { 4, local.Month,
|
||||
0, 0, 0,
|
||||
0, 0, // Peak 1
|
||||
0, 0, // Peak 2
|
||||
0, 0, // Peak 3
|
||||
0, 0, // Peak 4
|
||||
0, 0 // Peak 5
|
||||
};
|
||||
} else if(debugger->isActive(RemoteDebug::DEBUG)) {
|
||||
for(uint8_t i = 0; i < 5; i++) {
|
||||
debugger->printf("(EnergyAccounting) Peak hour from day %d: %d\n", data.peaks[i].day, data.peaks[i].value*10);
|
||||
}
|
||||
debugger->printf("(EnergyAccounting) Loaded cost yesterday: %d, this month: %d, last month: %d\n", data.costYesterday / 10.0, data.costThisMonth, data.costLastMonth);
|
||||
}
|
||||
init = true;
|
||||
}
|
||||
|
||||
if(!initPrice && eapi != NULL && eapi->getValueForHour(0) != ENTSOE_NO_VALUE) {
|
||||
if(debugger->isActive(RemoteDebug::INFO)) debugger->printf("(EnergyAccounting) Initializing prices at %lld\n", (int64_t) now);
|
||||
if(debugger->isActive(RemoteDebug::DEBUG)) debugger->printf("(EnergyAccounting) Initializing prices at %lld\n", (int64_t) now);
|
||||
calcDayCost();
|
||||
}
|
||||
|
||||
if(local.Hour != currentHour && (amsData->getListType() >= 3 || local.Minute == 1)) {
|
||||
if(debugger->isActive(RemoteDebug::INFO)) debugger->printf("(EnergyAccounting) New local hour %d\n", local.Hour);
|
||||
|
||||
if(calcDayUse()) ret = true;
|
||||
tmElements_t oneHrAgo;
|
||||
breakTime(now-3600, oneHrAgo);
|
||||
uint16_t val = ds->getHourImport(oneHrAgo.Hour) / 10;
|
||||
ret |= updateMax(val, local.Day);
|
||||
|
||||
if(local.Hour > 0) {
|
||||
calcDayCost();
|
||||
}
|
||||
@@ -66,8 +85,8 @@ bool EnergyAccounting::update(AmsData* amsData) {
|
||||
|
||||
if(local.Day != currentDay) {
|
||||
if(debugger->isActive(RemoteDebug::INFO)) debugger->printf("(EnergyAccounting) New day %d\n", local.Day);
|
||||
data.costYesterday = costDay * 100;
|
||||
data.costThisMonth += costDay * 100;
|
||||
data.costYesterday = costDay * 10;
|
||||
data.costThisMonth += costDay;
|
||||
costDay = 0;
|
||||
currentDay = local.Day;
|
||||
ret = true;
|
||||
@@ -77,7 +96,9 @@ bool EnergyAccounting::update(AmsData* amsData) {
|
||||
if(debugger->isActive(RemoteDebug::INFO)) debugger->printf("(EnergyAccounting) New month %d\n", local.Month);
|
||||
data.costLastMonth = data.costThisMonth;
|
||||
data.costThisMonth = 0;
|
||||
data.maxHour = 0;
|
||||
for(uint8_t i = 0; i < 5; i++) {
|
||||
data.peaks[i] = { 0, 0 };
|
||||
}
|
||||
data.month = local.Month;
|
||||
currentThresholdIdx = 0;
|
||||
ret = true;
|
||||
@@ -108,24 +129,6 @@ bool EnergyAccounting::update(AmsData* amsData) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool EnergyAccounting::calcDayUse() {
|
||||
time_t now = time(nullptr);
|
||||
tmElements_t local, utc;
|
||||
breakTime(tz->toLocal(now), local);
|
||||
|
||||
bool ret = false;
|
||||
uint8_t lim = local.Day == 1 ? local.Hour : 24;
|
||||
for(int i = 0; i < lim; i++) {
|
||||
breakTime(now - ((lim - i) * 3600), utc);
|
||||
int16_t val = ds->getHourImport(utc.Hour) / 10.0;
|
||||
if(val > data.maxHour) {
|
||||
data.maxHour = val;
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void EnergyAccounting::calcDayCost() {
|
||||
time_t now = time(nullptr);
|
||||
tmElements_t local, utc;
|
||||
@@ -170,7 +173,7 @@ double EnergyAccounting::getCostToday() {
|
||||
}
|
||||
|
||||
double EnergyAccounting::getCostYesterday() {
|
||||
return data.costYesterday / 100.0;
|
||||
return data.costYesterday / 10.0;
|
||||
}
|
||||
|
||||
double EnergyAccounting::getUseThisMonth() {
|
||||
@@ -189,11 +192,11 @@ double EnergyAccounting::getUseThisMonth() {
|
||||
}
|
||||
|
||||
double EnergyAccounting::getCostThisMonth() {
|
||||
return (data.costThisMonth / 100.0) + getCostToday();
|
||||
return data.costThisMonth + getCostToday();
|
||||
}
|
||||
|
||||
double EnergyAccounting::getCostLastMonth() {
|
||||
return data.costLastMonth / 100.0;
|
||||
uint16_t EnergyAccounting::getCostLastMonth() {
|
||||
return data.costLastMonth;
|
||||
}
|
||||
|
||||
uint8_t EnergyAccounting::getCurrentThreshold() {
|
||||
@@ -203,7 +206,31 @@ uint8_t EnergyAccounting::getCurrentThreshold() {
|
||||
}
|
||||
|
||||
float EnergyAccounting::getMonthMax() {
|
||||
return data.maxHour / 100.0;
|
||||
uint8_t count = 0;
|
||||
uint32_t maxHour = 0.0;
|
||||
bool included[5] = { false, false, false, false, false };
|
||||
|
||||
while(count < config->hours) {
|
||||
uint8_t maxIdx = 0;
|
||||
uint16_t maxVal = 0;
|
||||
for(uint8_t i = 0; i < 5; i++) {
|
||||
if(included[i]) continue;
|
||||
if(data.peaks[i].value > maxVal) {
|
||||
maxVal = data.peaks[i].value;
|
||||
maxIdx = i;
|
||||
}
|
||||
}
|
||||
included[maxIdx] = true;
|
||||
count++;
|
||||
}
|
||||
|
||||
for(uint8_t i = 0; i < 5; i++) {
|
||||
if(!included[i]) continue;
|
||||
if(data.peaks[i].day > 0) {
|
||||
maxHour += data.peaks[i].value;
|
||||
}
|
||||
}
|
||||
return maxHour > 0 ? maxHour / count / 100.0 : 0.0;
|
||||
}
|
||||
|
||||
bool EnergyAccounting::load() {
|
||||
@@ -219,15 +246,63 @@ bool EnergyAccounting::load() {
|
||||
File file = LittleFS.open(FILE_ENERGYACCOUNTING, "r");
|
||||
char buf[file.size()];
|
||||
file.readBytes(buf, file.size());
|
||||
EnergyAccountingData* data = (EnergyAccountingData*) buf;
|
||||
file.close();
|
||||
|
||||
if(data->version == 1) {
|
||||
if(debugger->isActive(RemoteDebug::DEBUG)) debugger->printf("(EnergyAccounting) Data version %d\n", buf[0]);
|
||||
if(buf[0] == 4) {
|
||||
EnergyAccountingData* data = (EnergyAccountingData*) buf;
|
||||
memcpy(&this->data, data, sizeof(this->data));
|
||||
} else if(buf[0] == 3) {
|
||||
EnergyAccountingData* data = (EnergyAccountingData*) buf;
|
||||
this->data = { 4, data->month,
|
||||
(uint16_t) (data->costYesterday / 10), (uint16_t) (data->costThisMonth / 100), (uint16_t) (data->costLastMonth / 100),
|
||||
data->peaks[0].day, data->peaks[0].value,
|
||||
data->peaks[1].day, data->peaks[1].value,
|
||||
data->peaks[2].day, data->peaks[2].value,
|
||||
data->peaks[3].day, data->peaks[3].value,
|
||||
data->peaks[4].day, data->peaks[4].value
|
||||
};
|
||||
ret = true;
|
||||
} else {
|
||||
ret = false;
|
||||
data = { 4, 0,
|
||||
0, 0, 0,
|
||||
0, 0, // Peak 1
|
||||
0, 0, // Peak 2
|
||||
0, 0, // Peak 3
|
||||
0, 0, // Peak 4
|
||||
0, 0 // Peak 5
|
||||
};
|
||||
if(buf[0] == 2) {
|
||||
EnergyAccountingData1* data = (EnergyAccountingData1*) buf;
|
||||
this->data.month = data->month;
|
||||
this->data.costYesterday = (uint16_t) (data->costYesterday / 10);
|
||||
this->data.costThisMonth = (uint16_t) (data->costThisMonth / 100);
|
||||
this->data.costLastMonth = (uint16_t) (data->costLastMonth / 100);
|
||||
uint8_t b = 0;
|
||||
for(uint8_t i = sizeof(this->data); i < file.size(); i+=2) {
|
||||
this->data.peaks[b].day = b;
|
||||
memcpy(&this->data.peaks[b].value, buf+i, 2);
|
||||
b++;
|
||||
if(b >= config->hours) break;
|
||||
}
|
||||
ret = true;
|
||||
} else if(buf[0] == 1) {
|
||||
EnergyAccountingData1* data = (EnergyAccountingData1*) buf;
|
||||
this->data.month = data->month;
|
||||
this->data.costYesterday = (uint16_t) (data->costYesterday / 10);
|
||||
this->data.costThisMonth = (uint16_t) (data->costThisMonth / 100);
|
||||
this->data.costLastMonth = (uint16_t) (data->costLastMonth / 100);
|
||||
this->data.peaks[0].day = 1;
|
||||
this->data.peaks[0].value = data->maxHour;
|
||||
ret = true;
|
||||
} else {
|
||||
if(debugger->isActive(RemoteDebug::WARNING)) debugger->printf("(EnergyAccounting) Unknown version\n");
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
|
||||
file.close();
|
||||
} else {
|
||||
if(debugger->isActive(RemoteDebug::WARNING)) debugger->printf("(EnergyAccounting) File not found\n");
|
||||
}
|
||||
|
||||
LittleFS.end();
|
||||
@@ -246,7 +321,7 @@ bool EnergyAccounting::save() {
|
||||
File file = LittleFS.open(FILE_ENERGYACCOUNTING, "w");
|
||||
char buf[sizeof(data)];
|
||||
memcpy(buf, &data, sizeof(data));
|
||||
for(unsigned long i = 0; i < sizeof(data); i++) {
|
||||
for(uint8_t i = 0; i < sizeof(buf); i++) {
|
||||
file.write(buf[i]);
|
||||
}
|
||||
file.close();
|
||||
@@ -263,3 +338,34 @@ EnergyAccountingData EnergyAccounting::getData() {
|
||||
void EnergyAccounting::setData(EnergyAccountingData& data) {
|
||||
this->data = data;
|
||||
}
|
||||
|
||||
bool EnergyAccounting::updateMax(uint16_t val, uint8_t day) {
|
||||
for(uint8_t i = 0; i < 5; i++) {
|
||||
if(data.peaks[i].day == day || data.peaks[i].day == 0) {
|
||||
if(val > data.peaks[i].value) {
|
||||
if(debugger->isActive(RemoteDebug::INFO)) debugger->printf("(EnergyAccounting) Adding new max %d for day %d which is larger than %d\n", val*10, day, data.peaks[i].value*10);
|
||||
data.peaks[i].day = day;
|
||||
data.peaks[i].value = val;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
uint16_t test = 0;
|
||||
uint8_t idx = 255;
|
||||
for(uint8_t i = 0; i < 5; i++) {
|
||||
if(val > data.peaks[i].value) {
|
||||
if(test < data.peaks[i].value) {
|
||||
test = data.peaks[i].value;
|
||||
idx = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(idx < 5) {
|
||||
if(debugger->isActive(RemoteDebug::INFO)) debugger->printf("(EnergyAccounting) Adding new max %d for day %d\n", val*10, day);
|
||||
data.peaks[idx].value = val;
|
||||
data.peaks[idx].day = day;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -6,7 +6,21 @@
|
||||
#include "AmsDataStorage.h"
|
||||
#include "entsoe/EntsoeApi.h"
|
||||
|
||||
struct EnergyAccountingPeak {
|
||||
uint8_t day;
|
||||
uint16_t value;
|
||||
};
|
||||
|
||||
struct EnergyAccountingData {
|
||||
uint8_t version;
|
||||
uint8_t month;
|
||||
uint16_t costYesterday;
|
||||
uint16_t costThisMonth;
|
||||
uint16_t costLastMonth;
|
||||
EnergyAccountingPeak peaks[5];
|
||||
};
|
||||
|
||||
struct EnergyAccountingData1 {
|
||||
uint8_t version;
|
||||
uint8_t month;
|
||||
uint16_t maxHour;
|
||||
@@ -15,13 +29,16 @@ struct EnergyAccountingData {
|
||||
uint16_t costLastMonth;
|
||||
};
|
||||
|
||||
|
||||
class EnergyAccounting {
|
||||
public:
|
||||
EnergyAccounting(RemoteDebug*);
|
||||
void setup(AmsDataStorage *ds, EntsoeApi *eapi, EnergyAccountingConfig *config);
|
||||
void setup(AmsDataStorage *ds, EnergyAccountingConfig *config);
|
||||
void setEapi(EntsoeApi *eapi);
|
||||
void setTimezone(Timezone*);
|
||||
EnergyAccountingConfig* getConfig();
|
||||
bool update(AmsData* amsData);
|
||||
bool load();
|
||||
bool save();
|
||||
|
||||
double getUseThisHour();
|
||||
@@ -31,7 +48,7 @@ public:
|
||||
double getCostYesterday();
|
||||
double getUseThisMonth();
|
||||
double getCostThisMonth();
|
||||
double getCostLastMonth();
|
||||
uint16_t getCostLastMonth();
|
||||
|
||||
float getMonthMax();
|
||||
uint8_t getCurrentThreshold();
|
||||
@@ -51,9 +68,8 @@ private:
|
||||
double use, costHour, costDay;
|
||||
EnergyAccountingData data = { 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
bool load();
|
||||
bool calcDayUse();
|
||||
void calcDayCost();
|
||||
bool updateMax(uint16_t val, uint8_t day);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -14,10 +14,32 @@ void HwTools::setup(GpioConfig* config, AmsConfiguration* amsConf) {
|
||||
config->tempSensorPin = 0xFF;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_IDF_TARGET_ESP32S2)
|
||||
analogReadResolution(13);
|
||||
analogRange = 8192;
|
||||
analogSetAttenuation(ADC_11db);
|
||||
#elif defined(ESP32)
|
||||
analogReadResolution(12);
|
||||
analogRange = 4096;
|
||||
analogSetAttenuation(ADC_6db);
|
||||
#endif
|
||||
if(config->vccPin > 0 && config->vccPin < 40) {
|
||||
getAdcChannel(config->vccPin, voltAdc);
|
||||
if(voltAdc.unit != 0xFF) {
|
||||
#if defined(CONFIG_IDF_TARGET_ESP32)
|
||||
#if defined(CONFIG_IDF_TARGET_ESP32S2)
|
||||
getAdcChannel(config->vccPin, voltAdc);
|
||||
if(voltAdc.unit != 0xFF) {
|
||||
if(voltAdc.unit == ADC_UNIT_1) {
|
||||
voltAdcChar = (esp_adc_cal_characteristics_t*) calloc(1, sizeof(esp_adc_cal_characteristics_t));
|
||||
esp_adc_cal_value_t adcVal = esp_adc_cal_characterize((adc_unit_t) voltAdc.unit, ADC_ATTEN_DB_11, ADC_WIDTH_BIT_13, 1100, voltAdcChar);
|
||||
adc1_config_channel_atten((adc1_channel_t) voltAdc.channel, ADC_ATTEN_DB_11);
|
||||
} else if(voltAdc.unit == ADC_UNIT_2) {
|
||||
voltAdcChar = (esp_adc_cal_characteristics_t*) calloc(1, sizeof(esp_adc_cal_characteristics_t));
|
||||
esp_adc_cal_value_t adcVal = esp_adc_cal_characterize((adc_unit_t) voltAdc.unit, ADC_ATTEN_DB_11, ADC_WIDTH_BIT_13, 1100, voltAdcChar);
|
||||
adc2_config_channel_atten((adc2_channel_t) voltAdc.channel, ADC_ATTEN_DB_11);
|
||||
}
|
||||
}
|
||||
#elif defined(ESP32)
|
||||
getAdcChannel(config->vccPin, voltAdc);
|
||||
if(voltAdc.unit != 0xFF) {
|
||||
if(voltAdc.unit == ADC_UNIT_1) {
|
||||
voltAdcChar = (esp_adc_cal_characteristics_t*) calloc(1, sizeof(esp_adc_cal_characteristics_t));
|
||||
esp_adc_cal_value_t adcVal = esp_adc_cal_characterize((adc_unit_t) voltAdc.unit, ADC_ATTEN_DB_6, ADC_WIDTH_BIT_12, 1100, voltAdcChar);
|
||||
@@ -27,10 +49,10 @@ void HwTools::setup(GpioConfig* config, AmsConfiguration* amsConf) {
|
||||
esp_adc_cal_value_t adcVal = esp_adc_cal_characterize((adc_unit_t) voltAdc.unit, ADC_ATTEN_DB_6, ADC_WIDTH_BIT_12, 1100, voltAdcChar);
|
||||
adc2_config_channel_atten((adc2_channel_t) voltAdc.channel, ADC_ATTEN_DB_6);
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
}
|
||||
#else
|
||||
pinMode(config->vccPin, INPUT);
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
voltAdc.unit = 0xFF;
|
||||
voltAdc.channel = 0xFF;
|
||||
@@ -109,6 +131,16 @@ void HwTools::getAdcChannel(uint8_t pin, AdcConfig& config) {
|
||||
config.unit = ADC_UNIT_1;
|
||||
config.channel = ADC1_CHANNEL_7;
|
||||
break;
|
||||
#if defined(CONFIG_IDF_TARGET_ESP32S2)
|
||||
case ADC1_CHANNEL_8_GPIO_NUM:
|
||||
config.unit = ADC_UNIT_1;
|
||||
config.channel = ADC1_CHANNEL_8;
|
||||
break;
|
||||
case ADC1_CHANNEL_9_GPIO_NUM:
|
||||
config.unit = ADC_UNIT_1;
|
||||
config.channel = ADC1_CHANNEL_9;
|
||||
break;
|
||||
#endif
|
||||
case ADC2_CHANNEL_0_GPIO_NUM:
|
||||
config.unit = ADC_UNIT_2;
|
||||
config.channel = ADC2_CHANNEL_0;
|
||||
@@ -156,7 +188,7 @@ void HwTools::getAdcChannel(uint8_t pin, AdcConfig& config) {
|
||||
double HwTools::getVcc() {
|
||||
double volts = 0.0;
|
||||
if(config->vccPin != 0xFF) {
|
||||
#if defined(CONFIG_IDF_TARGET_ESP32)
|
||||
#if defined(ESP32)
|
||||
if(voltAdc.unit != 0xFF) {
|
||||
uint32_t x = 0;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
@@ -164,7 +196,11 @@ double HwTools::getVcc() {
|
||||
x += adc1_get_raw((adc1_channel_t) voltAdc.channel);
|
||||
} else if(voltAdc.unit == ADC_UNIT_2) {
|
||||
int v = 0;
|
||||
#if defined(CONFIG_IDF_TARGET_ESP32S2)
|
||||
adc2_get_raw((adc2_channel_t) voltAdc.channel, ADC_WIDTH_BIT_13, &v);
|
||||
#elif defined(CONFIG_IDF_TARGET_ESP32)
|
||||
adc2_get_raw((adc2_channel_t) voltAdc.channel, ADC_WIDTH_BIT_12, &v);
|
||||
#endif
|
||||
x += v;
|
||||
}
|
||||
}
|
||||
@@ -176,20 +212,22 @@ double HwTools::getVcc() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
x += analogRead(config->vccPin);
|
||||
}
|
||||
volts = x / 40950;
|
||||
volts = (x * 3.3) / 10.0 / analogRange;
|
||||
}
|
||||
#else
|
||||
uint32_t x = 0;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
x += analogRead(config->vccPin);
|
||||
}
|
||||
volts = x / 10240;
|
||||
volts = (x * 3.3) / 10.0 / analogRange;
|
||||
#endif
|
||||
} else {
|
||||
#if defined(ESP8266)
|
||||
volts = ESP.getVcc() / 1024.0;
|
||||
#endif
|
||||
}
|
||||
if(volts == 0.0) return 0.0;
|
||||
|
||||
if(config->vccResistorGnd > 0 && config->vccResistorVcc > 0) {
|
||||
volts *= ((double) (config->vccResistorGnd + config->vccResistorVcc) / config->vccResistorGnd);
|
||||
}
|
||||
@@ -303,12 +341,7 @@ double HwTools::getTemperature() {
|
||||
double HwTools::getTemperatureAnalog() {
|
||||
if(config->tempAnalogSensorPin != 0xFF) {
|
||||
float adcCalibrationFactor = 1.06587;
|
||||
int volts;
|
||||
#if defined(ESP8266)
|
||||
volts = (analogRead(config->tempAnalogSensorPin) / 1024.0) * 3.3;
|
||||
#elif defined(ESP32)
|
||||
volts = (analogRead(config->tempAnalogSensorPin) / 4095.0) * 3.3;
|
||||
#endif
|
||||
int volts = ((double) analogRead(config->tempAnalogSensorPin) / analogRange) * 3.3;
|
||||
return ((volts * adcCalibrationFactor) - 0.4) / 0.0195;
|
||||
}
|
||||
return DEVICE_DISCONNECTED_C;
|
||||
|
||||
@@ -51,6 +51,7 @@ public:
|
||||
|
||||
HwTools() {};
|
||||
private:
|
||||
uint16_t analogRange = 1024;
|
||||
AdcConfig voltAdc, tempAdc;
|
||||
#if defined(ESP32)
|
||||
esp_adc_cal_characteristics_t* voltAdcChar, tempAdcChar;
|
||||
|
||||
@@ -1,11 +1,20 @@
|
||||
#include "IEC6205621.h"
|
||||
#include "ams/crc.h"
|
||||
|
||||
IEC6205621::IEC6205621(String payload) {
|
||||
if(payload.length() < 16)
|
||||
IEC6205621::IEC6205621(const char* p) {
|
||||
if(strlen(p) < 16)
|
||||
return;
|
||||
|
||||
String payload(p+1);
|
||||
int crc_pos = payload.lastIndexOf("!");
|
||||
String crc = payload.substring(crc_pos+1, crc_pos+5);
|
||||
//uint16_t crc_calc = crc16_x25((uint8_t*) (payload.startsWith("/") ? p+1 : p), crc_pos);
|
||||
|
||||
//Serial.printf("CRC %s :: %04X\n", crc.c_str(), crc_calc);
|
||||
|
||||
lastUpdateMillis = millis();
|
||||
listId = payload.substring(payload.startsWith("/") ? 1 : 0, payload.indexOf("\n"));
|
||||
|
||||
if(listId.startsWith("ADN")) {
|
||||
meterType = AmsTypeAidon;
|
||||
listId = listId.substring(0,4);
|
||||
@@ -21,7 +30,7 @@ IEC6205621::IEC6205621(String payload) {
|
||||
} else if(listId.startsWith("XMX")) {
|
||||
meterType = AmsTypeLandis;
|
||||
listId = listId.substring(0,6);
|
||||
} else if(listId.startsWith("Ene")) {
|
||||
} else if(listId.startsWith("Ene") || listId.startsWith("EST")) {
|
||||
meterType = AmsTypeSagemcom;
|
||||
listId = listId.substring(0,4);
|
||||
} else {
|
||||
@@ -55,10 +64,10 @@ IEC6205621::IEC6205621(String payload) {
|
||||
meterTimestamp = makeTime(tm); // TODO: Adjust for time zone
|
||||
}
|
||||
|
||||
activeImportPower = (uint16_t) (extractDouble(payload, "1.7.0") * 1000);
|
||||
activeExportPower = (uint16_t) (extractDouble(payload, "2.7.0") * 1000);
|
||||
reactiveImportPower = (uint16_t) (extractDouble(payload, "3.7.0") * 1000);
|
||||
reactiveExportPower = (uint16_t) (extractDouble(payload, "4.7.0") * 1000);
|
||||
activeImportPower = (uint16_t) (extractDouble(payload, "1.7.0"));
|
||||
activeExportPower = (uint16_t) (extractDouble(payload, "2.7.0"));
|
||||
reactiveImportPower = (uint16_t) (extractDouble(payload, "3.7.0"));
|
||||
reactiveExportPower = (uint16_t) (extractDouble(payload, "4.7.0"));
|
||||
|
||||
if(activeImportPower > 0)
|
||||
listType = 1;
|
||||
@@ -73,11 +82,40 @@ IEC6205621::IEC6205621(String payload) {
|
||||
|
||||
if(l1voltage > 0 || l2voltage > 0 || l3voltage > 0)
|
||||
listType = 2;
|
||||
|
||||
double val = 0.0;
|
||||
|
||||
activeImportCounter = extractDouble(payload, "1.8.0");
|
||||
activeExportCounter = extractDouble(payload, "2.8.0");
|
||||
reactiveImportCounter = extractDouble(payload, "3.8.0");
|
||||
reactiveExportCounter = extractDouble(payload, "4.8.0");
|
||||
val = extractDouble(payload, "1.8.0");
|
||||
if(val == 0) {
|
||||
for(int i = 1; i < 9; i++) {
|
||||
val += extractDouble(payload, "1.8." + String(i,10));
|
||||
}
|
||||
}
|
||||
if(val > 0) activeImportCounter = val / 1000;
|
||||
|
||||
val = extractDouble(payload, "2.8.0");
|
||||
if(val == 0) {
|
||||
for(int i = 1; i < 9; i++) {
|
||||
val += extractDouble(payload, "2.8." + String(i,10));
|
||||
}
|
||||
}
|
||||
if(val > 0) activeExportCounter = val / 1000;
|
||||
|
||||
val = extractDouble(payload, "3.8.0");
|
||||
if(val == 0) {
|
||||
for(int i = 1; i < 9; i++) {
|
||||
val += extractDouble(payload, "3.8." + String(i,10));
|
||||
}
|
||||
}
|
||||
if(val > 0) reactiveImportCounter = val / 1000;
|
||||
|
||||
val = extractDouble(payload, "4.8.0");
|
||||
if(val == 0) {
|
||||
for(int i = 1; i < 9; i++) {
|
||||
val += extractDouble(payload, "4.8." + String(i,10));
|
||||
}
|
||||
}
|
||||
if(val > 0) reactiveExportCounter = val / 1000;
|
||||
|
||||
if(activeImportCounter > 0 || activeExportCounter > 0 || reactiveImportCounter > 0 || reactiveExportCounter > 0)
|
||||
listType = 3;
|
||||
@@ -104,5 +142,14 @@ String IEC6205621::extract(String payload, String obis) {
|
||||
}
|
||||
|
||||
double IEC6205621::extractDouble(String payload, String obis) {
|
||||
return extract(payload, obis).toDouble();
|
||||
String str = extract(payload, obis);
|
||||
if(str.isEmpty()) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
int a = str.indexOf("*");
|
||||
String val = str.substring(0,a);
|
||||
String unit = str.substring(a+1);
|
||||
|
||||
return unit.startsWith("k") ? val.toDouble() * 1000 : val.toDouble();
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#ifndef _IEC62056_21_H
|
||||
#define _IEC62056_21_H
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "AmsData.h"
|
||||
|
||||
class IEC6205621 : public AmsData {
|
||||
public:
|
||||
IEC6205621(String payload);
|
||||
IEC6205621(const char* payload);
|
||||
|
||||
private:
|
||||
String extract(String payload, String obis);
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#include "IEC6205675.h"
|
||||
#include "lwip/def.h"
|
||||
#include "Timezone.h"
|
||||
#include "ams/ntohll.h"
|
||||
|
||||
IEC6205675::IEC6205675(const char* d, uint8_t useMeterType, MeterConfig* meterConfig, CosemDateTime packageTimestamp, HDLCConfig* hc) {
|
||||
IEC6205675::IEC6205675(const char* d, uint8_t useMeterType, MeterConfig* meterConfig, DataParserContext &ctx) {
|
||||
double val;
|
||||
char str[64];
|
||||
|
||||
@@ -10,7 +11,7 @@ IEC6205675::IEC6205675(const char* d, uint8_t useMeterType, MeterConfig* meterCo
|
||||
TimeChangeRule CET = {"CET ", Last, Sun, Oct, 3, 60};
|
||||
Timezone tz(CEST, CET);
|
||||
|
||||
this->packageTimestamp = getTimestamp(packageTimestamp);
|
||||
this->packageTimestamp = ctx.timestamp;
|
||||
|
||||
val = getNumber(AMS_OBIS_ACTIVE_IMPORT, sizeof(AMS_OBIS_ACTIVE_IMPORT), ((char *) (d)));
|
||||
if(val == NOVALUE) {
|
||||
@@ -107,7 +108,7 @@ IEC6205675::IEC6205675(const char* d, uint8_t useMeterType, MeterConfig* meterCo
|
||||
case CosemTypeOctetString: {
|
||||
if(data->oct.length == 0x0C) {
|
||||
AmsOctetTimestamp* amst = (AmsOctetTimestamp*) data;
|
||||
time_t ts = getTimestamp(amst->dt);
|
||||
time_t ts = decodeCosemDateTime(amst->dt);
|
||||
meterTimestamp = tz.toUTC(ts);
|
||||
}
|
||||
}
|
||||
@@ -157,8 +158,8 @@ IEC6205675::IEC6205675(const char* d, uint8_t useMeterType, MeterConfig* meterCo
|
||||
}
|
||||
}
|
||||
// Try system title
|
||||
if(meterType == AmsTypeUnknown && hc != NULL) {
|
||||
if(memcmp(hc->system_title, "SAGY", 4)) {
|
||||
if(meterType == AmsTypeUnknown) {
|
||||
if(memcmp(ctx.system_title, "SAGY", 4) == 0) {
|
||||
meterType = AmsTypeSagemcom;
|
||||
}
|
||||
}
|
||||
@@ -264,7 +265,7 @@ IEC6205675::IEC6205675(const char* d, uint8_t useMeterType, MeterConfig* meterCo
|
||||
CosemData* meterTs = findObis(AMS_OBIS_METER_TIMESTAMP, sizeof(AMS_OBIS_METER_TIMESTAMP), ((char *) (d)));
|
||||
if(meterTs != NULL) {
|
||||
AmsOctetTimestamp* amst = (AmsOctetTimestamp*) meterTs;
|
||||
time_t ts = getTimestamp(amst->dt);
|
||||
time_t ts = decodeCosemDateTime(amst->dt);
|
||||
if(meterType == AmsTypeKamstrup || meterType == AmsTypeAidon) {
|
||||
meterTimestamp = tz.toUTC(ts);
|
||||
} else {
|
||||
@@ -325,7 +326,7 @@ IEC6205675::IEC6205675(const char* d, uint8_t useMeterType, MeterConfig* meterCo
|
||||
CosemData* meterTs = getCosemDataAt(1, ((char *) (d)));
|
||||
if(meterTs != NULL) {
|
||||
AmsOctetTimestamp* amst = (AmsOctetTimestamp*) meterTs;
|
||||
time_t ts = getTimestamp(amst->dt);
|
||||
time_t ts = decodeCosemDateTime(amst->dt);
|
||||
meterTimestamp = ts;
|
||||
}
|
||||
|
||||
@@ -407,7 +408,7 @@ CosemData* IEC6205675::getCosemDataAt(uint8_t index, const char* ptr) {
|
||||
CosemData* item = (CosemData*) ptr;
|
||||
int i = 0;
|
||||
char* pos = (char*) ptr;
|
||||
do {
|
||||
while(pos-ptr < 900) {
|
||||
item = (CosemData*) pos;
|
||||
if(i == index) return item;
|
||||
switch(item->base.type) {
|
||||
@@ -438,8 +439,7 @@ CosemData* IEC6205675::getCosemDataAt(uint8_t index, const char* ptr) {
|
||||
pos += 2;
|
||||
}
|
||||
i++;
|
||||
if(pos-ptr > 900) break;
|
||||
} while(item->base.type != HDLC_FLAG);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -447,7 +447,7 @@ CosemData* IEC6205675::findObis(uint8_t* obis, int matchlength, const char* ptr)
|
||||
CosemData* item = (CosemData*) ptr;
|
||||
int ret = 0;
|
||||
char* pos = (char*) ptr;
|
||||
do {
|
||||
while(pos-ptr < 900) {
|
||||
item = (CosemData*) pos;
|
||||
if(ret == 1) return item;
|
||||
switch(item->base.type) {
|
||||
@@ -485,8 +485,7 @@ CosemData* IEC6205675::findObis(uint8_t* obis, int matchlength, const char* ptr)
|
||||
default:
|
||||
pos += 2;
|
||||
}
|
||||
if(pos-ptr > 900) break;
|
||||
} while(item->base.type != HDLC_FLAG);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -572,31 +571,10 @@ time_t IEC6205675::getTimestamp(uint8_t* obis, int matchlength, const char* ptr)
|
||||
case CosemTypeOctetString: {
|
||||
if(item->oct.length == 0x0C) {
|
||||
AmsOctetTimestamp* ts = (AmsOctetTimestamp*) item;
|
||||
return getTimestamp(ts->dt);
|
||||
return decodeCosemDateTime(ts->dt);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
time_t IEC6205675::getTimestamp(CosemDateTime timestamp) {
|
||||
tmElements_t tm;
|
||||
uint16_t year = ntohs(timestamp.year);
|
||||
if(year < 1970) return 0;
|
||||
tm.Year = year - 1970;
|
||||
tm.Month = timestamp.month;
|
||||
tm.Day = timestamp.dayOfMonth;
|
||||
tm.Hour = timestamp.hour;
|
||||
tm.Minute = timestamp.minute;
|
||||
tm.Second = timestamp.second;
|
||||
|
||||
//Serial.printf("\nY: %d, M: %d, D: %d, h: %d, m: %d, s: %d, deviation: 0x%2X, status: 0x%1X\n", tm.Year, tm.Month, tm.Day, tm.Hour, tm.Minute, tm.Second, timestamp.deviation, timestamp.status);
|
||||
|
||||
time_t time = makeTime(tm);
|
||||
int16_t deviation = ntohs(timestamp.deviation);
|
||||
if(deviation >= -720 && deviation <= 720) {
|
||||
time -= deviation * 60;
|
||||
}
|
||||
return time;
|
||||
}
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
#define _IEC62056_7_5_H
|
||||
|
||||
#include "AmsData.h"
|
||||
#include "ams/hdlc.h"
|
||||
#include "AmsConfiguration.h"
|
||||
#include "ams/DataParser.h"
|
||||
#include "ams/Cosem.h"
|
||||
|
||||
#define NOVALUE 0xFFFFFFFF
|
||||
|
||||
@@ -14,7 +15,7 @@ struct AmsOctetTimestamp {
|
||||
|
||||
class IEC6205675 : public AmsData {
|
||||
public:
|
||||
IEC6205675(const char* payload, uint8_t useMeterType, MeterConfig* meterConfig, CosemDateTime packageTimestamp, HDLCConfig* hc);
|
||||
IEC6205675(const char* payload, uint8_t useMeterType, MeterConfig* meterConfig, DataParserContext &ctx);
|
||||
|
||||
private:
|
||||
CosemData* getCosemDataAt(uint8_t index, const char* ptr);
|
||||
@@ -23,7 +24,6 @@ private:
|
||||
double getNumber(uint8_t* obis, int matchlength, const char* ptr);
|
||||
double getNumber(CosemData*);
|
||||
time_t getTimestamp(uint8_t* obis, int matchlength, const char* ptr);
|
||||
time_t getTimestamp(CosemDateTime timestamp);
|
||||
|
||||
uint8_t AMS_OBIS_VERSION[4] = { 0, 2, 129, 255 };
|
||||
uint8_t AMS_OBIS_METER_MODEL[4] = { 96, 1, 1, 255 };
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
#include "Arduino.h"
|
||||
#include "MbusAssembler.h"
|
||||
#include "ams/hdlc.h"
|
||||
|
||||
MbusAssembler::MbusAssembler() {
|
||||
buf = (uint8_t *)malloc((size_t)1024); // TODO find out from first package ?
|
||||
}
|
||||
|
||||
uint8_t MbusAssembler::append(const uint8_t* d, int length) {
|
||||
MbusHeader* h = (MbusHeader*) d;
|
||||
uint8_t* ptr = (uint8_t*) &h[1];
|
||||
|
||||
uint8_t len = h->len1;
|
||||
|
||||
uint8_t control = *ptr;
|
||||
ptr++; len--;
|
||||
|
||||
uint8_t address = *ptr;
|
||||
ptr++; len--;
|
||||
|
||||
uint8_t ci = *ptr;
|
||||
ptr++; len--;
|
||||
|
||||
uint8_t stsap = *ptr;
|
||||
ptr++; len--;
|
||||
|
||||
uint8_t dtsap = *ptr;
|
||||
ptr++; len--;
|
||||
|
||||
uint8_t sequenceNumber = ci & 0x0F;
|
||||
if(sequenceNumber == 0) {
|
||||
memcpy(buf, d, length - 2); // Do not include FCS and MBUS_STOP
|
||||
buf[6] = 0x10; // Mark that this is a single, complete frame
|
||||
pos = length - 2;
|
||||
lastSequenceNumber = 0;
|
||||
return 0;
|
||||
} else if(pos + len > 1024 || sequenceNumber != (lastSequenceNumber + 1)) { // TODO return error
|
||||
pos = 0;
|
||||
lastSequenceNumber = -1;
|
||||
return -1;
|
||||
} else {
|
||||
if(len > length) return -1;
|
||||
memcpy(buf + pos, ptr, len);
|
||||
pos += len;
|
||||
lastSequenceNumber = sequenceNumber;
|
||||
return 0;
|
||||
}
|
||||
return -2;
|
||||
}
|
||||
|
||||
uint16_t MbusAssembler::write(const uint8_t* d) {
|
||||
buf[1] = buf[2] = 0x00;
|
||||
buf[pos++] = mbusChecksum(buf+4, pos-4);
|
||||
buf[pos++] = MBUS_END;
|
||||
memcpy((uint8_t *) d, buf, pos);
|
||||
return pos;
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
#ifndef _MBUS_ASSEMBLER_H
|
||||
#define _MBUS_ASSEMBLER_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
class MbusAssembler {
|
||||
public:
|
||||
MbusAssembler();
|
||||
uint8_t append(const uint8_t* d, int length);
|
||||
uint16_t write(const uint8_t* d);
|
||||
|
||||
private:
|
||||
uint16_t pos = 0;
|
||||
uint8_t *buf;
|
||||
uint8_t lastSequenceNumber = -1;
|
||||
};
|
||||
|
||||
#endif
|
||||
24
src/ams/Cosem.cpp
Normal file
24
src/ams/Cosem.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include "Cosem.h"
|
||||
#include "lwip/def.h"
|
||||
#include <TimeLib.h>
|
||||
|
||||
time_t decodeCosemDateTime(CosemDateTime timestamp) {
|
||||
tmElements_t tm;
|
||||
uint16_t year = ntohs(timestamp.year);
|
||||
if(year < 1970) return 0;
|
||||
tm.Year = year - 1970;
|
||||
tm.Month = timestamp.month;
|
||||
tm.Day = timestamp.dayOfMonth;
|
||||
tm.Hour = timestamp.hour;
|
||||
tm.Minute = timestamp.minute;
|
||||
tm.Second = timestamp.second;
|
||||
|
||||
//Serial.printf("\nY: %d, M: %d, D: %d, h: %d, m: %d, s: %d, deviation: 0x%2X, status: 0x%1X\n", tm.Year, tm.Month, tm.Day, tm.Hour, tm.Minute, tm.Second, timestamp.deviation, timestamp.status);
|
||||
|
||||
time_t time = makeTime(tm);
|
||||
int16_t deviation = ntohs(timestamp.deviation);
|
||||
if(deviation >= -720 && deviation <= 720) {
|
||||
time -= deviation * 60;
|
||||
}
|
||||
return time;
|
||||
}
|
||||
92
src/ams/Cosem.h
Normal file
92
src/ams/Cosem.h
Normal file
@@ -0,0 +1,92 @@
|
||||
#ifndef _COSEM_H
|
||||
#define _COSEM_H
|
||||
|
||||
#include "lwip/def.h"
|
||||
|
||||
// Blue book, Table 2
|
||||
enum CosemType {
|
||||
CosemTypeNull = 0x00,
|
||||
CosemTypeArray = 0x01,
|
||||
CosemTypeStructure = 0x02,
|
||||
CosemTypeOctetString = 0x09,
|
||||
CosemTypeString = 0x0A,
|
||||
CosemTypeDLongSigned = 0x05,
|
||||
CosemTypeDLongUnsigned = 0x06,
|
||||
CosemTypeLongSigned = 0x10,
|
||||
CosemTypeLongUnsigned = 0x12,
|
||||
CosemTypeLong64Signed = 0x14,
|
||||
CosemTypeLong64Unsigned = 0x15,
|
||||
CosemTypeDateTime = 0x19
|
||||
};
|
||||
|
||||
struct CosemBasic {
|
||||
uint8_t type;
|
||||
uint8_t length;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct CosemString {
|
||||
uint8_t type;
|
||||
uint8_t length;
|
||||
uint8_t data[];
|
||||
} __attribute__((packed));
|
||||
|
||||
struct CosemLongSigned {
|
||||
uint8_t type;
|
||||
int16_t data;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct CosemLongUnsigned {
|
||||
uint8_t type;
|
||||
uint16_t data;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct CosemDLongSigned {
|
||||
uint8_t type;
|
||||
int32_t data;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct CosemDLongUnsigned {
|
||||
uint8_t type;
|
||||
uint32_t data;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct CosemLong64Signed {
|
||||
uint8_t type;
|
||||
int64_t data;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct CosemLong64Unsigned {
|
||||
uint8_t type;
|
||||
uint64_t data;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct CosemDateTime {
|
||||
uint8_t type;
|
||||
uint16_t year;
|
||||
uint8_t month;
|
||||
uint8_t dayOfMonth;
|
||||
uint8_t dayOfWeek;
|
||||
uint8_t hour;
|
||||
uint8_t minute;
|
||||
uint8_t second;
|
||||
uint8_t hundredths;
|
||||
int16_t deviation;
|
||||
uint8_t status;
|
||||
} __attribute__((packed));
|
||||
|
||||
typedef union {
|
||||
struct CosemBasic base;
|
||||
struct CosemString str;
|
||||
struct CosemString oct;
|
||||
struct CosemLongSigned ls;
|
||||
struct CosemLongUnsigned lu;
|
||||
struct CosemDLongSigned dls;
|
||||
struct CosemDLongUnsigned dlu;
|
||||
struct CosemLong64Signed l64s;
|
||||
struct CosemLong64Unsigned l64u;
|
||||
struct CosemDateTime dt;
|
||||
} CosemData;
|
||||
|
||||
time_t decodeCosemDateTime(CosemDateTime timestamp);
|
||||
|
||||
#endif
|
||||
31
src/ams/DataParser.h
Normal file
31
src/ams/DataParser.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef _DATAPASERSER_H
|
||||
#define _DATAPASERSER_H
|
||||
|
||||
#define DATA_TAG_NONE 0x00
|
||||
#define DATA_TAG_AUTO 0x01
|
||||
#define DATA_TAG_HDLC 0x7E
|
||||
#define DATA_TAG_LLC 0xE6
|
||||
#define DATA_TAG_DLMS 0x0F
|
||||
#define DATA_TAG_DSMR 0x2F
|
||||
#define DATA_TAG_MBUS 0x68
|
||||
#define DATA_TAG_GBT 0xE0
|
||||
#define DATA_TAG_GCM 0xDB
|
||||
|
||||
#define DATA_PARSE_OK 0
|
||||
#define DATA_PARSE_FAIL -1
|
||||
#define DATA_PARSE_INCOMPLETE -2
|
||||
#define DATA_PARSE_BOUNDRY_FLAG_MISSING -3
|
||||
#define DATA_PARSE_HEADER_CHECKSUM_ERROR -4
|
||||
#define DATA_PARSE_FOOTER_CHECKSUM_ERROR -5
|
||||
#define DATA_PARSE_INTERMEDIATE_SEGMENT -6
|
||||
#define DATA_PARSE_FINAL_SEGMENT -7
|
||||
#define DATA_PARSE_UNKNOWN_DATA -9
|
||||
|
||||
struct DataParserContext {
|
||||
uint8_t type;
|
||||
uint16_t length;
|
||||
time_t timestamp;
|
||||
uint8_t system_title[8];
|
||||
};
|
||||
|
||||
#endif
|
||||
13
src/ams/DataParsers.h
Normal file
13
src/ams/DataParsers.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef _DATAPASERSERS_H
|
||||
#define _DATAPASERSERS_H
|
||||
|
||||
#include "HdlcParser.h"
|
||||
#include "DlmsParser.h"
|
||||
#include "DsmrParser.h"
|
||||
#include "MbusParser.h"
|
||||
#include "GbtParser.h"
|
||||
#include "GcmParser.h"
|
||||
#include "LlcParser.h"
|
||||
|
||||
#endif
|
||||
|
||||
38
src/ams/DlmsParser.cpp
Normal file
38
src/ams/DlmsParser.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include "DlmsParser.h"
|
||||
#include "Cosem.h"
|
||||
|
||||
int8_t DLMSParser::parse(uint8_t *buf, DataParserContext &ctx) {
|
||||
if(ctx.length < 6) return DATA_PARSE_INCOMPLETE;
|
||||
|
||||
uint8_t* ptr = buf+1;
|
||||
ptr += 4; // Skip invoke ID and priority
|
||||
|
||||
CosemData* item = (CosemData*) ptr;
|
||||
if(item->base.type == CosemTypeOctetString) {
|
||||
if(item->base.length == 0x0C) {
|
||||
CosemDateTime* dateTime = (CosemDateTime*) (ptr+1);
|
||||
ctx.timestamp = decodeCosemDateTime(*dateTime);
|
||||
}
|
||||
uint8_t len = 5+14;
|
||||
ctx.length -= len;
|
||||
return len;
|
||||
} else if(item->base.type == CosemTypeNull) {
|
||||
ctx.timestamp = 0;
|
||||
uint8_t len = 5+1;
|
||||
ctx.length -= len;
|
||||
return len;
|
||||
} else if(item->base.type == CosemTypeDateTime) {
|
||||
CosemDateTime* dateTime = (CosemDateTime*) (ptr);
|
||||
ctx.timestamp = decodeCosemDateTime(*dateTime);
|
||||
uint8_t len = 5+13;
|
||||
ctx.length -= len;
|
||||
return len;
|
||||
} else if(item->base.type == 0x0C) { // Kamstrup bug...
|
||||
CosemDateTime* dateTime = (CosemDateTime*) (ptr);
|
||||
ctx.timestamp = decodeCosemDateTime(*dateTime);
|
||||
uint8_t len = 5+13;
|
||||
ctx.length -= len;
|
||||
return len;
|
||||
}
|
||||
return DATA_PARSE_UNKNOWN_DATA;
|
||||
}
|
||||
12
src/ams/DlmsParser.h
Normal file
12
src/ams/DlmsParser.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef _DLMSPARSER_H
|
||||
#define _DLMSPARSER_H
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "DataParser.h"
|
||||
|
||||
class DLMSParser {
|
||||
public:
|
||||
int8_t parse(uint8_t *buf, DataParserContext &ctx);
|
||||
};
|
||||
|
||||
#endif
|
||||
22
src/ams/DsmrParser.cpp
Normal file
22
src/ams/DsmrParser.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#include "DsmrParser.h"
|
||||
|
||||
int8_t DSMRParser::parse(uint8_t *buf, DataParserContext &ctx, bool verified) {
|
||||
uint16_t crcPos = 0;
|
||||
bool reachedEnd = verified;
|
||||
uint8_t lastByte = 0x00;
|
||||
int c = 0;
|
||||
for(int pos = 0; pos < ctx.length; pos++) {
|
||||
uint8_t b = *(buf+pos);
|
||||
if(pos == 0 && b != '/') return DATA_PARSE_BOUNDRY_FLAG_MISSING;
|
||||
if(pos > 0 && b == '!' && lastByte == '\n') crcPos = pos+1;
|
||||
if(crcPos > 0 && b == '\n') reachedEnd = true;
|
||||
lastByte = b;
|
||||
}
|
||||
if(!reachedEnd) return DATA_PARSE_INCOMPLETE;
|
||||
buf[ctx.length+1] = '\0';
|
||||
if(crcPos > 0) {
|
||||
// TODO: CRC
|
||||
Serial.printf("CRC: %s\n", buf+crcPos);
|
||||
}
|
||||
return DATA_PARSE_OK;
|
||||
}
|
||||
13
src/ams/DsmrParser.h
Normal file
13
src/ams/DsmrParser.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef _DSMRPARSER_H
|
||||
#define _DSMRPARSER_H
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "DataParser.h"
|
||||
|
||||
class DSMRParser {
|
||||
public:
|
||||
int8_t parse(uint8_t *buf, DataParserContext &ctx, bool verified);
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
32
src/ams/GbtParser.cpp
Normal file
32
src/ams/GbtParser.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#include "GbtParser.h"
|
||||
#include "lwip/def.h"
|
||||
|
||||
int8_t GBTParser::parse(uint8_t *d, DataParserContext &ctx) {
|
||||
GBTHeader* h = (GBTHeader*) (d);
|
||||
uint16_t sequence = ntohs(h->sequence);
|
||||
|
||||
if(h->flag != GBT_TAG) return DATA_PARSE_BOUNDRY_FLAG_MISSING;
|
||||
|
||||
if(sequence == 1) {
|
||||
if(buf == NULL) buf = (uint8_t *)malloc((size_t)1024); // TODO find out from first package ?
|
||||
pos = 0;
|
||||
} else if(lastSequenceNumber != sequence-1) {
|
||||
return DATA_PARSE_FAIL;
|
||||
}
|
||||
|
||||
if(buf == NULL) return DATA_PARSE_FAIL;
|
||||
|
||||
uint8_t* ptr = (uint8_t*) &h[1];
|
||||
memcpy(buf + pos, ptr, h->size);
|
||||
pos += h->size;
|
||||
lastSequenceNumber = sequence;
|
||||
|
||||
if((h->control & 0x80) == 0x00) {
|
||||
return DATA_PARSE_INTERMEDIATE_SEGMENT;
|
||||
} else {
|
||||
memcpy((uint8_t *) d, buf, pos);
|
||||
}
|
||||
ctx.length = pos;
|
||||
return DATA_PARSE_OK;
|
||||
|
||||
}
|
||||
26
src/ams/GbtParser.h
Normal file
26
src/ams/GbtParser.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef _GBTPARSER_H
|
||||
#define _GBTPARSER_H
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "DataParser.h"
|
||||
|
||||
#define GBT_TAG 0xE0
|
||||
|
||||
typedef struct GBTHeader {
|
||||
uint8_t flag;
|
||||
uint8_t control;
|
||||
uint16_t sequence;
|
||||
uint16_t sequenceAck;
|
||||
uint8_t size;
|
||||
} __attribute__((packed)) GBTHeader;
|
||||
|
||||
class GBTParser {
|
||||
public:
|
||||
int8_t parse(uint8_t *buf, DataParserContext &ctx);
|
||||
private:
|
||||
uint8_t lastSequenceNumber = 0;
|
||||
uint16_t pos = 0;
|
||||
uint8_t *buf = NULL;
|
||||
};
|
||||
|
||||
#endif
|
||||
131
src/ams/GcmParser.cpp
Normal file
131
src/ams/GcmParser.cpp
Normal file
@@ -0,0 +1,131 @@
|
||||
#include "GcmParser.h"
|
||||
#include "lwip/def.h"
|
||||
#if defined(ESP8266)
|
||||
#include "bearssl/bearssl.h"
|
||||
#elif defined(ESP32)
|
||||
#include "mbedtls/gcm.h"
|
||||
#endif
|
||||
|
||||
GCMParser::GCMParser(uint8_t *encryption_key, uint8_t *authentication_key) {
|
||||
memcpy(this->encryption_key, encryption_key, 16);
|
||||
memcpy(this->authentication_key, authentication_key, 16);
|
||||
}
|
||||
|
||||
int8_t GCMParser::parse(uint8_t *d, DataParserContext &ctx) {
|
||||
if(ctx.length < 12) return DATA_PARSE_INCOMPLETE;
|
||||
|
||||
uint8_t* ptr = (uint8_t*) d;
|
||||
if(*ptr != GCM_TAG) return DATA_PARSE_BOUNDRY_FLAG_MISSING;
|
||||
ptr++;
|
||||
// Encrypted APDU
|
||||
// http://www.weigu.lu/tutorials/sensors2bus/04_encryption/index.html
|
||||
|
||||
uint8_t systemTitleLength = *ptr;
|
||||
ptr++;
|
||||
|
||||
uint8_t initialization_vector[12];
|
||||
memcpy(ctx.system_title, ptr, systemTitleLength);
|
||||
memcpy(initialization_vector, ctx.system_title, systemTitleLength);
|
||||
|
||||
int len;
|
||||
int headersize = 2 + systemTitleLength;
|
||||
ptr += systemTitleLength;
|
||||
if(((*ptr) & 0xFF) == 0x81) {
|
||||
ptr++;
|
||||
len = *ptr;
|
||||
// 1-byte payload length
|
||||
ptr++;
|
||||
headersize += 2;
|
||||
} else if(((*ptr) & 0xFF) == 0x82) {
|
||||
GCMSizeDef* h = (GCMSizeDef*) ptr;
|
||||
|
||||
// 2-byte payload length
|
||||
len = (ntohs(h->format) & 0xFFFF);
|
||||
|
||||
ptr += 3;
|
||||
headersize += 3;
|
||||
}
|
||||
if(len + headersize > ctx.length)
|
||||
return DATA_PARSE_INCOMPLETE;
|
||||
|
||||
//Serial.printf("\nL: %d : %d, %d\n", length, len, headersize);
|
||||
|
||||
uint8_t additional_authenticated_data[17];
|
||||
memcpy(additional_authenticated_data, ptr, 1);
|
||||
|
||||
// Security tag
|
||||
uint8_t sec = *ptr;
|
||||
ptr++;
|
||||
headersize++;
|
||||
|
||||
// Frame counter
|
||||
memcpy(initialization_vector + 8, ptr, 4);
|
||||
ptr += 4;
|
||||
headersize += 4;
|
||||
|
||||
int footersize = 0;
|
||||
|
||||
// Authentication enabled
|
||||
uint8_t authentication_tag[12];
|
||||
uint8_t authkeylen = 0, aadlen = 0;
|
||||
if((sec & 0x10) == 0x10) {
|
||||
authkeylen = 12;
|
||||
aadlen = 17;
|
||||
footersize += authkeylen;
|
||||
memcpy(additional_authenticated_data + 1, authentication_key, 16);
|
||||
memcpy(authentication_tag, ptr + len - footersize - 5, authkeylen);
|
||||
}
|
||||
|
||||
#if defined(ESP8266)
|
||||
br_gcm_context gcmCtx;
|
||||
br_aes_ct_ctr_keys bc;
|
||||
br_aes_ct_ctr_init(&bc, encryption_key, 16);
|
||||
br_gcm_init(&gcmCtx, &bc.vtable, br_ghash_ctmul32);
|
||||
br_gcm_reset(&gcmCtx, initialization_vector, sizeof(initialization_vector));
|
||||
if(authkeylen > 0) {
|
||||
br_gcm_aad_inject(&gcmCtx, additional_authenticated_data, aadlen);
|
||||
}
|
||||
br_gcm_flip(&gcmCtx);
|
||||
br_gcm_run(&gcmCtx, 0, (void*) (ptr), len - authkeylen - 5); // 5 == security tag and frame counter
|
||||
if(authkeylen > 0 && br_gcm_check_tag_trunc(&gcmCtx, authentication_tag, authkeylen) != 1) {
|
||||
return GCM_AUTH_FAILED;
|
||||
}
|
||||
#elif defined(ESP32)
|
||||
uint8_t cipher_text[len - authkeylen - 5];
|
||||
memcpy(cipher_text, ptr, len - authkeylen - 5);
|
||||
|
||||
mbedtls_gcm_context m_ctx;
|
||||
mbedtls_gcm_init(&m_ctx);
|
||||
int success = mbedtls_gcm_setkey(&m_ctx, MBEDTLS_CIPHER_ID_AES, encryption_key, 128);
|
||||
if (0 != success) {
|
||||
return GCM_ENCRYPTION_KEY_FAILED;
|
||||
}
|
||||
if (0 < authkeylen) {
|
||||
success = mbedtls_gcm_auth_decrypt(&m_ctx, sizeof(cipher_text), initialization_vector, sizeof(initialization_vector),
|
||||
additional_authenticated_data, aadlen, authentication_tag, authkeylen,
|
||||
cipher_text, (unsigned char*)(ptr));
|
||||
if (authkeylen > 0 && success == MBEDTLS_ERR_GCM_AUTH_FAILED) {
|
||||
mbedtls_gcm_free(&m_ctx);
|
||||
return GCM_AUTH_FAILED;
|
||||
} else if(success == MBEDTLS_ERR_GCM_BAD_INPUT) {
|
||||
mbedtls_gcm_free(&m_ctx);
|
||||
return GCM_DECRYPT_FAILED;
|
||||
}
|
||||
} else {
|
||||
success = mbedtls_gcm_starts(&m_ctx, MBEDTLS_GCM_DECRYPT, initialization_vector, sizeof(initialization_vector),NULL, 0);
|
||||
if (0 != success) {
|
||||
mbedtls_gcm_free(&m_ctx);
|
||||
return GCM_DECRYPT_FAILED;
|
||||
}
|
||||
success = mbedtls_gcm_update(&m_ctx, sizeof(cipher_text), cipher_text, (unsigned char*)(ptr));
|
||||
if (0 != success) {
|
||||
mbedtls_gcm_free(&m_ctx);
|
||||
return GCM_DECRYPT_FAILED;
|
||||
}
|
||||
}
|
||||
mbedtls_gcm_free(&m_ctx);
|
||||
#endif
|
||||
|
||||
ctx.length -= footersize + headersize;
|
||||
return ptr-d;
|
||||
}
|
||||
27
src/ams/GcmParser.h
Normal file
27
src/ams/GcmParser.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef _GCMPARSER_H
|
||||
#define _GCMPARSER_H
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "DataParser.h"
|
||||
|
||||
#define GCM_TAG 0xDB
|
||||
#define GCM_AUTH_FAILED -51
|
||||
#define GCM_DECRYPT_FAILED -52
|
||||
#define GCM_ENCRYPTION_KEY_FAILED -53
|
||||
|
||||
typedef struct GCMSizeDef {
|
||||
uint8_t flag;
|
||||
uint16_t format;
|
||||
} __attribute__((packed)) GCMSizeDef;
|
||||
|
||||
|
||||
class GCMParser {
|
||||
public:
|
||||
GCMParser(uint8_t *encryption_key, uint8_t *authentication_key);
|
||||
int8_t parse(uint8_t *buf, DataParserContext &ctx);
|
||||
private:
|
||||
uint8_t encryption_key[16];
|
||||
uint8_t authentication_key[16];
|
||||
};
|
||||
|
||||
#endif
|
||||
58
src/ams/HdlcParser.cpp
Normal file
58
src/ams/HdlcParser.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
#include "HdlcParser.h"
|
||||
#include "lwip/def.h"
|
||||
#include "crc.h"
|
||||
|
||||
int8_t HDLCParser::parse(uint8_t *d, DataParserContext &ctx) {
|
||||
int len;
|
||||
|
||||
uint8_t flag = *d;
|
||||
|
||||
uint8_t* ptr;
|
||||
if(ctx.length < 3)
|
||||
return DATA_PARSE_INCOMPLETE;
|
||||
|
||||
HDLCHeader* h = (HDLCHeader*) d;
|
||||
ptr = (uint8_t*) &h[1];
|
||||
|
||||
// Frame format type 3
|
||||
if((h->format & 0xF0) == 0xA0) {
|
||||
// Length field (11 lsb of format)
|
||||
len = (ntohs(h->format) & 0x7FF) + 2;
|
||||
if(len > ctx.length)
|
||||
return DATA_PARSE_INCOMPLETE;
|
||||
|
||||
HDLCFooter* f = (HDLCFooter*) (d + len - sizeof *f);
|
||||
|
||||
// First and last byte should be HDLC_FLAG
|
||||
if(h->flag != HDLC_FLAG || f->flag != HDLC_FLAG)
|
||||
return DATA_PARSE_BOUNDRY_FLAG_MISSING;
|
||||
|
||||
// Verify FCS
|
||||
if(ntohs(f->fcs) != crc16_x25(d + 1, len - sizeof *f - 1))
|
||||
return DATA_PARSE_FOOTER_CHECKSUM_ERROR;
|
||||
|
||||
// Skip destination address, LSB marks last byte
|
||||
while(((*ptr) & 0x01) == 0x00) {
|
||||
ptr++;
|
||||
}
|
||||
ptr++;
|
||||
|
||||
// Skip source address, LSB marks last byte
|
||||
while(((*ptr) & 0x01) == 0x00) {
|
||||
ptr++;
|
||||
}
|
||||
ptr++;
|
||||
|
||||
HDLC3CtrlHcs* t3 = (HDLC3CtrlHcs*) (ptr);
|
||||
|
||||
// Verify HCS
|
||||
if(ntohs(t3->hcs) != crc16_x25(d + 1, ptr-d))
|
||||
return DATA_PARSE_HEADER_CHECKSUM_ERROR;
|
||||
ptr += 3;
|
||||
|
||||
// Exclude all of header and 3 byte footer
|
||||
ctx.length -= ptr-d+3;
|
||||
return ptr-d;
|
||||
}
|
||||
return DATA_PARSE_UNKNOWN_DATA;
|
||||
}
|
||||
29
src/ams/HdlcParser.h
Normal file
29
src/ams/HdlcParser.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef _HDLCPARSER_H
|
||||
#define _HDLCPARSER_H
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "DataParser.h"
|
||||
|
||||
#define HDLC_FLAG 0x7E
|
||||
|
||||
typedef struct HDLCHeader {
|
||||
uint8_t flag;
|
||||
uint16_t format;
|
||||
} __attribute__((packed)) HDLCHeader;
|
||||
|
||||
typedef struct HDLCFooter {
|
||||
uint16_t fcs;
|
||||
uint8_t flag;
|
||||
} __attribute__((packed)) HDLCFooter;
|
||||
|
||||
typedef struct HDLC3CtrlHcs {
|
||||
uint8_t control;
|
||||
uint16_t hcs;
|
||||
} __attribute__((packed)) HDLC3CtrlHcs;
|
||||
|
||||
class HDLCParser {
|
||||
public:
|
||||
int8_t parse(uint8_t *buf, DataParserContext &ctx);
|
||||
};
|
||||
|
||||
#endif
|
||||
7
src/ams/LlcParser.cpp
Normal file
7
src/ams/LlcParser.cpp
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "LlcParser.h"
|
||||
|
||||
int8_t LLCParser::parse(uint8_t *buf, DataParserContext &ctx) {
|
||||
LLCHeader* llc = (LLCHeader*) buf;
|
||||
ctx.length -= 3;
|
||||
return 3;
|
||||
}
|
||||
18
src/ams/LlcParser.h
Normal file
18
src/ams/LlcParser.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef _LLCPARSER_H
|
||||
#define _LLCPARSER_H
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "DataParser.h"
|
||||
|
||||
typedef struct LLCHeader {
|
||||
uint8_t dst;
|
||||
uint8_t src;
|
||||
uint8_t control;
|
||||
} __attribute__((packed)) LLCHeader;
|
||||
|
||||
class LLCParser {
|
||||
public:
|
||||
int8_t parse(uint8_t *buf, DataParserContext &ctx);
|
||||
};
|
||||
|
||||
#endif
|
||||
89
src/ams/MbusParser.cpp
Normal file
89
src/ams/MbusParser.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
#include "MbusParser.h"
|
||||
|
||||
int8_t MBUSParser::parse(uint8_t *d, DataParserContext &ctx) {
|
||||
int len;
|
||||
int headersize = 3;
|
||||
int footersize = 1;
|
||||
|
||||
uint8_t flag = *d;
|
||||
|
||||
uint8_t* ptr;
|
||||
|
||||
// https://m-bus.com/documentation-wired/06-application-layer
|
||||
if(ctx.length < 4)
|
||||
return DATA_PARSE_INCOMPLETE;
|
||||
|
||||
MbusHeader* mh = (MbusHeader*) d;
|
||||
if(mh->flag1 != MBUS_START || mh->flag2 != MBUS_START)
|
||||
return DATA_PARSE_BOUNDRY_FLAG_MISSING;
|
||||
|
||||
// First two bytes is 1-byte length value repeated. Only used for last segment
|
||||
if(mh->len1 != mh->len2)
|
||||
return MBUS_FRAME_LENGTH_NOT_EQUAL;
|
||||
len = mh->len1;
|
||||
ptr = (uint8_t*) &mh[1];
|
||||
headersize = 4;
|
||||
footersize = 2;
|
||||
|
||||
if(len == 0x00)
|
||||
len = ctx.length - headersize - footersize;
|
||||
// Payload can max be 255 bytes, so I think the following case is only valid for austrian meters
|
||||
if(len < headersize)
|
||||
len += 256;
|
||||
|
||||
if((headersize + footersize + len) > ctx.length)
|
||||
return DATA_PARSE_INCOMPLETE;
|
||||
|
||||
MbusFooter* mf = (MbusFooter*) (d + len + headersize);
|
||||
if(mf->flag != MBUS_END)
|
||||
return DATA_PARSE_BOUNDRY_FLAG_MISSING;
|
||||
if(checksum(d + headersize, len) != mf->fcs)
|
||||
return DATA_PARSE_FOOTER_CHECKSUM_ERROR;
|
||||
|
||||
ptr += 2; len -= 2;
|
||||
|
||||
// Control information field
|
||||
uint8_t ci = *ptr;
|
||||
|
||||
// Skip CI, STSAP and DTSAP
|
||||
ptr += 3; len -= 3;
|
||||
|
||||
// Bits 7 6 5 4 3 2 1 0
|
||||
// 0 0 0 Finished Sequence number
|
||||
uint8_t sequenceNumber = (ci & 0x0F);
|
||||
if((ci & 0x10) == 0x00) { // Not finished yet
|
||||
if(sequenceNumber == 0) {
|
||||
if(buf == NULL) buf = (uint8_t *)malloc((size_t)1024); // TODO find out from first package ?
|
||||
pos = 0;
|
||||
} else if(buf == NULL || pos + len > 1024 || sequenceNumber != (lastSequenceNumber + 1)) {
|
||||
return DATA_PARSE_FAIL;
|
||||
}
|
||||
memcpy(buf+pos, ptr, len);
|
||||
pos += len;
|
||||
lastSequenceNumber = sequenceNumber;
|
||||
return DATA_PARSE_INTERMEDIATE_SEGMENT;
|
||||
} else if(sequenceNumber > 0) { // This is the last frame of multiple, assembly needed
|
||||
if(buf == NULL || pos + len > 1024 || sequenceNumber != (lastSequenceNumber + 1)) {
|
||||
return DATA_PARSE_FAIL;
|
||||
}
|
||||
memcpy(buf+pos, ptr, len);
|
||||
pos += len;
|
||||
return DATA_PARSE_FINAL_SEGMENT;
|
||||
}
|
||||
return ptr-d;
|
||||
}
|
||||
|
||||
uint16_t MBUSParser::write(const uint8_t* d, DataParserContext &ctx) {
|
||||
if(buf != NULL) {
|
||||
memcpy((uint8_t *) d, buf, pos);
|
||||
ctx.length = pos;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t MBUSParser::checksum(const uint8_t* p, int len) {
|
||||
uint8_t ret = 0;
|
||||
while(len--)
|
||||
ret += *p++;
|
||||
return ret;
|
||||
}
|
||||
34
src/ams/MbusParser.h
Normal file
34
src/ams/MbusParser.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef _MBUSPARSER_H
|
||||
#define _MBUSPARSER_H
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "DataParser.h"
|
||||
|
||||
#define MBUS_START 0x68
|
||||
#define MBUS_END 0x16
|
||||
#define MBUS_FRAME_LENGTH_NOT_EQUAL -41
|
||||
|
||||
typedef struct MbusHeader {
|
||||
uint8_t flag1;
|
||||
uint8_t len1;
|
||||
uint8_t len2;
|
||||
uint8_t flag2;
|
||||
} __attribute__((packed)) MbusHeader;
|
||||
|
||||
typedef struct MbusFooter {
|
||||
uint8_t fcs;
|
||||
uint8_t flag;
|
||||
} __attribute__((packed)) MbusFooter;
|
||||
|
||||
class MBUSParser {
|
||||
public:
|
||||
int8_t parse(uint8_t *buf, DataParserContext &ctx);
|
||||
uint16_t write(const uint8_t* d, DataParserContext &ctx);
|
||||
private:
|
||||
uint8_t lastSequenceNumber = 0;
|
||||
uint16_t pos = 0;
|
||||
uint8_t *buf = NULL;
|
||||
uint8_t checksum(const uint8_t* p, int len);
|
||||
};
|
||||
|
||||
#endif
|
||||
308
src/ams/hdlc.cpp
308
src/ams/hdlc.cpp
@@ -1,308 +0,0 @@
|
||||
#include "Arduino.h"
|
||||
#include "hdlc.h"
|
||||
#include "crc.h"
|
||||
#include "lwip/def.h"
|
||||
#if defined(ESP8266)
|
||||
#include "bearssl/bearssl.h"
|
||||
#elif defined(ESP32)
|
||||
#include "mbedtls/gcm.h"
|
||||
#endif
|
||||
|
||||
void mbus_hexdump(const uint8_t* buf, int len) {
|
||||
printf("\nDUMP (%db) [ ", len);
|
||||
for(const uint8_t* p = buf; p-buf < len; ++p)
|
||||
printf("%02X ", *p);
|
||||
printf("]\n");
|
||||
}
|
||||
|
||||
int HDLC_validate(const uint8_t* d, int length, HDLCConfig* config, CosemDateTime* timestamp) {
|
||||
int len;
|
||||
int headersize = 3;
|
||||
int footersize = 1;
|
||||
|
||||
uint8_t flag = *d;
|
||||
|
||||
uint8_t* ptr;
|
||||
if(flag == HDLC_FLAG) {
|
||||
if(length < 3)
|
||||
return HDLC_FRAME_INCOMPLETE;
|
||||
|
||||
HDLCHeader* h = (HDLCHeader*) d;
|
||||
ptr = (uint8_t*) &h[1];
|
||||
|
||||
// Frame format type 3
|
||||
if((h->format & 0xF0) == 0xA0) {
|
||||
// Length field (11 lsb of format)
|
||||
len = (ntohs(h->format) & 0x7FF) + 2;
|
||||
if(len > length)
|
||||
return HDLC_FRAME_INCOMPLETE;
|
||||
|
||||
HDLCFooter* f = (HDLCFooter*) (d + len - sizeof *f);
|
||||
footersize = sizeof *f;
|
||||
|
||||
// First and last byte should be MBUS_HAN_TAG
|
||||
if(h->flag != HDLC_FLAG || f->flag != HDLC_FLAG)
|
||||
return HDLC_BOUNDRY_FLAG_MISSING;
|
||||
|
||||
// Verify FCS
|
||||
if(ntohs(f->fcs) != crc16_x25(d + 1, len - sizeof *f - 1))
|
||||
return HDLC_FCS_ERROR;
|
||||
|
||||
// Skip destination address, LSB marks last byte
|
||||
while(((*ptr) & 0x01) == 0x00) {
|
||||
ptr++;
|
||||
headersize++;
|
||||
}
|
||||
headersize++;
|
||||
ptr++;
|
||||
|
||||
// Skip source address, LSB marks last byte
|
||||
while(((*ptr) & 0x01) == 0x00) {
|
||||
ptr++;
|
||||
headersize++;
|
||||
}
|
||||
headersize++;
|
||||
ptr++;
|
||||
|
||||
HDLC3CtrlHcs* t3 = (HDLC3CtrlHcs*) (ptr);
|
||||
headersize += 3;
|
||||
|
||||
// Verify HCS
|
||||
if(ntohs(t3->hcs) != crc16_x25(d + 1, ptr-d))
|
||||
return HDLC_HCS_ERROR;
|
||||
|
||||
ptr += sizeof *t3;
|
||||
|
||||
// Extract LLC
|
||||
HDLCLLC* llc = (HDLCLLC*) ptr;
|
||||
ptr += sizeof *llc;
|
||||
headersize += sizeof *llc;
|
||||
} else {
|
||||
return HDLC_UNKNOWN_DATA;
|
||||
}
|
||||
} else if(flag == MBUS_START) {
|
||||
// https://m-bus.com/documentation-wired/06-application-layer
|
||||
if(length < 4)
|
||||
return HDLC_FRAME_INCOMPLETE;
|
||||
|
||||
MbusHeader* mh = (MbusHeader*) d;
|
||||
if(mh->flag1 != MBUS_START || mh->flag2 != MBUS_START)
|
||||
return MBUS_BOUNDRY_FLAG_MISSING;
|
||||
|
||||
// First two bytes is 1-byte length value repeated. Only used for last segment
|
||||
if(mh->len1 != mh->len2)
|
||||
return MBUS_FRAME_LENGTH_NOT_EQUAL;
|
||||
len = mh->len1;
|
||||
ptr = (uint8_t*) &mh[1];
|
||||
headersize = 4;
|
||||
footersize = 2;
|
||||
|
||||
if(len == 0x00)
|
||||
len = length - headersize - footersize;
|
||||
// Payload can max be 255 bytes, so I think the following case is only valid for austrian meters
|
||||
if(len < headersize)
|
||||
len += 256;
|
||||
|
||||
if((headersize + footersize + len) > length)
|
||||
return HDLC_FRAME_INCOMPLETE;
|
||||
|
||||
MbusFooter* mf = (MbusFooter*) (d + len + headersize);
|
||||
if(mf->flag != MBUS_END)
|
||||
return MBUS_BOUNDRY_FLAG_MISSING;
|
||||
if(mbusChecksum(d + headersize, len) != mf->fcs)
|
||||
return MBUS_CHECKSUM_ERROR;
|
||||
|
||||
ptr += 2;
|
||||
|
||||
// Control information field
|
||||
uint8_t ci = *ptr;
|
||||
|
||||
// Bits 7 6 5 4 3 2 1 0
|
||||
// 0 0 0 Finished Sequence number
|
||||
uint8_t sequenceNumber = (ci & 0x0F);
|
||||
if((ci & 0x10) == 0x00) { // Not finished yet
|
||||
return MBUS_FRAME_INTERMEDIATE_SEGMENT;
|
||||
} else if(sequenceNumber > 0) { // This is the last frame of multiple, assembly needed
|
||||
return MBUS_FRAME_LAST_SEGMENT;
|
||||
}
|
||||
|
||||
// Skip CI, STSAP and DTSAP
|
||||
ptr += 3;
|
||||
headersize += 5; // And also control and address that we didn't skip earlier, needed these for checksum.
|
||||
} else {
|
||||
return HDLC_UNKNOWN_DATA;
|
||||
}
|
||||
|
||||
if(((*ptr) & 0xFF) == 0x0F) {
|
||||
// Unencrypted APDU
|
||||
HDLCADPU* adpu = (HDLCADPU*) (ptr);
|
||||
ptr += sizeof *adpu;
|
||||
|
||||
// ADPU timestamp
|
||||
CosemData* dateTime = (CosemData*) ptr;
|
||||
if(dateTime->base.type == CosemTypeOctetString) {
|
||||
if(dateTime->base.length == 0x0C) {
|
||||
memcpy(timestamp, ptr+1, dateTime->base.length+1);
|
||||
}
|
||||
ptr += 2 + dateTime->base.length;
|
||||
} else if(dateTime->base.type == CosemTypeNull) {
|
||||
timestamp = 0;
|
||||
ptr++;
|
||||
} else if(dateTime->base.type == CosemTypeDateTime) {
|
||||
memcpy(timestamp, ptr, dateTime->base.length);
|
||||
} else if(dateTime->base.type == 0x0C) { // Kamstrup bug...
|
||||
memcpy(timestamp, ptr, 13);
|
||||
ptr += 13;
|
||||
} else {
|
||||
return HDLC_TIMESTAMP_UNKNOWN;
|
||||
}
|
||||
|
||||
return ptr-d;
|
||||
} else if(((*ptr) & 0xFF) == 0xDB) {
|
||||
if(length < headersize + 18)
|
||||
return HDLC_FRAME_INCOMPLETE;
|
||||
|
||||
ptr++;
|
||||
// Encrypted APDU
|
||||
// http://www.weigu.lu/tutorials/sensors2bus/04_encryption/index.html
|
||||
if(config == NULL)
|
||||
return HDLC_ENCRYPTION_CONFIG_MISSING;
|
||||
|
||||
uint8_t systemTitleLength = *ptr;
|
||||
ptr++;
|
||||
memcpy(config->system_title, ptr, systemTitleLength);
|
||||
memcpy(config->initialization_vector, config->system_title, systemTitleLength);
|
||||
|
||||
headersize += 2 + systemTitleLength;
|
||||
ptr += systemTitleLength;
|
||||
if(((*ptr) & 0xFF) == 0x81) {
|
||||
ptr++;
|
||||
len = *ptr;
|
||||
// 1-byte payload length
|
||||
ptr++;
|
||||
headersize += 2;
|
||||
} else if(((*ptr) & 0xFF) == 0x82) {
|
||||
HDLCHeader* h = (HDLCHeader*) ptr;
|
||||
|
||||
// 2-byte payload length
|
||||
len = (ntohs(h->format) & 0xFFFF);
|
||||
|
||||
ptr += 3;
|
||||
headersize += 3;
|
||||
}
|
||||
if(len + headersize + footersize > length)
|
||||
return HDLC_FRAME_INCOMPLETE;
|
||||
|
||||
//Serial.printf("\nL: %d : %d, %d : %d\n", length, len, headersize, footersize);
|
||||
|
||||
memcpy(config->additional_authenticated_data, ptr, 1);
|
||||
|
||||
// Security tag
|
||||
uint8_t sec = *ptr;
|
||||
ptr++;
|
||||
headersize++;
|
||||
|
||||
// Frame counter
|
||||
memcpy(config->initialization_vector + 8, ptr, 4);
|
||||
ptr += 4;
|
||||
headersize += 4;
|
||||
|
||||
// Authentication enabled
|
||||
uint8_t authkeylen = 0, aadlen = 0;
|
||||
if((sec & 0x10) == 0x10) {
|
||||
authkeylen = 12;
|
||||
aadlen = 17;
|
||||
footersize += authkeylen;
|
||||
memcpy(config->additional_authenticated_data + 1, config->authentication_key, 16);
|
||||
memcpy(config->authentication_tag, ptr + len - footersize - 2, authkeylen);
|
||||
}
|
||||
|
||||
#if defined(ESP8266)
|
||||
br_gcm_context gcmCtx;
|
||||
br_aes_ct_ctr_keys bc;
|
||||
br_aes_ct_ctr_init(&bc, config->encryption_key, 16);
|
||||
br_gcm_init(&gcmCtx, &bc.vtable, br_ghash_ctmul32);
|
||||
br_gcm_reset(&gcmCtx, config->initialization_vector, sizeof(config->initialization_vector));
|
||||
if(authkeylen > 0) {
|
||||
br_gcm_aad_inject(&gcmCtx, config->additional_authenticated_data, aadlen);
|
||||
}
|
||||
br_gcm_flip(&gcmCtx);
|
||||
br_gcm_run(&gcmCtx, 0, (void*) (ptr), len - authkeylen - 5); // 5 == security tag and frame counter
|
||||
if(authkeylen > 0 && br_gcm_check_tag_trunc(&gcmCtx, config->authentication_tag, authkeylen) != 1) {
|
||||
return HDLC_ENCRYPTION_AUTH_FAILED;
|
||||
}
|
||||
#elif defined(ESP32)
|
||||
uint8_t cipher_text[len - authkeylen - 5];
|
||||
memcpy(cipher_text, ptr, len - authkeylen - 5);
|
||||
|
||||
mbedtls_gcm_context m_ctx;
|
||||
mbedtls_gcm_init(&m_ctx);
|
||||
int success = mbedtls_gcm_setkey(&m_ctx, MBEDTLS_CIPHER_ID_AES, config->encryption_key, 128);
|
||||
if (0 != success) {
|
||||
return HDLC_ENCRYPTION_KEY_FAILED;
|
||||
}
|
||||
if (0 < authkeylen) {
|
||||
success = mbedtls_gcm_auth_decrypt(&m_ctx, sizeof(cipher_text), config->initialization_vector, sizeof(config->initialization_vector),
|
||||
config->additional_authenticated_data, aadlen, config->authentication_tag, authkeylen,
|
||||
cipher_text, (unsigned char*)(ptr));
|
||||
if (authkeylen > 0 && success == MBEDTLS_ERR_GCM_AUTH_FAILED) {
|
||||
mbedtls_gcm_free(&m_ctx);
|
||||
return HDLC_ENCRYPTION_AUTH_FAILED;
|
||||
} else if(success == MBEDTLS_ERR_GCM_BAD_INPUT) {
|
||||
mbedtls_gcm_free(&m_ctx);
|
||||
return HDLC_ENCRYPTION_DECRYPT_FAILED;
|
||||
}
|
||||
} else {
|
||||
success = mbedtls_gcm_starts(&m_ctx, MBEDTLS_GCM_DECRYPT, config->initialization_vector, sizeof(config->initialization_vector),NULL, 0);
|
||||
if (0 != success) {
|
||||
mbedtls_gcm_free(&m_ctx);
|
||||
return HDLC_ENCRYPTION_DECRYPT_FAILED;
|
||||
}
|
||||
success = mbedtls_gcm_update(&m_ctx, sizeof(cipher_text), cipher_text, (unsigned char*)(ptr));
|
||||
if (0 != success) {
|
||||
mbedtls_gcm_free(&m_ctx);
|
||||
return HDLC_ENCRYPTION_DECRYPT_FAILED;
|
||||
}
|
||||
}
|
||||
mbedtls_gcm_free(&m_ctx);
|
||||
#endif
|
||||
|
||||
HDLCADPU* adpu = (HDLCADPU*) (ptr);
|
||||
ptr += sizeof *adpu;
|
||||
|
||||
// ADPU timestamp
|
||||
CosemData* dateTime = (CosemData*) ptr;
|
||||
if(dateTime->base.type == CosemTypeOctetString) {
|
||||
if(dateTime->base.length == 0x0C) {
|
||||
memcpy(timestamp, ptr+1, dateTime->base.length);
|
||||
}
|
||||
ptr += 2 + dateTime->base.length;
|
||||
} else if(dateTime->base.type == CosemTypeNull) {
|
||||
timestamp = 0;
|
||||
ptr++;
|
||||
} else if(dateTime->base.type == CosemTypeDateTime) {
|
||||
memcpy(timestamp, ptr, dateTime->base.length);
|
||||
} else if(dateTime->base.type == 0x0C) { // Kamstrup bug...
|
||||
memcpy(timestamp, ptr, 13);
|
||||
ptr += 13;
|
||||
} else {
|
||||
return HDLC_TIMESTAMP_UNKNOWN;
|
||||
}
|
||||
|
||||
return ptr-d;
|
||||
}
|
||||
|
||||
// Unknown payload
|
||||
return HDLC_UNKNOWN_DATA;
|
||||
}
|
||||
|
||||
uint8_t mbusChecksum(const uint8_t* p, int len) {
|
||||
uint8_t ret = 0;
|
||||
while(len--)
|
||||
ret += *p++;
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint64_t ntohll(uint64_t x) {
|
||||
return (((uint64_t)ntohl((uint32_t)x)) << 32) + ntohl(x >> 32);
|
||||
}
|
||||
167
src/ams/hdlc.h
167
src/ams/hdlc.h
@@ -1,167 +0,0 @@
|
||||
#ifndef _HDLC_H
|
||||
#define _HDLC_H
|
||||
|
||||
#include "Arduino.h"
|
||||
#include <stdint.h>
|
||||
#include "lwip/def.h"
|
||||
|
||||
#define HDLC_FLAG 0x7E
|
||||
#define HDLC_BOUNDRY_FLAG_MISSING -1
|
||||
#define HDLC_FCS_ERROR -2
|
||||
#define HDLC_HCS_ERROR -3
|
||||
#define HDLC_FRAME_INCOMPLETE -4
|
||||
#define HDLC_UNKNOWN_DATA -9
|
||||
#define HDLC_ENCRYPTION_CONFIG_MISSING -90
|
||||
#define HDLC_ENCRYPTION_AUTH_FAILED -91
|
||||
#define HDLC_ENCRYPTION_KEY_FAILED -92
|
||||
#define HDLC_ENCRYPTION_DECRYPT_FAILED -93
|
||||
#define HDLC_TIMESTAMP_UNKNOWN -99
|
||||
|
||||
#define MBUS_START 0x68
|
||||
#define MBUS_END 0x16
|
||||
#define MBUS_BOUNDRY_FLAG_MISSING -1
|
||||
#define MBUS_FRAME_LENGTH_NOT_EQUAL -40
|
||||
#define MBUS_FRAME_INTERMEDIATE_SEGMENT -41
|
||||
#define MBUS_FRAME_LAST_SEGMENT -42
|
||||
#define MBUS_CHECKSUM_ERROR -2
|
||||
|
||||
struct HDLCConfig {
|
||||
uint8_t encryption_key[32];
|
||||
uint8_t authentication_key[32];
|
||||
uint8_t system_title[8];
|
||||
uint8_t initialization_vector[12];
|
||||
uint8_t additional_authenticated_data[17];
|
||||
uint8_t authentication_tag[12];
|
||||
};
|
||||
|
||||
typedef struct HDLCHeader {
|
||||
uint8_t flag;
|
||||
uint16_t format;
|
||||
} __attribute__((packed)) HDLCHeader;
|
||||
|
||||
typedef struct HDLCFooter {
|
||||
uint16_t fcs;
|
||||
uint8_t flag;
|
||||
} __attribute__((packed)) HDLCFooter;
|
||||
|
||||
typedef struct HDLC3CtrlHcs {
|
||||
uint8_t control;
|
||||
uint16_t hcs;
|
||||
} __attribute__((packed)) HDLC3CtrlHcs;
|
||||
|
||||
typedef struct HDLCLLC {
|
||||
uint8_t dst;
|
||||
uint8_t src;
|
||||
uint8_t control;
|
||||
} __attribute__((packed)) HDLCLLC;
|
||||
|
||||
typedef struct HDLCADPU {
|
||||
uint8_t flag;
|
||||
uint32_t id;
|
||||
} __attribute__((packed)) HDLCADPU;
|
||||
|
||||
typedef struct MbusHeader {
|
||||
uint8_t flag1;
|
||||
uint8_t len1;
|
||||
uint8_t len2;
|
||||
uint8_t flag2;
|
||||
} __attribute__((packed)) MbusHeader;
|
||||
|
||||
typedef struct MbusFooter {
|
||||
uint8_t fcs;
|
||||
uint8_t flag;
|
||||
} __attribute__((packed)) MbusFooter;
|
||||
|
||||
|
||||
// Blue book, Table 2
|
||||
enum CosemType {
|
||||
CosemTypeNull = 0x00,
|
||||
CosemTypeArray = 0x01,
|
||||
CosemTypeStructure = 0x02,
|
||||
CosemTypeOctetString = 0x09,
|
||||
CosemTypeString = 0x0A,
|
||||
CosemTypeDLongSigned = 0x05,
|
||||
CosemTypeDLongUnsigned = 0x06,
|
||||
CosemTypeLongSigned = 0x10,
|
||||
CosemTypeLongUnsigned = 0x12,
|
||||
CosemTypeLong64Signed = 0x14,
|
||||
CosemTypeLong64Unsigned = 0x15,
|
||||
CosemTypeDateTime = 0x19
|
||||
};
|
||||
|
||||
struct CosemBasic {
|
||||
uint8_t type;
|
||||
uint8_t length;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct CosemString {
|
||||
uint8_t type;
|
||||
uint8_t length;
|
||||
uint8_t data[];
|
||||
} __attribute__((packed));
|
||||
|
||||
struct CosemLongSigned {
|
||||
uint8_t type;
|
||||
int16_t data;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct CosemLongUnsigned {
|
||||
uint8_t type;
|
||||
uint16_t data;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct CosemDLongSigned {
|
||||
uint8_t type;
|
||||
int32_t data;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct CosemDLongUnsigned {
|
||||
uint8_t type;
|
||||
uint32_t data;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct CosemLong64Signed {
|
||||
uint8_t type;
|
||||
int64_t data;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct CosemLong64Unsigned {
|
||||
uint8_t type;
|
||||
uint64_t data;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct CosemDateTime {
|
||||
uint8_t type;
|
||||
uint16_t year;
|
||||
uint8_t month;
|
||||
uint8_t dayOfMonth;
|
||||
uint8_t dayOfWeek;
|
||||
uint8_t hour;
|
||||
uint8_t minute;
|
||||
uint8_t second;
|
||||
uint8_t hundredths;
|
||||
int16_t deviation;
|
||||
uint8_t status;
|
||||
} __attribute__((packed));
|
||||
|
||||
typedef union {
|
||||
struct CosemBasic base;
|
||||
struct CosemString str;
|
||||
struct CosemString oct;
|
||||
struct CosemLongSigned ls;
|
||||
struct CosemLongUnsigned lu;
|
||||
struct CosemDLongSigned dls;
|
||||
struct CosemDLongUnsigned dlu;
|
||||
struct CosemLong64Signed l64s;
|
||||
struct CosemLong64Unsigned l64u;
|
||||
struct CosemDateTime dt;
|
||||
} CosemData;
|
||||
|
||||
void mbus_hexdump(const uint8_t* buf, int len);
|
||||
int HDLC_validate(const uint8_t* d, int len, HDLCConfig* config, CosemDateTime* timestamp);
|
||||
|
||||
uint8_t mbusChecksum(const uint8_t* p, int len);
|
||||
|
||||
uint64_t ntohll(uint64_t x);
|
||||
|
||||
#endif
|
||||
5
src/ams/ntohll.cpp
Normal file
5
src/ams/ntohll.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
#include "ntohll.h"
|
||||
|
||||
uint64_t ntohll(uint64_t x) {
|
||||
return (((uint64_t)ntohl((uint32_t)x)) << 32) + ntohl(x >> 32);
|
||||
}
|
||||
8
src/ams/ntohll.h
Normal file
8
src/ams/ntohll.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef _NTOHLL_H
|
||||
#define _NTOHLL_H
|
||||
|
||||
#include "lwip/def.h"
|
||||
|
||||
uint64_t ntohll(uint64_t x);
|
||||
|
||||
#endif
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "DnbCurrParser.h"
|
||||
#include "Arduino.h"
|
||||
#include "HardwareSerial.h"
|
||||
|
||||
float DnbCurrParser::getValue() {
|
||||
return value;
|
||||
@@ -30,13 +29,14 @@ size_t DnbCurrParser::write(const uint8_t *buffer, size_t size) {
|
||||
}
|
||||
|
||||
size_t DnbCurrParser::write(uint8_t byte) {
|
||||
if(pos >= 64) pos = 0;
|
||||
if(pos >= 128) pos = 0;
|
||||
if(pos == 0) {
|
||||
if(byte == '<') {
|
||||
buf[pos++] = byte;
|
||||
}
|
||||
} else if(byte == '>') {
|
||||
buf[pos++] = byte;
|
||||
buf[pos++] = '\0';
|
||||
if(strncmp(buf, "<Series", 7) == 0) {
|
||||
for(int i = 0; i < pos; i++) {
|
||||
if(strncmp(buf+i, "UNIT_MULT=\"", 11) == 0) {
|
||||
|
||||
@@ -18,7 +18,7 @@ private:
|
||||
uint8_t scale = 0;
|
||||
float value = 1.0;
|
||||
|
||||
char buf[64];
|
||||
char buf[128];
|
||||
uint8_t pos = 0;
|
||||
uint8_t mode = 0;
|
||||
};
|
||||
|
||||
@@ -27,7 +27,10 @@ void EntsoeApi::setup(EntsoeConfig& config) {
|
||||
this->config = new EntsoeConfig();
|
||||
}
|
||||
memcpy(this->config, &config, sizeof(config));
|
||||
lastCurrencyFetch = 0;
|
||||
lastTodayFetch = lastTomorrowFetch = lastCurrencyFetch = 0;
|
||||
if(today != NULL) delete today;
|
||||
if(tomorrow != NULL) delete tomorrow;
|
||||
today = tomorrow = NULL;
|
||||
}
|
||||
|
||||
char* EntsoeApi::getToken() {
|
||||
@@ -91,34 +94,39 @@ bool EntsoeApi::loop() {
|
||||
|
||||
time_t t = time(nullptr);
|
||||
if(t < BUILD_EPOCH) return false;
|
||||
|
||||
bool ret = false;
|
||||
tmElements_t tm;
|
||||
breakTime(tz->toLocal(t), tm);
|
||||
if(currentHour != tm.Hour) {
|
||||
currentHour = tm.Hour;
|
||||
ret = today != NULL; // Only trigger MQTT publish if we have todays prices.
|
||||
}
|
||||
|
||||
if(midnightMillis == 0) {
|
||||
if(t <= 0) return false; // NTP not ready
|
||||
|
||||
time_t epoch = tz->toLocal(t);
|
||||
|
||||
breakTime(epoch, tm);
|
||||
if(tm.Year > 50) { // Make sure we are in 2021 or later (years after 1970)
|
||||
uint32_t curDayMillis = (((((tm.Hour * 60) + tm.Minute) * 60) + tm.Second) * 1000);
|
||||
|
||||
midnightMillis = now + (SECS_PER_DAY * 1000) - curDayMillis + 1000; // Adding 1s to ensure we have passed midnight
|
||||
if(debugger->isActive(RemoteDebug::INFO)) debugger->printf("(EntsoeApi) Setting midnight millis %lu\n", midnightMillis);
|
||||
}
|
||||
} else if(now > midnightMillis) {
|
||||
uint32_t curDayMillis = (((((tm.Hour * 60) + tm.Minute) * 60) + tm.Second) * 1000);
|
||||
midnightMillis = now + (SECS_PER_DAY * 1000) - curDayMillis;
|
||||
if(debugger->isActive(RemoteDebug::INFO)) debugger->printf("(EntsoeApi) Setting midnight millis %lu\n", midnightMillis);
|
||||
currentDay = tm.Day;
|
||||
return false;
|
||||
} else if(now > midnightMillis && currentDay != tm.Day) {
|
||||
if(debugger->isActive(RemoteDebug::INFO)) debugger->printf("(EntsoeApi) Rotating price objects at %lu\n", t);
|
||||
delete today;
|
||||
today = tomorrow;
|
||||
tomorrow = NULL;
|
||||
if(today != NULL) delete today;
|
||||
if(tomorrow != NULL) {
|
||||
today = tomorrow;
|
||||
tomorrow = NULL;
|
||||
}
|
||||
currentDay = tm.Day;
|
||||
midnightMillis = 0; // Force new midnight millis calculation
|
||||
return true;
|
||||
} else {
|
||||
breakTime(t, tm);
|
||||
breakTime(t, tm); // Break UTC to find UTC midnight
|
||||
if(today == NULL && (lastTodayFetch == 0 || now - lastTodayFetch > 60000)) {
|
||||
lastTodayFetch = now;
|
||||
time_t e1 = t - (tm.Hour * 3600) - (tm.Minute * 60) - tm.Second;
|
||||
time_t e1 = t - (tm.Hour * 3600) - (tm.Minute * 60) - tm.Second; // UTC midnight
|
||||
time_t e2 = e1 + SECS_PER_DAY;
|
||||
tmElements_t d1, d2;
|
||||
breakTime(tz->toUTC(e1), d1);
|
||||
breakTime(tz->toUTC(e1), d1); // To get day and hour for CET/CEST at UTC midnight
|
||||
breakTime(tz->toUTC(e2), d2);
|
||||
|
||||
snprintf(buf, BufferSize, "%s?securityToken=%s&documentType=A44&periodStart=%04d%02d%02d%02d%02d&periodEnd=%04d%02d%02d%02d%02d&in_Domain=%s&out_Domain=%s",
|
||||
@@ -185,7 +193,7 @@ bool EntsoeApi::loop() {
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool EntsoeApi::retrieve(const char* url, Stream* doc) {
|
||||
|
||||
@@ -32,6 +32,7 @@ private:
|
||||
RemoteDebug* debugger;
|
||||
EntsoeConfig* config = NULL;
|
||||
|
||||
uint8_t currentDay = 0, currentHour = 0;
|
||||
uint32_t tomorrowFetchMillis = 36000000; // Number of ms before midnight. Default fetch 10hrs before midnight (14:00 CE(S)T)
|
||||
uint64_t midnightMillis = 0;
|
||||
uint64_t lastTodayFetch = 0;
|
||||
|
||||
@@ -25,6 +25,8 @@ bool HomeAssistantMqttHandler::publish(AmsData* data, AmsData* previousState, En
|
||||
);
|
||||
mqtt->publish(topic + "/energy", json);
|
||||
}
|
||||
String meterModel = data->getMeterModel();
|
||||
meterModel.replace("\\", "\\\\");
|
||||
if(data->getListType() == 1) { // publish power counts
|
||||
snprintf_P(json, BufferSize, HA1_JSON,
|
||||
data->getActiveImportPower()
|
||||
@@ -34,7 +36,7 @@ bool HomeAssistantMqttHandler::publish(AmsData* data, AmsData* previousState, En
|
||||
snprintf_P(json, BufferSize, HA3_JSON,
|
||||
data->getListId().c_str(),
|
||||
data->getMeterId().c_str(),
|
||||
data->getMeterModel().c_str(),
|
||||
meterModel.c_str(),
|
||||
data->getActiveImportPower(),
|
||||
data->getReactiveImportPower(),
|
||||
data->getActiveExportPower(),
|
||||
@@ -92,7 +94,8 @@ bool HomeAssistantMqttHandler::publishPrices(EntsoeApi* eapi) {
|
||||
float min1hr, min3hr, min6hr;
|
||||
int8_t min1hrIdx = -1, min3hrIdx = -1, min6hrIdx = -1;
|
||||
float min = INT16_MAX, max = INT16_MIN;
|
||||
float values[24] = {0};
|
||||
float values[24];
|
||||
for(int i = 0;i < 24; i++) values[i] = ENTSOE_NO_VALUE;
|
||||
for(uint8_t i = 0; i < 24; i++) {
|
||||
float val = eapi->getValueForHour(now, i);
|
||||
values[i] = val;
|
||||
|
||||
@@ -12,6 +12,8 @@ bool JsonMqttHandler::publish(AmsData* data, AmsData* previousState, EnergyAccou
|
||||
if(topic.isEmpty() || !mqtt->connected())
|
||||
return false;
|
||||
|
||||
String meterModel = data->getMeterModel();
|
||||
meterModel.replace("\\", "\\\\");
|
||||
if(data->getListType() == 1) {
|
||||
snprintf_P(json, BufferSize, JSON1_JSON,
|
||||
WiFi.macAddress().c_str(),
|
||||
@@ -24,7 +26,8 @@ bool JsonMqttHandler::publish(AmsData* data, AmsData* previousState, EnergyAccou
|
||||
data->getActiveImportPower(),
|
||||
ea->getUseThisHour(),
|
||||
ea->getUseToday(),
|
||||
ea->getCurrentThreshold()
|
||||
ea->getCurrentThreshold(),
|
||||
ea->getMonthMax()
|
||||
);
|
||||
return mqtt->publish(topic, json);
|
||||
} else if(data->getListType() == 2) {
|
||||
@@ -38,7 +41,7 @@ bool JsonMqttHandler::publish(AmsData* data, AmsData* previousState, EnergyAccou
|
||||
hw->getTemperature(),
|
||||
data->getListId().c_str(),
|
||||
data->getMeterId().c_str(),
|
||||
data->getMeterModel().c_str(),
|
||||
meterModel.c_str(),
|
||||
data->getActiveImportPower(),
|
||||
data->getReactiveImportPower(),
|
||||
data->getActiveExportPower(),
|
||||
@@ -51,7 +54,8 @@ bool JsonMqttHandler::publish(AmsData* data, AmsData* previousState, EnergyAccou
|
||||
data->getL3Voltage(),
|
||||
ea->getUseThisHour(),
|
||||
ea->getUseToday(),
|
||||
ea->getCurrentThreshold()
|
||||
ea->getCurrentThreshold(),
|
||||
ea->getMonthMax()
|
||||
);
|
||||
return mqtt->publish(topic, json);
|
||||
} else if(data->getListType() == 3) {
|
||||
@@ -65,7 +69,7 @@ bool JsonMqttHandler::publish(AmsData* data, AmsData* previousState, EnergyAccou
|
||||
hw->getTemperature(),
|
||||
data->getListId().c_str(),
|
||||
data->getMeterId().c_str(),
|
||||
data->getMeterModel().c_str(),
|
||||
meterModel.c_str(),
|
||||
data->getActiveImportPower(),
|
||||
data->getReactiveImportPower(),
|
||||
data->getActiveExportPower(),
|
||||
@@ -83,7 +87,8 @@ bool JsonMqttHandler::publish(AmsData* data, AmsData* previousState, EnergyAccou
|
||||
data->getMeterTimestamp(),
|
||||
ea->getUseThisHour(),
|
||||
ea->getUseToday(),
|
||||
ea->getCurrentThreshold()
|
||||
ea->getCurrentThreshold(),
|
||||
ea->getMonthMax()
|
||||
);
|
||||
return mqtt->publish(topic, json);
|
||||
} else if(data->getListType() == 4) {
|
||||
@@ -97,7 +102,7 @@ bool JsonMqttHandler::publish(AmsData* data, AmsData* previousState, EnergyAccou
|
||||
hw->getTemperature(),
|
||||
data->getListId().c_str(),
|
||||
data->getMeterId().c_str(),
|
||||
data->getMeterModel().c_str(),
|
||||
meterModel.c_str(),
|
||||
data->getActiveImportPower(),
|
||||
data->getReactiveImportPower(),
|
||||
data->getActiveExportPower(),
|
||||
@@ -119,7 +124,8 @@ bool JsonMqttHandler::publish(AmsData* data, AmsData* previousState, EnergyAccou
|
||||
data->getMeterTimestamp(),
|
||||
ea->getUseThisHour(),
|
||||
ea->getUseToday(),
|
||||
ea->getCurrentThreshold()
|
||||
ea->getCurrentThreshold(),
|
||||
ea->getMonthMax()
|
||||
);
|
||||
return mqtt->publish(topic, json);
|
||||
}
|
||||
@@ -161,7 +167,8 @@ bool JsonMqttHandler::publishPrices(EntsoeApi* eapi) {
|
||||
float min1hr, min3hr, min6hr;
|
||||
int8_t min1hrIdx = -1, min3hrIdx = -1, min6hrIdx = -1;
|
||||
float min = INT16_MAX, max = INT16_MIN;
|
||||
float values[24] = {0};
|
||||
float values[24];
|
||||
for(int i = 0;i < 24; i++) values[i] = ENTSOE_NO_VALUE;
|
||||
for(uint8_t i = 0; i < 24; i++) {
|
||||
float val = eapi->getValueForHour(now, i);
|
||||
values[i] = val;
|
||||
|
||||
@@ -75,6 +75,7 @@ bool RawMqttHandler::publish(AmsData* data, AmsData* meterState, EnergyAccountin
|
||||
mqtt->publish(topic + "/realtime/import/hour", String(ea->getUseThisHour(), 3));
|
||||
mqtt->publish(topic + "/realtime/import/day", String(ea->getUseToday(), 2));
|
||||
mqtt->publish(topic + "/realtime/import/threshold", String(ea->getCurrentThreshold(), 10), true, 0);
|
||||
mqtt->publish(topic + "/realtime/import/monthmax", String(ea->getMonthMax(), 3), true, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -103,8 +104,8 @@ bool RawMqttHandler::publishPrices(EntsoeApi* eapi) {
|
||||
float min1hr, min3hr, min6hr;
|
||||
int8_t min1hrIdx = -1, min3hrIdx = -1, min6hrIdx = -1;
|
||||
float min = INT16_MAX, max = INT16_MIN;
|
||||
float values[34] = {0};
|
||||
memset(values, ENTSOE_NO_VALUE, 34);
|
||||
float values[34];
|
||||
for(int i = 0;i < 34; i++) values[i] = ENTSOE_NO_VALUE;
|
||||
for(uint8_t i = 0; i < 34; i++) {
|
||||
float val = eapi->getValueForHour(now, i);
|
||||
values[i] = val;
|
||||
@@ -180,7 +181,6 @@ bool RawMqttHandler::publishPrices(EntsoeApi* eapi) {
|
||||
float val = values[i];
|
||||
if(val == ENTSOE_NO_VALUE) {
|
||||
mqtt->publish(topic + "/price/" + String(i), "", true, 0);
|
||||
break;
|
||||
} else {
|
||||
mqtt->publish(topic + "/price/" + String(i), String(val, 4), true, 0);
|
||||
}
|
||||
|
||||
@@ -4,20 +4,11 @@
|
||||
#include "hexutils.h"
|
||||
#include "AmsData.h"
|
||||
|
||||
#if defined(ESP8266)
|
||||
#include "root/head8266_html.h"
|
||||
#define HEAD_HTML HEAD8266_HTML
|
||||
#define HEAD_HTML_LEN HEAD8266_HTML_LEN
|
||||
#elif defined(ESP32)
|
||||
#include "root/head32_html.h"
|
||||
#define HEAD_HTML HEAD32_HTML
|
||||
#define HEAD_HTML_LEN HEAD32_HTML_LEN
|
||||
#endif
|
||||
|
||||
#if defined(ESP32)
|
||||
#include <esp_task_wdt.h>
|
||||
#endif
|
||||
|
||||
#include "root/head_html.h"
|
||||
#include "root/foot_html.h"
|
||||
#include "root/index_html.h"
|
||||
#include "root/application_js.h"
|
||||
@@ -43,7 +34,6 @@
|
||||
#include "root/notfound_html.h"
|
||||
#include "root/data_json.h"
|
||||
#include "root/tempsensor_json.h"
|
||||
#include "root/lowmem_html.h"
|
||||
#include "root/dayplot_json.h"
|
||||
#include "root/monthplot_json.h"
|
||||
#include "root/energyprice_json.h"
|
||||
@@ -356,7 +346,11 @@ void AmsWebServer::configMeterHtml() {
|
||||
html.replace("{mid}", meterState->getMeterId());
|
||||
html.replace("{b}", String(meterConfig->baud));
|
||||
html.replace("{b2400}", meterConfig->baud == 2400 ? "selected" : "");
|
||||
html.replace("{b4800}", meterConfig->baud == 4800 ? "selected" : "");
|
||||
html.replace("{b9600}", meterConfig->baud == 9600 ? "selected" : "");
|
||||
html.replace("{b19200}", meterConfig->baud == 19200 ? "selected" : "");
|
||||
html.replace("{b38400}", meterConfig->baud == 38400 ? "selected" : "");
|
||||
html.replace("{b57600}", meterConfig->baud == 57600 ? "selected" : "");
|
||||
html.replace("{b115200}", meterConfig->baud == 115200 ? "selected" : "");
|
||||
html.replace("{c}", String(meterConfig->baud));
|
||||
html.replace("{c2}", meterConfig->parity == 2 ? "selected" : "");
|
||||
@@ -583,10 +577,7 @@ void AmsWebServer::configEntsoeHtml() {
|
||||
server.sendContent(html);
|
||||
server.sendContent_P(FOOT_HTML);
|
||||
} else {
|
||||
server.setContentLength(LOWMEM_HTML_LEN + HEAD_HTML_LEN + FOOT_HTML_LEN);
|
||||
server.send_P(200, MIME_HTML, HEAD_HTML);
|
||||
server.sendContent_P(LOWMEM_HTML);
|
||||
server.sendContent_P(FOOT_HTML);
|
||||
notFound();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -602,6 +593,7 @@ void AmsWebServer::configThresholdsHtml() {
|
||||
for(int i = 0; i < 9; i++) {
|
||||
html.replace("{t" + String(i) + "}", String(config->thresholds[i]));
|
||||
}
|
||||
html.replace("{h}", String(config->hours));
|
||||
|
||||
server.setContentLength(html.length() + HEAD_HTML_LEN + FOOT_HTML_LEN);
|
||||
server.send_P(200, MIME_HTML, HEAD_HTML);
|
||||
@@ -1048,6 +1040,16 @@ void AmsWebServer::handleSetup() {
|
||||
gpioConfig->vccResistorGnd = 22;
|
||||
gpioConfig->vccResistorVcc = 33;
|
||||
break;
|
||||
case 6: // Pow-P1
|
||||
gpioConfig->hanPin = 18;
|
||||
gpioConfig->apPin = 0;
|
||||
gpioConfig->ledPinRed = 13;
|
||||
gpioConfig->ledPinGreen = 14;
|
||||
gpioConfig->ledRgbInverted = true;
|
||||
gpioConfig->vccPin = 10;
|
||||
gpioConfig->vccResistorGnd = 22;
|
||||
gpioConfig->vccResistorVcc = 33;
|
||||
break;
|
||||
case 101: // D1
|
||||
gpioConfig->hanPin = 5;
|
||||
gpioConfig->apPin = 4;
|
||||
@@ -1081,6 +1083,15 @@ void AmsWebServer::handleSetup() {
|
||||
gpioConfig->ledPin = 2;
|
||||
gpioConfig->ledInverted = false;
|
||||
break;
|
||||
case 50: // S2
|
||||
gpioConfig->hanPin = 18;
|
||||
break;
|
||||
case 51: // S2-mini
|
||||
gpioConfig->hanPin = 18;
|
||||
gpioConfig->ledPin = 15;
|
||||
gpioConfig->ledInverted = false;
|
||||
gpioConfig->apPin = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
WiFiConfig wifi;
|
||||
@@ -1349,6 +1360,7 @@ void AmsWebServer::handleSave() {
|
||||
eac.thresholds[6] = server.arg("t6").toInt();
|
||||
eac.thresholds[7] = server.arg("t7").toInt();
|
||||
eac.thresholds[8] = server.arg("t8").toInt();
|
||||
eac.hours = server.arg("h").toInt();
|
||||
config->setEnergyAccountingConfig(eac);
|
||||
}
|
||||
|
||||
@@ -1482,8 +1494,13 @@ String AmsWebServer::getSerialSelectOptions(int selected) {
|
||||
gpioOptions += "<option value=\"3\">UART0 (GPIO3)</option>";
|
||||
}
|
||||
#if defined(CONFIG_IDF_TARGET_ESP32S2)
|
||||
int numGpio = 31;
|
||||
int gpios[] = {4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,21,22,23,25,32,33,34,35,36,39,40,41,42,43,44};
|
||||
int numGpio = 30;
|
||||
int gpios[] = {4,5,6,7,8,9,10,11,12,13,14,15,16,17,19,21,22,23,25,32,33,34,35,36,39,40,41,42,43,44};
|
||||
if(selected == 18) {
|
||||
gpioOptions += "<option value=\"18\" selected>UART1 (GPIO18)</option>";
|
||||
} else {
|
||||
gpioOptions += "<option value=\"18\">UART1 (GPIO18)</option>";
|
||||
}
|
||||
#elif 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};
|
||||
@@ -1605,11 +1622,15 @@ void AmsWebServer::firmwareHtml() {
|
||||
String html = String((const __FlashStringHelper*) FIRMWARE_HTML);
|
||||
|
||||
#if defined(ESP8266)
|
||||
html.replace("{chipset}", "ESP8266");
|
||||
html.replace("{chipset}", "ESP8266");
|
||||
#elif defined(CONFIG_IDF_TARGET_ESP32S2)
|
||||
html.replace("{chipset}", "ESP32S2");
|
||||
html.replace("{chipset}", "ESP32S2");
|
||||
#elif defined(ESP32)
|
||||
html.replace("{chipset}", "ESP32");
|
||||
#if defined(CONFIG_FREERTOS_UNICORE)
|
||||
html.replace("{chipset}", "ESP32SOLO");
|
||||
#else
|
||||
html.replace("{chipset}", "ESP32");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
server.setContentLength(html.length() + HEAD_HTML_LEN + FOOT_HTML_LEN);
|
||||
@@ -1657,8 +1678,9 @@ void AmsWebServer::firmwareDownload() {
|
||||
printI("Downloading firmware...");
|
||||
HTTPClient httpClient;
|
||||
httpClient.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
|
||||
httpClient.setTimeout(20000);
|
||||
httpClient.addHeader("User-Agent", "ams2mqtt/" + String(VERSION));
|
||||
httpClient.setReuse(false);
|
||||
httpClient.setTimeout(60000);
|
||||
httpClient.setUserAgent("ams2mqtt/" + String(VERSION));
|
||||
|
||||
#if defined(ESP8266)
|
||||
WiFiClient client;
|
||||
@@ -1687,18 +1709,28 @@ void AmsWebServer::firmwareDownload() {
|
||||
return;
|
||||
*/
|
||||
#elif defined(CONFIG_IDF_TARGET_ESP32S2)
|
||||
WiFiClientSecure client;
|
||||
client.setInsecure();
|
||||
httpClient.setConnectTimeout(60000);
|
||||
String url = "https://github.com/gskjold/AmsToMqttBridge/releases/download/" + version + "/ams2mqtt-esp32s2-" + versionStripped + ".bin";
|
||||
httpClient.addHeader("Referer", "https://github.com/gskjold/AmsToMqttBridge/releases");
|
||||
#elif defined(ESP32)
|
||||
WiFiClientSecure client;
|
||||
client.setInsecure();
|
||||
String url = "https://github.com/gskjold/AmsToMqttBridge/releases/download/" + version + "/ams2mqtt-esp32-" + versionStripped + ".bin";
|
||||
httpClient.setConnectTimeout(60000);
|
||||
#if defined(CONFIG_FREERTOS_UNICORE)
|
||||
String url = "https://github.com/gskjold/AmsToMqttBridge/releases/download/" + version + "/ams2mqtt-esp32solo-" + versionStripped + ".bin";
|
||||
#else
|
||||
String url = "https://github.com/gskjold/AmsToMqttBridge/releases/download/" + version + "/ams2mqtt-esp32-" + versionStripped + ".bin";
|
||||
#endif
|
||||
|
||||
httpClient.addHeader("Referer", "https://github.com/gskjold/AmsToMqttBridge/releases");
|
||||
#endif
|
||||
|
||||
printD("Downloading from URL:");
|
||||
printD(url);
|
||||
|
||||
#if defined(ESP8266)
|
||||
if(httpClient.begin(client, url)) {
|
||||
#elif defined(ESP32)
|
||||
if(httpClient.begin(url)) {
|
||||
#endif
|
||||
printD("HTTP client setup successful");
|
||||
int status = httpClient.GET();
|
||||
if(status == HTTP_CODE_OK) {
|
||||
@@ -1726,8 +1758,8 @@ void AmsWebServer::firmwareDownload() {
|
||||
}
|
||||
} else {
|
||||
printE("Communication error: ");
|
||||
debugger->printf("%d\n", status);
|
||||
printE(httpClient.errorToString(status));
|
||||
printI(url);
|
||||
printD(httpClient.getString());
|
||||
server.sendHeader("Location","/");
|
||||
server.send(303);
|
||||
@@ -1738,7 +1770,6 @@ void AmsWebServer::firmwareDownload() {
|
||||
server.send(303);
|
||||
}
|
||||
httpClient.end();
|
||||
client.stop();
|
||||
} else {
|
||||
printI("No firmware version specified...");
|
||||
server.sendHeader("Location","/");
|
||||
@@ -1857,7 +1888,7 @@ void AmsWebServer::mqttCa() {
|
||||
}
|
||||
LittleFS.end();
|
||||
} else {
|
||||
server.sendHeader("Location","/config-mqtt");
|
||||
server.sendHeader("Location","/mqtt");
|
||||
server.send(303);
|
||||
}
|
||||
}
|
||||
@@ -1869,7 +1900,7 @@ void AmsWebServer::mqttCaUpload() {
|
||||
uploadFile(FILE_MQTT_CA);
|
||||
HTTPUpload& upload = server.upload();
|
||||
if(upload.status == UPLOAD_FILE_END) {
|
||||
server.sendHeader("Location","/config-mqtt");
|
||||
server.sendHeader("Location","/mqtt");
|
||||
server.send(303);
|
||||
|
||||
MqttConfig mqttConfig;
|
||||
@@ -1885,7 +1916,7 @@ void AmsWebServer::mqttCaDelete() {
|
||||
|
||||
if(!uploading) { // Not an upload
|
||||
deleteFile(FILE_MQTT_CA);
|
||||
server.sendHeader("Location","/config-mqtt");
|
||||
server.sendHeader("Location","/mqtt");
|
||||
server.send(303);
|
||||
MqttConfig mqttConfig;
|
||||
if(config->getMqttConfig(mqttConfig) && mqttConfig.ssl) {
|
||||
@@ -1911,7 +1942,7 @@ void AmsWebServer::mqttCert() {
|
||||
}
|
||||
LittleFS.end();
|
||||
} else {
|
||||
server.sendHeader("Location","/config-mqtt");
|
||||
server.sendHeader("Location","/mqtt");
|
||||
server.send(303);
|
||||
}
|
||||
}
|
||||
@@ -1923,7 +1954,7 @@ void AmsWebServer::mqttCertUpload() {
|
||||
uploadFile(FILE_MQTT_CERT);
|
||||
HTTPUpload& upload = server.upload();
|
||||
if(upload.status == UPLOAD_FILE_END) {
|
||||
server.sendHeader("Location","/config-mqtt");
|
||||
server.sendHeader("Location","/mqtt");
|
||||
server.send(303);
|
||||
MqttConfig mqttConfig;
|
||||
if(config->getMqttConfig(mqttConfig) && mqttConfig.ssl) {
|
||||
@@ -1938,7 +1969,7 @@ void AmsWebServer::mqttCertDelete() {
|
||||
|
||||
if(!uploading) { // Not an upload
|
||||
deleteFile(FILE_MQTT_CERT);
|
||||
server.sendHeader("Location","/config-mqtt");
|
||||
server.sendHeader("Location","/mqtt");
|
||||
server.send(303);
|
||||
MqttConfig mqttConfig;
|
||||
if(config->getMqttConfig(mqttConfig) && mqttConfig.ssl) {
|
||||
@@ -1964,7 +1995,7 @@ void AmsWebServer::mqttKey() {
|
||||
}
|
||||
LittleFS.end();
|
||||
} else {
|
||||
server.sendHeader("Location","/config-mqtt");
|
||||
server.sendHeader("Location","/mqtt");
|
||||
server.send(303);
|
||||
}
|
||||
}
|
||||
@@ -1976,7 +2007,7 @@ void AmsWebServer::mqttKeyUpload() {
|
||||
uploadFile(FILE_MQTT_KEY);
|
||||
HTTPUpload& upload = server.upload();
|
||||
if(upload.status == UPLOAD_FILE_END) {
|
||||
server.sendHeader("Location","/config-mqtt");
|
||||
server.sendHeader("Location","/mqtt");
|
||||
server.send(303);
|
||||
MqttConfig mqttConfig;
|
||||
if(config->getMqttConfig(mqttConfig) && mqttConfig.ssl) {
|
||||
@@ -1991,7 +2022,7 @@ void AmsWebServer::mqttKeyDelete() {
|
||||
|
||||
if(!uploading) { // Not an upload
|
||||
deleteFile(FILE_MQTT_KEY);
|
||||
server.sendHeader("Location","/config-mqtt");
|
||||
server.sendHeader("Location","/mqtt");
|
||||
server.send(303);
|
||||
MqttConfig mqttConfig;
|
||||
if(config->getMqttConfig(mqttConfig) && mqttConfig.ssl) {
|
||||
@@ -2245,7 +2276,7 @@ void AmsWebServer::configFileDownload() {
|
||||
EnergyAccountingConfig eac;
|
||||
config->getEnergyAccountingConfig(eac);
|
||||
|
||||
if(eac.thresholds[9] > 0) server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("thresholds %d %d %d %d %d %d %d %d %d %d\n"),
|
||||
if(eac.thresholds[9] > 0) server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("thresholds %d %d %d %d %d %d %d %d %d %d %d\n"),
|
||||
eac.thresholds[0],
|
||||
eac.thresholds[1],
|
||||
eac.thresholds[2],
|
||||
@@ -2255,7 +2286,8 @@ void AmsWebServer::configFileDownload() {
|
||||
eac.thresholds[6],
|
||||
eac.thresholds[7],
|
||||
eac.thresholds[8],
|
||||
eac.thresholds[9]
|
||||
eac.thresholds[9],
|
||||
eac.hours
|
||||
));
|
||||
}
|
||||
|
||||
@@ -2401,15 +2433,28 @@ void AmsWebServer::configFileDownload() {
|
||||
}
|
||||
|
||||
if(ea != NULL) {
|
||||
EnergyAccountingConfig eac;
|
||||
config->getEnergyAccountingConfig(eac);
|
||||
EnergyAccountingData ead = ea->getData();
|
||||
server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("energyaccounting %d %d %.2f %.2f %.2f %.2f"),
|
||||
server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("energyaccounting %d %d %.2f %.2f %.2f %.2f %d %.2f %d %.2f %d %.2f %d %.2f %d %.2f"),
|
||||
ead.version,
|
||||
ead.month,
|
||||
ead.maxHour / 100.0,
|
||||
ead.costYesterday / 100.0,
|
||||
ead.costThisMonth / 100.0,
|
||||
ead.costLastMonth / 100.0
|
||||
0.0, // Old max
|
||||
ead.costYesterday / 10.0,
|
||||
ead.costThisMonth / 1.0,
|
||||
ead.costLastMonth / 1.0,
|
||||
ead.peaks[0].day,
|
||||
ead.peaks[0].value / 100.0,
|
||||
ead.peaks[1].day,
|
||||
ead.peaks[1].value / 100.0,
|
||||
ead.peaks[2].day,
|
||||
ead.peaks[2].value / 100.0,
|
||||
ead.peaks[3].day,
|
||||
ead.peaks[3].value / 100.0,
|
||||
ead.peaks[4].day,
|
||||
ead.peaks[4].value / 100.0
|
||||
));
|
||||
server.sendContent("\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@
|
||||
<a class="dropdown-item" href="/mqtt">MQTT</a>
|
||||
<a class="dropdown-item" href="/web">Web</a>
|
||||
<a class="dropdown-item" href="/ntp">NTP</a>
|
||||
<a class="dropdown-item" href="/entsoe">ENTSO-E API</a>
|
||||
<a class="dropdown-item d-none ssl-capable" href="/entsoe">ENTSO-E API</a>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item" href="https://github.com/gskjold/AmsToMqttBridge/wiki" target="_blank">Documentation</a>
|
||||
</div>
|
||||
@@ -1,102 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>AMS reader</title>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css" integrity="sha384-zCbKRCUGaJDkqS1kPbPd7TveP5iyJE0EjAuZQTgFLD2ylzuqKfdKlfG/eSrtxUkn" crossorigin="anonymous" referrerpolicy="no-referrer">
|
||||
<style>
|
||||
.navbar-expand .navbar-nav .nav-link,.navbar-brand {
|
||||
padding-top: 0px;
|
||||
padding-bottom: 0px;
|
||||
margin-top: 0px;
|
||||
margin-bottom: 0px;
|
||||
}
|
||||
.plot1 {
|
||||
width: 100%;
|
||||
height: 200px;
|
||||
}
|
||||
.plot2 {
|
||||
width: 100%;
|
||||
height: 224px;
|
||||
}
|
||||
.overlay-plot {
|
||||
position: relative;
|
||||
}
|
||||
.plot-overlay {
|
||||
position: absolute;
|
||||
top: 70px;
|
||||
left: 25%;
|
||||
width: 50%;
|
||||
text-align: center;
|
||||
}
|
||||
.ipo,.epo {
|
||||
font-size: 1.7rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
.ipoa,.epoa {
|
||||
font-size: 1.0rem;
|
||||
color: grey;
|
||||
}
|
||||
.pol {
|
||||
font-size: 1.0rem;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body class="bg-light">
|
||||
<main role="main" class="container">
|
||||
<header class="navbar navbar-expand navbar-dark flex-column flex-lg-row rounded shadow mt-2 mb-3" style="background-color: var(--purple);">
|
||||
<a href="/" class="">
|
||||
<h6 class="navbar-brand">AMS reader <small id="swVersion" data-url="https://api.github.com/repos/gskjold/AmsToMqttBridge/releases">${version}</small></h6>
|
||||
</a>
|
||||
<div class="navbar-nav-scroll">
|
||||
<ul class="navbar-nav bd-navbar-nav flex-row">
|
||||
<li class="nav-item">
|
||||
<div class="dropdown">
|
||||
<a class="dropdown-toggle nav-link" href="#" role="button" id="config-link" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
Config<span class="d-none d-md-inline d-lg-none d-xl-inline">uration</span>
|
||||
</a>
|
||||
|
||||
<div class="dropdown-menu" aria-labelledby="config-link">
|
||||
<a class="dropdown-item" href="/meter">Meter</a>
|
||||
<a class="dropdown-item" href="/wifi">WiFi</a>
|
||||
<a class="dropdown-item" href="/mqtt">MQTT</a>
|
||||
<a class="dropdown-item" href="/web">Web</a>
|
||||
<a class="dropdown-item" href="/ntp">NTP</a>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item" href="https://github.com/gskjold/AmsToMqttBridge/wiki" target="_blank">Documentation</a>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<div class="dropdown">
|
||||
<a class="dropdown-toggle nav-link" href="#" role="button" id="system-link" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
Sys<span class="d-none d-sm-inline">tem</span>
|
||||
</a>
|
||||
<div class="dropdown-menu" aria-labelledby="system-link">
|
||||
<a class="dropdown-item" href="/gpio">GPIO</a>
|
||||
<a class="dropdown-item" href="/debugging">Debugging</a>
|
||||
<a class="dropdown-item" href="/configfile">Configuration file</a>
|
||||
<a class="dropdown-item" href="/firmware">Firmware</a>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item" href="/restart">Restart</a>
|
||||
<a class="dropdown-item text-danger" href="/reset">Factory reset</a>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="flex-row">
|
||||
<div id="esp" class="d-none m-2">ESP</div>
|
||||
<div id="han" class="d-none m-2">HAN</div>
|
||||
<div id="wifi" class="d-none m-2">WiFi</div>
|
||||
<div id="mqtt" class="d-none m-2">MQTT</div>
|
||||
</div>
|
||||
<ul class="navbar-nav flex-row ml-md-auto d-none d-lg-flex">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link p-2" href="https://github.com/gskjold/AmsToMqttBridge" target="_blank" rel="noopener" aria-label="GitHub">
|
||||
<img class="d-inline-block align-text-top" style="width: 2rem; height: 2rem;" src="github.svg"/>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</header>
|
||||
@@ -12,6 +12,7 @@
|
||||
"realtime" : {
|
||||
"h" : %.2f,
|
||||
"d" : %.1f,
|
||||
"t" : %d
|
||||
"t" : %d,
|
||||
"x" : %.2f
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
"realtime" : {
|
||||
"h" : %.2f,
|
||||
"d" : %.1f,
|
||||
"t" : %d
|
||||
"t" : %d,
|
||||
"x" : %.2f
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
"realtime" : {
|
||||
"h" : %.2f,
|
||||
"d" : %.1f,
|
||||
"t" : %d
|
||||
"t" : %d,
|
||||
"x" : %.2f
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
"realtime" : {
|
||||
"h" : %.2f,
|
||||
"d" : %.1f,
|
||||
"t" : %d
|
||||
"t" : %d,
|
||||
"x" : %.2f
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
{
|
||||
"lv" : "%s",
|
||||
"id" : "%s",
|
||||
"type" : "%s",
|
||||
"P" : %d,
|
||||
"Q" : %d,
|
||||
"PO" : %d,
|
||||
"QO" : %d,
|
||||
"I1" : %.2f,
|
||||
"I2" : %.2f,
|
||||
"I3" : %.2f,
|
||||
"U1" : %.2f,
|
||||
"U2" : %.2f,
|
||||
"U3" : %.2f,
|
||||
"PF" : %.2f,
|
||||
"PF1" : %.2f,
|
||||
"PF2" : %.2f,
|
||||
"PF3" : %.2f,
|
||||
"tPI" : %.2f,
|
||||
"tPO" : %.2f,
|
||||
"tQI" : %.2f,
|
||||
"tQO" : %.2f,
|
||||
"rtc" : %lu
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
<div class="alert alert-info">There is currently not enough available heap space on your device to support this feature. If you are using ESP8266, you can consider switching to ESP32 to get enable this feature</div>
|
||||
@@ -36,7 +36,11 @@
|
||||
</div>
|
||||
<select class="form-control sd" name="b">
|
||||
<option value="2400" {b2400}>2400</option>
|
||||
<option value="4800" {b4800}>4800</option>
|
||||
<option value="9600" {b9600}>9600</option>
|
||||
<option value="19200" {b19200}>19200</option>
|
||||
<option value="38400" {b38400}>38400</option>
|
||||
<option value="57600" {b57600}>57600</option>
|
||||
<option value="115200" {b115200}>115200</option>
|
||||
</select>
|
||||
</div>
|
||||
@@ -54,11 +58,14 @@
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-3 col-md-4 col-sm-3 col-6">
|
||||
<div class="col-lg-2 col-md-4 col-sm-3 col-6">
|
||||
<div class="m-2">
|
||||
<label class="small"><input type="checkbox" name="i" value="true" {i}/> Invert <span class="d-none d-md-inline">signal</span></label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-4 col-sm-8">
|
||||
<a href="https://github.com/gskjold/AmsToMqttBridge/wiki/Known-hardware-configurations" target="_blank">Known hardware configurations</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-xl-3 col-lg-4 col-md-5 col-sm-7">
|
||||
|
||||
@@ -23,11 +23,13 @@
|
||||
<div class="row">
|
||||
<div class="col-xl-4 col-md-6">
|
||||
<h5>Hardware</h5>
|
||||
<select name="board" class="form-control">
|
||||
<select name="board" class="form-control" required>
|
||||
<option value=""></option>
|
||||
<optgroup label="Custom hardware">
|
||||
<option value="5" ${config.boardType2}>Pow-K+ (ESP32) from amsleser.no</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="6" ${config.boardType6}>Pow-P1 from amsleser.no</option>
|
||||
<option value="5" ${config.boardType5}>Pow-K+ (ESP32) from amsleser.no</option>
|
||||
<option value="4" ${config.boardType4}>Pow-U or Pow-K from amsleser.no (GPIO12)</option>
|
||||
<option value="3" ${config.boardType3}>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>
|
||||
@@ -41,7 +43,11 @@
|
||||
<option value="202" ${config.boardType202}>Adafruit HUZZAH32</option>
|
||||
<option value="203" ${config.boardType203}>DevKitC</option>
|
||||
<option value="200" ${config.boardType200}>Generic ESP32</option>
|
||||
</optgroup>
|
||||
</optgroup>
|
||||
<optgroup label="ESP32-S2">
|
||||
<option value="51" ${config.boardType51}>Wemos S2 mini</option>
|
||||
<option value="50" ${config.boardType50}>Generic ESP32-S2</option>
|
||||
</optgroup>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text">1</span>
|
||||
</div>
|
||||
<input class="form-control text-right" name="t0" type="number" min="5" max="255" step="1" value="{t0}"/>
|
||||
<input class="form-control text-right" name="t0" type="number" min="1" max="255" step="1" value="{t0}"/>
|
||||
<div class="input-group-append">
|
||||
<span class="input-group-text">kWh</span>
|
||||
</div>
|
||||
@@ -103,6 +103,19 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-lg-3 col-md-5 col-sm-6">
|
||||
<div class="m-2 input-group input-group-sm">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text">Average of top</span>
|
||||
</div>
|
||||
<input class="form-control text-right" name="h" type="number" min="1" max="5" step="1" value="{h}"/>
|
||||
<div class="input-group-append">
|
||||
<span class="input-group-text">hours</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<hr/>
|
||||
<div class="row form-group">
|
||||
|
||||
Reference in New Issue
Block a user