Hi guys mabe you can help me. My goal is to take the blynk example firmware wich is working fine with my particle core and just add 2 functions available to be call by ifttt one of em turn the relays on and the other turn them off. For doing this i wanted to mix the original blynk code with the relayshield code but i am having an error when verifying the code.
This is the code i ve modified:
// This #include statement was automatically added by the Particle IDE.
#include "RelayShield.h"
/**************************************************************
* 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.
*
* WARNING: It is recommended to use SparkCorePolledTimer library
* to make periodic actions (similar to SimpleTimer on Arduino).
*
**************************************************************/
//#define BLYNK_DEBUG // Uncomment this to see debug prints
#define BLYNK_PRINT Serial
#include "blynk/blynk.h"
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "28c37a37028140ac99847dc3ce851925";
// Create an instance of the RelayShield library, so we have something to talk to
RelayShield myRelays;
// Create prototypes of the Spark.functions we'll declare in setup()
int relayOn(String command);
int relayOff(String command);
// Attach a Button widget (mode: Switch) to the Digital pin 7 - and control the built-in blue led.
// Attach a Graph widget to Analog pin 1
// Attach a Gauge widget to Analog pin 2
// No coding required for direct pin operations!
void setup()
{
Serial.begin(9600);
delay(5000); // Allow board to settle
Blynk.begin(auth);
//.begin() sets up a couple of things and is necessary to use the rest of the functions
myRelays.begin(2);
// Use myRelays.begin(2); if you have the square, white RelayShield (from the Core)
// to use, just add a '2' between the parentheses in the code above.
// Register Spark.functions and assign them names
Particle.function("relayOn", relayOn);
Particle.function("relayOff", relayOff);
}
// Attach a Button widget (mode: Push) to the Virtual pin 1 - and send sweet tweets!
BLYNK_WRITE(V1) {
if (param.asInt() == 1) { // On button down...
// Tweeting!
// Note:
// We allow 1 tweet per minute for now.
// Twitter doesn't allow identical subsequent messages.
Blynk.tweet("My Particle project is tweeting using @blynk_app and it’s awesome!\n @Particle #IoT #blynk");
// Pushing notification to the app!
// Note:
// We allow 1 notification per minute for now.
Blynk.notify("You pressed the button and I know it ;)");
}
}
// Attach a ZeRGBa widget (mode: Merge) to the Virtual pin 2 - and control the built-in RGB led!
BLYNK_WRITE(V2) {
int r = param[0].asInt();
int g = param[1].asInt();
int b = param[2].asInt();
if (r > 0 && g > 0 && b > 0) {
RGB.control(true);
RGB.color(r, g, b);
} else {
RGB.control(false);
}
}
void loop()
{
Blynk.run();
if (ModeBtnPressed()) {
Blynk.notify("Mode button was pressed");
}
}
// *** Utility functions
bool ModeBtnPressed() {
if(millis() > 5000) {
if(BUTTON_GetDebouncedTime(BUTTON1) >= 50) {
BUTTON_ResetDebouncedState(BUTTON1);
return 1;
}
}
return 0;
}
int relayOn(String command){
// Ritual incantation to convert String into Int
char inputStr[64];
command.toCharArray(inputStr,64);
int i = atoi(inputStr);
// Turn the desired relay on
myRelays.on(i);
// Respond
return 1;
}
int relayOff(String command){
// Ritual incantation to convert String into Int
char inputStr[64];
command.toCharArray(inputStr,64);
int i = atoi(inputStr);
// Turn the desired relay off
myRelays.off(i);
// Respond
return 1;
}
and this is the error shown:
01_particle.cpp: In function 'int relayOn(String)':
01_particle.cpp:119:5: error: 'myRelays' was not declared in this scope
// Ritual incantation to convert String into Int
^
01_particle.cpp: In function 'int relayOff(String)':
01_particle.cpp:132:5: error: 'myRelays' was not declared in this scope
// Ritual incantation to convert String into Int
^
make[2]: *** [../build/target/user/platform-0-l01_particle.o] Error 1
make[1]: *** [user] Error 2
make: *** [main] Error 2
Error: Could not compile. Please review your code.
I see that the compiler is telling me that my functions are not declared but i thought that declaring them on the main code that would be enough. So how can i fix this?
Thanks folks for any advice.
Javier