Has anyone had any luck using a GUI tool rather than curl?
I’ve tried https://code.google.com/p/cocoa-rest-client/ and also two Chrome apps, but I get ‘permission denied’ errors when I’m sending the correct access_token value.
It would be good to use a GUI as they allow you to save URLs and hence test lots of functions very quickly.
What about a {
“code”: 400,
“error”: “invalid_request”,
“error_description”: “The access token was not found”
}
I have copied and pasted the access token from the wed ide.
It sounds like maybe the access token needs to be in a different spot, or is missing from the request, or maybe the parameter name is mistyped. For the PUT/POST requests, the access_token needs to be a body parameter, and for the GET requests it should be in the url.
I’m a complete noob don’t know what I’m missing. I’m using “Controlling LEDs over the Internet” example from the spark documents and putting my id and token numbers in the api example. I’m using postman to send the api request as I’m on a windows machine. The code seem to flash ok on the core.
@zach I tried the Spark API Helper it flashed success however the led did not turn on. I;ve doubled checked that the id and token are in the right place. I used “led”, ledControl for the function entry and l2,HIGH for the data entry. Appears I have a large learning curve with this core.
// Function prototypes
int ledControl(String command);
// 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(led1, OUTPUT);
pinMode(led2, OUTPUT);
// Initialize both the LEDs to be OFF
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
}
// This routine loops forever
void loop()
{
// Nothing to do here
}
// This function gets called whenever there is a matching API request
// the command string format is l,
// for example: l1,HIGH or l1,LOW
// l2,HIGH or l2,LOW
int ledControl(String command)
{
int state = 0;
//find out the pin number and convert the ascii to integer
int pinNumber = command.charAt(1) - ‘0’;
//Sanity check to see if the pin numbers are within limits
if (pinNumber < 0 || pinNumber > 1) return -1;
// find out the state of the led
if(command.substring(3,7) == “HIGH”) state = 1;
else if(command.substring(3,6) == “LOW”) state = 0;
else return -1;
// write to the appropriate pin
digitalWrite(pinNumber, state);
return 1;
}
@Dave Thanks a lot that worked just fine. Now I have to learn to more about function names and data.
Is there way that you can see the full post url that API Helper is sending I would like to learn more about post and get using that format?
Thanks again
sure thing! If you’re using that particular API helper page, you can open up chrome developer tools and view the network tab. Most browsers have a developer tools window that will show you what’s being sent, or you could use a tool like Fiddler, Charles, or Wireshark to watch the requests directly.
It work 3 times then hasn’t worked since and the development tools showed https://api.spark.io/v1/devices/deviceid/led POST
200
OK
application/json
jquery-2.0.3.js:7845
Script
389 B
125 B
156 ms
153 ms
153 ms3 ms
I’ve posted my Postman collection at https://www.getpostman.com/collections/80e0186c26d47b54fc93. Choose “Import from URL” and Postman should slurp it right up. You also need to set up a Postman environment with two variables for the above collection to work:
DEVICE_ID
ACCESS_TOKEN
I was not able to get the “Verifing and Flashing new firmware” to work.
I also put in the “Tinker” calls, but that of course requires that you have the Tinker sketch loaded on the Core.
If someone figures out the Flashing of firmware in Postman, please post back.