diy solar

diy solar

Monitoring Jakiper ( maybe SOK too?) server rack batteries via modbus to Esp8266 mqtt

I tried the latest changes in the Python code and the outcome is the same. Cannot get the PackCount
Code:
2022-10-25 23:22:52,292:INFO:PylonToMQTT:pylon_mqtt starting up...
2022-10-25 23:22:52,310:INFO:PylonToMQTT:pylonPort = /dev/ttyUSB0
2022-10-25 23:22:52,310:INFO:PylonToMQTT:rackName = Main
2022-10-25 23:22:52,311:INFO:PylonToMQTT:mqttHost = localhost
2022-10-25 23:22:52,311:INFO:PylonToMQTT:mqttPort = 1883
2022-10-25 23:22:52,311:INFO:PylonToMQTT:mqttRoot = PylonToMQTT
2022-10-25 23:22:52,311:INFO:PylonToMQTT:mqttUser = node_red
2022-10-25 23:22:52,311:INFO:PylonToMQTT:mqttPassword = **********
2022-10-25 23:22:52,311:INFO:PylonToMQTT:publishRate = 10
2022-10-25 23:22:52,311:INFO:PylonToMQTT:Connecting with clientId=node_red_mqttclient_741
2022-10-25 23:22:52,312:INFO:PylonToMQTT:Connecting to MQTT localhost:1883
2022-10-25 23:22:52,316:DEBUG:PylonToMQTT:MQTT connected OK Returned code=0
2022-10-25 23:22:52,317:DEBUG:PylonToMQTT:Subscribed to PylonToMQTT/Main/cmnd/#
2022-10-25 23:22:52,317:DEBUG:PylonToMQTT:Starting main loop...
2022-10-25 23:23:02,317:DEBUG:PylonToMQTT:send_cmd: 7e323030303436393030303030464441420d
2022-10-25 23:23:07,323:DEBUG:PylonToMQTT:received_response:
2022-10-25 23:23:07,324:ERROR:PylonToMQTT:Failed to process response!
2022-10-25 23:23:07,324:ERROR:PylonToMQTT:invalid literal for int() with base 16: b''
Traceback (most recent call last):
  File "/home/pi/PylonToMQTT/PylonToMQTT-main/Python/pylon_to_mqtt.py", line 167, in periodic
    number_of_packs = p.get_pack_count().PackCount
  File "/home/pi/PylonToMQTT/PylonToMQTT-main/Python/support/pylontech.py", line 155, in get_pack_count
    f =  self.read_frame()
  File "/home/pi/PylonToMQTT/PylonToMQTT-main/Python/support/pylontech.py", line 148, in read_frame
    f = self._decode_hw_frame(raw_frame)
  File "/home/pi/PylonToMQTT/PylonToMQTT-main/Python/support/pylontech.py", line 129, in _decode_hw_frame
    assert got_frame_checksum == int(frame_chksum, 16)
