I get this error: 'Particle' does not name a type and I haven't been able to find a solution that works for me

I used #include “application.h” and that didn’t fix my problem. My code was largely copied from the example for an IFTTT action. I am pretty new to Particle and I haven’t been able to find a solution to this.

Particle.function("ledtest", "lightup");
 #include "application.h"
 
// USAGE
int ledon(String command);
int led = D0;

void setup()
{
  // register the Particle function
  Particle.function("lightup", ledon);
  pinMode(led, OUTPUT);
}

void loop()
{
  // this loops forever, doing nothing
}

// this function automagically shows up in IFTTT
int ledon(String command)
{
  // look for the matching argument "coffee" <-- max of 64 characters long
  if(command == "light")
  {
    //things you want it to do
    digitalWrite(led, HIGH);

    //Returns the value "1" if it was successful
    return 1;
  }
  else return -1;
}

You should only have Particle function and variable declarations inside of the setup() function, not at the top level.

If you are building on the web-based IDE (Build button in a browser) then you don’t normally need the #include "application.h" either.

2 Likes

That fixed my initial error but now I am getting this error. Thanks for the help btw.
error: no matching function for call to 'CloudClass::_function(const char [8], const char*&)'
return _function(name, args…);

That is because the second parameter needs to be a function and not a string literal.

If you read the samples in the docs carefully you’ll see no double quotes around the second parameter.

But since you don’t even have a function int lightup() I don’t see any reason for this line at all.

1 Like