Web-connected LED example giving "the access token was not found"

I am desperately trying to get the “web-connected LED” webpage to work and not having alot of success. I can get the LED to turn on and off with the command line “particle call device_name led on” (obviously using my photon’s device_name), so I am confident the firmware side is working. However when I use the example HTML code and put in the device-id and access-token that I cut and paste out of the web based IDE I cannot get the webpage to turn the LED on or off. I just get the following in my browser:

{
“error”: “invalid_request”,
“error_description”: “The access token was not found”
}

I have tried this on multiple browsers and looked through the support area here, but I have not found a thread dealing with the webpage side of things from the sample. I have found the threads that talk about this error message, but they are mostly about other setups and not the straight html given in the sample… Any help is greatly appreciated!!!

Since you haven't provided a link to "web-connected LED" I'd have to guess you mean this one

I’m actually going to assume this one:
https://docs.particle.io/guide/getting-started/examples/photon/#use
And I’m also going to claim that that codes works just fine. Could you double check to see if you haven’t got any copy&paste errors?

1 Like

@Moors7: That makes more sense, despite the fact it’s not called “web-connected LED” there and hence my doc search did fail to tell me 'bout 't :wink:

How good that we have the possibility to LINK :+1:

The only reason I found it was because I vaguely remembered something like that being in the Web IDE as an example. When I couldn’t find the HTML code there, I moved to the docs, where I did manage to find it.

That said, I prefer the method you linked to (which is my example), for the fact that it uses JavaScript rather than HTML forms. Those things reload the page, whereas JavaScript can manage stuff in the background.

Linking indeed is neat :wink:

1 Like

Awesome responses! thanks for the inputs. I’m sorry I was not more specific with a link to the project. I am new to this web based collaboration. I am using the example apps that are on the default web IDE (link: example from docs )

By looking at the example sited by ScruffR I saw that I missed the “access_token=” after the “led?” . Once I added that to the code it worked :smile: It is a little cumbersome in that you have to hit the back button on your browser to switch it again, but it works! The rest of this will be learning the html coding…

Anyone have good suggestions on how to pick html up? I have been writing code since about 1980, starting with BASIC, FORTRAN, Turbo Pascal, DCL, MSDOS batch files, UNIX scripts, Visual Basic (4, 5, 6, and now in Visual Studio 2010), some simple BASIC stamp work, simple Arduino, and just touched Python on the Raspberry pi. I’m not a coder by trade at all (notice the lack of C…), and I’m not looking for a career in coding, but I would like to learn some simple HTML so I can make a few webpages do what I want them to do. I have a few different avenues that I know of, but since I got such quick and good advice here I thought I would ask :smile:

Thanks again!

I’m also using the Web-connected LED example and I had it working at one time. Now I’m getting the following message from my browser:
{
“ok”: false,
“error”: “Function led not found”
}

Here’s the line from my code where I register the function:
Particle.function(“led”, ledToggle);

(I changed Spark.function to Particle.function.)

Any help?
Ray

Could you check this to see if your function is listed? If it isn’t, there’s probably an issue with your code. If you could share that, we can have a look.

1 Like

Didn’t see anything at jordymoors.nl/interface. Is that a way to see registered variables and functions? If so, I’d be interested in how to do that. I’ve tried using Particle Dev, but to computer I use the most for this stuff is XP. I loaded Particle Dev on an Windows 8.1 machine I have, but I just haven’t been able yet to figure out Particle Dev. A simple way to see variables and functions would be nice.
Here’s my code:

// -----------------------------------
// Controlling LEDs over the Internet
// -----------------------------------

// First, let's create our "shorthand" for the pins
// Same as in the Blink an LED example:
// led1 is D0, led2 is D7

int led1 = D0;
int led2 = D7;

// Last time, we only needed to declare pins in the setup function.
// This time, we are also going to register our Spark function

