I’m working on a project the reads data from wunderground.com API from C# and I’m having problems passing data to the spark core.
I’m able to call the spark core function from c# but am unable to pass the correct data to the function.
---------------Here is the spark core code------------------
// name the pins
int led = D0;
int led2 = D7;
int delaytime = 10;
// This routine runs only once upon reset
void setup()
{
//Register our Spark function here
Spark.function("led", ledControl);
// Configure the pins to be outputs
pinMode(led, OUTPUT);
pinMode(led2, OUTPUT);
// Initialize both the LEDs to be OFF
digitalWrite(led, LOW);
digitalWrite(led2, LOW);
}
// This routine loops forever
void loop()
{
digitalWrite(led2, LOW);
digitalWrite(led, HIGH);
delay(delaytime);
digitalWrite(led2, HIGH);
digitalWrite(led, LOW);
delay(delaytime);
}
int ledControl(String command)
{
if(command == "0")
delaytime = 1000;
else if(command == "1")
delaytime = 2000;
else if(command == "2")
delaytime = 3000;
else if(command == "3")
delaytime = 4000;
else
delaytime = 50;//error did not get command
return 1;
}
---- Here is the C# code-----------------------
private void PrepConditionToSend(string con)
{
switch (con)
{
case "Chance of a Thunderstorm":
SendtoCore("0");
break;
case "Mostly Cloudy":
SendtoCore("1");
break;
case "Partly Cloudy":
SendtoCore("2");
break;
case "Clear":
SendtoCore("3");
break;
}
}
private byte[] SendtoCore(string command)
{
WebClient client = new WebClient();
byte[] response = client.UploadValues("https://api.spark.io/v1/devices/00000000000000000000000/led", new NameValueCollection()
{
{ "access_token", "0000000000000000000000000000000000" },
{ "parms", command }
});
return response;
}