Hi everybody,
I just started a little project on my own to make Spark Core working for C# developers after some comments/posts about that.
Take a look to Spark Sharp and feel free to add requests or issues.
I’m building a little iOS app too but it’s too buggy to make it work and share on Git, but we could talk about it (I’m not an Obj-C dev, I’m using Xamarin).
Hi @Barabba I’ve been playing with Spark and C# and this is how I get all variables and functions. First I get the devices and if they are connected I update my device object with data on variables and functions. I don’t get why a device listed by …/devices? call are different from the device listed by …/devices/[deviceID]? but I just parse out the significant device data from the second call (variables, functions etc).
using (HttpClient hc = new HttpClient())
{
string json = hc.GetStringAsync(“https://api.spark.io/v1/devices?access_token=” + _accessToken.token).Result;
devices = JsonConvert.DeserializeObject<List>(json);
foreach (Device device in devices)
{
if (device.connected)
{
device.accessToken = _accessToken;
json = hc.GetStringAsync(“https://api.spark.io/v1/devices/” + device.id + “?access_token=” + device.accessToken.token).Result;
Device tmpDevice = JsonConvert.DeserializeObject(json);
device.variables = tmpDevice.variables == null ? new Dictionary<string,string>() : tmpDevice.variables;
device.functions = tmpDevice.functions == null ? new List() : tmpDevice.functions;
device.cc3000_patch_version = tmpDevice.cc3000_patch_version;
}
}
}
@Barabba No, as far as I understand I just supports one argument and that’s a “args=string”? I don’t know the supported max length of the parameter value (if you can use JSON to turbo charge it). The way I see it you don’t really have any way of saying how your function is exposed, it’s just magic mapping the “args” parameter to your function (not like Web API). I need to do more testing (in lack of documentation ).
I have written code (in a C# Spark API of my own, before I saw yours) that:
Log in and gets all access tokens, creates a new one if needed (can delete old ones)
Gets all devices and their functions and variables
I made a naming convention for humidity, temperature, switches (relays) functions and variables on Spark so that the C# lib finds them and lists them as separate generic virtual sensors etc.
Added naming support so that one can give a temp sensor a name like “bathroom” and then check for the temp in the “bathroom” with a generics call regardless of where and how that sensor is connected
So I kind of took a different approach then you I think? It’s not on Github but I’d be happy to share code if it is anything you may need that I might have solved. In my API the Spark implementation is just a provider so that I can mix different providers that expose ITemperature devices for instance. Or something compleatly different like a ISun device that expose methods for sunrise and sunset from a weather site or a outdoor light sensor (my current uses yr.no).
Hi @Barabba
This looks great. I have been looking into developing something similar and thanks for doing it. Were you able to write the iPhoe app using Xamarin? I am not an Obj-C dev also and looking to develop iPhone and Android apps to control my spark cores using Xamarin.
My Xamarin Code is actually a piece of Class Library + a textbox area, nothing trascendental! I will keep you updated if something changes if you’re interested
coming a little late to this apparently. Are you building a lib to work with the spark core devices only or spark and photon, also is this meant to be only local or local and web?