How do I access the Particle from the internet? I have used an Arduino Yun and it ran its own web server so connecting to it was trivial. Do I have to run my own web server?
relay1.ino: In function 'void setup()':
relay1.ino:8:12: error: 'RELAY1' was not declared in this scope
relay1.ino:9:12: error: 'RELAY2' was not declared in this scope
relay1.ino:10:12: error: 'RELAY3' was not declared in this scope
relay1.ino:11:12: error: 'RELAY4' was not declared in this scope
relay1.ino: In function 'int relayControl(String)':
relay1.ino:43:11: error: expected '}' at end of input
../build/module.mk:267: recipe for target '../build/target/user/platform-6-msrc/relay1.o' failed
make: *** [../build/target/user/platform-6-msrc/relay1.o] Error 1
make: Leaving directory '/firmware/user'
../../../build/recurse.mk:11: recipe for target 'user' failed
make: *** [user] Error 2`
make: Leaving directory '/firmware/modules/photon/user-part'
../build/recurse.mk:11: recipe for target 'modules/photon/user-part' failed
make: *** [modules/photon/user-part] Error 2
Also the sample code for the reals shield will not compile
// This #include statement was automatically added by the Particle IDE.
//Initilize the relay control pins as output
// Initialize all relays to an OFF state
//register the Particle function
// This loops for ever
// command format r1,HIGH
int relayControl(String command)
int relayState = 0;
// parse the relay number
int relayNumber = command.charAt(1) - '0';
// do a sanity check
if (relayNumber < 1 || relayNumber > 4) return -1;
// find out the state of the relay
if (command.substring(3,7) == "HIGH") relayState = 1;
else if (command.substring(3,6) == "LOW") relayState = 0;
else return -1;
// write to the appropriate relay
In addition to @kennethlimcp’s comment, the error messages are rather clear.
You haven’t declared any of the RELAYx variables in your code, and the #define statements present in the library are probably not visible in your .ino file, but even if they were they are not defined as all capital letters.
The sample code does indeed work fine, you just didn’t cut and paste all of it. Not a big deal. The relays are defined at the top of the sample:
int RELAY1 = D3;
int RELAY2 = D4;
int RELAY3 = D5;
int RELAY4 = D6;
An “exposed function” is something you declare using Particle.function(). It is a way of letting you use the Particle cloud to call a function remotely on your Photon or Electron. A Particle function always takes a String argument and returns and int that generally indicates success or failure of the call, but you can decide what it means.
Here is a link to a tutorial I wrote a long time ago using both functions and variables. Note that Spark.function is now Particle.function and a few other small changes.
You will see that you don’t need your own webserver to use any of this–any modern browser will work. If you do have a webserver, that can let you do more advanced things, but it is not required.