#define publish_cycle 30000
unsigned int lastPublish = 0;
int led = D7;
double reading = 0.0;
double mvolts = 0.0;
double tempC = 0.0;
double tempF = 0.0;
boolean flag = false;
double readingl=0.0;
void setup() {
pinMode(led,OUTPUT);
Particle.keepAlive(120);
Particle.function("led", ledStatus);
}
void loop() {
unsigned long now = millis();
reading = analogRead(A0);
mvolts = (reading * 3300.0)/4095.0;
mvolts = mvolts -500.0;
tempC = mvolts/10.0;
tempF = (tempC*1.8) + 32.0;
readingl = analogRead(A1);
//to IFTTT
if ( tempC > 26.0 && flag == false){
Particle.publish("toohot");
flag = true;
}
if (tempC < 24.0 && flag == true){
Particle.publish("tempnormal");
flag = false;
}
if ((now - lastPublish) > publish_cycle) {
//to LOSANT
Particle.publish("temp-reading", String(tempC), PRIVATE) ;
Particle.publish("light-intensity",String(readingl), PRIVATE) ;
delay(500);
//to ThingSpeak
Particle.publish("temperature", "{ \"1\": \"" + String(tempC) + "\"," + "\"2\": \"" + String(readingl) + "\"}", PRIVATE);
lastPublish = now;
}
}
int ledStatus(String command){
if(command.equalsIgnoreCase("on")){
digitalWrite(led,HIGH);
return 1;
}
else if (command.equalsIgnoreCase("off")){
digitalWrite(led,LOW);
return 0;
}
else{
return -1;
}
}