Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 17:40 28 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : MM/DM: help for making a data logger

Author Message
Juri74

Senior Member

Joined: 06/02/2012
Location: Italy
Posts: 162
Posted: 05:32am 31 Dec 2013
Copy link to clipboard 
Print this post

hello to all!
months ago i created a simple meteo station with a duinomite plus some sensors.
it display instant humidity,pressure,temperature,wind direction and wind speed and it save this informations every minute in an array, so it is possible to view the 24 hours history. at 0:00 o'clock it save the array on sd then array is cleared and ready for another day data collection.
in this way i can view the previous day and the current day (to compare values for example)

i'm not satisfied with this way to collect data.. i would be able to collect data for 30 days, and view the past 24 hours.

i tried by myself to write some code but the problem is that i only ended in a routine that write on sd card every minute! i decreased the sampling frequency from one minute to 10 minutes, but i do not think this is the right way.

another problem is that when i reached the 30th day i have to delete the 1st day, rename all oter 29 days and save the 30th day again.. so writing on sd card again.
i do not know how many writhing have suffered my poor 1gb sd card but it is dead now..

are there some examples code for maximite/duinomite of a datalogger?

thank you and happy new year
JuriEdited by Juri74 2014-01-01
 
James_From_Canb

Senior Member

Joined: 19/06/2011
Location: Australia
Posts: 265
Posted: 10:00am 31 Dec 2013
Copy link to clipboard 
Print this post

Why not save the 24 hours of data from the array into a file with a name in the format yymmdd.dat, like 140101.dat? No old files would need to be overwritten or renamed. The files would also sort neatly into date order.

Can you post the bit of code that works out when to write to the file?

James
My mind is aglow with whirling, transient nodes of thought careening through a cosmic vapor of invention.

Hedley Lamarr, Blazing Saddles (1974)
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9308
Posted: 12:53pm 31 Dec 2013
Copy link to clipboard 
Print this post

I need something similar to this myself, so I will be watching this thread with interest.
Smoke makes things work. When the smoke gets out, it stops!
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9308
Posted: 04:02pm 31 Dec 2013
Copy link to clipboard 
Print this post

This is my first attempt at the logging:

[code]
SetLog:
D1$=mid$(date$,1,2):D2$=mid$(date$,4,2):D3$=mid$(date$,9,2)
if D2$="01" then D2$="JAN"
if D2$="02" then D2$="FEB"
if D2$="03" then D2$="MAR"
if D2$="04" then D2$="APR"
if D2$="05" then D2$="MAY"
if D2$="06" then D2$="JUN"
if D2$="07" then D2$="JUL"
if D2$="08" then D2$="AUG"
if D2$="09" then D2$="SEP"
if D2$="10" then D2$="OCT"
if D2$="11" then D2$="NOV"
if D2$="12" then D2$="DEC"
LFILE$="B:\LOG\" + D1$ + D2$ + D3$ + ".LOG"
return
[/code]

You call this gosub on the line before you send the data from your array(or whatever) to your log.

The routine will generate a date-specific filename, and store it in LFILE$.

Just open a filename handle to LFILE$ for APPEND - if the file is there, it will be appended to, if not, it will be created as part of the process. As the days/months/years change, the filename will also, all automatically.

Using today's date, the filename and path would be B:\LOG\01JAN14.LOG"

I am looking at ways of streamlining all those IF/THEN statements for the month reference - I am sure there is a neater/smaller way to do it, probably involving a table or DIM or something - others here will suggest, I have no doubt...Edited by Grogster 2014-01-02
Smoke makes things work. When the smoke gets out, it stops!
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9308
Posted: 04:52pm 31 Dec 2013
Copy link to clipboard 
Print this post

OK, plopping the month references into an array is a better way then all those IF/THEN's...

At the top of your code, define a simple one-dimensional array and fill it:

[code]
dim MTH$(12) length 3
MTH$(1)="JAN":MTH$(2)="FEB":MTH$(3)="MAR":MTH$(4)="APR":MTH$ (5)="MAY":MTH$(6)="JUN"
MTH$(7)="JUL":MTH$(8)="AUG":MTH$(9)="SEP":MTH$(10)="OCT":MTH $(11)="NOV":MTH$(12)="DEC"
[/code]

...then call the gosub just before the logfile writing:

