General area when it fits no where else

Moderator: Mmiscool

User avatar
By robert badiduwitz
#60241 Working on a relay clock program (4m Wemos D1 mini) that has several on and off times set by the user. If I use 5 or less on and off times, everything displays well in Firefox, Safari and Chrome. When it connects to the wifi and you enter the ip address in the browser, the page draws perfectly. You can see on the serial terminal that winsock connected and if you close the window, it shows winsock disconnected.

If I switch browsers while the program is running, and enter the ip address, everything works great, winsock connected, winsock disconnected. The problem comes in if a add more than 5 on off times. If there are more than 5 on off times, the page will not display after the very first time. If you switch browsers and try to load the page using the ip address, the page is just blank. No wisock connect or disconnect. I know the program is running as the 7 segment display is updating every second. I just can't get it to draw on the web page no matter how I try to do it. So I am guessing there is maybe a limit to how many things you can send to the web page?

Attached is the working program with the 5 on off times and 6, 7, and 8 are remmed out in the "DRAW GUI" sub. If you simply unrem the 6 - 8th on off times in the gui, the program will run, just won't display when you hit the ip address in the browser. I'm pretty sure you can run this program without the 7 segment display or relay connected for testing.

Is there a better way to draw the gui so that this can work?

Code: Select allcls
memclear

localip = ip()

brightness = 15
relay = D1
address = 112
count = 1
col = 0
dot = 0
timer 0

dim digits(11)
digits(0) = 63
digits(1) = 6
digits(2) = 91
digits(3) = 79
digits(4) = 102
digits(5) = 109
digits(6) = 125
digits(7) = 7
digits(8) = 127
digits(9) = 111
digits(10) = 0

'************ INITIALIZE DISPLAY  *************
i2c.setup(D4,D2)
i2c.begin(address)
i2c.write(33)
i2c.end()
i2c.begin(address)   
i2c.write(129)
i2c.end()
i2c.begin(address)
bright = 224 + brightness
i2c.write(bright) 
i2c.end()
delay 10

i2c.begin(address)
i2c.write(4)
i2c.write(0)
i2c.end()

'clear display
connum = 0
gosub [convertdig]
gosub [write4dig]

gosub [showip]

'************ CHECK IF AP MODE  *************
if localip = "192.168.4.1" then
'scan wifi here
cls
wprint "Welcome to Relay Clock <br>"
wprint "Enter your WIFI info below <br>"
wprint "Hit Save and Reboot <br><br>"

wprint "WIFI Name:"
textbox wifiname
wprint "<br>"
wprint "WIFI Pass:"
textbox wifipass
wprint "<br><br>"
button "Save WIFI Settings",[wifiupdate]
wprint "<br> <br>"
button "Reboot Clock",[reboot]
wprint "<br> <br>"
wait
end if

'************ GET SAVED INFO  *************
dst = read.val(DaylightSavings)
timezone = read.val(TZ)
wifiname = read(WIFIname)
wifipass = read(WIFIpass)

ontime1 = read(ontimes1)
ontime2 = read(ontimes2)
ontime3 = read(ontimes3)
ontime4 = read(ontimes4)
ontime5 = read(ontimes5)
ontime6 = read(ontimes6)
ontime7 = read(ontimes7)
ontime8 = read(ontimes8)

offtime1 = read(offtimes1)
offtime2 = read(offtimes2)
offtime3 = read(offtimes3)
offtime4 = read(offtimes4)
offtime5 = read(offtimes5)
offtime6 = read(offtimes6)
offtime7 = read(offtimes7)
offtime8 = read(offtimes8)


if dst = 1 then
tz = timezone + 1
else
tz = timezone
endif

timesetup(tz,dst)
delay 5000

gosub [drawgui]

timer 1000,[colon]

wait

'************ DRAW GUI *************
[drawgui]
wprint "<br><br>"
curtime = time("hour:min:sec")
wprint "Time Now:  "
textbox curtime

wprint "<br><br>"
wprint "Timezone:  "
textbox timezone
wprint "<br>"
wprint "DST 1 or 0:  "
textbox dst
wprint "<br><br>"
button "Update Time Info",[timeupdate]
wprint "<br><br>"

wprint "Enter relay times in HH:MM:SS 24 hour format"
wprint "<br>"
wprint |Press "Save Relay Times" button when done|
wprint "<br><br>"

wprint "On Time 1 "
textbox ontime1
wprint "Off Time 1"
textbox offtime1
wprint "<br>"

wprint "On Time 2 "
textbox ontime2
wprint "Off Time 2"
textbox offtime2
wprint "<br>"

wprint "On Time 3 "
textbox ontime3
wprint "Off Time 3"
textbox offtime3
wprint "<br>"

wprint "On Time 4 "
textbox ontime4
wprint "Off Time 4"
textbox offtime4
wprint "<br>"

wprint "On Time 5 "
textbox ontime5
wprint "Off Time 5"
textbox offtime5
wprint "<br>"

'wprint "On Time 6 "       '<<<<<<<<<<<<< UNREM this line and down and GUI won't display
'textbox ontime6
'wprint "Off Time 6"
'textbox offtime6
'wprint "<br>"

'wprint "On Time 7 "
'textbox ontime7
'wprint "Off Time 7"
'textbox offtime7
'wprint "<br>"

