Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
vortigont committed Dec 6, 2023
1 parent 7d839eb commit effd4fb
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 9 deletions.
73 changes: 64 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,74 @@ for [Peacefair](https://peacefair.aliexpress.com/store/1773456/) PZEM-004Tv30 Po
## Features
- WebUI via self-hosted HTTP/WebSocket server
- Real-time gauges and power charts
- metrics collector in controller's memory pool
- MQTT puplishing metrics data in json format
- 3 level Tiered TimeSeries metrics collector in controller's memory pool
- data/metrics export via json
- compressed OTA updating via [esp32-flashz](https://github.com/vortigont/esp32-flashz) lib
- espem could be build to run via DummyPZEM emulator for prototyping and firmware testing without connecting to a real PZEM device

## ESPEM WebUI Dashboard

<img src="/examples/espemembui.png" alt="espem ui" width="50%"/>

## MQTT
MQTT server publishing and connection could be configured via "Settings" - "MQTT".
It will publish pzem metrics to topic `~/pub/pzem/jmetrics` on each update cycle. Where `~` is topic prefix, default is `EmbUI/[DeviceID]/`.

Message structure is a dictionary with PZEM metrics in an integer format in a way PZEM sends it via MODBUS.
`[{"stale":false,"age":999,"U":2180,"I":503,"P":778,"W":560,"Pf":71,"freq":505}]`

I.e.
`U` - denoted voltage in decivolts
`I` - current im mA
`P` - power in deciwatts
`W` - energy in Wh
`Pg` - power factor in percents
`freq` - is frequency in dHz
`stale` - denotes if data is stale, i.e. has not been updated recently
`age` - data age in ms

## Tiered TimeSeries data Sampling
Controller will keep a history of previous data received from PZEM in it's memory in a tiered memory pool. It is commonly used for time series data where the longer the data age then less frequent is sampling rate of the data to keep. All data resides in volatale `memory`, so it will be lost on power cycle or reset.
By defaul there are 3 levels of TimeSeries in a pool

| Level | Samples count | Sampling interval | Time range |
| L1 | 900 | 1 sec | 15 min |
| L2 | 1000 | 15 sec | 250 min (abt 4 hrs) |
| L3 | 1000 | 300 sec | ~83 hrsn |

Number of samples and interval could be adjusted per each level via "Espem setup" - "TimeSeries collector" configuration.

#### ESPEM TS Options

<img src="/examples/ts_setup.png" alt="espem ts opts" width="50%"/>



#### Averaging
For levels with sampling interval more that 1 second an averaging function is used to calculate mean value between intervals. I.e. if sampling interval is set to 60 sec and you power level was about 5 watt for 55 seconds and became 100 watts for the last 5 sec when sampling was taken, then resulting power value would be slightly over 5 watts, but not 100 W.

#### Memory consumption
1000 samples takes about 25 KiB of RAM memory (one sample takes 28 bytes), so plan you pool accordingly. If your board has SPI-RAM then you can have a huge pool worth monthes of data to be kept :)

#### Data export
TimeSeries Data could be exported in json format per each tier level

Tier 1 URL - [http://espem/samples.json?tsid=1](http://espem/samples.json?tsid=1)
Tier 2 URL - [http://espem/samples.json?tsid=2](http://espem/samples.json?tsid=2)
Tier 3 URL - [http://espem/samples.json?tsid=3](http://espem/samples.json?tsid=3)

An example of exported data:
```
[
{"t":1701876803000,"U":216.60,"I":0.51,"P":88,"W":7,"hz":49.7,"pF":0.79},
{"t":1701877103000,"U":225.00,"I":0.52,"P":90,"W":14,"hz":50.1,"pF":0.77}
]
```
where:
`t` - is a unix timestamp in milliseconds (prefered for js processing)
other keys are PZEM metrics in float format


## Legacy v2.x version
An older ESPEM version 2 was based on 3rd party lib. It's code still available under [2.x branch](https://github.com/vortigont/espem/tree/v2).
Expand All @@ -32,14 +95,6 @@ ESPEM Ver 3 switched to it's own library [pzem-edl](https://github.com/vortigont



### ESPEM WebUI Dashboard

<img src="/examples/espemembui.png" alt="espem ui" width="50%"/>

### ESPEM WebUI Options

<img src="/examples/espemembui_setup.png" alt="espem opts" width="50%"/>

### Additional tools
Under /www there is a set of php/sql scripts that could be hosted undel LAMP to gather and calculate stats over long-term periods. Little bit outdated but still usable.
No need for any cloud services, spyware etc... just a raspberry/orangepi running web-server with sqlite/mysql DB. It's possible to collect data from any number of PZEM monitors and store it in the DB for a long-term stats or get a PowerChart sampled data from the espem itself.
Expand Down
Binary file added examples/ts_setup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit effd4fb

Please sign in to comment.