-->
Page 1 of 2

problem saving program with % (mod) operation in it

PostPosted: Sat Dec 31, 2016 6:09 pm
by robert badiduwitz
This is so weird and happens on multiple boards I have. I am trying to enter a program I wrote in a text editor where I make changes, copy and paste into the web browser edit page. Whenever I hit save and try to run the program, the program has syntax errors in very specific areas. The two subs that use the % (mod) function always get corrupted.

So when I try to go back and edit these lines in the edit tab and hit save, they still get corrupted. Even if I completely retype the couple of lines of code using the edit window and hit save, when I hit edit again, the lines are corrupted again. This is really driving me nuts as you can imagine.

I will include the whole code. In the CONVERT DIGITS sub, the 2nd thru 5th line should read...

dig1 = int(connum/1000)
dig2 = int((connum%1000)/100)
dig3 = int((connum%100)/10)
dig4 = int(connum%10)

After a save and edit it looks like this every time...

dig1 = int(connum/1000)
dig2 = int((connum00)/100) <<<<<<<<< here is the problem always
dig3 = int((connum%100)/10)
dig4 = int(connum%10)

Sometimes it happens in the only other section of code that uses %, that being the REFRESH TIME sub in the 4th thru 7th line.

Could this be an interpreter error? This happens on different boards, all of which are 4m esp8266 boards.

Here is the code...

Code: Select all'Relay timer clock using ESP8266 with an Adafruit 4 digit i2c display
'Display connected to D4 for SDA and D2 for SCL
'Active high relay on D1

cls
memclear

localip = ip()

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

'Digits 0 - 9
'digits(10) used to blank digit
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

'make sure colon is blank
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 code here later
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)

offtime1 = read(offtimes1)
offtime2 = read(offtimes2)
offtime3 = read(offtimes3)
offtime4 = read(offtimes4)
offtime5 = read(offtimes5)


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

timesetup(tz,dst)
delay 5000

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>"
button "Save Relay Times",[updrelay]

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

returngui

timer 1000,[colon]

wait


'************ 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]
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)
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

Re: problem saving program with % (mod) operation in it (Sol

PostPosted: Sun Jan 01, 2017 12:37 pm
by robert badiduwitz
After experiencing this problem on 3 different boards, I decided to re-flash one of them and reload the program. This worked! Re-flashed the rest and they all worked. Something I must have done corrupted the OS or something on all three boards. If all else fails, re-flash.

Re: problem saving program with % (mod) operation in it

PostPosted: Mon Jan 02, 2017 6:25 am
by bugs
Thanks for the update - did you flasher a newer version of BASIC or the same as you were using?

Re: problem saving program with % (mod) operation in it

PostPosted: Mon Jan 02, 2017 8:27 am
by robert badiduwitz
I used A65 during this time. I see that this is happening every once in a while. When it does, I reflash and all is well again. I seems that something is getting corrupted after a bit of time. The attached program is all I am playing with when this happens, so I don't know if I am doing something in my testing that makes this happen.