collapse

* Posts Recentes

Amplificador - Rockboard HA 1 In-Ear por almamater
[27 de Março de 2024, 19:13]


O que é isto ? por KammutierSpule
[26 de Março de 2024, 19:35]


Bateria - Portátil por almamater
[25 de Março de 2024, 22:14]


Emulador NES em ESP32 por dropes
[13 de Março de 2024, 21:19]


Escolher Osciloscópio por jm_araujo
[06 de Fevereiro de 2024, 23:07]


TP4056 - Dúvida por dropes
[31 de Janeiro de 2024, 14:13]


Leitura de dados por Porta Serie por jm_araujo
[22 de Janeiro de 2024, 14:00]


Distancia Cabo por jm_araujo
[08 de Janeiro de 2024, 16:30]


Meu novo robô por josecarlos
[06 de Janeiro de 2024, 16:46]


Laser Engraver - Alguém tem? por almamater
[16 de Dezembro de 2023, 14:23]

Autor Tópico: [Pedido de Ajuda] Arduino EthernetShield Armazenar um pagina html e imagem dentr  (Lida 27432 vezes)

0 Membros e 1 Visitante estão a ver este tópico.

Offline r16

  • Mini Robot
  • *
  • Mensagens: 339
Microbyte, agradeço novamente a tua intenção de querer ajudar.

Vamos entao por partes.

1 Parte:
O sketch que tenho de momento dentro do arduino é este:

Código: [Seleccione]
#include <LiquidCrystal.h>
#include <SPI.h>
#include <SdFat.h>
#include <SdFatUtil.h>
#include <Ethernet.h>
#define BUFSIZ 128
#define greenLEDandBEEP 2
#define redLEDpin 3
boolean led2 = true;
int hits = 0; // Set the number of hits the hit counter will start at.
int units = 0;
int count = 0;
int photocellPin = 2;
int photocellReading;
LiquidCrystal lcd(4, 5, 6, 7, 8, 9);

//Local ethernet setup
byte mac[] = {
  0x90, 0xA2, 0xDA, 0x00, 0x1C, 0x0E };
byte ip[] = {
  192, 168, 1, 80 };
char rootFileName[] = "index.htm";
Server server(8080);

//SD card stuff
Sd2Card card;
SdVolume volume;
SdFile root;
SdFile file;
#define error(s) error_P(PSTR(s))
void error_P(const char* str) {
  PgmPrint("error: ");
  SerialPrintln_P(str);
  if (card.errorCode()) {
    PgmPrint("SD error: ");
    Serial.print(card.errorCode(), HEX);
    Serial.print(',');
    Serial.println(card.errorData(), HEX);
  }
  while(1);
}

void setup() {
  lcd.begin(16, 2);
  lcd.print("Web Server v2.00");
  lcd.setCursor(0, 1);
  lcd.print("Hits:");

  Serial.begin(9600);

  pinMode(greenLEDandBEEP, OUTPUT);
  pinMode(redLEDpin, OUTPUT);

  PgmPrint("Free RAM: ");
  Serial.println(FreeRam()); 

  pinMode(10, OUTPUT);             
  digitalWrite(10, HIGH);             

  if (!card.init(SPI_HALF_SPEED, 4)) error("card.init failed!");

  if (!volume.init(&card)) error("vol.init failed!");

  PgmPrint("Volume is FAT");
  Serial.println(volume.fatType(),DEC);
  Serial.println();

  if (!root.openRoot(&volume)) error("openRoot failed");

  PgmPrintln("Files found in root:");
  root.ls(LS_DATE | LS_SIZE);
  Serial.println();

  PgmPrintln("Files found in all dirs:");
  root.ls(LS_R);

  Serial.println();
  PgmPrintln("Done");

  Ethernet.begin(mac, ip);
  server.begin();
}


