Netduino home hardware projects downloads community

Jump to content


Photo

Software Reboot for Netduino Plus


  • Please log in to reply
4 replies to this topic

#1 mohammad

mohammad

    Advanced Member

  • Members
  • PipPipPip
  • 79 posts

Posted 21 May 2013 - 11:58 PM

Hello,

 

I had a problem for 1 month to use a Watchdog mechanism in Netduino Plus. FYI, the "Watchdog" acts as a software reboot with a predefined timer.

The watchdog functions have been already developed in C# Micro Framework, but they never work. Based on the comment I got from Chris: "No watchdog implemented in the gen1 hardware.  We're currently designing a software update for gen2 hardware which would enable it."

Finally, I created my own watchdog function which works well to reboot the Netduino after a fixed time (e.g., 5h).

public class MainFrame{        const Int32 wdDelay = 1000 * 60 * 60 * 5;   // 5h        static Timer wdtimer = new Timer(watchdog, null, wdDelay, 0);                public static void Main()        {            // Write your codes here        }        public static void watchdog(object state)        {            PowerState.RebootDevice(false);     //Watchdog.Enabled = true;        }}

I hope it helps you in your project :)



#2 khmesmer

khmesmer

    Member

  • Members
  • PipPip
  • 11 posts

Posted 22 May 2013 - 04:57 PM

Interesting post mohammad I was unaware of the capability. I haven't tried it yet but I will keep it in mind. I am new to C# and the microcontroller world and I am always looking for documentation on these things. Do you mind if I ask where you got this information? My biggest problem is trying to create solutions when a solution already exists but I am unaware of it.

 

I realize I need to take the time and dig into the .net micro frame work at MSDN but the extent of the material leaves one  wanting. If there are resources that provide better explanations I would be interested in examining them.

Good post.



#3 mohammad

mohammad

    Advanced Member

  • Members
  • PipPipPip
  • 79 posts

Posted 23 May 2013 - 07:50 PM

Thanks Khmesmer.

I am working with Netduino Plus (or generally microcontroller programming) since 2012. I recommend you to follow the "getting started with the nternet of Things" book, first. Then, try to implement codes and ask your questions in this forum. To be honest, this forum and its members :) helped me a lot in my projects and learning.

If you have any questions, feel free to let me know.

 

Good Luck



#4 khmesmer

khmesmer

    Member

  • Members
  • PipPip
  • 11 posts

Posted 09 June 2013 - 05:14 PM

I will and thanks. I found a few resources that helped a little but it will take digging down into them and really learning it. If I come up with anything new I will post as well.



#5 ShVerni

ShVerni

    Advanced Member

  • Members
  • PipPipPip
  • 138 posts
  • LocationNew York, New York

Posted 09 June 2013 - 05:51 PM

This is very useful, thanks!

 

I made a few modifications to put the watchdog in its own class, and set it up so that if the main program doesn't check in with the watchdog after a certain amount of time, the device will reboot. It great for checking to make sure a particular thread doesn't lock-up, but won't help if the program throws exceptions or the whole thing crashes, unfortunately.

public class Watchdog    {        /// <summary>        /// Used by program to check in with the watchdog        /// </summary>        public bool running = true;        /// <summary>        /// Creates a watchdog        /// </summary>        /// <param name="period">Number of milliseconds between each watchdog check-in</param>        /// <param name="delay">Number of milliseconds before the watchdog starts running</param>        public Watchdog(int period, int delay = 0)        {            Timer wdtimer = new Timer(_watchdog, null, delay, period);        }        /// <summary>        /// The internal watchdog process        /// </summary>        /// <param name="state">Required by the Timer class, but not used</param>        private void _watchdog(object state)        {            if (!running)                PowerState.RebootDevice(false);            else                running = false;        }    }

You can use it like this:

 class Program    {        public static void Main()        {            Watchdog doggy = new Watchdog(5000);            for (int i = 0; i <= 5; i++)            {                //Check-in with the watch dog                doggy.running = true;                Thread.Sleep(4500);            }            //Uh oh, we stopped checking-in, the watchdog will reboot!            Thread.Sleep(Timeout.Infinite);        }    }





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.