Arduino Netduino: Spark.IO Windows 8 App

Thanks to Jerry Nixon for his assistance in turning an otherwise awful app into one that shines, as well morphing it into a Model View thing.  You will need to flash this code into your Spark.io device (for those readers not familiar with the Spark, check it out, super cheap for the WiFi capabilities).

If you have a Spark Core registered on the Spark.IO site (https://www.spark.io) then download the Windows 8 app from:

https://apps.microsoft.com/windows/app/spark-io-sensor-app/8988487c-296d-4c7e-bb5a-3980cb398ffa

You will need to have the code below flashed to your Spark.IO and you will need to have your deviceID and accessID for your core that you wish to use.  This is a very simple use of the Spark.IO, but there are quite a few blog posts built into the code.  The C# code was based on the Model View ViewModel approach, modified for use in C#, and I have to thank Jerry Nixon for his assistance. 

Other items like getting an app that only works with a separate device that the enduser has to purchase, program, register and then install Windows 8 is a complex effort.  Keeping it dirt simple is also a difficult approach, it makes me seem more lazy then I really am, and that is also hard work…

But the code shown below is the code you will need to use

 

 char resultstr[64];
//Code from: https://bit.ly/SparkSensorLab1<br>void setup()
{
    pinMode(A0, INPUT); // setup A0 as analog input
    pinMode(A1, INPUT); // setup A1 as analog input
    // expose your char buffer to the Cloud API
    Spark.variable("result", &resultstr, STRING); 
}

void loop()
{
    int data1 = analogRead(A0); // read some data
    int data2 = analogRead(A1); // some some other data
    // format your data as JSON, don't forget to escape the double quotes
    sprintf(resultstr, "{\"data1\":%d,\"data2\":%d}", data1, data2); 
    delay(1000); // wait for a second