void loop()
{
  if(count >=500)
  { 
    led2 = !led2;
    digitalWrite(redLEDpin, led2);
    count = 0;
  }
  count +=1;

  char clientline[BUFSIZ];
  char *filename;
  int image = 0;
  int index = 0;

  Client client = server.available();
  if (client) {
    boolean current_line_is_blank = true;

    index = 0;

    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        if (c != '\n' && c != '\r') {
          clientline[index] = c;
          index++;
          if (index >= BUFSIZ)
            index = BUFSIZ -1;

          continue;
        }

        clientline[index] = 0;
        filename = 0;

        Serial.println(clientline);

        if (strstr(clientline, "GET / ") != 0) {
          filename = rootFileName;

        }
        if (strstr(clientline, "GET /") != 0) {
          if (!filename) filename = clientline + 5;

          (strstr(clientline, " HTTP"))[0] = 0;

          Serial.println(filename);

          if (! file.open(&root, filename, O_READ)) {
            client.println("HTTP/1.1 404 Not Found");
            client.println("Content-Type: text/html");
            client.println();
            client.println("<h2>Error 404</h2>");
            client.println("<s2>The file does not exist.<s2>");
            client.println("");
            break;
          }

          Serial.println("Opened!");
          //File types
          client.println("HTTP/1.1 200 OK");
          if (strstr(filename, ".htm") != 0)
            client.println("Content-Type: text/html");
          else if (strstr(filename, ".css") != 0)
            client.println("Content-Type: text/css");
          else if (strstr(filename, ".png") != 0)
            client.println("Content-Type: image/png");
          else if (strstr(filename, ".jpg") != 0)
            client.println("Content-Type: image/jpeg");
          else if (strstr(filename, ".gif") != 0)
            client.println("Content-Type: image/gif");
          else if (strstr(filename, ".3gp") != 0)
            client.println("Content-Type: video/mpeg");
          else if (strstr(filename, ".pdf") != 0)
            client.println("Content-Type: application/pdf");
          else if (strstr(filename, ".js") != 0)
            client.println("Content-Type: application/x-javascript");
          else if (strstr(filename, ".xml") != 0)
            client.println("Content-Type: application/xml");
          else
            client.println("Content-Type: text");
          client.println();

          int16_t c;
          while ((c = file.read()) >= 0) {
            //Serial.print((char)c); //Prints all HTML code to serial (For debuging)
            client.print((char)c); //Prints all HTML code for web page
          }

          //Hit counter math
          if(units >= 2)
          {
            hits ++;
            units = 0;
          }
          units +=1;
          //End hit counter math

          //Print the hit counters and light value
          lcd.setCursor(6, 1);
          lcd.print(hits); //Print hits for LCD hit counter

          client.print("<html><body>"); //HTML code starts here
          client.print("<P align=\"center\">");
          client.print("Hits since reset: ");   
          client.print(hits); //Print hits to client
          client.print("
");

          photocellReading = analogRead(photocellPin);
          client.print("Light reading: ");
          client.print(photocellReading); //Prints light reading to client

          // A few threshholds
          if (photocellReading < 10) {
            client.print(" - Dark");
          }
          else if (photocellReading < 200) {
            client.print(" - Dim");
          }
          else if (photocellReading < 500) {
            client.print(" - Light");
          }
          else if (photocellReading < 800) {
            client.print(" - Bright");
          }
          else {
            client.print(" - Very bright");
          }

          client.print("</p></body></html>"); //HTML code ends here
          //End hit counter and light value

          file.close();

        }
        else {
          client.println("HTTP/1.1 404 Not Found");
          client.println("Content-Type: text/html");
          client.println();
          client.println("<h2>Error 404</h2>");
          client.println("");
        }
        break;
      }
    }
    digitalWrite(greenLEDandBEEP, HIGH);
    delay(1);
    digitalWrite(greenLEDandBEEP, LOW);
    client.stop();
  }

}

//The End /*

ora bem, o que esse codigo faz?? Esse codigo , quando eu digito no browser o ip do arduino,ele vai me abrir um index.html que esta armezando no SD juntamente com uma imagem, aqui fica o codigo html do index.html

Código: [Seleccione]
<html>
<body>

<img src="w3schools.jpg" width="104" height="142" />

</body>
</html>


Agora o que eu pretendo?? o que pretendo é saber que resto de código falta ai no index.html, e qual é o codigo que tenho que por aqui:

Código: [Seleccione]
#include <LiquidCrystal.h>
#include <SPI.h>
#include <SdFat.h>
#include <SdFatUtil.h>
#include <Ethernet.h>
#define BUFSIZ 128
#define greenLEDandBEEP 2
#define redLEDpin 3
boolean led2 = true;
int hits = 0; // Set the number of hits the hit counter will start at.
int units = 0;
int count = 0;
int photocellPin = 2;
int photocellReading;
LiquidCrystal lcd(4, 5, 6, 7, 8, 9);

