and i wana to save the file to csv,so i change the code a little bit
-- slboat_get_temp.lua
wserial=io.open("/dev/ttyUSB0","w")
wserial:write("Serial Port OK")
wserial:flush()
rserial=io.open("/dev/ttyUSB0","r")
while true do
chaine = nil
while chaine==nil do
--to get and to lose the flush
chaine=rserial:read();rserial:flush()
if lasttemp ~= chaine then
-- for csv,we just need a ","
outstr=os.date("%x %X", os.time()).." , ".. string.gsub(chaine,"Temp Now: ","The Temp is:")
print(outstr)
-- the record file,as csv type
f = assert(io.open("logicetemp.csv", "a"))
-- that's not kind good way,we can save a old string just for write file
f:write(string.gsub(outstr,"The Temp is:","").."\n");f:close()
lasttemp = chaine
else
print ("The temp has not change yet")
end
end
end
now run it
root@OpenWrt:~/fun4me# nohup lua io232.lua &
root@OpenWrt:~/fun4me# nohup: ignoring input and appending output to `nohup.out'
root@OpenWrt:~/fun4me# tail -f logicetemp.csv
05/15/12 10:06:49 ,-5.38
05/15/12 10:06:52 ,-5.31
05/15/12 10:06:55 ,-5.25
05/15/12 10:07:05 , -5.06
05/15/12 10:07:07 , -5.00
05/15/12 10:07:10 , -4.94
05/15/12 10:07:12 , -4.88
05/15/12 10:07:16 , -4.81
05/15/12 10:07:18 , -4.75
05/15/12 10:07:21 , -4.69
05/15/12 10:07:24 , -4.63
05/15/12 10:07:27 , -4.56
05/15/12 10:07:30 , -4.50
05/15/12 10:07:33 , -4.44
05/15/12 10:07:35 , -4.38
05/15/12 10:07:05 , -5.06
05/15/12 10:07:07 , -5.00
05/15/12 10:07:10 , -4.94
05/15/12 10:07:12 , -4.88
05/15/12 10:07:16 , -4.81
05/15/12 10:07:18 , -4.75
05/15/12 10:07:21 , -4.69
05/15/12 10:07:24 , -4.63
05/15/12 10:07:27 , -4.56
05/15/12 10:07:30 , -4.50
05/15/12 10:07:39 , -4.31
05/15/12 10:07:42 , -4.25
05/15/12 10:07:44 , -4.19
05/15/12 10:07:47 , -4.13
05/15/12 10:07:50 , -4.06
05/15/12 10:07:53 , -4.00
05/15/12 10:07:56 , -3.94
05/15/12 10:07:57 , -4.00
05/15/12 10:07:57 , -3.94
05/15/12 10:07:59 , -3.88
05/15/12 10:08:02 , -3.81
05/15/12 10:08:06 , -3.75
05/15/12 10:08:09 , -3.69
05/15/12 10:08:12 , -3.63
05/15/12 10:08:14 , -3.56
05/15/12 10:08:17 , -3.50
05/15/12 10:08:20 , -3.44
05/15/12 10:08:23 , -3.38
05/15/12 10:08:25 , -3.31
05/15/12 10:08:28 , -3.25
05/15/12 10:08:31 , -3.19
05/15/12 10:08:34 , -3.13
05/15/12 10:08:37 , -3.06
05/15/12 10:08:40 , -3.00
05/15/12 10:08:44 , -2.94
05/15/12 10:08:46 , -2.88
05/15/12 10:08:49 , -2.81
05/15/12 10:08:52 , -2.75
05/15/12 10:08:56 , -2.69
05/15/12 10:08:59 , -2.63
05/15/12 10:09:02 , -2.56
05/15/12 10:09:06 , -2.50
05/15/12 10:09:08 , -2.44
05/15/12 10:09:13 , -2.38
05/15/12 10:09:17 , -2.31
05/15/12 10:09:19 , -2.25
05/15/12 10:09:23 , -2.19
05/15/12 10:09:26 , -2.13
05/15/12 10:09:30 , -2.06
05/15/12 10:09:33 , -2.00
05/15/12 10:09:37 , -1.94
05/15/12 10:09:41 , -1.88
here we got a csv file
A benefit about the csv maybe is the excel can support it,so let's use it
here is what i final get:
the simple csv file i got is here:
http://see.sl088.com/wiki/%E6%96%87%E4% … cetemp.zip