For a school project, I’m connecting my spark core to a Senseo coffee machine using a relay switch and temperature sensor. The Particle sends a command to the coffee maker to turn on the device and waits a while for the coffee maker to warm up. If the coffee maker is hot enough, it will send a command to pour the coffee out of the machine.
The problem I am facing is that when I run the function, it will give a time out after 30 seconds. I still want the Particle core to send something back when your coffee is ready. How can I do this?
// This #include statement was automatically added by the Spark IDE.
#include "elapsedMillis/elapsedMillis.h"
// This #include statement was automatically added by the Spark IDE.
#include "spark-dallas-temperature/spark-dallas-temperature.h"
// This #include statement was automatically added by the Spark IDE.
#include "OneWire/OneWire.h"
//#define DHTPIN D2 // Digital pin D2
//#define DHTTYPE DHT11
#define ONE_WIRE_BUS D2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensor(&oneWire);
elapsedMillis timeElapsed;
unsigned int interval = 90000; // timer na een minuut en een half
int OnOff = D6; // IN4 en bruin // on and off trigger for the Senseo
int eencup = D5; //IN1 en blauw // 1 cup trigger for the Senseo
int tweecup = D4; // 2 cup trigger for the Senseo
//float h; // humidity
float t; // temperature
char h1[10]; // humidity string
char t1[10]; // temperature string
int f = 0; // failed?
double brewTemp = 30;
double cofTemp = 0;
int tempTemp =0;
void setup() {
pinMode(OnOff, OUTPUT); // set the D7 LED as output
pinMode(eencup, OUTPUT);
pinMode(tweecup, OUTPUT);
Spark.variable("humidity", &h1, STRING); // for checking the sensor values manually without the function makeCoffee.
Spark.variable("temperature", &t1, STRING); // for checking the sensor values manually without the function makeCoffee.
Spark.variable("status", &f, INT); // for checking the status manually without the unction makeCoffee.
sensor.begin(); // for starting the function that says what pin should be used for measuring the temp.
Spark.function("coffee", makeCoffee); // a POST request for "blink" will reference blinkfunc, defined below
// Spark.function("readtemp", readTemp);
}
// call the below function when the POST request matches it
int makeCoffee(String command)
{
return 1;
// turn the coffee maker on
// the coffee maker signal only has to be triggered once, then the trigger can be turn off.
digitalWrite(OnOff, LOW);
delay(500);
digitalWrite(OnOff, HIGH);
// delay(40000); //wait a minute for the senseo to start up.
sensor.requestTemperatures();
cofTemp = sensor.getTempCByIndex( 0 ); // reads the Temperature of the tempsensor.
while (cofTemp < brewTemp)
{
sensor.requestTemperatures();
cofTemp = sensor.getTempCByIndex( 0 ); // reads the Temperature of the tempsensor.
if( cofTemp > brewTemp)
{
if (command =="1cups")
{
digitalWrite(eencup, LOW);
delay(500);
digitalWrite(eencup,HIGH);
delay(30000);
digitalWrite(OnOff, LOW);
delay(500);
digitalWrite(OnOff, HIGH);
timeElapsed = 0;
return 1;
}
else if (command=="2cups")
{
digitalWrite(tweecup, LOW);
delay(500);
digitalWrite(tweecup,HIGH);
delay(30000);
digitalWrite(OnOff, LOW);
delay(500);
digitalWrite(OnOff, HIGH);
timeElapsed = 0;
return 1;
}
else
{
timeElapsed = 0;
return -1;
}
}
if (timeElapsed > interval)
{
digitalWrite(OnOff, LOW);
delay(500);
digitalWrite(OnOff, HIGH);
timeElapsed = 0;
return -1;
}
delay(1000);
}
}
void loop()
{
digitalWrite(OnOff, HIGH);
digitalWrite(eencup, HIGH);
digitalWrite(tweecup, HIGH);
sensor.requestTemperatures();
cofTemp=sensor.getTempCByIndex( 0 );
sprintf(t1, "%2.2f",cofTemp);
delay(1000);
// }
}