' ' Datalogger with FTP upload. WC9 rev 1 - gsm (c) Avisaro AG, 05.10.2013 ' ' ------------------------------------------------ ' Insert here FTP Server Information let ip$ = "www.avisaro.com" let port = 21 let usr$ = "p35753187-public" let pass$ = "avisaro!!" ' ------------------------------------------------ ' One (=1) or two (=2) CAN Ports - ' not yet supported let ports = 1 ' ------------------------------------------------ ' Portbelegung der LED's bei CAN if ports = 2 then let green = -207 let inkey = -208 ' --------------------------------------------- ' Define 2nd CAN Port auxopen -8, 125000, 0, 536870910, 0, 0 else let green = -203 let inkey = -204 end if let red = -202 ' ------------------------------------------------ DIM A(28) let re$ = "" let er = 0 let port2 = 0 let t_up = time let komma$ = chr$(44) let bus$ = "C1" let crlf$ = chr$(13) + chr$(10) 'if no battery if time < 10000 then exec "time 2014 01 01 00 00 01" end if sleep 1 inmode -3 outmode -2 close 1 put red, #0 put green, #0 ' Version for web site let x$ = "CAN Logger (MC9-1) ," let x$ = x$ + str$(ports) put -100, x$, len(x$) BEGIN: put green, #1 ' Debounce keys if (KEYS & 1) = 1 then goto BEGIN end if sleep 500 if lof(0) = 0 then sleep 0 goto BEGIN end if open "AB", 1, "logdata.txt" if LASTERR <> 0 then open "WB", 1, "logdata.txt" if LASTERR <> 0 then goto BEGIN end if end if put -202, #1 let t = time let t_up = time + 30 do ' get CAN Data get -7, A if BYTESREAD = 28 then let bus$ = "C1" gosub STORE_CAN end if ' Check file status if t < time then put red, #1 put green, #1 let t = time + 1 if lof(0) = 0 or status(1) <> 2 then put red, #0 close 1 goto BEGIN end if end if ' use "= status(-4)" for wlan and "= 1" for GSM let w = 1 if (time > t_up) and (w = 1) then ' upload file to FTP Server put -203, #0 put -202, #1 let g = resolv(ip$) close 101 connect 101, g, port, 5 let er = 0 while (status(101) <> 9) sleep 100 let er = er + 1 if er > 50 then goto FTP_ERR end if wend let er = 0 get 101, re$ let se$ = "USER " + usr$ gosub READ_RET let se$ = "PASS " + pass$ gosub READ_RET let se$ = "PASV" gosub READ_RET gosub GET_PORT let se$ = "TYPE I" gosub READ_RET let se$ = "APPE logdata.txt" sleep 1000 gosub READ_RET if port2 = 0 then let er = 2001 goto FTP_ERR end if close 102 connect 102, g, port2, 5 while status(102) <> 9 let er = er + 1 if er > 50 then goto FTP_ERR end if sleep 100 wend close 1 open "R", 1, "logdata.txt" READ_FILE: get 1, A if BYTESREAD > 0 then let bre = BYTESREAD REPEAT: put 102, A, bre if LASTERR <> 0 then sleep 100 let er = er + 1 if er > 50 then goto FTP_ERR end if goto REPEAT else if status(102) <> 9 then let er = 1000 goto FTP_ERR end if let er = 0 goto READ_FILE end if end if FTP_ERR: let temp = lof(102) while temp > 0 sleep 10 let temp = lof(102) wend sleep 500 close 1 close 102 if er < 50 then kill "logdata.txt" end if let se$ = "QUIT" + chr$(13) + chr$(10) gosub READ_RET close 101 let er = 0 put -203, #1 goto BEGIN end if ' end ? if (KEYS & 1) = 1 then close 1 goto FIN_KEY end if loop FIN_KEY: ' debounce key if (KEYS & 1) = 1 then goto FIN_KEY end if FINISH: put -202, #1 'debounce key let x = lof(0) if (x < 500) or ((KEYS & 1) = 1) then goto BEGIN else goto FINISH end if goto BEGIN READ_RET: let se$ = se$ + chr$(13) + chr$(10) put 101, se$ let ti = millis + 2000 let re$ = "" let count = 0 while ti > millis get 101, temp$ if BYTESREAD > 0 then let count = count + BYTESREAD if count > 250 then let re$ = "" else let re$ = re$ + temp$ end if end if wend return GET_PORT: let p1$ = "" let p2$ = "" for n = 1 to (len(re$) -3) let temp$ = mid$(re$, n, 1) if temp$ = "," then let p2$ = p1$ let p1$ = "" else let p1$ = p1$ + mid$(re$, n, 1) end if next n let port2 = val(p2$) * 256 + val(p1$) return ' write CAN to memory card STORE_CAN: ' LED on put red, #1 let t = time + 1 let temp$ = bus$ + komma$ let temp$ = temp$ + date$ + komma$ let temp$ = temp$ + time$ + komma$ let x$ = CANCSV$ let temp$ = temp$ + X$ + crlf$ repeat_put: put 1, temp$ if LASTERR <> 0 then sleep 0 if status(1) <> 2 then close 1 put red, #0 goto BEGIN end if goto repeat_put end if ' LED off put red, #0 return ' store_can ' +++