tinha um código simples pra monitorar meu alarme via web,o mesmo foi feito em sima do
código exemplo webserver, só que agora preciso,alem de monitorar controlar o acionamento
via web, já tentei de varias formas o jeito que deu certo foi com php e serial,mas nao e o ideal
para min uma vez que quero que o Arduíno seja o único responsável pelo monitoramento e
acionamento do alarme,segue abaixo o código,por favor me dei uma força entendo pouco de
programação mas tenho força de vontade.
-----------------------------------------------------------------------------------
include <SPI.h>
#include <Ethernet.h>
byte alarme = 0;
byte disparo = 0;
byte bateria = 0;
int n;
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,0, 177);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(8085);
char msg[3] = "0#";
void setup()
{
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.begin(9600);
pinMode(2,INPUT);
pinMode(3,INPUT);
pinMode(5,INPUT);
digitalWrite(2,1);
digitalWrite(3,1);
digitalWrite(5,1);
}
void loop()
{
// if (Serial.available()>0)
// {
// n = Serial.read();
// switch(n)
// {
/// case '1': // Ligar
// digitalWrite(A0,HIGH);
// break;
// case '2': // Desliga
/// digitalWrite(A0,LOW);
// break;
//}
// }
EthernetClient client = server.available();
// SE receber um caracter..
if (client) {
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
// output the value of each analog input pin
alarme = digitalRead(2);
if(alarme == 1){
client.println("<button style=\"height: 24px; width:80px; background-color: #FF0000 ;font: bold 14px Arial\" type = \"Submit\" Name = \"led1\">desarmado</button></br></br></br>");
}else{
client.println("<button style=\"height: 24px; width:80px; background-color: #00FF00 ;font: bold 14px Arial\" type = \"Submit\" Name = \"led1\">Armado</button></br></br></br>");
}
disparo = digitalRead(3);
if(disparo == 1){
client.println("<button style=\"height: 24px; width:75; background-color: #FF0000 ;font: bold 14px Arial\" type = \"Submit\" Name = \"led1\">disparado</button>");
Serial.println("normal");
}else{
client.println("<button style=\"height: 24px; width:75; background-color: #00FF00 ;font: bold 14px Arial\" type = \"Submit\" Name = \"led1\">normal</button>");
Serial.println("disparado");
}
bateria = digitalRead(5);
if(bateria == 1){
client.println("<button style=\"height: 24px; width:75; background-color: #FF0000 ;font: bold 14px Arial\" type = \"Submit\" Name = \"led1\">mod.dc</button>");
}else{
client.println("<button style=\"height: 24px; width:75; background-color: #00FF00 ;font: bold 14px Arial\" type = \"Submit\" Name = \"led1\">mod.ac</button>");
}
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
}
}
-----------------------------------------------------------------------------------------------------------------------------
qualquer ajuda e bem vinda!!!
Tags:
Bem-vindo a
Laboratorio de Garagem (arduino, eletrônica, robotica, hacking)
© 2024 Criado por Marcelo Rodrigues. Ativado por