REM d. bodnar M  10-16-03
REM revised for autorefresh tags
REM reads "1wireout.txt" & creates HTML table from most recent 100 readings
REM also finds min, max and average for each of 4 readings
REM readings are ambient, main32, main12, bog6
REM REVISED END TO REFLECT ORDER OF READINGS (6534)

DIM dte$(100, 4), tme$(100, 4), tmp(100, 4), code$(100, 4), aa$(6)
REM the following numbers are the last 2 hex digits of the device code
CLS
ambient$ = "92": main32$ = "7F": main12$ = "0B": bog6$ = "E6"
tture$(1) = ambient$: tture$(2) = main32$: tture$(3) = main12$: tture$(4) = bog6$
OPEN "i", 1, "1wireout.txt"
DO
c = c + 1
PRINT c;
FOR x = 1 TO 6
INPUT #1, a$
NEXT
LOOP UNTIL EOF(1)
CLOSE

OPEN "i", 1, "1wireout.txt"
DO
c2 = c2 + 1
REM skip all but last 100 readings (4 sensors = 400 lines of data)
IF c <= 100 THEN GOTO skip1:
IF c2 < c - 100 * 4 + 1 THEN
  FOR x = 1 TO 6
    INPUT #1, a$
  NEXT
END IF
skip1:
REM work with last 100 readings - record in array
IF c2 >= c - 100 * 4 AND NOT EOF(1) THEN
  c3 = c3 + 1:
 FOR y = 1 TO 4
  FOR x = 1 TO 6
   IF NOT EOF(1) THEN INPUT #1, aa$(x)
  NEXT x
  dte$(c3, y) = aa$(1): tme$(c3, y) = aa$(2): tmp(c3, y) = VAL(aa$(6)): code$(c3, y) = aa$(4)
 NEXT y
END IF
CLS
LOOP UNTIL EOF(1) OR c3 = 100
REM print out data as test
FOR x = 100 TO 1 STEP -1
  FOR y = 1 TO 4
    PRINT x; y; dte$(x, y); " "; tme$(x, y); " "; tmp(x, y); code$(x, y)
  NEXT y
'DO: LOOP UNTIL INKEY$ <> ""
NEXT x

REM find max, min, average for each reading
FOR y = 1 TO 4: max(y) = 0: min(y) = 9999
  top = c / 4: IF c > 400 THEN top = 100
  FOR x = 1 TO top
    IF tmp(x, y) > max(y) THEN max(y) = tmp(x, y)
    IF tmp(x, y) < min(y) THEN min(y) = tmp(x, y)
    ttl(y) = ttl(y) + tmp(x, y)
  NEXT x
NEXT y
FOR y = 1 TO 4: PRINT max(y); min(y); ttl(y) / 100: NEXT
 
'ername$ = "er" + LEFT$(DATE$, 2) + MID$(DATE$, 4, 2) + RIGHT$(DATE$, 2) + ".htm"
flname$ = "pond_tmp.htm"
PRINT flname$
OPEN "o", 2, flname$
PRINT #2, "<html>"
PRINT #2, "<head>"
PRINT #2, "<META HTTP-EQUIV=" + CHR$(34) + "REFRESH" + CHR$(34) + " CONTENT=" + CHR$(34) + "600" + CHR$(34) + ">"

PRINT #2, "<title>Pond Temperature Report (" + DATE$; ")</title>"
PRINT #2, "</head>"
PRINT #2, "<body>"
PRINT #2, "Pond Temperature Report as of: " + DATE$ + " at: " + TIME$
PRINT #2, "<br>"
PRINT #2, ""
PRINT #2, "<br>"
PRINT #2, "<br>"
PRINT #2, "Mininum temperatures in <b> bold</b> - Maximum in <b><u>bold/underlined</b></u>"

PRINT #2, "<table BORDER COLS=6 WIDTH=" + CHR$(34) + "70%" + CHR$(34) + " > "
PRINT #2, "<tr><td>"; "Date"; "</td>"; "<td>"; "Time"; "</td>"; "<td>"; "Ambient"; "</td>"; "<td>"; "Main 32" + CHR$(34); "</td>"; "<td>"; "Main 12" + CHR$(34); "</td>"; "<td>"; "Bog 6" + CHR$(34); "</td></tr>"

'FOR x = 1 TO 100
'  yy = 1
'    htm$(1) = dte$(x, yy): htm$(2) = tme$(x, yy): htm$(3) = STR$(tmp(x, yy))
'    htm$(4) = STR$(tmp(x, yy + 1)): htm$(5) = STR$(tmp(x, yy + 2)): htm$(6) = STR$(tmp(x, yy + 3))
'NEXT x

top = c3: IF c3 > 100 THEN top = 100
FOR x = top TO 1 STEP -1
  yy = 1
    htm$(1) = dte$(x, yy): htm$(2) = tme$(x, yy):
    htm$(6) = STR$(tmp(x, yy))
    IF tmp(x, yy) = max(yy) THEN htm$(6) = "<b><u>" + htm$(6) + "</b></u>"
    IF tmp(x, yy) = min(yy) THEN htm$(6) = "<b>" + htm$(6) + "</b>"

    htm$(5) = STR$(tmp(x, yy + 1)):
    IF tmp(x, yy + 1) = max(yy + 1) THEN htm$(5) = "<b><u>" + htm$(5) + "</b></u>"
    IF tmp(x, yy + 1) = min(yy + 1) THEN htm$(5) = "<b>" + htm$(5) + "</b>"
    htm$(3) = STR$(tmp(x, yy + 2)):
    IF tmp(x, yy + 2) = max(yy + 2) THEN htm$(3) = "<b><u>" + htm$(3) + "</b></u>"
    IF tmp(x, yy + 2) = min(yy + 2) THEN htm$(3) = "<b>" + htm$(3) + "</b>"
    htm$(4) = STR$(tmp(x, yy + 3))
    IF tmp(x, yy + 3) = max(yy + 3) THEN htm$(4) = "<b><u>" + htm$(4) + "</b></u>"
    IF tmp(x, yy + 3) = min(yy + 3) THEN htm$(4) = "<b>" + htm$(4) + "</b>"



FOR y = 1 TO 6
x$ = htm$(y)
PRINT #2, "<td>" + x$ + "</td>"
NEXT y
PRINT #2, "</tr>"

NEXT x



PRINT #2, "</table> </html>"
CLOSE

