In my Office Palms IoT experiment https://cosm.com/feeds/78110 I have the device uploading data every 5 minutes, however recently the data has only been making it every 15 minutes and the other uploads fail and typically after a while the device just stops sending data. I’ve been trying different things lately until today when this annoyed me to the point of breaking out some network sniffers and routing the device traffic through a sniffer so I could see what the heck was going on. Interestingly it seemed that the KeepAlive stuff was causing me grief and I had to add a line in the code to turn it off:
//Copyright 2011 Cuno Pfister
//
//Licensed under the Apache License, Version 2.0 (the "License");
//you may not use this file except in compliance with the License.
//You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//Unless required by applicable law or agreed to in writing, software
//distributed under the License is distributed on an "AS IS" BASIS,
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//See the License for the specific language governing permissions and
//limitations under the License.
//Developed for the book
// "Getting Started with the Internet of Things", by Cuno Pfister.
// Copyright 2011 Cuno Pfister, Inc., 978-1-4493-9357-1.
//
//Version 0.9 (beta release)
using System;
using System.IO;
using System.Net;
using System.Text;
using Microsoft.SPOT;
namespace Gsiot.PachubeClient
{
public static class PachubeClient
{
const string baseUri = "http://api.pachube.com/v2/feeds/";
public static void Send(string apiKey, string feedId,
string sample)
{
Debug.Print("Attempting upload to COSM");
Debug.Print("time: " + DateTime.Now);
Debug.Print("memory available: " + Debug.GC(true));
try
{
using (var request = CreateRequest(apiKey, feedId, sample))
{
request.KeepAlive = false; <<<<<<----- Added this line
request.Timeout = 5000; // 5 seconds
// send request and receive response
using (var response =
(HttpWebResponse)request.GetResponse())
{
Debug.Print("COSM Response: " + response.StatusDescription);
HandleResponse(response);
}
}
}
catch (Exception e)
{
Debug.Print("COSM Error: " + e.ToString());
}
Debug.Print("COSM time finished: " + DateTime.Now);
}
static HttpWebRequest CreateRequest(string apiKey, string feedId,
string sample)
{
byte[] buffer = Encoding.UTF8.GetBytes(sample);
var request = (HttpWebRequest)WebRequest.Create
(baseUri + feedId + ".csv");
// request line
request.Method = "PUT";
// request headers
request.ContentLength = buffer.Length;
request.ContentType = @ "text/csv";
request.Headers.Add(@ "X-PachubeApiKey", apiKey);
// request body
using (Stream stream = request.GetRequestStream())
{
stream.Write(buffer, 0, buffer.Length);
}
return request;
}
public static void HandleResponse(HttpWebResponse response)
{
Debug.Print("COSM Status code: " + response.StatusCode);
}
}
}
It now appears my data is going up every 5 minutes and not hanging (testing is still in progress however). This app has been running for the last six months or more and was doing really well until late March which makes me wonder if some code changes in the ENC28 module / Cerberus might have happened.