Tasker + ifttt + photon

hello!

I’m new here but i’m glad to be apart of this community, thanks in advance for your assistence.

I’m trying to add voice control over a couple photons that control my lighting, using relays. i already use blynk app and proximity sensors to manage them but i think it’s possible to use the google now service and auto voice to trigger an action ifttt, activating the relays and have another form of automation.

this is my simple code, but its not compiling after i added Particle.function, don’t reply know if thats correct…


/**************************************************************
 * Blynk is a platform with iOS and Android apps to control
 * Arduino, Raspberry Pi and the likes over the Internet.
 * You can easily build graphic interfaces for all your
 * projects by simply dragging and dropping widgets.
 *
 *   Downloads, docs, tutorials: http://www.blynk.cc
 *   Blynk community:            http://community.blynk.cc
 *   Social groups:              http://www.fb.com/blynkapp
 *                               http://twitter.com/blynk_app
 *
 * Blynk library is licensed under MIT license
 * This example code is in public domain.
 *
 **************************************************************/
//#define BLYNK_DEBUG // Uncomment this to see debug prints
#define BLYNK_PRINT Serial
#include "blynk/BlynkSimpleParticle.h"


char auth[] = "asasassa";


const int relay1 = A0;
const int sensor1 = A1;

void setup()
{
    Serial.begin(9600);
    delay(1000);
    Blynk.begin(auth);
    pinMode(relay1, OUTPUT);  
    
    Particle.function("relay", relay1);

}

void loop()
{
    Blynk.run();
    
    static boolean lastSensorHit = false;
 static boolean relayValue = LOW;

 int sensorValue = map(analogRead(sensor1), 0, 1024, 0 , 200);
 bool sensorHit = sensorValue > 0 && sensorValue <200;

 if (sensorHit && !lastSensorHit) 
   {
   relayValue = !relayValue; 
   digitalWrite(relay1, relayValue);
   } 
 lastSensorHit = sensorHit;
 delay(100);
}

error

In file included from blynk/BlynkParticle.h:16:0,
                 from blynk/BlynkSimpleParticle.h:14,
                 from 01_particle.cpp:18:
blynk/BlynkApiParticle.h:78:6: warning: #warning "analogInputToDigitalPin not defined => Named analog pins will not work" [-Wcpp]
     #warning "analogInputToDigitalPin not defined => Named analog pins will not work"
      ^
01_particle.cpp: In function 'void setup()':
01_particle.cpp:34:38: error: invalid conversion from 'int' to 'int (*)(String)' [-fpermissive]
     Serial.begin(9600);
                                      ^

In file included from ../wiring/inc/spark_wiring.h:48:0,
                 from ./inc/application.h:36,
                 from 01_particle.cpp:16:
../wiring/inc/spark_wiring_cloud.h:135:17: error:   initializing argument 2 of 'static bool CloudClass::function(const char*, int (*)(String))' [-fpermissive]
     static bool function(const char *funcKey, user_function_int_str_t* func)
                 ^

make[1]: *** [../build/target/user/platform-601_particle.o] Error 1
make: *** [user] Error 2
Error: Could not compile. Please review your code.

what am i doing wrong? thank you

You need to create the function relay1 since the Particle.function is going to call it when you trigger the function.

See: https://docs.particle.io/reference/firmware/photon/#particle-function-

2 Likes

And you should choose a different function name, since you are already using const int relay1 = A0;.

And replace 1024 with 4095 as the Photon uses a 12bit ADC (not 10bit as the Arduinos).

int sensorValue = map(analogRead(sensor1), 0, 1024, 0 , 200);

Just for clarity also add pinMode(sensor1, INPUT); in setup() - even if it’s not required on some platforms on others it is, so it’s not a bad idea to be more verbose.

For Blynk.run() try to remove the delay(100); and wrap the rest of your loop() in a “soft delay” block.

Great tips! Im trying to really work on my coding knowlodge and its allways good to get this kind of feedback, when i get home ill give it a try.

