I’ve personally got a couple of files in which my acces tokens are stored. Could it be that you’ve taken yours out of a similar one, while the “live” one has expired in the mean time? Or did you really take it directly out of the IDE?
Which works when a core publishes the brett-test event.
I’ve been trying to recreate your error. If I switch one of the letters in my access token from lower case to upper case, then I get the exact error message. Maybe that’s your problem?
UPDATE: I tried my access token with all upper case letters, and I get the invalid_grant error. All lower case works.
Hmm, no reason why the bearer token shouldn’t work, but it’s possible curl was not sending a GET request, so it might help to specify that method with a -X GET or something.
Hey @bko, great suggestion, the URL you shared is not the public stream though, subtle mistake, no need for the “/devices” in there. I thought you had it right too, but then tried it myself, and looked closer at the docs Both the following requests do the same thing:
Here’s my code I commented out (and don’t publish all the code) and left only the Spark.publish event statement.
void setup() {
}
void loop() {
Spark.publish("my-event", "TEST", 60, PRIVATE);
}
UPDATE: obviously the { and } are not part of the statement in the curl; as @jgoggins mentions
curl -H “Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx” https://api.spark.io/v1/events/my-event
works; it displays “:ok”, but not “TEST” during the execution of every loop.
You know that event publishing is rate-limited, right? You will be limited to one per second on average with a burst of up to four events allowed. Have you factored that into your sketch somehow?
@bko yes i did. I only publish when an interrupt event (so in an interrupt handler) happens. The code I showed was only to solve the problem with the access token.