How to configure IFTTT to trigger Particle device?

Hello:

I am currently have an applet set up like this:

If a button pressed then trigger Particle (call a function)

Since the latest change, I have to figure a way to achieve the same. Can someone direct me to the right steps to do that please?

I use IFTTT widget on my phone, when pressed, it would trigger Boron to lock/unlock/star my car.

Thank you,
Yazen

The documentation is here. You’ll need to create the IFTTT service and access token. Skip over the section on publishing and event and the next item is calling a function.

Thank you very much. I followed the instructions but ran into an issue. When I trigger my action, I get the following error message:
image

Here is my applet:

Can you please assist me figure out how to solve this?

Thank you,
Yazen

If you don’t have any parameters to your function call you still need to put an empty JSON body in the Body field. I’m not positive this is the problem, but it might be. Just put left and right curly brackets in the Body field of the applet:

{}

Added the curl in the body and tested it. Still threw the same error message;

I am thinking the URL is incorrect. Although the instructions says to use that URL and add my device id to it then the function.

Any other suggestions?

Thank you,
Yazen

The URL was my second guess.

  • Make sure the Device ID is correct and letters are all lowercase.
  • Make sure the function name is correct. It’s case-sensitive.
  • From the console, make sure the functions were registered properly for the device.
  • Make sure the access token is valid and for the same account the device is claimed to.

Thabk you,

Just to make sure, where to find function names?

How to register the functions?

Thank you,
Yazen

In your code and the Particle.function()
is registered in setup()
e.g:



Best,
Arek

1 Like

Thank you.

Function names are accurate. I have three functions; lock, unlock and start. They are registered as well.

I am guessing the URL is incorrect for some reason.

Any other suggestions?

Thank you,
Yazen

Could you please run this minimal html code withchrome and you
deviceID, accessToken and function name and then go inspect → console and give us back console logs.
I believe that it’s an issue with your access token but this is just guessing.
Minimal code:


<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/particle-api-js@8/dist/particle.min.js"></script>

<style>
</style>
</head>
<body>


<script>
var accessToken = "your access token here"; //not display for security
var deviceID = "your dev. id here" //not display for security

var particle = new Particle();


function test(cmd){
     	var fnPr = particle.callFunction({ deviceId:deviceID, name:'your_function_name', argument: cmd, auth: accessToken});
		fnPr.then(
		  function(data) {
			console.log('Function called succesfully:', data);
         }, function(err) {
			console.log('An error occurred:', err);
		  });
           
     }

test('');

setInterval(function() {


test('');

}, 5000); 

</script>
</body>
</html>

1 Like

Thank you very your help. I ran the code. Here it is:

I used postman to validate device id and token, both seem accurate.

I attempted to call a function, which resulted in an error. “error”: “Function lock not found”

Although: here it is correct in my code:

SYSTEM_THREAD(ENABLED);


void setup()
{
    
   // Pin Configuration
   pinMode(D2, OUTPUT); // Output to optoisolator, controls REMOTE START output
   pinMode(D3, OUTPUT); // Output to optoisolator, controls UNLOCK output
   pinMode(D4, OUTPUT); // Output to optoisolator, controls LOCK output
   digitalWrite(D2,LOW); 
   digitalWrite(D3,LOW); 
   digitalWrite(D4,LOW); 
   
   // We'll declare our Particle.function that controls the start, lock, and unlock outputs
   Particle.function("control",control);  // When the IFTTT service asks for the function "control", the electron will employ the function control() from this app.


}


void loop() 
{
   // For this project, we don't have anything happening in the void loop
}


int control(String command) // 
{
    if (command=="lock")
    {
        digitalWrite(D4,HIGH);  // Write pin D4 high to activate optoisolator, effectively sending a ground pulse to the car's LOCK wire 
        delay (250);            // Wait 1/4 second
        digitalWrite(D4,LOW);   // Turn off output to the optoisolator
    }

    if (command=="unlock")
    {
            digitalWrite(D3,HIGH);  // Write pin D3 high to activate optoisolator, effectively sending a ground pulse to the car's UNLOCK wire
            delay (160);            // Wait 1/4 second
            digitalWrite(D3,LOW);   // Turn off output to optoisolator
    } 
    
    if (command=="start")
    {
            digitalWrite(D2,HIGH);  // Write pin D2 high to activate optoisolator, effectively sending a ground pulse to the REMOTE START input wire
            delay (250);            // Wait 1/4 second
            digitalWrite(D2,LOW);   // Turn off output to optoisolator
    } 
    
}

