Mountainer stop talking to Xively bwetween 5000 and 7000 messages

I’ve just started using the Mountaineer board to start and learn how to build solutions using wired Ethernet. The board, with built-in Ethernet, works great and using Cuno’s examples from Getting Started with the Internet of Things (GSIOT) I am able to write data to Xively (used to be Pachube) very easily.

However, after between 5000 and 7000 writes, spaced by 30 seconds, the hardware seems to stop writing. The code below is what I am using.

It takes several days to reach the count and so debugging using VS is not really an option. Any ideas what might be happening or why the writes are stopping?


using System;
using System.Threading;
using Microsoft.SPOT;
using System.Net;
using System.Text;
using System.IO;

namespace MountaineerXivelyTestApp
{
    public partial class Program
    {
        string baseUri = "http://api.xively.com/v2/feeds/";
        string FeedId = "....";
        string ApiKey = "....";
        int period = 30000;

        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {
            Debug.Print("Program Started");
            ThreadStart ts = new ThreadStart(SendMessages);
            Thread t = new Thread(ts);
            t.Start();
        }

        private void SendMessages()
        {
            Random rnd = new Random();
            int x = 0;
            while (true)
            {
                WaitUntilNextPeriod(period);
                double value = x++;
                SendToXively(ApiKey, FeedId, value);
            }
        }

        private void SendToXively(string apiKey, string feedId, double value)
        {
            byte[] buffer = Encoding.UTF8.GetBytes("Temp2," + value.ToString("F"));
            var request = (HttpWebRequest)WebRequest.Create(baseUri + feedId + ".csv");
            request.Method = "PUT";
            request.ContentType = "text/csv";
            request.Headers.Add("X-ApiKey", apiKey);
            request.ContentLength = buffer.Length;

            using (Stream requestStream = request.GetRequestStream())
            {
                requestStream.Write(buffer, 0, buffer.Length);
            }

            using(var response = (HttpWebResponse)request.GetResponse())
            {
                Debug.Print("Status Code : " + response.StatusCode);
            }
            request.Dispose();
        }

        static void WaitUntilNextPeriod(int period)
        {
            long now = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
            var offset = (int)(now % period);
            int delay = period - offset;
            Debug.Print("sleep for " + delay + " ms\r\n");
            Thread.Sleep(delay);
        }

    }
}

can I check what framework version you’re using ? 4.2? Or the 4.3 beta ?

@ Brett - I’m using the 4.3.1 Beta firmware from the Mountaineer website.