ai-republic / bms-to-inverter

Use, monitor and control any battery brand with any inverter! Application to read and monitor data from BMSes and write data to an inverter using any protocol (e.g. UART, RS485, ModBus or CAN)
https://github.com/ai-republic/bms-to-inverter
Other
32 stars 6 forks source link

First time running with Daly TTL #6

Closed sanitariu closed 5 months ago

sanitariu commented 7 months ago

Here is the debug info as requested:

root@sol:~/test # java -jar bms-to-inverter-main-0.0.1-SNAPSHOT.jar

debug.txt

also I am attaching my pom.xml and config.properties files

ai.zip

sanitariu commented 7 months ago

I think i need help with config.properties setting things for RS485 port. It must be /dev/ttyUSB0

sanitariu commented 7 months ago

This is my last changes. I think i am little ahead. Seems like the problem is opening serial port.

root@sol:~/test # java -jar bms-to-inverter-main-0.0.1-SNAPSHOT.jar 20:11:10.622 INFO : WELD-000900: 5.1.1 (Final) 20:11:11.140 WARN : WELD-ENV-002008: Bean class module-info found in multiple bean archives - this may result in incorrect behavior:

20:11:14.950 ERROR: Failed to perform initial reading of BMS values! java.lang.NoClassDefFoundError: android/content/Context at java.lang.Class.getDeclaredFields0(Native Method) ~[?:?] at java.lang.Class.privateGetDeclaredFields(Class.java:3297) ~[?:?] at java.lang.Class.getDeclaredFields(Class.java:2371) ~[?:?] at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:237) ~[gson-2.10.1.jar:?] at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:130) ~[gson-2.10.1.jar:?] at com.google.gson.Gson.getAdapter(Gson.java:556) ~[gson-2.10.1.jar:?] at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:160) ~[gson-2.10.1.jar:?] at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:294) ~[gson-2.10.1.jar:?] at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:130) ~[gson-2.10.1.jar:?] at com.google.gson.Gson.getAdapter(Gson.java:556) ~[gson-2.10.1.jar:?] at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:160) ~[gson-2.10.1.jar:?] at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:294) ~[gson-2.10.1.jar:?] at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:130) ~[gson-2.10.1.jar:?] at com.google.gson.Gson.getAdapter(Gson.java:556) ~[gson-2.10.1.jar:?] at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:55) ~[gson-2.10.1.jar:?] at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:196) ~[gson-2.10.1.jar:?] at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:368) ~[gson-2.10.1.jar:?] at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:70) ~[gson-2.10.1.jar:?] at com.google.gson.internal.bind.ArrayTypeAdapter.write(ArrayTypeAdapter.java:104) ~[gson-2.10.1.jar:?] at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:70) ~[gson-2.10.1.jar:?] at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:196) ~[gson-2.10.1.jar:?] at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:368) ~[gson-2.10.1.jar:?] at com.google.gson.Gson.toJson(Gson.java:842) ~[gson-2.10.1.jar:?] at com.google.gson.Gson.toJson(Gson.java:812) ~[gson-2.10.1.jar:?] at com.google.gson.Gson.toJson(Gson.java:759) ~[gson-2.10.1.jar:?] at com.google.gson.Gson.toJson(Gson.java:736) ~[gson-2.10.1.jar:?] at com.airepublic.bmstoinverter.core.bms.data.EnergyStorage.toJson(EnergyStorage.java:82) ~[core-api-0.0.1-SNAPSHOT.jar:?] at com.airepublic.bmstoinverter.BmsToInverter.start(BmsToInverter.java:142) [bms-to-inverter-main-0.0.1-SNAPSHOT.jar:?] at com.airepublic.bmstoinverter.BmsToInverter$Proxy$_$$_WeldClientProxy.start(Unknown Source) [bms-to-inverter-main-0.0.1-SNAPSHOT.jar:?] at com.airepublic.bmstoinverter.BmsToInverter.main(BmsToInverter.java:68) [bms-to-inverter-main-0.0.1-SNAPSHOT.jar:?] Caused by: java.lang.ClassNotFoundException: android.content.Context at jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[?:?] at jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[?:?] at java.lang.ClassLoader.loadClass(ClassLoader.java:525) ~[?:?] ... 30 more

