Things used in this project

Schematics

Architecture
High level architecture
Screen shot 2016 12 24 at 12 27 08 am adcpjhby83 k3kpmwldh8

Code

hook.io codeJavaScript
This is the hook used to trigger from API.io
module['exports'] = function coffeenator (hook) {
  var myResponse;
  var Particle = require('particle-api-js');
var particle = new Particle();
  
  function output(data) {
    hook.res.end(JSON.stringify(data, true, 2));
  }
  
  var token = 'PUT YOUR TOKEN HERE';


  
  
  
   console.log(hook.params.result.parameters.action + " coffee request recieved");
  
  
  if(hook.params.result.parameters.action=="warm")
  {
	warmCoffeeMachine();
   
  
  var fnPr = particle.callFunction({ deviceId: 'PUT YOUR DEVICE ID HERE', name: 'warmmachine', argument: 'D0:HIGH', auth: token });;
  
    fnPr.then(
      function(data) {
        console.log("success called warmcoffee succesfuly");
 //      output('Function called succesfully:', data);
        myResponse =new MyResponse("Warming coffee machine for you","Coffee Machine Being Warmed","Coffee Machine");
   	   hook.res.writeHead(200, {"Content-Type": "application/json"});
  
  		hook.res.end(JSON.stringify(myResponse, true, 2));
        
      }, function(err) {
        output('An error occurred:', err);
      });
    
    myResponse =new MyResponse("Warming coffee machine for you","Coffee Machine Being Warmed","Coffee Machine");
    
    
  }else if (hook.params.result.parameters.action=="make")
  {
    makeCoffeeMachine();
    
    var fnPr = particle.callFunction({ deviceId: 'PUT YOUR DEVICE ID HERE', name: 'makecoffee', argument: 'D0:HIGH', auth: token });;
  
    fnPr.then(
      function(data) {
                console.log("success called make coffee succesfuly");
     //  output('Function called succesfully:', data);
        myResponse =new MyResponse("Making coffee  for you","Coffee Being made ","Coffee Machine");
          hook.res.writeHead(200, {"Content-Type": "application/json"});
  
  			hook.res.end(JSON.stringify(myResponse, true, 2));
 
      }, function(err) {
        output('An error occurred:', err);
      });
    
        myResponse =new MyResponse("Making coffee  for you","Coffee Being made ","Coffee Machine");
        
 
  }
   
	console.log("****************end end end end end end ");
  

  
  function MyResponse(aSpeech,aDisplaytext,aSource){
    this.speech = aSpeech;
    this.displayText= aDisplaytext;
   
    this.source=aSource;
    
  }
  

};

function warmCoffeeMachine()
{
  
  console.log("machine is warming");
    
}
function makeCoffeeMachine()
{
  console.log("machine is making");
}
FirmwareArduino
This firm ware receives commands such as warm or make coffee and moves the servo
int servoPin = D0;
Servo myServo;
int servoPos = 0;

int servoOn = D7;


void setup() {

pinMode(servoOn, OUTPUT);

myServo.attach( servoPin );

     Particle.function("press", press);
     Particle.function("servo", servoControl);
     Particle.function("makecoffee", makecoffee);
     
     Particle.function("warmmachine", warmmachine);
     
     
     digitalWrite(servoOn, LOW);

}

void loop() {

//   myServo.write( 100 );
//   delay(2000);
//   myServo.write( 120 );
//   delay(3500);
}


int servoControl(String command)
{
    
    
     digitalWrite(servoOn, HIGH);

    // Convert
   int newPos = command.toInt();
   // Make sure it is in the right range
   // And set the position
   servoPos = constrain( newPos, 0 , 180);

   // Set the servo
   myServo.write( servoPos );


 digitalWrite(servoOn, LOW);
   // done
   return 1;
}

int press(String command) {
 digitalWrite(servoOn, HIGH);
  myServo.write( 130 );
  delay(2000);
  myServo.write( 150 );
  delay(1500);
  myServo.write( 125 );
   delay(1000);
 digitalWrite(servoOn, LOW);
   return 1;
}


int  makecoffee(String command) {


     digitalWrite(servoOn, HIGH);

  myServo.write( 125 );
  delay(2000);
  myServo.write( 150 );
  delay(1500);
  myServo.write( 125 );
  
  delay(3000);
  
   myServo.write( 125 );
  delay(2000);
  myServo.write( 150 );
  delay(1500);
  myServo.write( 125 );
  delay(1000);
 digitalWrite(servoOn, LOW);
  
   return 1;
}


int  warmmachine(String command) {
    
     digitalWrite(servoOn, HIGH);

  myServo.write( 125 );
  delay(2000);
  myServo.write( 150 );
  delay(1500);
  myServo.write( 125 );
  
  delay(1000);
 digitalWrite(servoOn, LOW);
  
   return 1;
}

Credits

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Blynk GPS Tracker
Intermediate
  • 41
  • 2

Full instructions

Simple GPS tracker using a Particle Photon (or Electron) and an EM406 GPS module with location visible on Blynk app map.

Pool Buddy
Intermediate
  • 1,619
  • 11

Work in progress

Monitor and log water quality (pH & ORP) and temperature from everywhere.

IoT Thermometer Using Python
Intermediate
  • 986
  • 8

Full instructions

How to develop a simple but powerful IoT thermometer using a Zerynth-powered single-board MCU and the Zerynth App.

Particle Photon Flip Dot Clock
Intermediate
  • 2,162
  • 31

Full instructions

The flip dot display uses an electromechanical dot matrix that spin from black to yellow to display text, numbers and more!

Patriot iOS App
Intermediate
  • 547
  • 9

Use an old iPhone device to control and display the status of your Patriot IoT devices.

Patriot iOS App

Team Patriot

What To Wear LCD
Intermediate
  • 48
  • 1

Ever wondered what to wear due to unpredictable weather??? Wonder no longer!

Add projectSign up / Login