• Welcome to LusoRobótica - Robótica em Português.
 

[Pedido de Ajuda] Arduino EthernetShield Armazenar um pagina html e imagem dentr

Started by r16, 07 de April de 2012, 16:40

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Hugu

Acho que o problema é que o nosso amigo pensa que o problema é um, mas o que o pessoal está a tentar dizer-te é que é outro e nao aquele que pensas ser.. :P

@R16: nao consegues meter já o teu codigo html num servidor gratuito para o pessoal ver o que está feito ou nao no teu html (bem co ficheiro html em txt!)

E ja agora, posta fotos dos equipamentos/hardware que estás a usar! Convem saber que toutch-screen estás a usar e como tens o teu arduino/ethernet shield ligado?

r16

Viva, já consegui resolver o meu problema.
Agora so falta descobrir um ponto... que não consigo resolver e dai peço ajuda.

o codigo que esta a funcionar e este:

#include <Ethernet.h>
#include <SPI.h>
/*
    Simple Ethernet Test

Arduino server outputs simple text to browser

     The circuit:
     * Arduino Duemilanove
* Arduino Ethernet shield
* Basic FTDI breakout 5V
*LED connected to GND and digital pin 4 via resistor

By Minde
     http://www.sciencprog.com/
*/

byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x49, 0xD6 };
byte ip[]    = {192,168,1,70}; // IP address of WiShield
byte gateway[]  = {192,168,1,254}; // router or gateway IP address
byte subnet[] = {255,255,255,0};


Server server(6969);        //server port
int ledPin = 4;  // LED pin
int LEDpin = 7;
String state = String(3);
word Adc = 0;
String readString = String(30); //string for fetching data from address
boolean LEDON = false; //LED status flag



void Pasword();
void Portada();


void setup(){
  //start Ethernet
  Ethernet.begin(mac, ip, gateway, subnet);
  //Set pin 4 to output
  pinMode(LEDpin,OUTPUT);
 
  digitalWrite(LEDpin,LOW);
  state = "OFF";
String state = String(3);
  //enable serial datada print
  Serial.begin(9600);
}


void loop(){
  // Create a client connection
 
  Client client = server.available();
  if (client) {
    while (client.connected()){   
      char c = client.read();
      if (readString.length() < 30){
         readString += c;
      }
      Serial.print(c);
      if (c == '\n') {     
        if(readString.trim() == ("GET /?C=1678 HTTP/1.1")){
          //client.println("<h1>Clave Ok</h1>");
          Portada();
       }else{
          //client.println("<h1>Clave Erronea</h1>");
       }     
   
   
       //client.println("HTTP/1.1 200 OK");
       //client.println("Content-Type: text/html");
       client.println();
       client.print("<body style=background-color:#ffffff>");     

       client.println("<h1>Control de Acceso</h1>");       
       client.println("<form method=get name=LED>");
       client.println("<input type=""password"" name=C>");
     
     
       client.println("<input type=submit value=submit></form>");
     

       //clearing string for next read
       readString="";
       //stopping client
       client.stop();     
    }
  }
}
}



void Portada(){
while(1){
  // Create a client connection
  Client client = server.available();
if (client) {
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply

        if (readString.length() < 30) {
          readString.concat(c);
        }

        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          int LED = readString.indexOf("LED=");

          if (readString.substring(LED,LED+5) == "LED=T") {
            digitalWrite(LEDpin,HIGH);
            state = "ON";
          }
          else if (readString.substring(LED,LED+5) == "LED=F") {
            digitalWrite(LEDpin,LOW);
            state = "OFF";
          }
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          client.println("<form  method=get name=form>");
         
          client.println("<img src='http://dl.dropbox.com/u/6916111/tvoff.png' style=\"position:fixed;left:68px;top:80px;width:636px;height:431px;z-index:1;padding:0;\">");
          if (state == "ON") { 
       //   client.print("TESTE ");       
          client.println("<img src='http://dl.dropbox.com/u/6916111/tvon.png' type='image' style=\"position:fixed;left:254px;top:146px;width:146px;height:93px;z-index:2;padding:0;\">");
          client.println("<a href=\"./?LED=F\" src='http://dl.dropbox.com/u/6916111/off.png' type='image' style=\"position:fixed;left:254px;top:146px;width:146px;height:93px;z-index:2;padding:0;\">");
}

else {
client.println("<img src='http://dl.dropbox.com/u/6916111/off.png' type='image' style=\"position:fixed;left:254px;top:146px;width:146px;height:93px;z-index:2;padding:0;\">");
          client.println("<a href=\"./?LED=T\" src='http://dl.dropbox.com/u/6916111/tvon.png' type='image' style=\"position:fixed;left:254px;top:146px;width:146px;height:93px;z-index:2;padding:0;\">");
}

          //client.print("LED is ");
         // client.print(state);
          client.print("<br><br>");

         
          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);
    readString = "";
    // close the connection:
    client.stop();
     }
      }
}
void Pasword();