//Local ethernet setup
byte mac[] = {
  0x90, 0xA2, 0xDA, 0x00, 0x1C, 0x0E };
byte ip[] = {
  192, 168, 1, 80 };
char rootFileName[] = "index.htm";
Server server(8080);

//SD card stuff
Sd2Card card;
SdVolume volume;
SdFile root;
SdFile file;
#define error(s) error_P(PSTR(s))
void error_P(const char* str) {
  PgmPrint("error: ");
  SerialPrintln_P(str);
  if (card.errorCode()) {
    PgmPrint("SD error: ");
    Serial.print(card.errorCode(), HEX);
    Serial.print(',');
    Serial.println(card.errorData(), HEX);
  }
  while(1);
}

void setup() {
  lcd.begin(16, 2);
  lcd.print("Web Server v2.00");
  lcd.setCursor(0, 1);
  lcd.print("Hits:");

  Serial.begin(9600);

  pinMode(greenLEDandBEEP, OUTPUT);
  pinMode(redLEDpin, OUTPUT);

  PgmPrint("Free RAM: ");
  Serial.println(FreeRam()); 

  pinMode(10, OUTPUT);             
  digitalWrite(10, HIGH);             

  if (!card.init(SPI_HALF_SPEED, 4)) error("card.init failed!");

  if (!volume.init(&card)) error("vol.init failed!");

  PgmPrint("Volume is FAT");
  Serial.println(volume.fatType(),DEC);
  Serial.println();

  if (!root.openRoot(&volume)) error("openRoot failed");

  PgmPrintln("Files found in root:");
  root.ls(LS_DATE | LS_SIZE);
  Serial.println();

  PgmPrintln("Files found in all dirs:");
  root.ls(LS_R);

  Serial.println();
  PgmPrintln("Done");

  Ethernet.begin(mac, ip);
  server.begin();
}


void loop()
{
  if(count >=500)
  { 
    led2 = !led2;
    digitalWrite(redLEDpin, led2);
    count = 0;
  }
  count +=1;

  char clientline[BUFSIZ];
  char *filename;
  int image = 0;
  int index = 0;

  Client client = server.available();
  if (client) {
    boolean current_line_is_blank = true;

    index = 0;

    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        if (c != '\n' && c != '\r') {
          clientline[index] = c;
          index++;
          if (index >= BUFSIZ)
            index = BUFSIZ -1;

          continue;
        }

        clientline[index] = 0;
        filename = 0;

        Serial.println(clientline);

        if (strstr(clientline, "GET / ") != 0) {
          filename = rootFileName;

        }
        if (strstr(clientline, "GET /") != 0) {
          if (!filename) filename = clientline + 5;

          (strstr(clientline, " HTTP"))[0] = 0;

          Serial.println(filename);

          if (! file.open(&root, filename, O_READ)) {
            client.println("HTTP/1.1 404 Not Found");
            client.println("Content-Type: text/html");
            client.println();
            client.println("<h2>Error 404</h2>");
            client.println("<s2>The file does not exist.<s2>");
            client.println("");
            break;
          }

          Serial.println("Opened!");
          //File types
          client.println("HTTP/1.1 200 OK");
          if (strstr(filename, ".htm") != 0)
            client.println("Content-Type: text/html");
          else if (strstr(filename, ".css") != 0)
            client.println("Content-Type: text/css");
          else if (strstr(filename, ".png") != 0)
            client.println("Content-Type: image/png");
          else if (strstr(filename, ".jpg") != 0)
            client.println("Content-Type: image/jpeg");
          else if (strstr(filename, ".gif") != 0)
            client.println("Content-Type: image/gif");
          else if (strstr(filename, ".3gp") != 0)
            client.println("Content-Type: video/mpeg");
          else if (strstr(filename, ".pdf") != 0)
            client.println("Content-Type: application/pdf");
          else if (strstr(filename, ".js") != 0)
            client.println("Content-Type: application/x-javascript");
          else if (strstr(filename, ".xml") != 0)
            client.println("Content-Type: application/xml");
          else
            client.println("Content-Type: text");
          client.println();

          int16_t c;
          while ((c = file.read()) >= 0) {
            //Serial.print((char)c); //Prints all HTML code to serial (For debuging)
            client.print((char)c); //Prints all HTML code for web page
          }

          //Hit counter math
          if(units >= 2)
          {
            hits ++;
            units = 0;
          }
          units +=1;
          //End hit counter math

          //Print the hit counters and light value
          lcd.setCursor(6, 1);
          lcd.print(hits); //Print hits for LCD hit counter

          client.print("<html><body>"); //HTML code starts here
          client.print("<P align=\"center\">");
          client.print("Hits since reset: ");   
          client.print(hits); //Print hits to client
          client.print("
");

          photocellReading = analogRead(photocellPin);
          client.print("Light reading: ");
          client.print(photocellReading); //Prints light reading to client

          // A few threshholds
          if (photocellReading < 10) {
            client.print(" - Dark");
          }
          else if (photocellReading < 200) {
            client.print(" - Dim");
          }
          else if (photocellReading < 500) {
            client.print(" - Light");
          }
          else if (photocellReading < 800) {
            client.print(" - Bright");
          }
          else {
            client.print(" - Very bright");
          }

          client.print("</p></body></html>"); //HTML code ends here
          //End hit counter and light value

          file.close();

        }
        else {
          client.println("HTTP/1.1 404 Not Found");
          client.println("Content-Type: text/html");
          client.println();
          client.println("<h2>Error 404</h2>");
          client.println("");
        }
        break;
      }
    }
    digitalWrite(greenLEDandBEEP, HIGH);
    delay(1);
    digitalWrite(greenLEDandBEEP, LOW);
    client.stop();
  }

}

