R.A.C.O.

Remote Alarma Control with Options

 

 












 

Desarrollo del Código

 

Inicialmente, se establecen los parámetros de Temboo, los cuales van asociados a la cuenta personal. En base a estos parámetros, Nexmo genera un identificador único para el código, de manera de poder realizar llamada telefónica.

 

 



Posterior a eso, se genera el header de Temboo con la Información de la cuenta:

 

Es importante destacar la necesidad de inicialización de Bridge y Console en la etapa de Setup, ya que de lo contrario no se estableceran los vinculos con Linino


Código de Programa:
#include <Bridge.h>
#include <Temboo.h>
#include <Servo.h>
#include <Console.h>
#include "TembooAccount.h"

Servo myservo;

const int mag_sensor = 4;
const int light_control = 6;

int maxCalls = 10;

int calls = 0;

void setup() {

Bridge.begin();

// Initialize pins
pinMode(mag_sensor, INPUT);
pinMode(light_control, OUTPUT);
myservo.attach(9);

myservo.write(90); //unlock door
digitalWrite(light_control,LOW);

Console.begin();

delay(100);
while (!Console){
; // wait for Console port to connect.
}
Console.println("You're connected to the Console!!!!");



Console.println("Setup complete.\n");
}

void loop() {
int sensorValue = digitalRead(mag_sensor);

Console.println("Sensor: " + String(sensorValue));

if (sensorValue == HIGH) {

digitalWrite(light_control,HIGH);
myservo.write(0); //unlock door

if (calls < maxCalls) {
Console.println("\nTriggered! Calling /Library/Nexmo/Voice/CaptureTextToSpeechPrompt...");

String choice = makeNexmoCall();
if (choice == "1") {
digitalWrite(light_control,LOW);
}
if (choice == "2") {
myservo.write(90); //unlock door
}
if (choice == "3") {
myservo.write(0); //close up
digitalWrite(light_control,HIGH);
}
calls++;
} else {
Console.println("\nInvalid Choice, try another action.\n");
}
}
delay(250);
}

String makeNexmoCall() {
String choice = "";
TembooChoreo CaptureTextToSpeechPromptChoreo;

// Invoke the Temboo client
CaptureTextToSpeechPromptChoreo.begin();

// Set Temboo account credentials
CaptureTextToSpeechPromptChoreo.setAccountName(TEMBOO_ACCOUNT);
CaptureTextToSpeechPromptChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
CaptureTextToSpeechPromptChoreo.setAppKey(TEMBOO_APP_KEY);

// Set profile to use for execution
CaptureTextToSpeechPromptChoreo.setProfile("ProjectELO330");

// Set Choreo inputs
String MaxDigitsValue = "1";
CaptureTextToSpeechPromptChoreo.addInput("MaxDigits", MaxDigitsValue);
String ByeTextValue = "Ok, your wish is my command. Goodbye!";
CaptureTextToSpeechPromptChoreo.addInput("ByeText", ByeTextValue);

// Set Choreo output filters
CaptureTextToSpeechPromptChoreo.addOutputFilter("choice", "/digits", "CallbackData");

// Identify the Choreo to run
CaptureTextToSpeechPromptChoreo.setChoreo("/Library/Nexmo/Voice/CaptureTextToSpeechPrompt");

// Run the Choreo
unsigned int returnCode = CaptureTextToSpeechPromptChoreo.run();

// A return code of zero means everything worked
if (returnCode == 0) {
Console.println("Done!\n");
} else {
// A non-zero return code means there was an error
// Read and print the error message
while (CaptureTextToSpeechPromptChoreo.available()) {
char c = CaptureTextToSpeechPromptChoreo.read();
Console.print(c);
}
Console.println();
}

// Parse the results
while(CaptureTextToSpeechPromptChoreo.available()) {
// Read the name of the next output item
String name = CaptureTextToSpeechPromptChoreo.readStringUntil('\x1F');
name.trim(); // Use "trim" to get rid of newlines

// Read the value of the next output item
String data = CaptureTextToSpeechPromptChoreo.readStringUntil('\x1E');
data.trim(); // Use "trim" to get rid of newlines

// Parse the user's choice out of the response data
if (name == "choice") {
choice = data;
}
}

CaptureTextToSpeechPromptChoreo.close();

// Return the choice that the user made
return choice;
}