Any suggestions?

Thank you,
Yazen

Your function is not called lock but control - lock is the parameter.

It’s the first parameter that is relevant for the naming of the exposed function in the cloud.
If you wrote

  Particle.function("remote_control",control);

You’d need to call remote_control from IFTTT.

1 Like

But I have three different commands, how to call them separately?

I have; lock, unlock, and start.

Thank you,
Yazen

Change your function name in URL to
control
And then in
Body you can put this

{"arg":"lock"}

or

{"arg":"unlock"}

or

{"arg":"start"}

e.g:

2 Likes

So I did that but, that Particle Boron did not receive the command.

I also fixed the html code and ran it, came back with no errors:

Is there a way to validate the connection between webhook and particle?

Thank you,
Yazen

I guess your Boron will be crashing with an SOS panic (unless you are on a really old device OS version) since you haven’t got a return statement in your function handler.

The function signature promises to return an int so your code has to do so.

I’d use three values for the three different commands and one in case none of the expected commands was executed.

int control(String command) {
  if (command=="lock") {
    digitalWrite(D4,HIGH);  // Write pin D4 high to activate optoisolator, effectively sending a ground pulse to the car's LOCK wire 
    delay (250);            // Wait 1/4 second
    digitalWrite(D4,LOW);   // Turn off output to the optoisolator
    return 1;
  }

  if (command=="unlock") {
    digitalWrite(D3,HIGH);  // Write pin D3 high to activate optoisolator, effectively sending a ground pulse to the car's UNLOCK wire
    delay (160);            // Wait 1/4 second
    digitalWrite(D3,LOW);   // Turn off output to optoisolator
    return 2;
  } 
    
  if (command=="start") {
    digitalWrite(D2,HIGH);  // Write pin D2 high to activate optoisolator, effectively sending a ground pulse to the REMOTE START input wire
    delay (250);            // Wait 1/4 second
    digitalWrite(D2,LOW);   // Turn off output to optoisolator
    return 3;
  } 
  return -1;
}
2 Likes

One more important thing
Your control function should return some integer
if you not getting any compiler complains it’s mean that device OS is pretty old :grin:
If you decide to update your device OS you can get in trouble :stuck_out_tongue_winking_eye:

2 Likes

Thank you very much for assisting me with the code.

You are right, the os ver is old :smiley: it is on 1.4.2.

I am kind of worried to update the OS, I don’t want to break things up.

Okay so I updated the code, but i got the following errors:

The new code is:

SYSTEM_THREAD(ENABLED);


void setup()
{
    
   // Pin Configuration
   pinMode(D2, OUTPUT); // Output to optoisolator, controls REMOTE START output
   pinMode(D3, OUTPUT); // Output to optoisolator, controls UNLOCK output
   pinMode(D4, OUTPUT); // Output to optoisolator, controls LOCK output
   digitalWrite(D2,LOW); 
   digitalWrite(D3,LOW); 
   digitalWrite(D4,LOW); 
   
   // We'll declare our Particle.function that controls the start, lock, and unlock outputs
   Particle.function("control",control);  // When the IFTTT service asks for the function "control", the electron will employ the function control() from this app.


}


void loop() 
{
   // For this project, we don't have anything happening in the void loop
}


int control(String command) // {
  if (command=="lock") {
    digitalWrite(D4,HIGH);  // Write pin D4 high to activate optoisolator, effectively sending a ground pulse to the car's LOCK wire 
    delay (250);            // Wait 1/4 second
    digitalWrite(D4,LOW);   // Turn off output to the optoisolator
    return 1;
  }

  if (command=="unlock") {
    digitalWrite(D3,HIGH);  // Write pin D3 high to activate optoisolator, effectively sending a ground pulse to the car's UNLOCK wire
    delay (250);            // Wait 1/4 second
    digitalWrite(D3,LOW);   // Turn off output to optoisolator
    return 2;
  } 
    
  if (command=="start") {
    digitalWrite(D2,HIGH);  // Write pin D2 high to activate optoisolator, effectively sending a ground pulse to the REMOTE START input wire
    delay (250);            // Wait 1/4 second
    digitalWrite(D2,LOW);   // Turn off output to optoisolator
    return 3;
  } 
  return -1;
    
}