A firmware for the ESP-32 microcontroller to act as a gateway between an EBC charger and an MQTT broker. Currently this software supports only an EBC-A20 charger/discharger from ZKETech, but may easily ported for other models.
The software uses the arduino framework and the homie library. So it complies to the homie 3.0.1 specification. The software is written for an ESP-32 microcontroller but may run with limitations on an ESP-8266 as well.
Use Visual Studio Code and the PlatformIO extension to compile the source code.
The ESP-32 and the ESP8266 uses different voltages as the EBC chargers. So you have to use a logic level shifter between this components. The ESP uses 3.3V and the EBC uses 5V. Here is an example for an ESP development board, which contains a voltage regulator from 5V to 3.3V.
Power supply ESP-32 level shifter EBC (mini USB port / pin, color)
GND ----------- GND ------ GND -- GND --------- GND (4/5, black)
5V ----------- 5V ------------- HV --------- VCC (1, red)
3.3V ------ LV
TX2 ------ LV1 HV1 --------- D- (2, white)
RX2 ------ LV2 HV2 --------- D+ (3, green)
If you use an ESP development board, you can use the onboard USB port for the 5V power supply.
See configuration for Homie 3.0.1.
This Software comes with no user interface. It is controlled entirly throug the MQTT interface. Use a home automation system of your choice to build your own user interface. An example of an user interface in node-red can be found in the source code folder ui/node-red.
Debug messages.
Informational messages.
Error messages.
Binary dump of every message send from the ESP controller to the EBC charger.
Binary dump of every message received by the ESP controller from the EBC charger.
Connection state (on or off).
If connected, the model of the EBC charger.
The current operation mode of the EBC charger (charging, discharging, stopped).
An object, formatted as json string, containing all received values from the EBC charger.
The actual voltage (V).
The actual current (A).
The calculated capacity (Ah).
The loaded program. This topic can be set by homie/ebc-control/cpu/program/set
and contains the program running on the ESP. The program is formatted as a json string and looks like this example:
{
"id":"LF280",
"name":"LiFePo4, 280Ah, 3.60V",
"steps":
[
{
"command":"C-CV",
"parameters":
{
"voltageV":3.6,
"currentA":5,
"cutoffA":0.5
}
},
{
"command":"D-CC",
"parameters":
{
"cutoffV":2.6,
"currentA":20
}
},
{
"command":"C-CV",
"parameters":
{
"voltageV":3.3,
"currentA":5,
"cutoffA":0.5
}
}
]
}
This program has three steps.
-
The first step runs the command C-CV (charge constant voltage) at 3.6V and 5.0A. The cut off current is 0.5A.
-
The second step runs the command D-CC (discharge constant current) at 20A. The cut off voltage is 2.6V.
-
The third step runs the command C-CV (charge constant voltage) at 3.3V and 5.0A. The cut off current is 0.5A.
The list of available commands differs and depends on the used EBC charger. There are two commands that are always available:
-
Wait: It performs a pause. It has one parameter seconds or minutes which specify the duration.
-
Cycle: It cycles to a previous step. It has two parameters step and count. step specifies the step number to jump to (first step has number 0). count tells how often the backcycle should be performed. count must be between 0 and 65535.
See section Program Commands for a list of available commands and parameters.
Remark: loading a program is only possible if an EBC charger is connected. If not in the connected state the gateway tries to connect first, load the program and disconnects at last step. If there is no EBC charger pluged to the gateway, the program loading fails!
Run state (on or off).
The state of the current program.
Actual step of a running program.
The results of the program. This topic is updated after each program step and contains the results of all finished steps.
Example:
[
{"step":0,"command":"C-CV","capacityAh":199.01},
{"step":1,"command":"D-CC","capacityAh":267.2},
{"step":2,"command":"C-CV","capacityAh":68.48}
]
Controller | Command | Parameters |
---|---|---|
all | Wait | seconds or minutes |
all | Cycle | step, count |
EBC-A20 | C-CV | currentA, voltageV, cutoffA |
EBC-A20 | D-CC | currentA, cutoffV, maxTimeM |
EBC-A20 | D-CP | powerW, cutoffV, maxTimeM |
This software has support for additional stop conditions on every program step.
Here is a full program example:
{
"name": "Li-Ion, 700mAh, 3.7V, 70%",
"steps": [
{
"command": "C-CV",
"parameters": {
"voltageV": 4.2,
"currentA": 0.35,
"cutoffA": 0.1
}
},
{
"command": "D-CC",
"parameters": {
"cutoffV": 2.75,
"currentA": 0.35
}
},
{
"command": "C-CV",
"parameters": {
"voltageV": 4.2,
"currentA": 0.35,
"cutoffA": 0.1
},
"stopCondition": {
"capacityAh": "70%"
}
}
]
}
The last step stops if the capacity reaches 70% of the previous step. So this program do charge the cell to 100% SOC, than it discharges it to 0% SOC and measures the full capacity of the cell. In the last step it charges the cell to 70% of it's capacity.
The stop condition capacityAh can be relativ (percent) like in this example or it can be an absolute value in Ah like "capacityAh": 0.65
.
This software supports only the EBC-A20 charger but can be expanded to support more chargers from ZKETech. To do so, you only have to create a copy of the files EbcA20.hpp
and EbcA20.cpp
and modify them to meet the protocol of your desired charger. Expand the method EbcController::GetController(uint8_t id)
in EbcController.hpp
as well.