By the way, any of you guys done this? Using google now, tasker, ifttt and photons? Theoretically its possible i think, id rather make myself a jarvis look a like than to spend 180$ on a limited amazon echo

Many thanks

You can do HTTP Posts with tasker so you don’t Need iftt for hat. The benefit is a Shorter Delay which I guess is a good thing when Switching your lights.

Server: https://api.spark.io

Path: /v1/devices/DEVICEID/FUNCTIONNAME?access_token=ACCESSTOKEN

Data: args=2|047b23827b4880
(input for your function if needed)

I didnt know it was possible, for blynk its for local users only, even better then! Whats the data refering to? Do you have any examples? Thank you

i made a few changes but i still can’t compile… can you tell me whats wrong? i dint remove the delay because i don’t know what a soft delay is lol thank you

#define BLYNK_PRINT Serial
#include "blynk/BlynkSimpleParticle.h"


char auth[] = "blabla";


const int relay1 = A0;
const int sensor1 = A1;


void setup()
{
    Serial.begin(9600);
    delay(1000);
    Blynk.begin(auth);
    pinMode(relay1, OUTPUT);  
    pinMode(sensor1, INPUT)
    Particle.function("luz1", luz_state);

}

void loop()
{
    Blynk.run();
    
    static boolean lastSensorHit = false;
 static boolean relayValue = LOW;

 int sensorValue = map(analogRead(sensor1), 0, 4095, 0 , 200);
 bool sensorHit = sensorValue > 0 && sensorValue <200;

 if (sensorHit && !lastSensorHit) 
   {
   relayValue = !relayValue; 
   digitalWrite(relay1, relayValue);
   } 
 lastSensorHit = sensorHit;
 delay(100);
 
 int luz_state(String command) {

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

You’re missing a semicolon in setup (pinMode(sensor1, INPUT)), and your function, luz_state(String command) is written inside of loop(). You need to move that outside of loop.

Another problem might be your include. If you choose the Blynk library in Build, and add it to your project, you should automatically get an include that says “blynk/blynk.h”. The file (“blynk/BlynkSimpleParticle.h”) you included is just one of the files from that library.

im getting this… how do i move it outside the loop? and how do i add the rest of the library? i know im asking too much but i really don’t know much

In file included from blynk/BlynkParticle.h:16:0,
                 from blynk/BlynkSimpleParticle.h:14,
                 from 01_particle.cpp:3:
blynk/BlynkApiParticle.h:78:6: warning: #warning "analogInputToDigitalPin not defined => Named analog pins will not work" [-Wcpp]
     #warning "analogInputToDigitalPin not defined => Named analog pins will not work"
      ^
01_particle.cpp: In function 'void loop()':
01_particle.cpp:42:32: error: a function-definition is not allowed here before '{' token
    relayValue = !relayValue; 
                                ^

01_particle.cpp:56:1: error: expected '}' at end of input
         return 0;
 ^

make[1]: *** [../build/target/user/platform-601_particle.o] Error 1
make: *** [user] Error 2
Error: Could not compile. Please review your code.

EDIT: I think i have the whole library because on the side it says included library: blynk

I’m not sure exactly what your asking about moving the method outside of loop. You just cut and paste it, like with any other editing task (select the whole function, cut, move the cursor to outside the closing curly brace of the loop method, and paste). I don’t know about the library inclusion. How did you add it in the first place? When I select the library from the list of libraries, and click the “Include In App” button, I get the include statement I mentioned in my last post.

so heres my code now, i removed the libraries and included again:

// This #include statement was automatically added by the Particle IDE.
#include "blynk/blynk.h"

char auth[] = "blabla";
    
const int relay1 = A0;
const int sensor1 = A1;
    
    
void setup()
{
  Serial.begin(9600);
  delay(1000);
  Blynk.begin(auth);
  pinMode(relay1, OUTPUT);  
  pinMode(sensor1, INPUT);
  Particle.function("luz1", luz_state);
}
    
void loop()
{
  Blynk.run();
        
  static boolean lastSensorHit = false;
  static boolean relayValue = LOW;
    
  int sensorValue = map(analogRead(sensor1), 0, 4095, 0 , 200);
  bool sensorHit = sensorValue > 0 && sensorValue <200;
    
  if (sensorHit && !lastSensorHit) 
  {
     relayValue = !relayValue; 
     digitalWrite(relay1, relayValue);
  } 
  lastSensorHit = sensorHit;
}
    
{ // <-- this is wrong
int luz_state(String command) 
{
  if (command=="on") 
  {
    digitalWrite(relay1,HIGH);
    return 1;
  }
  else if (command=="off") 
  {
    digitalWrite(relay1,LOW);
    return 0;
  }
  else 
  {
    return -1;
  }
}
} // <-- this is wrong too

and heres the errors:

    In file included from blynk/BlynkParticle.h:16:0,
                     from blynk/BlynkSimpleParticle.h:14,
                     from blynk/blynk.h:2,
                     from 01_particle.cpp:2:
    blynk/BlynkApiParticle.h:78:6: warning: #warning "analogInputToDigitalPin not defined => Named analog pins will not work" [-Wcpp]
         #warning "analogInputToDigitalPin not defined => Named analog pins will not work"
          ^
    01_particle.cpp:44:1: error: expected unqualified-id before '{' token
        digitalWrite(relay1, relayValue);
     ^
    
    make[1]: *** [../build/target/user/platform-601_particle.o] Error 1
    make: *** [user] Error 2

You have an extra “{”, just above the “int luz_state(String command) {” line. Remove that, and it should work.

And an extra } at the end.

You should try to get your indentation sorted, this makes it easier to see such mistakes.

I have edited your post to properly format code and text blocks (and reworked your indentation for clarity).

For future reference do it this way

 ```cpp
 // enclose your code-blocks with a set of these
and any arbitrary text-block like error output or logs with this
1 Like

oh im sorry, will do from now on!

ok it compiles, i think its good. now im on tasker making an http post but it does nothing, no errors but it doesn’t triggers the relay…

14.06.33/E prot: http:// serverport: https:/api.particle.io contenttype: application/x-www-form-urlencoded
14.06.33/E get/head or null
14.06.33/E method: POST url: http://https:/api.particle.io/v1/devices/devicecode/luz1?acess_token=acesstoken timout: 10000 dataisfile false save null
14.06.33/WakeLockManager setClearAlarm: not setting, last set 10ms ago
14.06.33/WakeLockManager setClearAlarm: not setting, last set 11ms ago
14.06.33/E body isfile: false cont: params=A0%2C+HIGH
14.06.33/E set content-length: 17
14.06.33/E write postBody string
14.06.33/E Unknown Host in http://https:/api.particle.io/v1/devices/devicecode/luz1?acess_token=acesscode

server port:
https://api.particle.io

path:
/v1/devices/DEVICECODE/luz1?acess_token=MYACESSTOKEN

did you also fill out the “data” in tasker? should be something like args=on or args=off in your case.

also your error text contains your device id and accesstoken - i would remove that.

In my tasker tasks i set the timeout to 1 and select trust any certificate and continue task on error (not sure why i did that though nor if it worked without those settings)

edited, thank you. well i had a0=high but even with args=on it doesn’t do nothing, but i got it to work with ifttt but theres a little delay…

edit:

is luz1 correct? or should it be luz_state? http://https:/api.particle.io/v1/devices/devicecode/luz1?acess_token=acesstoken

I’d say the access_token has to be passed the same way as args=on and not URL encoded.

see docs

curl https://api.particle.io/v1/devices/0123456789abcdef/brew -d access_token=123412341234 -d "args=coffee"

(brew equals your luz1, coffee equals your on or off, and …)

BTW: It’s luz1 as this is the name you chose for exposing your local function luz_state().