ValueError: invalid literal for int() with base 16: b''
2022-10-25 23:23:17,329:DEBUG:PylonToMQTT:send_cmd: 7e323030303436393030303030464441420d
2022-10-25 23:23:22,335:DEBUG:PylonToMQTT:received_response:
2022-10-25 23:23:22,335:ERROR:PylonToMQTT:Failed to process response!
2022-10-25 23:23:22,336:ERROR:PylonToMQTT:invalid literal for int() with base 16: b''
I got an ESP32 and flashed it with the firmware. Tomorrow I'll plug it to the battery because it is at remote location.
Managed to configure the Wifi and after connecting to it with Putty I got a different command sent from the ESP to the battery:
Code:
[  5312][I][IOT.cpp:55] connectToMqtt(): Connecting to MQTT...
[  5318][D][IOT.cpp:67] connectToMqtt(): rootTopicPrefix: PylonToMQTT/Penevi
[  5572][D][IOT.cpp:32] onMqttConnect(): Connected to MQTT. Session present: 0
[  5575][I][IOT.cpp:37] onMqttConnect(): Subscribed to [PylonToMQTT/Penevi/cmnd/#], qos: 0
[ 10098][D][Pylon.cpp:123] send_cmd(): send_cmd: ~25FF4690E002FFFCD7
[ 20101][E][Pylon.h:34] timeout(): AsyncSerial: timeout
It gives timeout because I haven't connected the RS232 converter and the battery. Tomorrow morning I'll be testing it. Graham I hope this can help you. I have VPN access to the Raspberry Pi connected to the batteries and I can try new changes.
Wait on trying the Raspberry Pi - might be some issue with it. I will let you know if I get it going here first.
 
I tried the latest changes in the Python code and the outcome is the same. Cannot get the PackCount
Code:
2022-10-25 23:22:52,292:INFO:PylonToMQTT:pylon_mqtt starting up...
2022-10-25 23:22:52,310:INFO:PylonToMQTT:pylonPort = /dev/ttyUSB0
2022-10-25 23:22:52,310:INFO:PylonToMQTT:rackName = Main
2022-10-25 23:22:52,311:INFO:PylonToMQTT:mqttHost = localhost
2022-10-25 23:22:52,311:INFO:PylonToMQTT:mqttPort = 1883
2022-10-25 23:22:52,311:INFO:PylonToMQTT:mqttRoot = PylonToMQTT
2022-10-25 23:22:52,311:INFO:PylonToMQTT:mqttUser = node_red
2022-10-25 23:22:52,311:INFO:PylonToMQTT:mqttPassword = **********
2022-10-25 23:22:52,311:INFO:PylonToMQTT:publishRate = 10
2022-10-25 23:22:52,311:INFO:PylonToMQTT:Connecting with clientId=node_red_mqttclient_741
2022-10-25 23:22:52,312:INFO:PylonToMQTT:Connecting to MQTT localhost:1883
2022-10-25 23:22:52,316:DEBUG:PylonToMQTT:MQTT connected OK Returned code=0
2022-10-25 23:22:52,317:DEBUG:PylonToMQTT:Subscribed to PylonToMQTT/Main/cmnd/#
2022-10-25 23:22:52,317:DEBUG:PylonToMQTT:Starting main loop...
2022-10-25 23:23:02,317:DEBUG:PylonToMQTT:send_cmd: 7e323030303436393030303030464441420d
2022-10-25 23:23:07,323:DEBUG:PylonToMQTT:received_response:
2022-10-25 23:23:07,324:ERROR:PylonToMQTT:Failed to process response!
2022-10-25 23:23:07,324:ERROR:PylonToMQTT:invalid literal for int() with base 16: b''
Traceback (most recent call last):
  File "/home/pi/PylonToMQTT/PylonToMQTT-main/Python/pylon_to_mqtt.py", line 167, in periodic
    number_of_packs = p.get_pack_count().PackCount
  File "/home/pi/PylonToMQTT/PylonToMQTT-main/Python/support/pylontech.py", line 155, in get_pack_count
    f =  self.read_frame()
  File "/home/pi/PylonToMQTT/PylonToMQTT-main/Python/support/pylontech.py", line 148, in read_frame
    f = self._decode_hw_frame(raw_frame)
  File "/home/pi/PylonToMQTT/PylonToMQTT-main/Python/support/pylontech.py", line 129, in _decode_hw_frame
    assert got_frame_checksum == int(frame_chksum, 16)
ValueError: invalid literal for int() with base 16: b''
2022-10-25 23:23:17,329:DEBUG:PylonToMQTT:send_cmd: 7e323030303436393030303030464441420d
2022-10-25 23:23:22,335:DEBUG:PylonToMQTT:received_response:
2022-10-25 23:23:22,335:ERROR:PylonToMQTT:Failed to process response!
2022-10-25 23:23:22,336:ERROR:PylonToMQTT:invalid literal for int() with base 16: b''
I got an ESP32 and flashed it with the firmware. Tomorrow I'll plug it to the battery because it is at remote location.
Managed to configure the Wifi and after connecting to it with Putty I got a different command sent from the ESP to the battery:
Code:
[  5312][I][IOT.cpp:55] connectToMqtt(): Connecting to MQTT...
[  5318][D][IOT.cpp:67] connectToMqtt(): rootTopicPrefix: PylonToMQTT/Penevi
[  5572][D][IOT.cpp:32] onMqttConnect(): Connected to MQTT. Session present: 0
[  5575][I][IOT.cpp:37] onMqttConnect(): Subscribed to [PylonToMQTT/Penevi/cmnd/#], qos: 0
[ 10098][D][Pylon.cpp:123] send_cmd(): send_cmd: ~25FF4690E002FFFCD7
[ 20101][E][Pylon.h:34] timeout(): AsyncSerial: timeout
It gives timeout because I haven't connected the RS232 converter and the battery. Tomorrow morning I'll be testing it. Graham I hope this can help you. I have VPN access to the Raspberry Pi connected to the batteries and I can try new changes.
Looks like the ESP is not getting any response from the battery, and you're getting the same error on the Pi as Larry (bad checksum on the response).
We reverted to the code that was getting the pack count on Monday and it still doesn't work, the logs show a garbage checksum on the response (xa3TAB)

If you would like to try the attached node-red script on the PI, it sends a Get Pack Count (0x90) and checks the response for a valid checksum.
this would confirm that the comms are working between the Pi and battery (you'll need to change the COM9 port to the Pi's USB...), I have the serial port set to 9600, 8bit, 1 stop, no parity
 

Attachments

  • GetPackCount.zip
    1.2 KB · Views: 10
I tried the latest changes in the Python code and the outcome is the same. Cannot get the PackCount
Code:
2022-10-25 23:22:52,292:INFO:PylonToMQTT:pylon_mqtt starting up...
2022-10-25 23:22:52,310:INFO:PylonToMQTT:pylonPort = /dev/ttyUSB0
2022-10-25 23:22:52,310:INFO:PylonToMQTT:rackName = Main
2022-10-25 23:22:52,311:INFO:PylonToMQTT:mqttHost = localhost
2022-10-25 23:22:52,311:INFO:PylonToMQTT:mqttPort = 1883
2022-10-25 23:22:52,311:INFO:PylonToMQTT:mqttRoot = PylonToMQTT
2022-10-25 23:22:52,311:INFO:PylonToMQTT:mqttUser = node_red
2022-10-25 23:22:52,311:INFO:PylonToMQTT:mqttPassword = **********
2022-10-25 23:22:52,311:INFO:PylonToMQTT:publishRate = 10
2022-10-25 23:22:52,311:INFO:PylonToMQTT:Connecting with clientId=node_red_mqttclient_741
2022-10-25 23:22:52,312:INFO:PylonToMQTT:Connecting to MQTT localhost:1883
2022-10-25 23:22:52,316:DEBUG:PylonToMQTT:MQTT connected OK Returned code=0
2022-10-25 23:22:52,317:DEBUG:PylonToMQTT:Subscribed to PylonToMQTT/Main/cmnd/#
2022-10-25 23:22:52,317:DEBUG:PylonToMQTT:Starting main loop...
2022-10-25 23:23:02,317:DEBUG:PylonToMQTT:send_cmd: 7e323030303436393030303030464441420d
2022-10-25 23:23:07,323:DEBUG:PylonToMQTT:received_response:
2022-10-25 23:23:07,324:ERROR:PylonToMQTT:Failed to process response!
2022-10-25 23:23:07,324:ERROR:PylonToMQTT:invalid literal for int() with base 16: b''
Traceback (most recent call last):
  File "/home/pi/PylonToMQTT/PylonToMQTT-main/Python/pylon_to_mqtt.py", line 167, in periodic
    number_of_packs = p.get_pack_count().PackCount
  File "/home/pi/PylonToMQTT/PylonToMQTT-main/Python/support/pylontech.py", line 155, in get_pack_count
    f =  self.read_frame()
  File "/home/pi/PylonToMQTT/PylonToMQTT-main/Python/support/pylontech.py", line 148, in read_frame
    f = self._decode_hw_frame(raw_frame)
  File "/home/pi/PylonToMQTT/PylonToMQTT-main/Python/support/pylontech.py", line 129, in _decode_hw_frame
    assert got_frame_checksum == int(frame_chksum, 16)
ValueError: invalid literal for int() with base 16: b''
2022-10-25 23:23:17,329:DEBUG:PylonToMQTT:send_cmd: 7e323030303436393030303030464441420d
2022-10-25 23:23:22,335:DEBUG:PylonToMQTT:received_response:
2022-10-25 23:23:22,335:ERROR:PylonToMQTT:Failed to process response!
2022-10-25 23:23:22,336:ERROR:PylonToMQTT:invalid literal for int() with base 16: b''
I got an ESP32 and flashed it with the firmware. Tomorrow I'll plug it to the battery because it is at remote location.
Managed to configure the Wifi and after connecting to it with Putty I got a different command sent from the ESP to the battery:
Code:
[  5312][I][IOT.cpp:55] connectToMqtt(): Connecting to MQTT...
[  5318][D][IOT.cpp:67] connectToMqtt(): rootTopicPrefix: PylonToMQTT/Penevi
[  5572][D][IOT.cpp:32] onMqttConnect(): Connected to MQTT. Session present: 0
[  5575][I][IOT.cpp:37] onMqttConnect(): Subscribed to [PylonToMQTT/Penevi/cmnd/#], qos: 0
[ 10098][D][Pylon.cpp:123] send_cmd(): send_cmd: ~25FF4690E002FFFCD7
[ 20101][E][Pylon.h:34] timeout(): AsyncSerial: timeout
It gives timeout because I haven't connected the RS232 converter and the battery. Tomorrow morning I'll be testing it. Graham I hope this can help you. I have VPN access to the Raspberry Pi connected to the batteries and I can try new changes.
I got the Raspberry Pi working . Part of the problem was that two of the wires in the DB9 connector from Jakiper supplied cable broke off. The wires inside the connector had been hot glued to plastic cover , and I guess the small amount of flexing on the metal DB9 connector was enough to break the wires at the solder joint. The copper in the wires are very thin. Fixed that and now it all works. I think Graham was starting to pull hairs out of his head trying to find the problem in the code ! Now all is well that ends well.IMG_33411.jpg
 
Last edited:
Looks like the ESP is not getting any response from the battery
Yes because I didn't connect it to the batteries because I was on a different location.

The ESP is working and sending data. After I managed to make my own cable I was able to connect the ESP and I can gather data from the batteries. There are some issues and I'm not sure if they are on my side only. I'm using HomeAssistant as the receiver. The auto discovery worked for the first battery of the pack. There is data about the second battery but no templates are discovered by HA. I mean the messages sent to the topic like:
Code:
homeassistant/sensor/ESP<ID>_Pack1_Cell_12/config
I can see data for all four batteries on topics: <prefix>/<pack name>/stat/readings/Pack1 to Pack4

If you would like to try the attached node-red script on the PI, it sends a Get Pack Count (0x90) and checks the response for a valid checksum.
this would confirm that the comms are working between the Pi and battery (you'll need to change the COM9 port to the Pi's USB...), I have the serial port set to 9600, 8bit, 1 stop, no parity
I tried it on the Pi and still no response from the battery. Currently I'm powering the ESP from the Raspberry to monitor the battery and I can't easily swap the cables. After you added the log messages of the commands sent from the ESP and the Pi I can see that they are different. I'm not sure if this is because of a different conversion to HEX between the Python and C implementation. I'll be going there tomorrow morning and I can try something else if you like.
I got the Raspberry Pi working . Part of the problem was that two of the wires in the DB9 connector from Jakiper supplied cable broke off. The wires inside the connector had been hot glued to plastic cover
Well done on your side. I opened my connector to check how is it wired and it is also hot glued. but on mine it is glued all the way to the connector and cannot get loose
 
Well done on your side. I opened my connector to check how is it wired and it is also hot glued. but on mine it is glued all the way to the connector and cannot get loose
Mine was also hot glued to connector. The problem was that there was no slack in the wires so that any flex on that metal plug cracked the wires off at solder joint. Good to hear you have the Esp 32 working !
If you ever get telegraf, influx, and grafana set up , I can share my grafana so you can get it going fast.
 
Version 1.02 monitor adds temperatures, battery charge current, and cycle count to the data https://github.com/ClassicDIY/JakiperMQTT
View attachment 113915
This GitHub project is missing..... where did it go???

I'd like to use this to get a temperature reading from my Pace battery pack. I'm designing a variable output PID heating pad system for battery heating pads and it needs a temp sensor for feedback. I'd rather read it from the bms (hard) than use a probe (easy).
 
Last edited:
This GitHub project is missing..... where did it go???

I'd like to use this to get a temperature reading from my Pace battery pack. I'm designing a variable output PIR heating pad system for battery heating pads and it needs a temp sensor for feedback. I'd rather read it from the bms (hard) than use a probe (easy).
oh - I guess it was renamed , it evolved to do a better job.
Check here - I will find and fix the old link in thread .
Let me know how it goes and if you have any questions.
 
Awesome. Really good info!
So I'm currently using the RS232 port for Solar Assistant that I figured out a while back...

Do you know if there a way to use the RS485 port as well?
I know I could just consume the BMS temp data from my home assistant setup and do the same thing, but if that system goes down, that's bad. So getting the temp reading directly off of the rs485 port from the bottom battery appears to be a bette4 way to go. Nothing breaks that way...

Whoops... looks like this won't work. I'm using ESPHome, not platform.io.
I'll keep looking...
 
Last edited:
This GitHub project is missing..... where did it go???

I'd like to use this to get a temperature reading from my Pace battery pack. I'm designing a variable output PIR heating pad system for battery heating pads and it needs a temp sensor for feedback. I'd rather read it from the bms (hard) than use a probe (easy).
Keep us posted how your battery heating goes. I have my batteries in cold and built an insulated box around them, and put in a space heater that is controlled by inexpensive temp controller https://www.amazon.com/gp/product/B01KMA6EAM/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1.
Something of an issue I encountered is that I did a fast build of my insulated enclosure using some scrap stuff around and didn't do that best job. It does keep the batteries above freezing but I noticed that the top battery in stack is warmer than the bottom one by around 10 degrees F . The temperature difference seems to effect the SOC of batteries somewhat in that the bms keeps voltage of packs the same, but resistance of each pack varies some due to resistance I guess. Anyway it all works okay but a better way I could have done it is first to build a better box , but also having a fan in there to move the air for even heating would help - or individual heating pads under each battery pack with controls to keep each of them close to the same temperature.
What I have is oil filled space heater set on lower watts setting and it will get me by for this winter , and hopefully this next summer I can work on building a proper insulated box for them.
 
Awesome. Really good info!
So I'm currently using the RS232 port for Solar Assistant that I figured out a while back...

Do you know if there a way to use the RS485 port as well?
I know I could just consume the BMS temp data from my home assistant setup and do the same thing, but if that system goes down, that's bad. So getting the temp reading directly off of the rs485 port from the bottom battery appears to be a bette4 way to go. Nothing breaks that way...
Not sure on that - I would think you could get the rs485 data at same time as the console port. But I never tried that. The original project started by using RS485 port to get data from just one battery pack.
 
Awesome. Really good info!
So I'm currently using the RS232 port for Solar Assistant that I figured out a while back...

Do you know if there a way to use the RS485 port as well?
I know I could just consume the BMS temp data from my home assistant setup and do the same thing, but if that system goes down, that's bad. So getting the temp reading directly off of the rs485 port from the bottom battery appears to be a bette4 way to go. Nothing breaks that way...
Another way might be to just use a esp8266 with a one wire temperature sensor , you could actually put multiple temperature sensors on an esp8266 and label the source of each sensor. I use Tasmota and makes it very simple to use one wire sensors and make the data mqtt.
 
Keep us posted how your battery heating goes. I have my batteries in cold and built an insulated box around them, and put in a space heater that is controlled by inexpensive temp controller https://www.amazon.com/gp/product/B01KMA6EAM/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1.
Something of an issue I encountered is that I did a fast build of my insulated enclosure using some scrap stuff around and didn't do that best job. It does keep the batteries above freezing but I noticed that the top battery in stack is warmer than the bottom one by around 10 degrees F . The temperature difference seems to effect the SOC of batteries somewhat in that the bms keeps voltage of packs the same, but resistance of each pack varies some due to resistance I guess. Anyway it all works okay but a better way I could have done it is first to build a better box , but also having a fan in there to move the air for even heating would help - or individual heating pads under each battery pack with controls to keep each of them close to the same temperature.
What I have is oil filled space heater set on lower watts setting and it will get me by for this winter , and hopefully this next summer I can work on building a proper insulated box for them.
I'm using these heating pads
I now have the battery temps very well bounded and controlled right in the sweet spot using an on/off switch and an automation. You can see when I first started and the batts were below 0C. The spikes up and down are when home assistant became unavailable, which I will avoid by using a local temp measurement instead of via a home assistant sensor. I just got these 4A dimmers that I'm planning on using for the PID controller.
This might all be overkill, but batteries are the most expensive part of these setups so care taken on maintaining them I gpfeel is a good investment...
1673714527075.png
 
FYI, the PID controller component in ESPHome is a very complete implementation and even includes an auto tune feature!


This will take my temp graph and turn it into something like this over time, ultimately creating a completely stable, single temperature to maintain the batteries at using the least energy to do so.

1673715372283.png
 
Last edited:
It will be interesting to see how well your PID and those dimmers work out.
I think you could have also just used some inexpensive SSR too ?
I haven't jumped into the Home Assistant world yet since I would want to run it on a Raspberry Pi which of course you can't get these days.
I was going to work with Graham on a PWM project but we didnt' get very far. What I wanted to do was use a IGBT block to be able to divert some incoming PV ( 240v dc) around the controller and to a direct DC load like water or space heater. That would let batteries stay charged but save the inefficiencies of controller and inverter ( less heat ).
 
No, relays are just on/off. I actually want to reduce the current going to the warmers, but do it intelligently, hence the PID controller. I'm battling a Pellet Stove right now. But this is next on the agenda.

You can always go the orangePi route. I bought one and was impressed.
 
There is a Jakiper monitoring project now on Github that I am helping with. It is a work in progress so if you would like to try or contribute check this out https://github.com/ClassicDIY/PylonToMQTT . Thanks to Graham on ClassicDIY who wrote the esp32 code to make this work.
I am trying to get up to speed on learning how to use VS Code and Platformio . ( edited post to new link for project )
Tnx. This project is usefull
 
Great project and just what I was hoping to find.
I was able to get it working on an ESP32 connected via RS 232/TTL to a SOK 48V 5kWh battery.
However the only thing it publishes by MQTT is SOK/SOK/tele/LWT "online"
Is there any way i can activate the "SOK mode" to get the SOC published?
Thanks!
 
Back
Top