Re: Making a combi project using esp8266 and arduino uno
Posted: Fri Mar 10, 2017 12:26 pm
martinayotte wrote:It is not clear what is your question.
Is it only to add gpio code to turn on relay ?
if yes, is it according to the temperature send to handle_feed() callback ?
Maybe something like this from your AP :Code: Select all// Handling the /feed page from my server
void handle_feed() {
String t = server.arg("temp");
String h = server.arg("hum");
server.send(200, "text/plain", "This is response to client");
setupStMode(t, h);
// new code added here for the relay
long temp = t.toFloat();
if (temp < 20.0)
digitalWrite(2, HIGH); // Turn ON Relay on GPIO2
else
digitalWrite(2, LOW); // Turn OFF Relay on GPIO2
}
You also need to add in setup :Code: Select allpinMode(2, OUTPUT); // Make GPIO2 as an OUTPUT to drive Relay MOSFET
Ok the project is now working but I don't know why? Because when I try the code below using a led it is working as supposed to. When the temperature is below 20 GPIO2 lights up the led and when it is above 20 degrees it turns it off. But what surprises me happens when I connect a relay instead of led. When the temp is below 20 it turns off the relay but when it is above 20 it turns out on, I realized this by chance I just changed the low into high and high into low and it works vice versa. Why this happens like this?
void handle_feed() {
String t = server.arg("temp");
String h = server.arg("hum");
server.send(200, "text/plain", "This is response to client");
setupStMode(t, h);
long temp = t.toFloat();
if (temp < 20.0)
digitalWrite(2, HIGH); // Turn ON Relay on GPIO2
else
digitalWrite(2, LOW); // Turn OFF Relay on GPIO2
}
}