Samstag, 14. Juni 2025

OpenDTU-OnBattery code upgrade with "tiny" ESP32-WROOM-32U

 As a reminder on how to do the OpenDTU-OnBattery code upgrade with "tiny" ESP32-WROOM-32U let me remind myself to do it like this:

  https://github.com/hoylabs/OpenDTU-OnBattery

 

 PS C:\Users\user\AppData\Local\Arduino15\packages\esp32\tools\esptool_py> C:\Users\user\AppData\Local\Arduino15\packages\esp32\tools\esptool_py\4.9.dev3\esptool.exe --chip auto --port COM4 --baud 115200 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size 4MB 0x0 'C:\Users\user\Documents\2025\opendtu backup 06\opendtu-onbattery-2025.06.11-generic_esp32_4mb_no_ota.factory.bin'
esptool.py v4.8.1
Serial port COM4
Connecting.....
Detecting chip type... Unsupported detection protocol, switching and trying again...
Connecting....
Detecting chip type... ESP32
Chip is ESP32-D0WD-V3 (revision v3.0)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: a8:42:e3:4b:f3:1c
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Flash will be erased from 0x00000000 to 0x0027efff...
Compressed 2616400 bytes to 1567250...
Wrote 2616400 bytes (1567250 compressed) at 0x00000000 in 137.9 seconds (effective 151.8 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...
PS C:\Users\user\AppData\Local\Arduino15\packages\esp32\tools\esptool_py>

Montag, 17. März 2025

Using the Arduino IDE to flash an ESP32-S3 with a CP2102 serial adapter after you did not do any of that in a LONG time

PS C:\Users\user\Downloads> C:\Users\user\AppData\Local\Arduino15\packages\esp32\tools\esptool_py\4.9.dev3\esptool.exe --port COM6 erase_flash
esptool.py v4.8.1
Serial port COM6
Connecting...
Detecting chip type... ESP32-S3
Chip is ESP32-S3 (QFN56) (revision v0.2)
Features: WiFi, BLE, Embedded PSRAM 8MB (AP_3v3)
Crystal is 40MHz
MAC: cc:ba:97:14:07:44
Uploading stub...
Running stub...
Stub running...
Erasing flash (this may take a while)...
Chip erase completed successfully in 8.0 seconds.
Hard resetting via RTS pin...

 

If you order everything from the cheapest vendor and your CP2102 has the weirdest cables, you may want to stick with 115200 baud instead of  921600 baud.

PS C:\Users\user\Downloads> C:\Users\user\AppData\Local\Arduino15\packages\esp32\tools\esptool_py\4.9.dev3\esptool.exe --baud 115200 --port COM4 --chip esp32s3 --before default_reset --after hard_reset write_flash --flash_mode dout --flash_freq 40m --flash_size detect 0x0 opendtu-onbattery-generic_esp32s3.factory.bin
esptool.py v4.8.1
Serial port COM4
Connecting....
Chip is ESP32-S3 (QFN56) (revision v0.2)
Features: WiFi, BLE, Embedded PSRAM 8MB (AP_3v3)
Crystal is 40MHz
MAC: cc:ba:97:14:07:44
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 16MB
Flash will be erased from 0x00000000 to 0x00242fff...
Flash params set to 0x0340
SHA digest in image updated
Compressed 2371296 bytes to 1444488...
Wrote 2371296 bytes (1444488 compressed) at 0x00000000 in 130.1 seconds (effective 145.8 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...
PS C:\Users\user\Downloads>

Dienstag, 11. Juli 2023

Using the Arduino IDE to flash an ESP32 with a CP2102 serial adapter after you did not do that in a LONG time

Currently trying to run the openDTU project on one of my ESP32. But well, how to get it on there...

 

The programming command the openDTU docs state:

 

 esptool.py --port /dev/ttyUSB0 --chip esp32 --before default_reset --after hard_reset write_flash --flash_mode dout --flash_freq 40m --flash_size detect 0x0 opendtu-generic.factory.bin


Playing around with the ArduinoIDE this is one of the programming commands from the extended serial output there:


 
"C:\Users\user\AppData\Local\Arduino15\packages\esp32\tools\esptool_py\4.5.1/esptool.exe" --chip esp32 --port "COM4" --baud 115200  --before default_reset --after hard_reset write_flash  -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x1000 "C:\Users\user\AppData\Local\Temp\arduino\sketches\507DD89FBC5B73B753AA5D4AE9A38EF2/WiFiScan.ino.bootloader.bin" 0x8000 "C:\Users\user\AppData\Local\Temp\arduino\sketches\507DD89FBC5B73B753AA5D4AE9A38EF2/WiFiScan.ino.partitions.bin" 0xe000 "C:\Users\user\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.9/tools/partitions/boot_app0.bin" 0x10000 "C:\Users\user\AppData\Local\Temp\arduino\sketches\507DD89FBC5B73B753AA5D4AE9A38EF2/WiFiScan.ino.bin"
esptool.py v4.5.1



The command I derived from the two above:


C:\Users\user\AppData\Local\Arduino15\packages\esp32\tools\esptool_py\4.5.1/esptool.exe --chip esp32 --port "COM4" --before default_reset --after hard_reset write_flash --flash_mode dout --flash_freq 40m --flash_size detect 0x0 opendtu-generic.factory.bin

A successfull programming run looks like this. You still have to unplug and replug the CP2102 with the ESP32 attached while pressing the "right" button:


C:\Users\user\Downloads>C:\Users\user\AppData\Local\Arduino15\packages\esp32\tools\esptool_py\4.5.1/esptool.exe --chip esp32 --port "COM4" --before default_reset --after hard_reset write_flash --flash_mode dout --flash_freq 40m --flash_size detect 0x0 opendtu-generic.factory.bin
esptool.py v4.5.1
Serial port COM4
Connecting....
Chip is ESP32-D0WDQ6 (revision v1.0)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: cc:50:e3:8b:c9:18
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Flash will be erased from 0x00000000 to 0x00186fff...
Compressed 1598240 bytes to 1022460...
Wrote 1598240 bytes (1022460 compressed) at 0x00000000 in 92.1 seconds (effective 138.8 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...

C:\Users\user\Downloads>


Sonntag, 26. März 2023

New power meter, new tracking aka "Eingespeister Strom MUSS erfasst werden!"

Welcome to Germany: Eingespeister Strom MUSS erfasst werden!

 

So lets switch my perfectly good and gauged "EasyMeter Drehstrom-Einrichtungszähler 60A Typ Q3AA1054" to an even better gauged "eBZ DD3 2r06 eta odz1".

The eBZ model comes in 32 different variations, I guess I have a 3phase model caunting in two directions. Overproduction will be displayed as negative values in the Tasmota tracking.

 

Following up on:

https://tasmota.github.io/docs/Scripting-Language/#script-sections
https://tasmota.github.io/docs/Smart-Meter-Interface/#meter-metrics
https://tasmota.github.io/docs/Smart-Meter-Interface/#ebz-dd3-obis

I modded the example script for the eBZ model, changed the granularity from WH to kWH and voila:


>D
>B
TelePeriod 30
=>sensor53 r
>M 1
; Device: eBZ DD3 2R06 ODZ1
; protocol is D0 OBIS ASCII
; 9600@7E1 for OP-type devices, 9600@8N1 for SM-type devices
+1,3,o,0,9600,SM,1
; Zählerstand zu +A, tariflos,
; Zählerstände Auflösung 10 µW*h (6 Vorkomma- und 8 Nachkommastellen)
1,1-0:1.8.0*255(@1,Energie Bezung,kWh,1_8_0,8
; Zählerstand zu +A, Tarif 1
; 1,1-0:1.8.1*255(@0.001,Energie Bezung T1,Wh,1_8_1,8
; Zählerstand zu +A, Tarif 2
; 1,1-0:1.8.2*255(@0.001,Energie Bezung T2,Wh,1_8_2,8
; Zählerstand zu -A, tariflos
1,1-0:2.8.0*255(@1,Energie Export,kWh,2_8_0,8
; Summe der Momentan-Leistungen in allen Phasen, Auflösung 0,01W (5 Vorkomma- und 2 Nachkommastellen)
1,1-0:16.7.0*255(@1,Leistung,W,16_7_0,18
; Momentane Leistung in Phase Lx, Auflösung 0,01W (5 Vorkomma- und 2 Nachkommastellen)
1,1-0:36.7.0*255(@1,Leistung L1,W,36_7_0,18
1,1-0:56.7.0*255(@1,Leistung L2,W,56_7_0,18
1,1-0:76.7.0*255(@1,Leistung L3,W,76_7_0,18
; Spannung in Phase Lx, Auflösung 0,1V (nur über MSB)
1,1-0:32.7.0*255(@1,Spannung L1,V,32_7_0,1
1,1-0:52.7.0*255(@1,Spannung L2,V,52_7_0,1
1,1-0:72.7.0*255(@1,Spannung L3,V,72_7_0,1
; Statuswort, 4 Byte Information über den Betriebszustand, HEX string
; tasmota can decode one string per device only!
;1,1-0:96.5.0*255(@#),Status1,,96_5_0,0
;1,1-0:96.8.0*255(@#),Status2,,96_8_0,0
; Geräte-Identifikation, Nach DIN 43863-5
1,1-0:96.1.0*255(@#),Identifikation,,96_1_0,0
;1,1-0:0.0.0*255(@#),Identifikation,,0_0_0,0
#

Update:


Well, it took me a while, but the above script has a logical flaw in it. The following one will fix it. If you look closely I matched the individual phase values against 36_7_0, 56_7_0 and 76_7_0. But the actual phase values are 16_7_0, 36_7_0and 56_7_0. The sum of the phase values is 76_7_0, So this has been easy to fix but hard to find, at least for me. So always make sure to have your values under control.

>D
>B
TelePeriod 30
=>sensor53 r
>M 1
; Device: eBZ DD3 2R06 ODZ1
; protocol is D0 OBIS ASCII
; 9600@7E1 for OP-type devices, 9600@8N1 for SM-type devices
+1,3,o,0,9600,SM,1
; Summen der bezogenen und eingespeisten Leistung
1,1-0:1.8.0*255(@1,Energie Bezung,kWh,z1_8_0,8
1,1-0:2.8.0*255(@1,Energie Export,kWh,z2_8_0,8
; Momentane Leistung in Phase Lx, Auflösung 0,01W (5 Vorkomma- und 2 Nachkommastellen)
1,1-0:36.7.0*255(@1,Leistung L1,W,z16_7_0,18
1,1-0:56.7.0*255(@1,Leistung L2,W,z36_7_0,18
1,1-0:76.7.0*255(@1,Leistung L3,W,z56_7_0,18
; Summe der Momentan-Leistungen in allen Phasen, Auflösung 0,01W (5 Vorkomma- und 2 Nachkommastellen)
1,1-0:16.7.0*255(@1,Leistung,W,z76_7_0,18
#


Dienstag, 18. Oktober 2022

Getting your power meter tracked properly

 Running Tasmota Based readout hardware with the following script

 

>D
>B
=>sensor53 r
>M 1
+1,3,s,0,9600,SML
1,77070100010801ff@1000,Verbrauch_Tarif_1,kWh,Verbrauch_T1,7
1,77070100010802ff@1000,Verbrauch_Tarif_2,kWh,Verbrauch_T2,7
1,77070100010800ff@1000,Verbrauch_Summe,kWh,Verbrauch_Summe,7
1,77070100020800ff@1000,Einspeisung_Summe,kWh,Einspeisung_Summe,7
1,=h--
1,77070100240700ff@1,Leistung_L1,W,Watt_L1,2
1,77070100380700ff@1,Leistung_L2,W,Watt_L2,2
1,770701004c0700ff@1,Leistung_L3,W,Watt_L3,2
1,77070100100700ff@1,Leistung_Summe,W,Watt_Summe,2
1,=h--
1,77070100200700ff@1,Spannung_L1,V,Volt_L1,1
1,77070100340700ff@1,Spannung_L2,V,Volt_L2,1
1,77070100480700ff@1,Spannung_L3,V,Volt_L3,1
#


Working mqtt2prometheus config file:

metrics:
  # The name of the metric in prometheus
  - prom_name: consumed_energy_kilowatthours_total
    mqtt_name: "ENERGY.Total"
    help: "total measured kilowatthours since flash"
    type: counter
  - prom_name: voltage_volts
    mqtt_name: "ENERGY.Voltage"
    help: "Currently measured voltage"
    type: gauge
  - prom_name: current_amperes
    mqtt_name: "ENERGY.Current"
    help: "Currently measured current"
    type: gauge
  - prom_name: power_watts
    mqtt_name: "ENERGY.Power"
    help: "Currently measured power"
    type: gauge
  - prom_name: apparent_power_watt
    mqtt_name: "ENERGY.ApparentPower"
    help: "Currently apparent power"
    type: gauge
  - prom_name: reactive_power_watt
    mqtt_name: "ENERGY.ReactivePower"
    help: "Currently reactive power"
    type: gauge
  - prom_name: power_voltage
    mqtt_name: "ENERGY.Voltage"
    help: "Current Voltage"
    type: gauge
  - prom_name: consumed_energy_kilowatthours_today
    mqtt_name: "ENERGY.Today"
    help: "total measured kilowatthours today"
    type: counter
  - prom_name: consumed_energy_kilowatthours_yesterday
    mqtt_name: "ENERGY.Yesterday"
    help: "total measured kilowatthours yesterday"
    type: counter
  - prom_name: power_meter_consumed_energy_kilowatthours_total
    mqtt_name: "SML.Verbrauch_Summe"
    help: "total measured kilowatthours on power meter"
    type: counter
  - prom_name: power_meter_current_active_power_l1
    mqtt_name: "SML.Watt_L1"
    help: "Currently measured active power l1"
    type: gauge
  - prom_name: power_meter_current_active_power_l2
    mqtt_name: "SML.Watt_L2"
    help: "Currently measured active power l2"
    type: gauge
  - prom_name: power_meter_current_active_power_l3
    mqtt_name: "SML.Watt_L3"
    help: "Currently measured active power l3"
    type: gauge
  - prom_name: power_meter_current_active_power_total
    mqtt_name: "SML.Watt_Summe"
    help: "Currently measured active power l1 + l2 +l3"
    type: gauge
  - prom_name: power_meter_current_volts_l1
    mqtt_name: "SML.Volt_L1"
    help: "Currently measured volts l1"
    type: gauge
  - prom_name: power_meter_current_volts_l2
    mqtt_name: "SML.Volt_L2"
    help: "Currently measured volts l2"
    type: gauge
  - prom_name: power_meter_current_volts_l3
    mqtt_name: "SML.Volt_L3"
    help: "Currently measured volts l3"
    type: gauge

Freitag, 12. August 2022

Tasmota / Sonoff MQTT Cheat Sheet


Weil ich nach 2 Jahren mal wieder vergessen hatte wie das hier geht:

 

Prefix defaults are/can be:
cmnd/stat/tele


Full Topic consists of %prefix%/%topic%/ in Tasmota language, e.g. listening like this

mosquitto_sub -h 192.168.178.32 -t tele/#
mosquitto_sub -h 192.168.178.32 -t tele/solar/#
mosquitto_sub -h 192.168.178.32 -t tele/solar/SENSOR

... and e.g. acting like this:

mosquitto_pub -h 192.168.178.32 -t cmnd/fluter/POWER -m ON
mosquitto_pub -h 192.168.178.32 -t cmnd/fluter/POWER -m OFF

 

Vielleicht noch folgendes in der Console setzen:

PowerDelta 110

TelePeriod 60


Von https://tasmota.github.io/docs/Commands/#power-monitoring

 
TelePeriod     See current value and force publish STATE and SENSOR message
0 = disable telemetry messages
1 = reset telemetry period to firmware default (TELE_PERIOD)
10..3600 = set telemetry period in seconds (default = 300)

PowerDelta<x>
    Set maximum delta of phase a<x> in energy monitoring devices to report on active power load change while the power is ON. PowerDelta will not report when the power turns off. 
0 = disable reporting on power change
1..100 = set reporting on percentage power change to send an MQTT telemetry message
101..32000 = set reporting on absolute power change to send an MQTT telemetry message (offset by 100, e.g., 101=1W, 207=107W)

Dienstag, 1. September 2020

Creating a very unsecure but working "proxy" registry

 
mkdir -p auth

htpasswd -Bbn testuser testpassword > auth/htpasswd

mkdir -p certs

openssl req \
  -newkey rsa:4096 -nodes -sha256 -keyout certs/domain.key \
  -x509 -days 365 -out certs/domain.crt
 
Be sure to use the "right" name as a CN, e.g. myregistrydomain.com or here: (gtn.fritz.box)

Copy domain.crt to /etc/docker/certs.d/gtn.fritz.box:5000/ca.crt, otherwise the login will complain about "Error response from daemon: Get https://gtn.fritz.box:5000/v2/: x509: certificate signed by unknown authority
"

root@gtn gtn.fritz.box:5000]# pwd
/etc/docker/certs.d/gtn.fritz.box:5000
[root@gtn gtn.fritz.box:5000]# ls -la
-rw-r--r-- 1 root root 1996 Sep  1 21:23 ca.crt

Run the thingy with a bunch of funny options

docker run -d \
  -p 5000:5000 \
  --restart=always \
  --name registry \
  -v "$(pwd)"/auth:/auth \
  -e "REGISTRY_AUTH=htpasswd" \
  -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
  -e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \
  -v "$(pwd)"/certs:/certs \
  -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt \
  -e REGISTRY_HTTP_TLS_KEY=/certs/domain.key \
  registry:2