Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Navigate data on an SD


  • Please log in to reply
4 replies to this topic

#1 mcinnes01

mcinnes01

    Advanced Member

  • Members
  • PipPipPip
  • 325 posts
  • LocationManchester UK

Posted 08 October 2011 - 07:54 PM

Hi,

I am just looking a little further in to data logging, I building an aquarium controller and will measure multiple temperatures, ph and maybe a few other things as my project grows...

Basically I want to know if its possible and how I would go about navigating through data that I log, and logging multiple things?

Background: I am using a netduino standard and a sparkfun microSD shield and a gain span wifi module. (Not the N+)

I also want to store user variables on to the sd that can be used to reset the device if the power is disonnected.

Eventually I plan on having the data upload to an SQL database, but it will always write to the sd as a backup, then reconcile the server when the connection is restored. Perhaps keeping a week of backup on the SD, so the navigation will come in to select all records that are older that 1 week and delete them. I just about have my head around databases but I don't really understand how data is held on the sd?

This is the code I have used to write to the sd so far in testing:

using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
using SecretLabs.NETMF.IO;
using System.IO;

namespace SDCardTest
{
    public class Program
    {
        public static void Main()
        {
            StorageDevice.MountSD("SD", SPI.SPI_module.SPI1, Pins.GPIO_PIN_D8);

            using (var filestream = new FileStream(@"SD\dontpanic.txt", FileMode.Create))
            {
                StreamWriter streamWriter = new StreamWriter(filestream);
                streamWriter.WriteLine("This is a test of the SD card support on the netduino...This is only a test...");
                streamWriter.Close();
            }

            using (var filestream = new FileStream(@"SD\dontpanic.txt", FileMode.Open))
            {
                StreamReader reader = new StreamReader(filestream);
                Debug.Print(reader.ReadToEnd());
                reader.Close();
            }
            StorageDevice.Unmount("SD");    
        }
    }
}

Thanks in advance for the help, also how would I go about having this as a background process, I am totally new to multi-threading and still don't understand it much, but I guess this project is going to end up with a lot of processes occuring symultaneously. I've seen OMAR's example but could do with understanding how I could apply it to a situation like data logging while other things like readings are being taken and decisions made to turn things on and off at the same time, along with pwm lighting control and fan control etc.

Andy

#2 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 09 October 2011 - 05:39 AM

Not sure to understand what's your actual goal. Do you mean to log the whole set of vars every specific interval? For instance, every hour? Anyway, I would use a file of each "sample" set of vars. Each file is named sequentially (e.g. Log0001.bin, Log0002.bin, etc) For the file format, I'd consider the raw-binary, the plain-text (ASCII) or the Xml. The easiest is the last, but it also requires enough resources (and CPU time) compared to the others. Hope it helps. Cheers
Biggest fault of Netduino? It runs by electricity.

#3 mcinnes01

mcinnes01

    Advanced Member

  • Members
  • PipPipPip
  • 325 posts
  • LocationManchester UK

Posted 16 October 2011 - 05:00 PM

Hi Mario, How is the data held using ascii or raw binary and how can I use the data in that format to query e.g. to delete data over 24hours old as a write of new data is done. Or to enquire on the largest value in a time or date range? What method would you recommend and can you provide any examples or expand on the code example above? Cheers, Andy

#4 georgejh

georgejh

    Advanced Member

  • Members
  • PipPipPip
  • 87 posts
  • LocationGlasgow, UK

Posted 17 October 2011 - 06:29 PM

Hi Mario,

How is the data held using ascii or raw binary and how can I use the data in that format to query e.g. to delete data over 24hours old as a write of new data is done. Or to enquire on the largest value in a time or date range?


What method would you recommend and can you provide any examples or expand on the code example above?

Cheers,

Andy


I would suggest you to use XML file(s). Have each record attributed with ID and DateTime.
You can then navigate the records with XmlReader (System.Xml) or write them with XmlWriter. To use XmlWriter you need to add reference to MFDpwsExtensions.dll from "le" (little endian") folder of .NETMF (wherever you installed it to - example: "C:\Program Files\Microsoft .NET Micro Framework\v4.1\Assemblies\le\MFDpwsExtensions.dll". Then add "using System.Ext.Xml;". Now you should have access to XmlWriter.

#5 mcinnes01

mcinnes01

    Advanced Member

  • Members
  • PipPipPip
  • 325 posts
  • LocationManchester UK

Posted 17 October 2011 - 10:18 PM

cool thanks will give it a whirl and will let you know.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.