o que se esta a passar é:
assim que acedo ao meu shield atraves do browser
ele entra OK , e faz o que tem a fazer que é:

Mostrar um campo onde se coloca a password e depois fazer submit a um botao e prosseguir para a pagina principal.

Ate ai tudo certo.

O que está mal, é se eu fechar o browser e voltar a colocar o ip do meu shield no browser,ele ja nao pede a senha mas sim entra directamente na pagina principal e eu nao quero isso.

Alguem sabe resolver?

Obrigado

senso

Avr fanboy

r16

Ja me disseram isso noutro lado mas sabes porque acho que nao tem muita logica?
Porque se eu te der o site a ti... depois de eu aqui ter aqui tambem ter entrado e ter pedido pass... a ti nao te a vai pedir.


E se eu desligar o arduino e voltar a ligar... ja pede novamente...
Por isso acho que nao tem haver com isso.


Alias testei tambem no telemovel e noutros pc e acontece sempre a mesma coisa.. deve faltar algo ai no codigo.

zedlav

Boas.

Não testei mas só de olhar para o código diria que a variavel "state" uma vez ficando "ON" ficará sempre nesse estado, é por isso que quem se ligar a seguir ao primeiro cliente que meteu a passaword vai ter acesso directo.

r16

Quote from: zedlav on 15 de April de 2012, 17:20
Boas.

Não testei mas só de olhar para o código diria que a variavel "state" uma vez ficando "ON" ficará sempre nesse estado, é por isso que quem se ligar a seguir ao primeiro cliente que meteu a passaword vai ter acesso directo.

zedlav nao porque o proprio codigo mae de onde eu tirei para adaptar ao meu codigo nao tinha esse state e ja acontecia o mesmo...
esse state é para outra coisa que eu sei.


r16

Se quiseres ajudar teria todo o gosto em saber que havia mais um interessado querer me ajudar a acabar o projecto. falta apenas isso

Wolfz

Tirem-me só uma duvida, afinal conseguimos colocar uma pagina html no ethernet shield (SD) e conseguimos visualizala com o arduino?

senso

Avr fanboy


Wolfz

Obrigado. Já peguei no codigo e compilei so para ver se me aparecia algum erro, e aparece-me o mesmo erro e mais alguns que aparece com o código que tem o site que o r16 utiliza.


Quote









sketch_jul01b.cpp:22:19: error: SdFat.h: No such file or directory
sketch_jul01b.cpp:23:23: error: SdFatUtil.h: No such file or directory
sketch_jul01b:41: error: no matching function for call to 'Server::Server(int)'

As of Arduino 1.0, the Server class in the Ethernet library has been renamed to EthernetServer.