//The End /

Para que quando clique na imagem....do site me faça um digitalwrite ao pino 7 que faz acender um led, e quando clicar novamente na imagem me faca desligar o led com o digitalwrite low.

desta vez fiz me entender? ou nao estou a ser claro ainda?
obrigado

Offline senso

  • Global Moderator
  • Mini Robot
  • *****
  • Mensagens: 9.733
  • Helpdesk do sitio
Tens de ir ler uns tutorias de HTML para fazer o que queres..
Avr fanboy

Offline r16

  • Mini Robot
  • *
  • Mensagens: 339
Senso.. obrigado.

Offline Marvin

  • Mini Robot
  • *
  • Mensagens: 677
    • The scientist and the geek
R16, precisas de compreender qual é o evento (se é que existe algum) disparado quando existe um postback no servidor. De seguida então fazer seguir o tratamento desse evento na arduino. Pessoalmente nunca fiz isso, mas isto é como funciona o html e um servidor web.

Se o que eu disse não te faz sentido, então segue o conselho do Senso.
Dronetech BlogThe Scientist and the Geek

Offline r16

  • Mini Robot
  • *
  • Mensagens: 339
Faz tudo sentido... so que de tanto que ja escrevi ainda nao compreederam que eu nao sei e qual o codigo que se poe no sketch do arduino..

o codigo da pagina html e uma coisa...


e o codigo do arduino é outra... mas ainda nao entendera essa parte e nao me consigo explicar melhor...ou entao aqui tambem ninguem sabe como se faz, que pode ser esse outro problema.

Offline poliveira1978

  • Mini Robot
  • *
  • Mensagens: 335
se o que pretendes é alterar o estado da saida:

saida=!saida -> inverte, ou seja:
se ligado -> desliga;
se desligado -> liga;

Offline r16

  • Mini Robot
  • *
  • Mensagens: 339
 :-\ Desisto..é só tiros ao lado.

é  a ultima vez que me vou explicar... porque já vi que não estao a entender o que quero..

tenho um index.html... com uma imagem... e quero saber qual o codigo que ponho no sketch do arduino, para que quando clico na imagem, me faca um digitalwrite high ao pino7, e quando clicar novamente o digitalwrite low ao pino7.

........uffffff

Offline senso

  • Global Moderator
  • Mini Robot
  • *****
  • Mensagens: 9.733
  • Helpdesk do sitio
Precisas de código html que coloque as imagens que queres como botões, e código html que envie uma resposta ao servidor, ou seja o arduino, com essa resposta é um if e um digitalWrite, portanto a tua duvida é unica e simplesmente sobre HTML.
Tens um exemplo com radio-buttons, experimenta-o, se calhar é mais simples usar esses radio-buttons que imagens clicaveis.

Por muito gosto que tenha em ajudar não pesco nada de html, portanto faz como te disse acima e vai ler tutoriais sobre html.
Avr fanboy

