memclear
udpbegin 7531
io(po,16,0) 'Gas Valve & Ignition
io(po,5,0) 'Starter Solenoid
io(po,4,0) 'Alternator Control
io(po,14,0) 'Alternator High Charge
io(po,12,0) 'Oil Change Pump Fill
io(po,13,0) 'Oil Change Pump Empty
io(pi,3) ' Engine Running Input
delay 100
overcrank = 0
normal = 0
high = 0
starttimer = 0
stoptimer = 0
starthour = 0
oilchange = 0
R = 0
T = 0
reset = " "
system = "Auto"
hourmeter = read.val(hours)
hourmeter = hourmeter / 10
starthour = hourmeter
time.setup(-6,-5)
[status]
cls
R = io(pi,3)
analog = io(ai)
voltage = analog * .029
udpwrite "192.168.10.240", 10000, str(voltage * 10)
celsius = temp(0)
if celcius > -60 then oiltemperature = (celsius * 1.8) + 32
round(oiltemperature)
celsius1 = temp(1)
if celcius1 > -60 then alternatortemperature = (celsius1 * 1.8) + 32
round(alternatortemperature)
wprint "Daveco Engine Charge Controller APU#1 "
wprint "<br>"
wprint "System Control "
dropdown system, "Auto,Manual Start,Off"
wprint "<br>"
wprint "OverCrank Reset "
dropdown reset, "Reset"
if reset = "Reset" then gosub [clearovercrank]
wprint "<br>"
wprint "<hr>"
wprint "Update Time = "
wprint time("hour")
wprint ":"
wprint time("min")
wprint "<br>"
wprint "Engine Total Hours = "
wprint hourmeter
wprint "<br>"
wprint "Battery Bank Voltage = "
wprint voltage
wprint "<br>"
wprint "<br>"
wprint "Crankcase Temperature = "
wprint oiltemperature
wprint " F "
wprint "<br>"
wprint "<br>"
wprint "Alternator Temperature = "
wprint alternatortemperature
wprint " F "
wprint "<br>"
wprint "<br>"
if R = 0 then wprint "Engine is Stopped "
if R = 1 then wprint "Engine is Running "
wprint "<br>"
wprint "<br>"
if R = 0 and overcrank = 1 then wprint "Engine Overcrank "
if R = 1 and normal = 0 and high = 0 then wprint "Cold Engine Delay "
if R = 1 and normal = 1 and high = 0 then wprint "Bank is Charging at Normal Rate "
if R = 1 and normal = 0 and high = 1 then wprint "Bank is Charging at High Rate "
wprint "<br>"
if starttimer > 0 then wprint "Timing for Start "
if stoptimer > 0 then wprint "Timing for Stop "
if oilchange > 0 then wprint "Engine in Maintenance Cycle "
wprint "<br>"
wprint "<br>"
wprint "<hr>"
wprint "Last / Current Cycle Time = "
wprint (hourmeter - starthour)
if voltage < 11.8 and R= 0 and overcrank = 0 and system = "Auto" then starttimer = starttimer + 1
If voltage < 11.8 and overcrank=0 and R = 0 and starttimer > 10 and system = "Auto" and oilchange = 0 then gosub [start]
if R = 0 and system = "Manual Start" and overcrank = 0 then gosub [start]
If R = 1 and oiltemperature > 55 and normal = 0 and high = 0 then gosub [normalcharge]
if voltage > 12.8 and R = 0 then starttimer = 0
if voltage > 14.0 and R = 1 and normal = 1 and (hourmeter - starthour) > 1.0 then gosub [highcharge]
if voltage < 14.0 and R = 1 then stoptimer = 0
if voltage > 14.4 and R = 1 and (hourmeter - starthour) > 3.0 then stoptimer = stoptimer + 1
if voltage > 14.4 and R = 1 and stoptimer > 20 and (hourmeter - starthour) > 3.0 then gosub [shutdown]
if voltage > 14.7 and R = 1 and (hourmeter - starthour) > 2.0 then stoptimer = stoptimer + 1
if voltage > 14.7 and R = 1 and stoptimer > 20 and (hourmeter - starthour) > 2.0 then gosub [shutdown]
If R = 0 and normal = 1 then gosub [shutdown]
if R = 0 and high = 1 then gosub [shutdown]
if R = 1 and system = "Off" then gosub [shutdown]
if R = 1 then hourmeter = hourmeter + .0038
if oilchange = 1 and oiltemperature < 125 then gosub [drain]
if oilchange = 1 and voltage < 12 then gosub [drain]
timer 10000,[status]
wait
[start]
starttimer = 0
stoptimer = 0
io(po,16,1) ' Turn on Gas Valve & Ignition
delay 5000
' Crank #1
R = io(pi,3)
if R = 0 then io(po,5,1)
delay 5000
io(po,5,0)
delay 5000
R = io(pi,3)
' Crank #2
if R = 0 then io(po,5,1)
R = io(pi,3)
if R = 0 then delay 5000
io(po,5,0)
if R = 0 then delay 5000
R = io(pi,3)
' Crank #3
if R = 0 then io(po,5,1)
R = io(pi,3)
if R = 0 then delay 5000
io(po,5,0)
if R = 0 then delay 5000
R = io(pi,3)
if R = 0 then delay 5000
R = io(pi,3)
if R = 0 then overcrank = 1
if R = 1 then overcrank = 0
if R = 1 then starthour = hourmeter
If overcrank = 1 then io(po,16,0) ' Turn off Gas Valve & Ignition for Overcrank
system = "Auto"
return
[normalcharge]
io(po,4,1)
normal = 1
return
[highcharge]
io(po,14,1)
normal = 0
high = 1
return
[shutdown]
starttimer = 0
stoptimer = 0
io(po,14,0) ' Turn off High Charge
delay 10000
io(po,4,0) ' Turn off Normal Charge
delay 10000
io(po,16,0) ' Turn off Gas Valve & Ignition
overcrank=0
normal = 0
high = 0
write(hours,hourmeter * 10)
R = io(pi,3)
if R = 1 then delay 10000
R = io(pi,3)
if R = 1 then delay 10000
R = io(pi,3)
if R = 1 then delay 10000
R = io(pi,3)
if R = 0 then io(po,12,1)
delay 40000
io(po,12,0)
oilchange = 1
return
[drain]
io(po,13,1)
delay 40000
io(po,13,0)
oilchange = 0
return
[clearovercrank]
overcrank = 0
reset = " "
return
Moderator: Mmiscool
Not fully understood your code (tiny phone screen) so please excuse any idiocy.
If you remove the write statement does it eliminate the crash?
How often do you write hours away? I did say I hadn't fully understood code, for which read and I'm not going back and forth between screens - it's horrible reading a program when only a few chars are visible at a time. This is a great forum but imho the mobile implementation of the forum software is not great. How many key presses for next page sorry rant over...
Checked free memory? It doesn't look resource hungry but stuff happens, especially when you have communications... Queued reads and writes etc.
My question to the forum was mostly if my syntax was correct for the write command, or if possibly there was a better way to do it.
Presumably you created the initial value of hours.dat separately. Does your previously stored hours value remains unchanged when the program crashes? If you replace the calculated value to be written with an arbitrary numeric value, does that have the same issue?
If the program is expected to sometimes run headless, perhaps a test for wifi connected before generating wprint etc. I also wonder how the udp stack handles any incoming traffic if no handler is defined. I'd assume it just ignores it, but ...
Does the program autorun on boot, and auto reboot ok after a crash?
You could, if the device is always connected, poll the esp for hours periodically.cumbersome, but...