C:\Users\João\Documents\arduino-1.0\hardware\arduino\cores\arduino/Server.h:4: note: candidates are: Server::Server()
C:\Users\João\Documents\arduino-1.0\hardware\arduino\cores\arduino/Server.h:4: note:                 Server::Server(const Server&)
sketch_jul01b:41: error: cannot declare variable 'server' to be of abstract type 'Server'
C:\Users\João\Documents\arduino-1.0\hardware\arduino\cores\arduino/Server.h:4: note:   because the following virtual functions are pure within 'Server':
C:\Users\João\Documents\arduino-1.0\hardware\arduino\cores\arduino/Print.h:48: note:    virtual size_t Print::write(uint8_t)
C:\Users\João\Documents\arduino-1.0\hardware\arduino\cores\arduino/Server.h:6: note:    virtual void Server::begin()
sketch_jul01b:44: error: 'Sd2Card' does not name a type
sketch_jul01b:45: error: 'SdVolume' does not name a type
sketch_jul01b:46: error: 'SdFile' does not name a type
sketch_jul01b:47: error: 'SdFile' does not name a type
sketch_jul01b.cpp: In function 'void error_P(const char*)':
sketch_jul01b:50: error: 'PgmPrint' was not declared in this scope
sketch_jul01b:51: error: 'SerialPrintln_P' was not declared in this scope
sketch_jul01b:52: error: 'card' was not declared in this scope
sketch_jul01b.cpp: In function 'void setup()':
sketch_jul01b:72: error: 'PgmPrint' was not declared in this scope
sketch_jul01b:73: error: 'FreeRam' was not declared in this scope
sketch_jul01b:78: error: 'card' was not declared in this scope
sketch_jul01b:78: error: 'SPI_HALF_SPEED' was not declared in this scope
sketch_jul01b:80: error: 'volume' was not declared in this scope
sketch_jul01b:80: error: 'card' was not declared in this scope
sketch_jul01b:83: error: 'volume' was not declared in this scope
sketch_jul01b:86: error: 'root' was not declared in this scope
sketch_jul01b:88: error: 'PgmPrintln' was not declared in this scope
sketch_jul01b:89: error: 'root' was not declared in this scope
sketch_jul01b:89: error: 'LS_DATE' was not declared in this scope
sketch_jul01b:89: error: 'LS_SIZE' was not declared in this scope
sketch_jul01b:93: error: 'LS_R' was not declared in this scope
sketch_jul01b.cpp: In function 'void loop()':
sketch_jul01b:118: error: 'class Server' has no member named 'available'
sketch_jul01b:118: error: cannot declare variable 'client' to be of abstract type 'Client'
C:\Users\João\Documents\arduino-1.0\hardware\arduino\cores\arduino/Client.h:7: note:   because the following virtual functions are pure within 'Client':
C:\Users\João\Documents\arduino-1.0\hardware\arduino\cores\arduino/Client.h:12: note:    virtual size_t Client::write(uint8_t)
C:\Users\João\Documents\arduino-1.0\hardware\arduino\cores\arduino/Client.h:13: note:    virtual size_t Client::write(const uint8_t*, size_t)
C:\Users\João\Documents\arduino-1.0\hardware\arduino\cores\arduino/Client.h:14: note:    virtual int Client::available()
C:\Users\João\Documents\arduino-1.0\hardware\arduino\cores\arduino/Client.h:15: note:    virtual int Client::read()
C:\Users\João\Documents\arduino-1.0\hardware\arduino\cores\arduino/Client.h:17: note:    virtual int Client::peek()
C:\Users\João\Documents\arduino-1.0\hardware\arduino\cores\arduino/Client.h:18: note:    virtual void Client::flush()
C:\Users\João\Documents\arduino-1.0\hardware\arduino\cores\arduino/Client.h:10: note:    virtual int Client::connect(IPAddress, uint16_t)
C:\Users\João\Documents\arduino-1.0\hardware\arduino\cores\arduino/Client.h:11: note:    virtual int Client::connect(const char*, uint16_t)
C:\Users\João\Documents\arduino-1.0\hardware\arduino\cores\arduino/Client.h:16: note:    virtual int Client::read(uint8_t*, size_t)
C:\Users\João\Documents\arduino-1.0\hardware\arduino\cores\arduino/Client.h:19: note:    virtual void Client::stop()
C:\Users\João\Documents\arduino-1.0\hardware\arduino\cores\arduino/Client.h:20: note:    virtual uint8_t Client::connected()
C:\Users\João\Documents\arduino-1.0\hardware\arduino\cores\arduino/Client.h:21: note:    virtual Client::operator bool()
sketch_jul01b:153: error: 'file' was not declared in this scope
sketch_jul01b:153: error: 'root' was not declared in this scope
sketch_jul01b:153: error: 'O_READ' was not declared in this scope
sketch_jul01b:189: error: 'file' was not declared in this scope
sketch_jul01b:237: error: 'file' was not declared in this scope

Obrigado e desculpem o encomodo ;)

Já agora se me poderem adicionar no msn para me darem uma ajuda agradecia.
joaocarlosveloso@hotmail.com

senso

Não tens as bibliotecas SdFat, por isso é que dá esses erros todos.
Avr fanboy


Wolfz

alguem me pode arranjar a libraria SDFat visto que a que arranjei não está a funcionar