Offline r16

  • Mini Robot
  • *
  • Mensagens: 339
ok..... entao vamos fazer de outra forma....
 
Este codigo que tenho aqui esta a funcionar em pleno... quando clico no radio botton que diz COZINHA ON ele activa o pino 7, e quando clico em COZINHA OFF ele desliga o pino 7, mas atencao,.. este codigo nada tem haver com o outro pois este gera o html dentro do proprio sketch.

Código: [Seleccione]
#include <SPI.h>
#include <Ethernet.h>

// ethernet configuration
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x49, 0xD6 };
byte ip[] = { 192, 168, 1, 76 }; // P1 --> { 10, 1, 1, 5 };
EthernetServer server(6969);              // port 80 is default for HTTP

// initial
int LED = 7;          // led is connected to digital pin 3

char c = 0;           // received data
char command[2] = "\0";  // command


void setup()
{
  Ethernet.begin(mac, ip);
  server.begin();
  pinMode(LED, OUTPUT);

}


void loop()
{
  EthernetClient client = server.available();
  // detect if current is the first line
  boolean current_line_is_first = true;

  if (client) {
    // an http request ends with a blank line
    boolean current_line_is_blank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        // if we've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so we can send a reply
        if (c == '\n' && current_line_is_blank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
         
         [b] // webpage title
         // client.println("<left><p><h1>Arduino + Ethernet Shield Application v1.0</h1></p><left><hr><br />");

         
         
          // button functions
          client.println("<form  method=get name=form>");
          client.println("<button name=b value=1 type=submit style=height:50px;width:100px>Cozinha ON</button>");
          client.println("<button name=b value=2 type=submit style=height:50px;width:100px>Cozinha OFF</button>");
         
         client.println("</form><br />");
         
         
          //<img src="http://4.bp.blogspot.com/-S6G5PgB28q4/Tnb7zaPegmI/AAAAAAAAR50/peD5LeP0ar0/s1600/sw_Auto_Giardino-500x293.jpg" id="Image1" alt="" border="0" style="width:479px;height:324px;"></div>
       

         
          break;
        }
        if (c == '\n') {
          // we're starting a new line
          current_line_is_first = false;
          current_line_is_blank = true;
        }
        else if (c != '\r') {
          // we've gotten a character on the current line
          current_line_is_blank = false;
        }
        // get the first http request
        if (current_line_is_first && c == '=') {
          for (int i = 0; i < 1; i++) {
            c = client.read();
            command[i] = c;
          }
          // LED control
          if (!strcmp(command, "1")) {
            digitalWrite(LED, HIGH);
          }
          else if (!strcmp(command, "2")) {
            digitalWrite(LED, LOW);
          }
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    client.stop();
  }
}[/b]



Pronto esse codigo eu tenho a funcionar neste momento e funciona bem,,,
agora quero que me ajudem a passar essa parte do codigo que está em negrito....para este codigo..

Código: [Seleccione]
#include <LiquidCrystal.h>
#include <SPI.h>
#include <SdFat.h>
#include <SdFatUtil.h>
#include <Ethernet.h>
#define BUFSIZ 128
#define greenLEDandBEEP 2
#define redLEDpin 3
boolean led2 = true;
int hits = 0; // Set the number of hits the hit counter will start at.
int units = 0;
int count = 0;
int photocellPin = 2;
int photocellReading;
LiquidCrystal lcd(4, 5, 6, 7, 8, 9);

//Local ethernet setup
byte mac[] = {
  0x90, 0xA2, 0xDA, 0x00, 0x1C, 0x0E };
byte ip[] = {
  192, 168, 1, 80 };
char rootFileName[] = "index.htm";
Server server(8080);

//SD card stuff
Sd2Card card;
SdVolume volume;
SdFile root;
SdFile file;
#define error(s) error_P(PSTR(s))
void error_P(const char* str) {
  PgmPrint("error: ");
  SerialPrintln_P(str);
  if (card.errorCode()) {
    PgmPrint("SD error: ");
    Serial.print(card.errorCode(), HEX);
    Serial.print(',');
    Serial.println(card.errorData(), HEX);
  }
  while(1);
}

void setup() {
  lcd.begin(16, 2);
  lcd.print("Web Server v2.00");
  lcd.setCursor(0, 1);
  lcd.print("Hits:");

  Serial.begin(9600);

  pinMode(greenLEDandBEEP, OUTPUT);
  pinMode(redLEDpin, OUTPUT);

  PgmPrint("Free RAM: ");
  Serial.println(FreeRam()); 

  pinMode(10, OUTPUT);             
  digitalWrite(10, HIGH);             

  if (!card.init(SPI_HALF_SPEED, 4)) error("card.init failed!");

  if (!volume.init(&card)) error("vol.init failed!");

  PgmPrint("Volume is FAT");
  Serial.println(volume.fatType(),DEC);
  Serial.println();

  if (!root.openRoot(&volume)) error("openRoot failed");

  PgmPrintln("Files found in root:");
  root.ls(LS_DATE | LS_SIZE);
  Serial.println();

  PgmPrintln("Files found in all dirs:");
  root.ls(LS_R);

  Serial.println();
  PgmPrintln("Done");

  Ethernet.begin(mac, ip);
  server.begin();
}


void loop()
{
  if(count >=500)
  { 
    led2 = !led2;
    digitalWrite(redLEDpin, led2);
    count = 0;
  }
  count +=1;

  char clientline[BUFSIZ];
  char *filename;
  int image = 0;
  int index = 0;

  Client client = server.available();
  if (client) {
    boolean current_line_is_blank = true;

    index = 0;

    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        if (c != '\n' && c != '\r') {
          clientline[index] = c;
          index++;
          if (index >= BUFSIZ)
            index = BUFSIZ -1;

          continue;
        }

        clientline[index] = 0;
        filename = 0;

        Serial.println(clientline);

        if (strstr(clientline, "GET / ") != 0) {
          filename = rootFileName;

        }
        if (strstr(clientline, "GET /") != 0) {
          if (!filename) filename = clientline + 5;

          (strstr(clientline, " HTTP"))[0] = 0;

          Serial.println(filename);

          if (! file.open(&root, filename, O_READ)) {
            client.println("HTTP/1.1 404 Not Found");
            client.println("Content-Type: text/html");
            client.println();
            client.println("<h2>Error 404</h2>");
            client.println("<s2>The file does not exist.<s2>");
            client.println("");
            break;
          }

          Serial.println("Opened!");
          //File types
          client.println("HTTP/1.1 200 OK");
          if (strstr(filename, ".htm") != 0)
            client.println("Content-Type: text/html");
          else if (strstr(filename, ".css") != 0)
            client.println("Content-Type: text/css");
          else if (strstr(filename, ".png") != 0)
            client.println("Content-Type: image/png");
          else if (strstr(filename, ".jpg") != 0)
            client.println("Content-Type: image/jpeg");
          else if (strstr(filename, ".gif") != 0)
            client.println("Content-Type: image/gif");
          else if (strstr(filename, ".3gp") != 0)
            client.println("Content-Type: video/mpeg");
          else if (strstr(filename, ".pdf") != 0)
            client.println("Content-Type: application/pdf");
          else if (strstr(filename, ".js") != 0)
            client.println("Content-Type: application/x-javascript");
          else if (strstr(filename, ".xml") != 0)
            client.println("Content-Type: application/xml");
          else
            client.println("Content-Type: text");
          client.println();

          int16_t c;
          while ((c = file.read()) >= 0) {
            //Serial.print((char)c); //Prints all HTML code to serial (For debuging)
            client.print((char)c); //Prints all HTML code for web page
          }

          //Hit counter math
          if(units >= 2)
          {
            hits ++;
            units = 0;
          }
          units +=1;
          //End hit counter math

          //Print the hit counters and light value
          lcd.setCursor(6, 1);
          lcd.print(hits); //Print hits for LCD hit counter

          client.print("<html><body>"); //HTML code starts here
          client.print("<P align=\"center\">");
          client.print("Hits since reset: ");   
          client.print(hits); //Print hits to client
          client.print("
");

          photocellReading = analogRead(photocellPin);
          client.print("Light reading: ");
          client.print(photocellReading); //Prints light reading to client

          // A few threshholds
          if (photocellReading < 10) {
            client.print(" - Dark");
          }
          else if (photocellReading < 200) {
            client.print(" - Dim");
          }
          else if (photocellReading < 500) {
            client.print(" - Light");
          }
          else if (photocellReading < 800) {
            client.print(" - Bright");
          }
          else {
            client.print(" - Very bright");
          }

          client.print("</p></body></html>"); //HTML code ends here
          //End hit counter and light value

          file.close();

        }
        else {
          client.println("HTTP/1.1 404 Not Found");
          client.println("Content-Type: text/html");
          client.println();
          client.println("<h2>Error 404</h2>");
          client.println("");
        }
        break;
      }
    }
    digitalWrite(greenLEDandBEEP, HIGH);
    delay(1);
    digitalWrite(greenLEDandBEEP, LOW);
    client.stop();
  }

}