void setup()
{

   // Here's the pin configuration, same as last time
   pinMode(led1, OUTPUT);
   pinMode(led2, OUTPUT);

   // We are also going to declare a Spark.function so that we can turn the LED on and off from the cloud.
   Particle.function("led", ledToggle);
   // This is saying that when we ask the cloud for the function "led", it will employ the function ledToggle() from this app.

   // For good measure, let's also make sure both LEDs are off when we start:
   digitalWrite(led1, HIGH);
   digitalWrite(led2, HIGH);
   delay(5000);
   digitalWrite(led1, LOW);
   digitalWrite(led2, LOW);

}


// Last time, we wanted to continously blink the LED on and off
// Since we're waiting for input through the cloud this time,
// we don't actually need to put anything in the loop

void loop()
{
   // Nothing to do here
}

// We're going to have a super cool function now that gets called when a matching API request is sent
// This is the ledToggle function we registered to the "led" Spark.function earlier.


int ledToggle(String command) {
    /* Spark.functions always take a string as an argument and return an integer.
    Since we can pass a string, it means that we can give the program commands on how the function should be used.
    In this case, telling the function "on" will turn the LED on and telling it "off" will turn the LED off.
    Then, the function returns a value to us to let us know what happened.
    In this case, it will return 1 for the LEDs turning on, 0 for the LEDs turning off,
    and -1 if we received a totally bogus command that didn't do anything to the LEDs.
    */

    if (command=="on") {
        digitalWrite(led1,HIGH);
        digitalWrite(led2,HIGH);
        return 1;
    }
    else if (command=="off") {
        digitalWrite(led1,LOW);
        digitalWrite(led2,LOW);
        return 0;
    }
    else {
        return -1;
    }
}

If you have CLI running, the simplest way to see exposed functions and variables is particle list
In Dev you have a menu Particle where you first have to “Select device …” and after that can use “Show cloud variables”/"Show cloud functions"
And if you want to see how Jordy’s page does it, just look at the source code (which should be an option of any web browser) or have a look at ParticleJS in the docs.

1 Like

The code you’ve got looks fine on first glance. Could you try flashing it again, to make sure nothing strange happened while doing that last time?
My page will indeed show you the functions and variables of your online devices, so feel free to use that. Otherwise Particle Dev, and the CLI are some good official tools.

Thanks for the response. I’ve got to take the time to understand Dev and get running properly.

Jordy,

Thanks for the reply and for the dashboard.

I renamed the led Function in my code. Then, I completely reloaded the sample html code, put in my Device ID and Access Token, and renamed the function to match the function registration in my Particle code. Now it works.

I may have a clue what was happening:

It seems that sometimes when I flash code to the photon from Build, my device starts, but fails to come online. If I power down and back up it comes online. Not sure why. But, I’m guessing when I was having my “problem”, I was flashing my code, but not making sure the device had come on line.

At any rate, tanks again for the help.

Ray

1 Like

Hi,

I’m having a similar problem with the HTML code except I’m getting the message:
{
“ok”: false,
“error”: “Not Found”,
“device_name”: “hoosier hunter wombat crazy captain”
}

I’ve check that the Photon is online and that the led function is listed. I can also turn the LEDs on and off using the command line “particle call device_name led on / off.”

I’ve attempted coping the HTML code directly from the example code page, and put in the device ID and access token, a couple of times to rule out copy and past errors.

Any Ideas??

I’m very new to HTML and online forums, let me know if there is any other information that would help.

Cheers,
Jake

Could you post both the Photon as well as the HTML code? That should help figure things out.

Thanks for the quick response!!

I’m using the code directly out of the “Control LEDs over the 'net” example https://docs.particle.io/guide/getting-started/examples/photon/#control-leds-over-the-39-net

I actually just got it to work though. It seams that something was going wrong when I pasted the example html code into the .txt file and then changed the extension to .html.
I just ran it through Xcode and now it works fine.

Cheers,
Jake

1 Like