Initial Code
// Demo to control motor using transistor
int motorPin1 = D1;
int motorPin2 = D2;
unsigned long timePassed;
unsigned long getTime;
unsigned int sample = 3000; //time in ms for desired duration
String weatherIcon = "";
double temperature = 0;
double precipProbability = 0;
double precipIntensity = 0;
void setup(){
Particle.subscribe("hook-response/forecast", handleForecastReceived, MY_DEVICES);
getData();
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
// test motors to make sure that they are working
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
delay(2000);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
delay(2000);
digitalWrite(motorPin2, LOW);
}
void loop(){
//getTime = millis();
//if (getTime - millis() == sample){
getData();
delay(5000);
if (weatherIcon == "rain"){
digitalWrite(motorPin1, HIGH);
delay(2000);
digitalWrite(motorPin1, LOW);
}else if(weatherIcon != "rain"){
digitalWrite(motorPin2, HIGH);
delay(2000);
digitalWrite(motorPin2, LOW);
}
//}
}
void getData()
{
// Publish an event to trigger the webhook
Particle.publish("forecast", "19.0896,72.8656", PRIVATE);
}
void handleForecastReceived(const char *event, const char *data) {
// Handle the integration response
String receivedStr = String( data );
int loc1 = 0;
int loc2 = 0;
int loc3 = 0;
int loc4 = 0;
loc1 = receivedStr.indexOf("~");
weatherIcon = receivedStr.substring(0,loc1);
loc2 = receivedStr.indexOf("~",loc1+1);
temperature = (double) String(receivedStr.substring(loc1+1,loc2)).toFloat();
loc3 = receivedStr.indexOf("~",loc2+1);
precipProbability = (double) String(receivedStr.substring(loc2+1,loc3)).toFloat();
loc4 = receivedStr.indexOf("~",loc3+1);
precipIntensity = (double) String(receivedStr.indexOf(loc3+1)).toFloat();
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .