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

Plus SD card slot


  • Please log in to reply
15 replies to this topic

#1 PhilG

PhilG

    Advanced Member

  • Members
  • PipPipPip
  • 42 posts
  • LocationMaine

Posted 18 October 2011 - 02:37 PM

I am working on a watchdog for the roll-off roof of our local observatory. Since it is used remotely by amateur astronomers, the owner is concerned about his equimpment being damaged if the roof is open and the web connection goes down. The Netduino Plus periodically attempts to make connection to a Webswitch near by but connected to the web. If it's down for a couple of five minute test cycles, or if the Boltwood cloud sensor sends a close roof switch closure, the roof is closed afer a delay during which an alarm is actuated. The processor's RTC is set to UTC time at power-up using SNTP (thanks to Michael Schwarz) so it could time stamp and log any closures or errors for future examination. All this works except logging to the SD card is not being done yet. I need some help getting started with using the built-in micro SD card.

#2 Robert L.

Robert L.

    Advanced Member

  • Members
  • PipPipPip
  • 100 posts

Posted 18 October 2011 - 04:34 PM

Using version 4.2, here is some sample code to get you started:
private string path1 = @"\SD\yourfile.txt";    

// write 4 lines to a file, overwriting what is there
        using (StreamWriter file = new StreamWriter(path1))  {
            for (u = 0; u < 4; u++)  {
                file.Write(u.ToString() + "\n");   
                }
            }


// position the seek point in the file
        using (FileStream num = new FileStream(path1, FileMode.Open)) {
            long offset = inx * 100;   
            num.Seek(offset, SeekOrigin.Begin);  
            b = num.ReadByte();            // read one byte at that location
            }




In your application, it sounds like you would want to append to an existing file. To do that, set FileMode.Append

#3 PhilG

PhilG

    Advanced Member

  • Members
  • PipPipPip
  • 42 posts
  • LocationMaine

Posted 18 October 2011 - 08:51 PM

Robert L. That looks easy enough. I thing I have ver 4.1.0.6. Where do I get 4.2 and how do I make the change?

#4 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 18 October 2011 - 08:53 PM

Hi PhilG, For Netduino Plus, 4.1.0.6 should work fine with that code. Chris

#5 PhilG

PhilG

    Advanced Member

  • Members
  • PipPipPip
  • 42 posts
  • LocationMaine

Posted 18 October 2011 - 11:00 PM

Well, I jumped the gun and made the changes to 4.2.0.0. I didn't realize I had to go through so many steps to update the bootloader and firmware as well as .Net and Netduino SDK. I also changed the Target Framework for my app in VS to .Net 4.2. Now I have even more incidences of no connects than with 4.1.0.6. When it does connect and in debug it reboots the board and returns done and then doesn't run the program. I attached a screen shot of MFDeploy/Target/Device Capabilites after updating the firmware. Am I missing something? Further testing determined that if I hit the reset button the program starts up while in debug mode. So the reboot does not seem to work as it did with 4.1.0.6. I reset the MAC address and it shows up on my router DHCP list but doesn't connect anymore to the web. With the previous version I had to change the Static IP address to something in my router's DHCP range and the Default gateway to my router address to get it to connect. I redid that after updating but it does not connect to the SNTP site. Attached the latest debugger output screen. Further update: The timer server must be unavailable. I tested another address and it connects to an available server. When it cant connect it hangs at the socket.connect(ip) statement. It used to throw an exceoption.

Attached Files



#6 Robert L.

Robert L.

    Advanced Member

  • Members
  • PipPipPip
  • 100 posts

Posted 19 October 2011 - 02:09 AM

Further update: The timer server must be unavailable. I tested another address and it connects to an available server. When it cant connect it hangs at the socket.connect(ip) statement. It used to throw an exceoption.


I think you are better off with 4.2 even though it does have issues. I have seen the same things you are seeing with connect hanging, and strange behavior while debugging. But the production release of 4.2 is due out any day now, and the rumor is that these problems have been fixed.

Robert

#7 PhilG

PhilG

    Advanced Member

  • Members
  • PipPipPip
  • 42 posts
  • LocationMaine

Posted 19 October 2011 - 06:45 PM

Do you have to push the reset button every time to get the debugger to start? As far as the connect is concerned I have tried to implement an ExtendedTimer interrupt in the method that hangs trying to connect. But, I am not able to force the Connect method to quit without throwing an exception. My timeout timer callback is calling socket.Close(). Is there a graceful way to timeout the connect process so I can keep the program running? Also, I have tried a handful of time servers and none of them work. So either I am locked out or there is something about 4.2 that is preventing the code from connecting.

#8 PhilG

PhilG

    Advanced Member

  • Members
  • PipPipPip
  • 42 posts
  • LocationMaine

Posted 20 October 2011 - 12:58 PM

My code is successfully appending text to a log file in the built-in SD card...thanks for the kickstart Robert. This leads me to another question. How can this text file be sent to a PC over ethernet so that I don't have to remove the card and plug it in?

#9 Robert L.

Robert L.

    Advanced Member

  • Members
  • PipPipPip
  • 100 posts

Posted 20 October 2011 - 01:19 PM

My code is successfully appending text to a log file in the built-in SD card...thanks for the kickstart Robert.
This leads me to another question. How can this text file be sent to a PC over ethernet so that I don't have to remove the card and plug it in?


If the PC is running Linux, I would run a PHP-supporting Apache web server and transfer the data to it. The Netduino Plus, then takes the role of the web client and sends the data using POST operations. I would code this at the socket level, if I were you, so there is still memory left over for your own code. This is what I am doing for my current project. The coding on both the server side and the client side has turned out to be straight forward. The main issue I needed to overcome was the need for a hardware Watchdog connected to the Netduino (see other posts in these forums for details), as I have found the socket support in the Netduino (at least at the today's state-of-the-art) to occasionally lock up. This approach also has the advantage that the PC can send information/data/commands to the Netduino if desired.

If the PC is running a Windows OS, I would code the PC's server in Python. The Netduino side would be nearly the same, just leave out the HTTPd headers, as they would not be needed. This second approach might be more work for you depending on what languages/systems you are familiar with.

#10 PhilG

PhilG

    Advanced Member

  • Members
  • PipPipPip
  • 42 posts
  • LocationMaine

Posted 20 October 2011 - 02:58 PM

Robert, The PC will be running XP or Win7 . I have tried running a simple server on the N+ (that I found from Zimmers and modified) and just dumping all the text in the file to Explorer when a get is received. It works but if the file is bigger than a page it is clumsy. What I was thinking was to have the PC request the file using ftp. I don't know how to do that (a newb at web related stuff). I just want a way to occasionally grab the log file on the SD from a remote PC and later open it in a text editor or Excel.

#11 Stefan W.

Stefan W.

    Advanced Member

  • Members
  • PipPipPip
  • 153 posts

Posted 20 October 2011 - 04:55 PM

FTP is far harder to implement than HTTP, for no real gain ... why do you think HTTP is clumsy?
I believe that no discovery of fact, however trivial, can be wholly useless to the race, and that no trumpeting of falsehood, however virtuous in intent, can be anything but vicious.
-- H.L. Mencken, "What I Believe"

#12 PhilG

PhilG

    Advanced Member

  • Members
  • PipPipPip
  • 42 posts
  • LocationMaine

Posted 20 October 2011 - 05:29 PM

I didn't mean HTTP is clumsy. Sending all the text in a file line by line to a browser is clumsy. What I would like to do is send the file not it's contents and I don't know how to do that. I guess what I am asking is how do I set up the server on the N+ that will allow me to download a file from the SD card to my PC over the network. Eventually I may want to upload a similar file to the SD card from the PC too.

#13 Stefan W.

Stefan W.

    Advanced Member

  • Members
  • PipPipPip
  • 153 posts

Posted 20 October 2011 - 08:01 PM

When you send the contents of the file, you send the file :) HTTP is a protocol many clients speak, not just browsers (for example, http://gnuwin32.sour...ckages/wget.htm is a small commandline utility that can download files over http, . You can also tell a browser to "download" the file and not show it in its own window by sending a Content-Disposition header in the HTTP response. Now, if you wanted to serve multiple files, with a file-explorer-like interface, that'd be a different story, but if you just want so save one file, i'd leave the part on the netduino as-is and just use a tool on your computer to download it.
I believe that no discovery of fact, however trivial, can be wholly useless to the race, and that no trumpeting of falsehood, however virtuous in intent, can be anything but vicious.
-- H.L. Mencken, "What I Believe"

#14 PhilG

PhilG

    Advanced Member

  • Members
  • PipPipPip
  • 42 posts
  • LocationMaine

Posted 20 October 2011 - 08:33 PM

When you send the contents of the file, you send the file :) HTTP is a protocol many clients speak, not just browsers (for example, http://gnuwin32.sour...ckages/wget.htm is a small commandline utility that can download files over http, . You can also tell a browser to "download" the file and not show it in its own window by sending a Content-Disposition header in the HTTP response. Now, if you wanted to serve multiple files, with a file-explorer-like interface, that'd be a different story, but if you just want so save one file, i'd leave the part on the netduino as-is and just use a tool on your computer to download it.


Stefan
Well, I need to be able to download the file to any standard browser without special code on that end. So I'm guessing I need to have the N+ serve up a download page with a button to start the process. The browser would then display the typical download dialog for the user to decide where to save the file then start the process. There may be some settings files on the SD that would be nice to overwrite from the pc in the event they need to be changed. It would probably need a remote reset after that to update the settings.

#15 mike2307

mike2307

    New Member

  • Members
  • Pip
  • 1 posts

Posted 02 December 2011 - 07:24 PM

Hello everyone,

when using the code
string path1 = @"\SD\yourfile.txt";

            // write 4 lines to a file, overwriting what is there
            using (StreamWriter file = new StreamWriter(path1))
            {
                for (int u = 0; u < 4; u++)
                {
                    file.Write(u.ToString() + "\n");
                }
            }
with references to System.IO and a using- directive to System.IO, I get a System.NotSupportedException.
I'm using the latest 4.2 RC3 firmware.
The microSD card I'm using in my NetduinoPlus is a Sandisk 4GB one.

How can I write a damn file on my SD card?
Thanx.

#16 Magpie

Magpie

    Advanced Member

  • Members
  • PipPipPip
  • 279 posts
  • LocationAustralia (south island)

Posted 02 December 2011 - 10:04 PM

Hi Mike

I had what I think is the same problem.

http://forums.netdui...h__1#entry20265

Try another card or try 4.1 firmware.
STEFF Shield High Powered Led Driver shield.




1 user(s) are reading this topic

0 members, 1 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.