[code]SetLog:
D1$=mid$(date$,1,2):D2$=mid$(date$,9,2)
RP=val(mid$(date$,4,2))
LFILE$="B:\LOG\" + D1$ + MTH$(RP) + D2$ + ".LOG"
return[/code]

Now write your data to LFILE$, which includes the path too.

Example for today will be: B:\LOG\01JAN14.LOG

D1$ is the day reference from the MM RTC.
D2$ is the year reference from the MM RTC.
RP is a numerical reference to the month, which is used as an index to suck out of the MTH$ array, the three letters we need for the month part of the filename.

I am sure there are other ways of doing it, but this seems to be working for me... Edited by Grogster 2014-01-02
Smoke makes things work. When the smoke gets out, it stops!
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6101
Posted: 06:37pm 31 Dec 2013
Copy link to clipboard 
Print this post

A simpler way to get the months:

month$="xxJANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC"
do
INPUT "Month"; Mth
Mth = int(Mth)
if Mth = 99 then endit = 1
if Mth<13 and Mth >0 then
print mid$(month$,Mth*3,3)
endif
loop until endit =1

I usually name files with the year first and stick to numbers only.
That way they will be sorted in date order.
For international use, having the months in letters does save wondering if the date is yymmdd or yyddmm.

Jim
VK7JH
MMedit   MMBasic Help
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9308
Posted: 07:27pm 31 Dec 2013
Copy link to clipboard 
Print this post

  TassyJim said  I usually name files with the year first and stick to numbers only.
That way they will be sorted in date order.

Jim


Yes, that is a point - I guess it kinda depends on what you want or need.

...but ain't that always the case!
Smoke makes things work. When the smoke gets out, it stops!
 
Juri74

Senior Member

Joined: 06/02/2012
Location: Italy
Posts: 162
Posted: 01:27am 01 Jan 2014
Copy link to clipboard 
Print this post

i'm not at home for some days now,
so i can't post the exact code however all the writings happen at 0:00
only the data from sensors is saved because i know that the first data group correspond to 0:01, the second to 0:02 and so on.
file saved is always "30.log"
before saving a routine kill file "01.log" and rename all 29 files: "02.log" became "01.log", "03.log" became "02.log" and so on until "30.log" that became "29.log" so there is a room for file "30.log"

James naming the file to YYMMDD.log format is a great idea, i can leave files on sd too and easily reach the year log capacity because every log file takes about 10k of space.

but how can i retrive the last 30 files?
suppose i have a lot of files starting from 140101 up to, for example, 141003

maybe i could modify my routine to write files from "001.log" upward without deleting and renaming all files, then add at the beginning of log files the date.
in this way i know that, for example this is day n.234 and if i have to view previous 30 days i have load and display files from 204 to 233
using this method i could save files from "00000001.log" to "99999999.log"
the log capacity would be 99999998 days corresponding to a little bit less than 274000 years, i think i can't live so long :D

juri
 
James_From_Canb

Senior Member

Joined: 19/06/2011
Location: Australia
Posts: 265
Posted: 11:16am 01 Jan 2014
Copy link to clipboard 
Print this post

Personally, I would write a small program in DOS MMBasic that uses the current date and works out which of the data files need to be processed to cover the most recent 30 days. I would then open each of the data files and write the data to a single output file. I would add the date (which we know from the filename) to the start of each line before it is written to the output file.

By doing it in DOS you already have the output file on the PC so it's easy to analyse in Excel or whatever, and you minimise wear and tear on your sd card.

You could fudge the process for working out which files to process by simply starting one month earlier, but that won't give you exactly 30 days. Ie.. On 25 May 2014 process all files from 25 April 2014. If you want exactly 30 days, one means would be to use a Julian Date to Integer conversion algorithm, then subtract 30 and convert back to a Date. Alternately, if you're using Excel to analyse the data, you could use Excel filters to just look at the most recent 30 days. That would simplify your programming because you could just aggregate all your data files into one and analyse it. That's probably the way I would do it.

James
My mind is aglow with whirling, transient nodes of thought careening through a cosmic vapor of invention.

Hedley Lamarr, Blazing Saddles (1974)
 
Juri74

Senior Member

Joined: 06/02/2012
Location: Italy
Posts: 162
Posted: 08:47am 04 Jan 2014
Copy link to clipboard 
Print this post

that could be a good idea to have only one file and append data at the end, then when i know how long data packet is, i can retrive last 2,3,5,10,30 days.

on 8th january i will start some experimentations.
thank you again

Juri
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024