ai-republic commented 7 months ago

I have checked your config.properties. Do you really have 16 battery packs? A battery pack consists (usually) of more lithium cells like 4 for 12V, 8 for 24V and 16 for 48V, etc. I assume you have 1 battery pack consisting of 16 x 3.6V cells (1P16S), so the numBatteryPacks parameter should be 1.

If you need to change the MQTT broker locator port (61616) please be aware to change it also in the application.properties of the webserver project if you want use the web-app.

Also, please pull the latest version, I just fixed an issue in the JSerialCommPort to ensure the port is open. That was lost in the commit yesterday and should work now.

sanitariu commented 7 months ago

Thank you very much for the support ! I hope we will make it working ... even if you need remote shell i can arrange it ! Now seems like ttyUSB0 is opened and much better. Still there is something wrong in reading or sending data from the com port. Attaching the log files with debug enabled.

config.properties.txt debug.txt pom.xml.txt

sanitariu commented 7 months ago

I think something should be added like protocol RS232 instead 485 ...

ai-republic commented 7 months ago

My bad, the port wasn't initialized properly with the frameLength, baudrate and startFlag. I committed the fix.

I will try and setup another PI today with the RS485/CAN hat so I can retest the RS485. I've been concentrating on CAN lately and only had one PI ready for testing.

sanitariu commented 7 months ago

Hello, now is littler better ... we have some responses :) 09:28:44.140 WARN : Command 0x50 to BMS 1 successfully sent and received! 09:28:44.219 WARN : Command 0x53 to BMS 1 successfully sent and received! 09:28:44.289 WARN : Command 0x5a to BMS 1 successfully sent and received! 09:28:44.379 WARN : Command 0x5b to BMS 1 successfully sent and received!

But still have errors for id. Attaching the file.

debug1.txt

ai-republic commented 7 months ago

Could you run this in debug mode please, then I can have a look what the frame looks like that has been received and why the msg.cmd is null. Thanks Todor! BTW I've got my 2nd PI setup with the RS485 hat now so I can do some effective debugging again tomorrow

sanitariu commented 7 months ago

Here is full debug. I see some good data ! 10:03:09.365 DEBUG: ratedCellmV=3200, ratedCapacitymAh=280000 This is my battery 280AH 10:03:09.444 DEBUG: battery type={}=0 - this one is emtpy ? 10:03:09.612 DEBUG: maxPackChargeCurrent=2400, maxPackDischargeCurrent=-2400 - this i am not sure ... Anyway i see the light in the tunnel :)

fulldebug.txt

ai-republic commented 7 months ago

Ok, I fixed the issue with the RS485 msg.cmd (id). Please pull again :) More tomorrow....

sanitariu commented 7 months ago

Thanks. Much much better ! Now i see info like this 10:41:10.911 INFO : BMS SOC V A CellMinV CellMaxV CellDiff 1 1.7 52.2 7.4 3.259 - 2 3.271(#0.009) 0.012

Seems like USB (RS232) is working too :)

Here is the log file

fulldebug.txt

ai-republic commented 7 months ago

Ok - that looks all good :)

I think I know where the last exception (gson - android/content/Context) is coming from. I fixed it

sanitariu commented 7 months ago

Here is the latest debug log. Also i have tested webserver and it shows some data. I think data is not correct. Maybe this is wrong ? 10:41:17.731 DEBUG: BMS 1, Frame No.: 5, Cell No: 17. 3253mV 10:41:17.731 DEBUG: BMS 1, Frame No.: 5, Cell No: 18. 3255mV

I have noticed that it is reading data too fast. Is it possible that some data is not returned from the serial port ? Can we put reading like each 10 seconds or something like that ? Maybe it is crashing from that ?! (bad data)

Here it stops - java.lang.NoClassDefFoundError: android/content/Context

fulldebug.txt Screenshot 2023-11-23 at 10 46 47

ai-republic commented 7 months ago

I fixed the gson error now and made the code more resilient against errors.

The data that's received is correct. That's what's reported by the BMS. The 'Cell 17/18' is actually reported in the 5th frame but can be ignored. It's only because Daly sends a 5th frame to send the 16th cells value. I guess they don't clear their buffer properly - that's where cell 17 and 18 result

sanitariu commented 7 months ago

