I'm not sure where SL is headed with their IOT plans, but that doesn't really help me right at the moment, so my original plan had been to write something fairly similar to (but more purpose built than) Xively in php and use it to data log and be a middleware to sharing current trends within my project. Seems like with a free developer account I don't need to do that and can just use Xively.
There are a couple examples of connecting to Xively via .netMF out there (http://forums.netdui...ely/#entry53968 for example) but none that met all my needs. Many Hat Tips to those out there, as with those as inspiration I'm working to produce the following:
[*]XivelyConnection class creates and manages a connection to a Xively project. I'll only have one, but lord knows someone will find a need for multiple, so you can do that. You tell it your API bits and how you want to push updates (real time? Queued? Time limit between pushes?) and if you call it properly it'll handle making sure you don't flood Xively and use too many updates. Has a queue of updates within, which when not in direct push mode will allow you build up a few different readings from a few different places and send them all in one update if there are more than one of them (including multiple readings for the same Channel).
[*]XivelyMeasurement is a helper class (really probably not required) which just stores the data, date/time, and the channel. Will need to work hard to make sure that memory is freed up quickly after pushing
[/list]
Thoughts- do I need to have an array of channels pre-defined somewhere, or do we trust ourselves to pass in the channel name properly with the creation of each measurement?
I don't like that this model is a turn/burn (measurements will be flushed and wait for GC to come clean them up after each push) but I don't want to limit the ability for the system to handle a bunch of measurements... thoughts?
I need to do some experimenting but it appears that the API assumes you're either pushing a few measurements or the one you are is current- often in my case the readings will all be historical (though you can set it to push on demand) I had figured on this being more a queue and push system, though I guess it could be configured the other way (go and collect when told to push, though lots of work to have both)... I will probably stick with my original plan (easier implementation across projects) but would like to hear thoughts on it.
Probably going to flesh this out tonight and try to get it going.. here is the skeleton:
class XivelyConnection { private const string CRLF = "rn"; private static string _ApiKey; private static string _FeedId; private static string _UserAgent; // user agent is the project name private int _pushType; //specifies if we should do updates in real time (0) away or que them up and obey the _delay (1) private TimeSpan _delay; //delay (in seconds) between possible pushes private DateTime _lastPush; //last time we pushed information private ArrayList _commands; //arraylist of updates to push private static IPAddress remote_IP = IPAddress.Parse("216.52.233.120"); private static IPEndPoint remoteEndPoint = new IPEndPoint(remote_IP, 80); private Socket serversocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); public XivelyConnection(string ApiKey, string FeedID, string UserAgent, int PushType=1, int delay=10) { _ApiKey = ApiKey; _FeedId = FeedID; _UserAgent = UserAgent; _pushType = PushType; _delay = TimeSpan.FromTicks(delay * 10000000); //no .FromSeconds in .netMF :( } public bool CheckAndPush() { //if there are commands & push_type is real time OR if there are commands & the delay time has passed if( (_commands.Count > 0 && _pushType == 0) || (_commands.Count > 0 && ( (DateTime.Now - _lastPush).Duration()) > _delay)) { foreach (XivelyMeasurement measurement in _commands) { //format commands into XML } } //make the Push Request return true; } public bool AddElement(XivelyMeasurement reading) { _commands.Add(reading); // add it to the things we want to push next time if (_pushType == 0) //real-time pushing is enabled { if (this.CheckAndPush()) //go ahead and push it all up return true; //looks like the push was ok else return false; // push failed } return true; //command added } }