'wprint "On Time 8 "
'textbox ontime8
'wprint "Off Time 8"
'textbox offtime8
'wprint "<br>"               '<<<<<<<<<<<<< UNREM to here

wprint "<br>"
button "Save Relay Times",[updrelay]

wprint "<br><br>"
button "Test Relay",[testrelay]
button "End Program",[exit]

returngui

return

'************ COLON 1000ms  *************
[colon]
if col = 0 then dot = 0 else dot = 2
i2c.begin(address)
i2c.write(4)
i2c.write(dot)
i2c.end()
delay 10
if col = 1 then col = 0 else col = 1

curtime = time("hour:min:sec")
gosub [checkrelay]
gosub [refresh]

wait

'************ CHECK RELAY TIMES  *************
[checkrelay]
if curtime = ontime1 then gosub [relayon]
if curtime = offtime1 then gosub [relayoff]
if curtime = ontime2 then gosub [relayon]
if curtime = offtime2 then gosub [relayoff]
if curtime = ontime3 then gosub [relayon]
if curtime = offtime3 then gosub [relayoff]
if curtime = ontime4 then gosub [relayon]
if curtime = offtime4 then gosub [relayoff]
if curtime = ontime5 then gosub [relayon]
if curtime = offtime5 then gosub [relayoff]
if curtime = ontime6 then gosub [relayon]
if curtime = offtime6 then gosub [relayoff]
if curtime = ontime7 then gosub [relayon]
if curtime = offtime7 then gosub [relayoff]
if curtime = ontime8 then gosub [relayon]
if curtime = offtime8 then gosub [relayoff]
return

'************ REFRESH TIME  *************
[refresh]
minx = val(time("min"))
hourx = val(time("hour"))
dig4 = minx%10
dig3 = int((minx/10))
dig2 = hourx%10
dig1 = int((hourx/10))

'remove leading zeros
if dig1 = 0 then
dig1 = 10
if dig2 = 0 then
dig2 = 10
if dig3 = 0 then
dig3 = 10
if dig4 = 0 then
dig4 = 10
end if
end if
end if
end if

gosub [write4dig]
return

'************  SHOW IP ADDRESS  *************
[showip]
for zz = 1 to 4
ipnumstr = word(localip,zz,".")
connum = val(ipnumstr)
gosub [convertdig]
gosub [write4dig]
delay 1000
connum = 0
gosub [convertdig]
gosub [write4dig]
delay 400
next zz
delay 500
return

'************  CONVERT DIGITS  *************
[convertdig]
dig1 = int(connum/1000)
dig2 = int((connum%1000)/100)
dig3 = int((connum%100)/10)
dig4 = int(connum%10)
'remove leading zeros
if dig1 = 0 then
dig1 = 10
if dig2 = 0 then
dig2 = 10
if dig3 = 0 then
dig3 = 10
if dig4 = 0 then
dig4 = 10
end if
end if
end if
end if
return

'************  WRITE 4 DIGITS  *************
[write4dig]
i2c.begin(address)
i2c.write(0)
i2c.write(digits(dig1))
i2c.end()
delay 10
i2c.begin(address) 
i2c.write(2)
i2c.write(digits(dig2))
i2c.end()
delay 10
i2c.begin(address) 
i2c.write(6)
i2c.write(digits(dig3))
i2c.end()
delay 10
i2c.begin(address) 
i2c.write(8)
i2c.write(digits(dig4))
i2c.end()
delay 10
return

'************  TEST RELAY  *************
[testrelay]
for yy = 1 to 3
gosub [relayon]
delay 750
gosub [relayoff]
delay 750
next yy
wait

'************ UPDATE RELAY ON/OFF TIMES  *************
[updrelay]
write(ontimes1,ontime1)
write(offtimes1,offtime1)
write(ontimes2,ontime2)
write(offtimes2,offtime2)
write(ontimes3,ontime3)
write(offtimes3,offtime3)
write(ontimes4,ontime4)
write(offtimes4,offtime4)
write(ontimes5,ontime5)
write(offtimes5,offtime5)
write(ontimes6,ontime6)
write(offtimes6,offtime6)
write(ontimes7,ontime7)
write(offtimes7,offtime7)
write(ontimes8,ontime8)
write(offtimes8,offtime8)
wait

'************  UPDATE TIME INFO  *************
[timeupdate]
write(DaylightSavings,str(dst))
write(TZ,str(timezone))
if dst = 1 then
 tz = timezone + 1
else
 tz = timezone
endif
timesetup(tz,dst)
delay 5000
curtime = time("hour:min:sec")
wait

'************  UPDATE WIFI INFO  *************
[wifiupdate]
write(WIFIname,wifiname)
write(WIFIpass,wifipass)
wprint "WIFI info saved..."
wait

'************  REBOOT CLOCK  *************
[reboot]
cls
wprint "REBOOTING..."
delay 1000
reboot
wait

'************ RELAY ON SUB  *************
[relayon]
io(po,relay,1)
return

'************ RELAY OFF SUB  *************
[relayoff]
io(po,relay,0)
return

'************ EXIT PROGRAM  *************
[exit]
timer 0
wprint "<a href='/'>Menu</a>"
end