Notes
Notes - notes.io |
#include <Ethernet.h>
#include <EthernetClient.h>
#include <DHT.h>
#include <LiquidCrystal.h>
#include <SPI.h>
#define DHTPIN 7
#define DHTTYPE DHT22
#define time 2000
LiquidCrystal lcd(9, 8, 5, 4, 3, 2);
DHT dht(DHTPIN, DHTTYPE);
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 3, 5);
IPAddress dns(192, 168, 0, 2);
IPAddress gateway(192, 168, 0, 254);
IPAddress subnet(255, 255, 240, 0);
byte server[] = { 200, 147, 99, 132 };
float t;
float h;
bool rodouUma = false;
EthernetClient client;
EthernetServer webserver(80);
byte grau[8] ={ B00001100,
B00010010,
B00010010,
B00001100,
B00000000,
B00000000,
B00000000,
B00000000,};
void setup()
{
lcd.begin(16, 2);
lcd.clear();
lcd.createChar(0, grau);
lcd.setCursor(0,0);
lcd.print("Temp: ");
lcd.setCursor(13,0);
lcd.write(byte(0));
lcd.print("C");
lcd.setCursor(0,1);
lcd.print("Umid: ");
lcd.setCursor(14,1);
lcd.print("%");
Serial.begin(9600);
Serial.println("Aguardando dados...");
dht.begin();
Ethernet.begin(mac, ip, dns, gateway, subnet);
webserver.begin();
Serial.print("O endereço da página é: ");
Serial.println(Ethernet.localIP());
}
void loop()
{
EthernetClient client = webserver.available();
if (client) {
Serial.println("Nova pagina");
bool linhaEmBranco = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
if (c == 'n' && linhaEmBranco) {
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println("Refresh: 5");
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
for (int analogChannel = 0; analogChannel < 1; analogChannel++) {
int sensorReading = analogRead(analogChannel);
client.print("<h1>");
client.print("<center>");
client.print("TEMPERATURA: ");
client.print(t);
client.println("<br>");
client.print("UMIDADE: ");
client.print(h);
client.print("<center/>");
client.print("<h1/>");
client.println("<br />");
client.println("<br />");
}
client.println("</html>");
break;
}
if (c == 'n') {
linhaEmBranco = true;
} else if (c != 'r') {
linhaEmBranco = false;
}
}
}
delay(1);
client.stop();
Serial.println("client disconnected");
}
delay(2000);
h = dht.readHumidity();
t = dht.readTemperature();
if (isnan(h) || isnan(t))
{
Serial.println("Falha ao ler dados do sensor DHT !!!");
return;
}
Serial.print("Temperatura: ");
Serial.print(t);
lcd.setCursor(8,0);
lcd.print(t);
Serial.print(" *C ");
Serial.print("Umidade : ");
Serial.print(h);
Serial.println(" %");
lcd.setCursor(8,1);
lcd.print(h);
if(t >= 25 && rodouUma == false){
rodouUma = true;
envia();
}
if (t < 25 && rodouUma == true){
rodouUma = false;
enviaNormal();
}
}
void envia(){
delay(time);
Serial.println("conectando...");
if (client.connect(server, 587)){
Serial.println("conectado!");
Serial.println("enviando email...");
Serial.println();
client.println("HELO localhost");
recebe();
delay(time);
client.println("AUTH LOGIN");
recebe();
delay(time);
client.println("cXVpbXRpYS5icmFzaWxAYm9sLmNvbS5icg==");
recebe();
delay(time);
client.println("cTFiMmYzKio=");
recebe();
delay(time);
client.println("mail from: <[email protected]>");
recebe();
delay(time);
client.println("rcpt to: <[email protected]>");
recebe();
delay(time);
client.println("data");
recebe();
delay(time);
client.println("Subject: Alta temperatura no datacenter!");
recebe();
delay(time);
client.println("Atenção!!!n");
client.println("A temperatura do datacenter em graus celsius é: ");
client.println(t);
recebe();
delay(time);
client.println(".");
recebe();
delay(time);
client.println();
recebe();
delay(time);
Serial.println("email enviado!");
delay(time);
if (client.connected()){
Serial.println();
Serial.println("desconectando...");
client.stop();
Serial.println();
Serial.println();
}
}
else{
Serial.println("connection failed");
}
}
void enviaNormal(){
delay(time);
Serial.println("conectando...");
if (client.connect(server, 587)){
Serial.println("conectado!");
Serial.println("enviando email...");
Serial.println();
client.println("HELO localhost");
recebe();
delay(time);
client.println("AUTH LOGIN");
recebe();
delay(time);
client.println("cXVpbXRpYS5icmFzaWxAYm9sLmNvbS5icg==");
recebe();
delay(time);
client.println("cTFiMmYzKio=");
recebe();
delay(time);
client.println("mail from: <[email protected]>");
recebe();
delay(time);
client.println("rcpt to: <[email protected]>");
recebe();
delay(time);
client.println("data");
recebe();
delay(time);
client.println("Subject: Temperatura normalizada no datacenter!");
recebe();
delay(time);
client.println("Atenção!!!n");
client.println("A temperatura do datacenter em graus celsius é: ");
client.println(t);
recebe();
delay(time);
client.println(".");
recebe();
delay(time);
client.println();
recebe();
delay(time);
Serial.println("email enviado!");
delay(time);
if (client.connected()){
Serial.println();
Serial.println("desconectando...");
client.stop();
Serial.println();
Serial.println();
}
}
else{
Serial.println("connection failed");
}
}
void recebe(){
while (client.available()){
char conteudo = client.read();
Serial.print(conteudo);
}
}
|
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team