mirror of
https://github.com/timberjoegithub/SmartThingsPublic.git
synced 2026-07-21 23:52:03 +00:00
Create cloudcontrol.ino
This commit is contained in:
@@ -0,0 +1,73 @@
|
|||||||
|
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "NCD8Relay.h"
|
||||||
|
#include "spark_wiring_print.h"
|
||||||
|
|
||||||
|
SYSTEM_MODE(AUTOMATIC);
|
||||||
|
NCD8Relay relayController;
|
||||||
|
int triggerRelay(String command);
|
||||||
|
|
||||||
|
/* This function is called once at start up ----------------------------------*/
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
Serial.begin(115200);
|
||||||
|
relayController.setAddress(0,0,0);
|
||||||
|
Spark.function("controlRelay", triggerRelay);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* This function loops forever --------------------------------------------*/
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int triggerRelay(String command){
|
||||||
|
if(command.equalsIgnoreCase("turnonallrelays")){
|
||||||
|
relayController.turnOnAllRelays();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if(command.equalsIgnoreCase("turnoffallrelays")){
|
||||||
|
relayController.turnOffAllRelays();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if(command.startsWith("setBankStatus:")){
|
||||||
|
int status = command.substring(14).toInt();
|
||||||
|
if(status < 0 || status > 255){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
Serial.print("Setting bank status to: ");
|
||||||
|
Serial.println(status);
|
||||||
|
relayController.setBankStatus(status);
|
||||||
|
Serial.println("done");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
//Relay Specific Command
|
||||||
|
int relayNumber = command.substring(0,1).toInt();
|
||||||
|
Serial.print("relayNumber: ");
|
||||||
|
Serial.println(relayNumber);
|
||||||
|
String relayCommand = command.substring(1);
|
||||||
|
Serial.print("relayCommand:");
|
||||||
|
Serial.print(relayCommand);
|
||||||
|
Serial.println(".");
|
||||||
|
if(relayCommand.equalsIgnoreCase("on")){
|
||||||
|
Serial.println("Turning on relay");
|
||||||
|
relayController.turnOnRelay(relayNumber);
|
||||||
|
Serial.println("returning");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if(relayCommand.equalsIgnoreCase("off")){
|
||||||
|
relayController.turnOffRelay(relayNumber);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if(relayCommand.equalsIgnoreCase("toggle")){
|
||||||
|
relayController.toggleRelay(relayNumber);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if(relayCommand.equalsIgnoreCase("momentary")){
|
||||||
|
relayController.turnOnRelay(relayNumber);
|
||||||
|
delay(300);
|
||||||
|
relayController.turnOffRelay(relayNumber);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user