//The End /


Assim, ja fica a funcionar penso eu.........depois e uma questao de por a imagem em vez dos raddio button.

Offline senso

  • Global Moderator
  • Mini Robot
  • *****
  • Mensagens: 9.733
  • Helpdesk do sitio
É meteres isso no teu index.html que lês do cartão SD, simplesmente um tem o html no código do arduino de modo explicito e o outro lê de um cartão.
Avr fanboy

Offline CBX

  • Mini Robot
  • *
  • Mensagens: 1.315
lê isto: http://www.nuelectronics.com/estore/index.php?main_page=project_eth

em todos os projectos "arduino web server" tens exemplos disso...

Offline r16

  • Mini Robot
  • *
  • Mensagens: 339
Certo...
Mas esse ultimo sketch que é o que le o index.html do cartao... nao tem este codigo que é o que me interessa:
So nao sei onde o por sem dar erros na compilacao

Código: [Seleccione]
// button functions
          client.println("<form  method=get name=form>");
          client.println("<button name=b value=1 type=submit style=height:50px;width:100px>Cozinha ON</button>");
          client.println("<button name=b value=2 type=submit style=height:50px;width:100px>Cozinha OFF</button>");
          client.println("<img src=http://4.bp.blogspot.com/-S6G5PgB28q4/Tnb7zaPegmI/AAAAAAAAR50/peD5LeP0ar0/s1600/sw_Auto_Giardino-500x293.jpg>");
         
          client.println("<form  method=get name=form>");
          client.println("<button style="background-color:transparent" name=b value=1 type=submit style=height:400px;width:200px></button>");
          client.println("<button name=b value=2 type=submit style=height:50px;width:100px>Cozinha OFF</button>");
          client.println("</form><br />");

          client.println("</form><br />");
         
         
          //<img src="http://4.bp.blogspot.com/-S6G5PgB28q4/Tnb7zaPegmI/AAAAAAAAR50/peD5LeP0ar0/s1600/sw_Auto_Giardino-500x293.jpg" id="Image1" alt="" border="0" style="width:479px;height:324px;"></div>
       

         
          break;
        }
        if (c == '\n') {
          // we're starting a new line
          current_line_is_first = false;
          current_line_is_blank = true;
        }
        else if (c != '\r') {
          // we've gotten a character on the current line
          current_line_is_blank = false;
        }
        // get the first http request
        if (current_line_is_first && c == '=') {
          for (int i = 0; i < 1; i++) {
            c = client.read();
            command[i] = c;
          }
          // LED control
          if (!strcmp(command, "1")) {
            digitalWrite(LED, HIGH);
          }
          else if (!strcmp(command, "2")) {
            digitalWrite(LED, LOW);
          }
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    client.stop();
  }
}



Ou seja eu no index.html que esta no cartao...ja tenho o codigo la todo certinho.. agora e so passar esse que ta ai em cima para dentro do sketch.


Eu ja tentei... mas como nao tou "entendido" na programacao estarei a passa-lo para o sitio incorrecto e da me erro a compilar.

Offline r16

  • Mini Robot
  • *
  • Mensagens: 339
lê isto: http://www.nuelectronics.com/estore/index.php?main_page=project_eth

em todos os projectos "arduino web server" tens exemplos disso...

Obrigado pelo teu comentario mas se tivesses lido bem, nao se trata disso.

Offline senso

  • Global Moderator
  • Mini Robot
  • *****
  • Mensagens: 9.733
  • Helpdesk do sitio
Se já lá tens o html o importante centra-se unica e exclusivamente no client.read()
Avr fanboy

Offline r16

  • Mini Robot
  • *
  • Mensagens: 339
Certo,correcto... e precisamente agora essa parte que nao sei transferir de um codigo para o outro.