I have a ND Plus 2 that has a PIR sensor attached.
Everytime the PIR is triggered by movement I log the bit into Azure.
I have a heartbeat bit I loggin to Azure every 15 minutes to tell me the gateway is alive.
I have been running this code on my ND Plus 2 for many months. 24 X 7 without issue.
As the weeks wear on, my PIR data stops getting logged to Azure.
I reboot the board and things run fine for weeks before I have to reboot.
Then and they run fine for a week before I have to reboot.
Now I have to reboot every day and then the PIR only logs for a few hours.
My HeartBeat interupt keeps on logging to Azure.
So my thought is that the PIR interupt is not firing.
But I have no idea, I am new at this fun area of micro boards and IOT.
Any idea on what might be happening, or how to improve my code to make it more robust?
Thank you.
public class Program { #region Properties private static string SubLocationID = "Gateway"; private static int HeartBeatTimerPeriod = 15; private static Timer HeartBeatTimer = null; private static TimerCallback TimerCallback = null; private static DateTime LastMotionDetectedTime; private static OutputPort led = new OutputPort(Pins.ONBOARD_LED, false); private static bool MotionDetected = false; private static InterruptPort PIRInterupt; private static string MACAddress; private static InterruptPort sdCardStatusPort; #endregion #region Methods public static void Main() { if (Program.GetIPAddressAndSetTime(out Program.MACAddress)) { Program.AddData(Program.MACAddress, PIRLocal.MessageType.START); Program.TimerCallback = new TimerCallback(HeartBeatTimerInterrupt); Program.HeartBeatTimer = new Timer(Program.TimerCallback, null, 0, Program.HeartBeatTimerPeriod * 60000); //set the interupts after we get an ip address and time. PIRInterupt = new InterruptPort(Pins.GPIO_PIN_D8, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeHigh); PIRInterupt.OnInterrupt += PIRInterupt_OnInterrupt; NetworkChange.NetworkAddressChanged += new NetworkAddressChangedEventHandler(NetworkChange_NetworkAddressChanged); NetworkChange.NetworkAvailabilityChanged += new NetworkAvailabilityChangedEventHandler(NetworkChange_NetworkAvailabilityChanged); while (true) { if (MotionDetected) { Program.MotionDetected = false; //turn this off. Program.Blink(1, 75); Program.AddData(Program.MACAddress, PIRLocal.MessageType.PIR); } Thread.Sleep(500); } } } private static bool GetIPAddressAndSetTime(out string macAddress) { while (!Network.GetIPAddress(out macAddress)) { } if (NTP.SetUTCTimeFromNtpServer()) { return true; } else { return false; } } private static void AddData(string macAddress, PIRLocal.MessageType messageType) { WebClient wc = new WebClient("http://xxxxxxx.azurewebsites.net/api/values", "Post"); PIRLocal sd = new PIRLocal(macAddress, Program.SubLocationID, messageType); wc.Data = sd.ToJson(); wc.Submit(); Debug.Print(wc.ResponseStatusCode); Debug.Print(wc.ResponseStatusDescription); Debug.Print(wc.Data); } #endregion #region Interupts private static void HeartBeatTimerInterrupt(object state) { Program.AddData(Program.MACAddress, PIRLocal.MessageType.HB); } static void PIRInterupt_OnInterrupt(uint data1, uint data2, DateTime time) { Program.MotionDetected = true; Debug.Print(data1.ToString() + " - " + data2.ToString() + " - " + time.AddHours(-6).ToString()); //bool pin = pirInterupt.Read(); } static void NetworkChange_NetworkAvailabilityChanged(object sender, NetworkAvailabilityEventArgs e) { //Program.GetIPAddressAndSetTime(); Program.AddData(Program.MACAddress, PIRLocal.MessageType.NetworkAddressChanged); } static void NetworkChange_NetworkAddressChanged(object sender, EventArgs e) { Program.GetIPAddressAndSetTime(out Program.MACAddress); Program.AddData(Program.MACAddress, PIRLocal.MessageType.NetworkAvailabilityChanged); } #endregion }