I am trying to create an application using VB in Visual Studio 2010 to remotely control a Spark Core. To test, I am using the “control an LED over the net” example. So the command is:
Putting this in console2 works so I know the core is set up correctly…
In VB, the commands are:
"Dim addbase as String
addbase = “https://api.spark.io/v1/devices/123456789/led -d access_token=abcdef123456789 -d params=l1,HIGH"
Dim client As New WebClient()
Dim res1 As String
res1 = client.DownloadString(addbase)”
But this gives rise to a 400 error. Replacing the command line with:
-d, --data <data>
(HTTP) Sends the specified data in a POST request to the HTTP
server, in the same way that a browser does when a user has
filled in an HTML form and presses the submit button. This will
cause curl to pass the data to the server using the content-type
application/x-www-form-urlencoded. Compare to -F, --form.
...
If any of these options is used more than once on the same com‐
mand line, the data pieces specified will be merged together
with a separating &-symbol. Thus, using '-d name=daniel -d
skill=lousy' would generate a post chunk that looks like
'name=daniel&skill=lousy'.
I don’t know too much about Visual Studio but the -d is a switch to curl not to any other POST command that I know, so you have to remove that and pass the parameters a different way.
If you like, you can have a read of this two-part tutorial (part1, part2). It demonstrates how to remote control a Core powered RC car from a C# project.
There you can also find a link to Chris Loris’ C#ore library SparkIODotNet.zip, which did help me a lot to get my own projects up and running.
Some good news… the library is now up on GitHub! And I have created an EventsAPI class to handle the Spark Core’s SSE events as native .Net events. Please have a look and comment! and contribute!
Thanks to all for your very helpful reponses. Unfortunately, I have yet to be able to make it work! However, one reason for my delay in replying is that in looking around for help I came across Krishnaraj Varma’s Smart Things and Spark Core project. Played around with this and in a very short time I now have an Iphone app that I can use to control my Spark Core. Thanks Krishnaraj for a very useful project. In time I will get back to Visual Studio and VB but for the moment Smart Things is doing exacgly what I need.