wifi.mode(wifi.STATION)
wifi.sta.sethostname("ESP001")
wifi.setphymode(wifi.PHYMODE_N)
wifi.start()
wifi.sta.connect()
-- ADC config mode needs to be set
if adc.force_init_mode(adc.INIT_ADC)
then
print('ADC set restarting.....')
node.restart()
return
end
myip={192,168,0,79}
mygate={192,168,0,1}
mysubnet={255,255,255,0}
wifi.config(myip,mygate,mysubnet)
mqt:on("connect", function(client)
print('MQTT Connected')
while adcpush > adcpop do
kvp={mymac,advdata[adcpop]}
mqmsg = sjson.encoder(kvp)
client:publish("/adc", mqmsg, 0, 0, function(client)
advdata[adcpop] = nil
adcpop = adcpop +1
end
print("MQTT Messages sent")
end)
end)
sendwifi = tmr.create()
sendwifi:register(5000, tmr.ALARM_AUTO, function()
if not wifibusy then
wifibusy = true
wifi.start()
end
end)
sendwifi:start()
local adcdata{}
local adcpush = 0
local adcpop = 0
getadc = tmr.create()
getadc:register(500, tmr.ALARM_AUTO, function()
adcnew={}
adcnew[1]=timer.time
adcnew[1]=adc.read(0)}
adcdata[adcpush] = adckvp
adcpush = adcpush + 1
end)
getadc:start()
completelycharged said:I had started a BMS version with the ESP in LUA on the ESP and postponed it due to the low memory left after adding the required libraries, that was until the recent update which moved the code and freed up a lot of memory.
The method was to have DC-DC convertes for each ESP device (boost for LTO and buck for other Lithium cells).
Each ESP would then lod the cell voltage once per second into memory and then send this to the base server every 60 seconds or so.
Each ESP would then listen for back commands from the server to switch in/out a balance/bypass load for a pre-determined duration.
The data would be time stamped so that each cell can then be syncronised to cope with voltage drop/increase seen when load is switched on/off. This is quite important and was starting to look at a higher frequency of data capture to analyse IR changes over time seen by observing different voltage drops per cell across the pack.
The issue with trying to implement on a 22s system (22 x ESP devices) was mainly due to WiFi and the limited ability of a cheap consumer hub to handle a lot of signals in parallel without messing around changing channels, reducing power, etc. The spread of a 60 second window self balances over time between all of the units due to collision retry wait. I was trying this out with 5 second window and a few devices to simulate a conjested wireless network to see how well each device time separated.
The data would be sent with MQTT as it cuts out a lot of data handling issues at the battery/server ends and allows a queue and return messaging per cell.
---snipped rest of post
Riplash said:22 x ESP all trying to connect to a hub or servers sounds like a wifi nightmare to me, but maybe the MQTT protocall makes it more manageable? Is it possible to make one ESP a Master and all the others slaves, and connect all the ESPs through I2C or SPI and just use the Master ESP32 to transmitt and receiveall the data in onepacket through MQTT? That is my plan of attack when I start working on BMS later tonight.
May I ask why you would need 22pcs of ESPs instead of just one ESP + a multiplexer?I had started a BMS version with the ESP in LUA on the ESP and postponed it due to the low memory left after adding the required libraries, that was until the recent update which moved the code and freed up a lot of memory.
The method was to have DC-DC convertes for each ESP device (boost for LTO and buck for other Lithium cells).
Each ESP would then lod the cell voltage once per second into memory and then send this to the base server every 60 seconds or so.
Each ESP would then listen for back commands from the server to switch in/out a balance/bypass load for a pre-determined duration.
The data would be time stamped so that each cell can then be syncronised to cope with voltage drop/increase seen when load is switched on/off. This is quite important and was starting to look at a higher frequency of data capture to analyse IR changes over time seen by observing different voltage drops per cell across the pack.
The issue with trying to implement on a 22s system (22 x ESP devices) was mainly due to WiFi and the limited ability of a cheap consumer hub to handle a lot of signals in parallel without messing around changing channels, reducing power, etc. The spread of a 60 second window self balances over time between all of the units due to collision retry wait. I was trying this out with 5 second window and a few devices to simulate a conjested wireless network to see how well each device time separated.
The data would be sent with MQTT as it cuts out a lot of data handling issues at the battery/server ends and allows a queue and return messaging per cell.
With all that said and done I like the idea from charlie144 of using a 14s BS just to get the cell voltages back and then switch balancing with an opto isolator/FET as above.... would still use an ESP though as most cheap RS232 implementations usually use just 5V or 3.3V so may be able hook it direct into the ESP....
Battery ESP device code
---------------------------------------------------------------------------
Code:wifi.mode(wifi.STATION) wifi.sta.sethostname("ESP001") wifi.setphymode(wifi.PHYMODE_N) wifi.start() wifi.sta.connect() -- ADC config mode needs to be set if adc.force_init_mode(adc.INIT_ADC) then print('ADC set restarting.....') node.restart() return end myip={192,168,0,79} mygate={192,168,0,1} mysubnet={255,255,255,0} wifi.config(myip,mygate,mysubnet) mqt:on("connect", function(client) print('MQTT Connected') while adcpush > adcpop do kvp={mymac,advdata[adcpop]} mqmsg = sjson.encoder(kvp) client:publish("/adc", mqmsg, 0, 0, function(client) advdata[adcpop] = nil adcpop = adcpop +1 end print("MQTT Messages sent") end) end) sendwifi = tmr.create() sendwifi:register(5000, tmr.ALARM_AUTO, function() if not wifibusy then wifibusy = true wifi.start() end end) sendwifi:start() local adcdata{} local adcpush = 0 local adcpop = 0 getadc = tmr.create() getadc:register(500, tmr.ALARM_AUTO, function() adcnew={} adcnew[1]=timer.time adcnew[1]=adc.read(0)} adcdata[adcpush] = adckvp adcpush = adcpush + 1 end) getadc:start()
---------------------------------------------------------------------------
hahaha... guess I need a code text wrapper.