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.
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
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.
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
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
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
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)