Hello, tested again with latest fixes. Now it is working better. Actually it is flooding the console with info each second which i think is too fast sending / getting data. It should be maybe 5-10 seconds interval. Anyway it was working for 2-3 minutes then stops. Do you know how i can log all the output ?

These are the last lines received:

09:39:52.438 DEBUG: Validation of frame failed! 09:39:52.438 DEBUG: Ignoring frame: RX Buffer (HEX): [0x00, 0x01, 0x95, 0x08, 0x05, 0x0C, 0xCD, 0x0C, 0xC7, 0x0C, 0xCC, 0x01, 0x95]

09:40:06.981 DEBUG: Scanning for expires on energystorage 09:40:06.982 DEBUG: Scanning for expires on energystorage done

Also on the webserver i noticed that you have BMS8 but they should be only 1. Maybe config.properties is not read by the webserver. It is serial 9600 and maybe too fast or some result is not good. When it stops it does not continue / retry

ai-republic commented 7 months ago

Hi Todor, I could put in a configurable poll interval - that's no problem.

I guess that when it stops maybe the buffers are full on the PI. I'll have a look into that.

You can also log everything to file. I added a configuration to log to console and rotational log file. You'll find the log file in the logs folder.

sanitariu commented 7 months ago

Here is the lates log file. I have tried 4-5 seconds but it does not help. I think it is stopping at the same time. Maybe buffer ?! You can login to my machine and test if you like. It is okay for me.

BMS-to-Inverter.log.gz

ai-republic commented 7 months ago

I've checked the log file and I guess its shutting down the BMS and inverter processing threads because of an uncaught exception coming from the MQTT service. I've generalized the exception handling so there shouldn't be any exceptions falling through.

Also I noticed that there are still 8 battery packs in your system. Is that correct? Or is it only 1? In that case you might need to check the numBatteryPacks configuration in config.properties and set it to 1.

sanitariu commented 7 months ago

Hello, i have 1 pack and i fixed it now. Still it reads some data 5-6 times then it does not try anymore.

BMS-to-Inverter.log.gz

BMS-to-Inverter.log-2.gz

Second one is crashing on email but i have disabled email at all ...

sanitariu commented 7 months ago

Ok i setup email and seems like it is working from 5 minutes :))) I put bms/inverter read data to 10 seconds. On the webserver you must fix the number of packs. Maybe they are hardcoded. For the above crash maybe it was because email info was empty. You can fix it i think. I was too hurry :( ... Crashed again but this time it took longer time. Here is the log

BMS-to-Inverter-3.log.gz

sanitariu commented 7 months ago

I tested today with latest fixes. Working for some minutes then it stops. I think it is from "2023-11-29 18:48:00.909 | DEBUG | 2-thread-1 | s485.JSerialCommPort:132 | Validation of frame failed!" Maybe some data is corrupted or lagged but it should ignore data from that time and do not send to inverter anything ... then just retry on the next period ? Attaching log file if you need it. Maybe you should try different approach like open com port , read data , close com port , then after the period open/read/close. I think com ports are more unstable than can and sometimes stuck for some period maybe ?!

BMS-to-Inverter.log.gz

ai-republic commented 6 months ago

Hi Todor, sorry for the late reply - I was very busy the last few days. I logged in, tested and updated the application on your PI. Also made a small script in the home folder to speed things up with pulling a new version, building and starting the app.

Now to the problem. I've observed this also on my PI when running RS485 that Daly starts sending rubbish messages addressed to ID FF (255) or messages that are to short. I've tried to compensate the short messages by reading data from the stream and searching for the start flag (0xA5) and restarting from there but it didn't make any difference because the data was rubbish.

The next approach I want to try would be to read the RS485 stream and buffer it locally and start reading the messages from there (also better for debugging) and when it starts sending rubbish try to send a reset command and see if it starts sending correct messages again.

I will try to implement this on the weekend, since I'm still busy the next couple of days.

sanitariu commented 6 months ago

Thank you very much for the support ! Waiting for stable 485 version so we can continue with the inverter :)

sanitariu commented 6 months ago

Hello, Tested latest fixes and data is read only once. Maybe the number of bytes is wrong always.

debug.log

ai-republic commented 5 months ago

Closed this issue. All is fixed in the current version.