stuartpittaway / diyBMSv4ESP32

diyBMS v4 code for the ESP32 and new controller hardware
Other
186 stars 81 forks source link

PYLON LFP battery communication protocol over RS485 #182

Open elmozwo opened 1 year ago

elmozwo commented 1 year ago

Possibility to connect a Pylontech batterie via RS485 for inverters or Logger wich don't have a Can bus interface e.g. FSP Hybrid Power Manager and Plexlog.

Protokoll description: URL

If there are more informations required, just ask me. Possibly I can find them.

ruza87 commented 1 year ago

Hi Stuart, I have a simple implementation of Pylontech protocol over RS485 integrated into diyBMS code and running with the PIP5048 / Voltronic VM III inverter.

The integration into diyBMS isn't perfect, I didn't know how to make it work together with existing RX/TX queues in main.cpp, so I commented those lines (I'm not using RS485 current shunt) and it's calling uart_read_bytes / uart_write_bytes directly.

What's implemented:

What's not:

Let me know what you need, I can share the code.

stuartpittaway commented 1 year ago

If you can do a GitHub pull request {PR) I can take a look

ruza87 commented 1 year ago

Ok, will do.

stuartpittaway commented 1 year ago

@elmozwo do you have anyway to test the changes @ruza87 has made?

I don't have the necessary inverters/equipment to test the RS485 protocol.

elmozwo commented 1 year ago

Yes, I have. If I get some time next days I can try. How can I get this build?

stuartpittaway commented 1 year ago

@ruza87 can you help with some build instructions?

ruza87 commented 1 year ago

@elmozwo Are you familiar with compiling of the sources in Visual Studio Code using PlatformIO addon? Clone the sources from https://github.com/ruza87/diyBMSv4ESP32/tree/pylon_rs485 and the next steps to build & flash are the same as in the original Stuart's repo.

Or you might try to use already compiled code from my (first, highly experimental:-) release. You can download it here https://github.com/ruza87/diyBMSv4ESP32/releases/download/v1.0.0/release_2023-04-14-09-07.zip and follow the original instructions to flash it: https://github.com/stuartpittaway/diyBMSv4ESP32/blob/master/ProgrammingHardware.md

Jestergnet commented 1 year ago

How is it going? Also interested in this area...

stuartpittaway commented 1 year ago

For people who want to test this (@Jestergnet and @elmozwo ) GITHUB actions have pre-compiled the release.

https://github.com/stuartpittaway/diyBMSv4ESP32/actions/runs/4740188233?pr=195

Look at the bottom of that page for "[DIYBMS-Compiled]"(https://github.com/stuartpittaway/diyBMSv4ESP32/suites/12332390974/artifacts/654416283)

And use this file for the controller. image

Jestergnet commented 1 year ago

Has anyone already tested the code? After the RS485 firmware, I don’t show any signs at all. Diybms acting as a host? Who is contacting whom? Inverter to BMS or BMS to inverter? After flashing the screen is terribly slow ...

ruza87 commented 1 year ago

@Jestergnet I did. Mine is working with PIP 5048 (same as Voltronic VM III), the battery icon on the inverter is flashing, which means the communication is running OK. The inverter is a host, asking BMS for a reply.

Did you select PylonTech RS485 emulation on the diyBMS "Charge/Discharge configuration" page? Also, is your RS485 speed set correctly? For this inverter it needs to be set to 9600 baud, you can do it on "Current &Voltage Monitoring" page.

Regarding the screen issue - I don't have the screen attached so I cannot tell.

Jestergnet commented 1 year ago

@Jestergnet I did. Mine is working with PIP 5048 (same as Voltronic VM III), the battery icon on the inverter is flashing, which means the communication is running OK. The inverter is a host, asking BMS for a reply.

Did you select PylonTech RS485 emulation on the diyBMS "Charge/Discharge configuration" page? Also, is your RS485 speed set correctly? For this inverter it needs to be set to 9600 baud, you can do it on "Current &Voltage Monitoring" page.

Regarding the screen issue - I don't have the screen attached so I cannot tell.

Ok, I'll try.

elmozwo commented 1 year ago

Finaly I also get some time to test. It looks good! The only thing is that it produces many warning popups about discharging/ charging is prevented. Even check or uncheck the boxes will not change anything.

ruza87 commented 1 year ago

Do you have an external temp sensor connected to the BMS, so it can measure battery temperature? Without any external temp sensor the charging/discharging is blocked.

elmozwo commented 1 year ago

I just have the two sensors from the batterie modules. Do I need a additional one?

ruza87 commented 1 year ago

Two sensors are fine. Can you check all the rules to see if any of them is preventing the charging? Is the communication between your inverter and diyBMS working? What inverter model do you have?

Jestergnet commented 1 year ago

Found a problem, after activating PylonTech RS485, the screen loses its refresh rate. If you disable this option, the screen returns to the normal refresh rate of the image. In order for one page to load, it probably takes 20 seconds, or even more ...

Logs: I (458680) diybms-webreq: API call: monitor2 I (458756) diybms-webreq: API call: chargeconfig I (460865) diybms: Task 1 W (461052) diybms-rules: Cell V>Max I (461053) diybms-rules: Set warning 9 I (461053) diybms-rules: Set warning 7 I (461053) diybms-rules: Set warning 8 I (462270) diybms-webreq: API call: monitor2 I (463361) diybms-webpost: API post: savechargeconfig W (463363) diybms-webfuncs: Missing key named 'stopchargebalance' W (463363) diybms-webfuncs: Missing key named 'socoverride' W (463366) diybms-webfuncs: Missing key named 'socforcelow' W (463372) diybms-webfuncs: Missing key named 'preventcharging' W (463377) diybms-webfuncs: Missing key named 'preventdischarge'

photo_2023-06-14_17-30-21

ruza87 commented 1 year ago

Hi @stuartpittaway, do you have any idea what could cause the issue described by @Jestergnet ? Could it be the modified loop in rs485_rx task consuming more CPU time? (code here: https://github.com/ruza87/diyBMSv4ESP32/blob/pylon_rs485/ESPController/src/main.cpp#L2772) I don't have the LCD to replicate the issue.

stuartpittaway commented 1 year ago

From a quick review of the code @ruza87 I think you are in a near-infinite loop waiting for serial data to arrive.

The original code uses this ulTaskNotifyTake(pdTRUE, portMAX_DELAY); as a delay (part of the RTOS) until the transmit function triggers (notifies) it.

ruza87 commented 1 year ago

Oh, I see it now, thanks @stuartpittaway. I call uart_read_bytes when the RX buffer contains at least pylon protocol header. This is tested in uart_get_buffered_data_len. But, if the buffer is empty (or contains less data) the task is not suspended which leads to quick looping... I'll add vTaskDelay to pause the task in that case.

Jestergnet commented 1 year ago

Oh, I see it now, thanks @stuartpittaway. I call uart_read_bytes when the RX buffer contains at least pylon protocol header. This is tested in uart_get_buffered_data_len. But, if the buffer is empty (or contains less data) the task is not suspended which leads to quick looping... I'll add vTaskDelay to pause the task in that case.

Let me know when you make a fix, I'll check.

ruza87 commented 1 year ago

I fixed it in my repository. You can download the new release from here (https://github.com/ruza87/diyBMSv4ESP32/releases/tag/v1.0.1) or preferably wait for @stuartpittaway to approve GITHUB actions to create automated release.

Jestergnet commented 1 year ago

I fixed it in my repository. You can download the new release from here (https://github.com/ruza87/diyBMSv4ESP32/releases/tag/v1.0.1) or preferably wait for @stuartpittaway to approve GITHUB actions to create automated release.

Hi, thanks for the fix. Checked, now the screen does not slow down.