collapse

* Posts Recentes

Amplificador - Rockboard HA 1 In-Ear por almamater
[Ontem às 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: Ajuda com Código  (Lida 2781 vezes)

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

Offline m2snd

  • Mini Robot
  • *
  • Mensagens: 65
Ajuda com Código
« em: 25 de Agosto de 2011, 22:23 »
Boas pessoal!!

Podem-me explicar, porque é que ao acrescentar a parte do código correspondente a INTERRUPTOR WC 2 na parte final do códido, o browser fica a moer e não abre a página? Faço o upload do scketch, carrega sem erros, mas ao ir abrir, fica sempre a moer e não sai dali....
Código: [Seleccione]
#include <SPI.h>
#include <Ethernet.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[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 66 }; // ip in lan
byte gateway[] = { 192, 168, 1, 254 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
Server server(80);   //server port
byte sampledata=50;
//some sample data - outputs 2 (ascii = 50 DEC)
int luzDaCozinha = 9;  // LED pin 8
int luzDaSalaDeEstar = 8;
int luzDoHall = 7;
int luzDoQuarto1 = 6;
int luzDoWc1 = 5;
int luzDoQuartoDoSimao= 4;
int luzDoQuarto2 = 3;


String readString = String(30); //string for fetching data from address
boolean luzDaCozinhaON = false; //LED status flag
boolean luzDaSalaDeEstarON = false;
boolean luzDoHallON = false;
boolean luzDoQuarto1ON = false;
boolean luzDoWc1ON = false;
boolean luzDoQuartoDoSimaoON = false;
boolean luzDoQuarto2ON = false;




void setup(){
//start Ethernet
  Ethernet.begin(mac, ip, subnet);
//--------------------------------------INDICAR PINos COMO OUTPUT--------------------
  pinMode(luzDaCozinha, OUTPUT);
  pinMode(luzDaSalaDeEstar, OUTPUT); 
  pinMode(luzDoHall, OUTPUT);
  pinMode(luzDoQuarto1, OUTPUT);
  pinMode(luzDoWc1, OUTPUT);
pinMode(luzDoQuartoDoSimao, OUTPUT);
  pinMode(luzDoQuarto2, OUTPUT);
 
//-----------------------------------------------------------------------------------
//enable serial datada print
  Serial.begin(9600);
}
void loop(){
// Create a client connection
Client client = server.available();
  if (client) {
    while (client.connected()) {
   if (client.available()) {
    char c = client.read();
    //read char by char HTTP request
    if (readString.length() < 30)
{
  //store characters to string
  //-----readString.append(c);
    readString.concat(c);
}
  //output chars to serial port
  Serial.print(c);
  //if HTTP request has ended
  if (c == '\n') {
    //lets check if LED should be lighted
//**********************************************************************************************************************************************************************

//-----------------------------------------------------------------------------------------------------------------------
 //------------LE INTERRUPTOR LUZ DA COZINHA-----------------------------------
       if (readString.substring(6,11) == "L9=ON")
     {
digitalWrite(luzDaCozinha, HIGH);    // set the LED on
luzDaCozinhaON = true;
     }
else if (readString.substring(6,12) == "L9=OFF")
{
digitalWrite(luzDaCozinha, LOW);    // set the LED OFF
luzDaCozinhaON = false;
}
//---------------LUZ DA SALA DE ESTAR-----------------------------------------------------------
            if (readString.substring(6,11) == "L8=ON")
     {
digitalWrite(luzDaSalaDeEstar, HIGH);    // set the LED on
luzDaSalaDeEstarON = true;
     }
else if (readString.substring(6,12) == "L8=OFF")
{
digitalWrite(luzDaSalaDeEstar, LOW);    // set the LED OFF
luzDaSalaDeEstarON = false;
              }
//----------------LUZ DO HALL-----------------------------------------------------------------------
               if (readString.substring(6,11) == "L7=ON")
     {
digitalWrite(luzDoHall, HIGH);    // set the LED on
luzDoHallON = true;
     }
else if (readString.substring(6,12) == "L7=OFF")
{
digitalWrite(luzDoHall, LOW);    // set the LED OFF
luzDoHallON = false;
              }
//-------------------------LUZ DO QUARTO 1-------------------------------------------------------
          if (readString.substring(6,11) == "L6=ON")
     {
digitalWrite(luzDoQuarto1, HIGH);    // set the LED on
luzDoQuarto1ON = true;
     }
else if (readString.substring(6,12) == "L6=OFF")
{
digitalWrite(luzDoQuarto1, LOW);    // set the LED OFF
luzDoQuarto1ON = false;
              }
//-------------------------LUZ DO WC1-------------------------------------------------------
          if (readString.substring(6,11) == "L5=ON")
     {
digitalWrite(luzDoWc1, HIGH);    // set the LED on
luzDoWc1ON = true;
     }
else if (readString.substring(6,12) == "L5=OFF")
{
digitalWrite(luzDoWc1, LOW);    // set the LED OFF
luzDoWc1ON = false;
              }

//-------------------------quarto 2-------------------------------------------------------
          if (readString.substring(6,11) == "L4=ON")
     {
digitalWrite(luzDoQuartoDoSimao, HIGH);    // set the LED on
luzDoQuartoDoSimaoON = true;
     }
else if (readString.substring(6,12) == "L4=OFF")
{
digitalWrite(luzDoQuartoDoSimao, LOW);    // set the LED OFF
luzDoQuartoDoSimaoON = false;
              }

//------------------------- INTERRUPTOR WC 2------------------------------------------------------
          if (readString.substring(6,11) == "L3=ON")
     {
digitalWrite(luzDoQuartoDoSimao, HIGH);    // set the LED on
luzDoQuartoDoSimaoON = true;
     }
else if (readString.substring(6,12) == "L3=OFF")
{
digitalWrite(luzDoQuartoDoSimao, LOW);    // set the LED OFF
luzDoQuartoDoSimaoON = false;
              }







    // now output HTML data starting with standart header
    client.println("HTTP/1.1 200 OK");
    client.println("Content-Type: text/html");
    client.println();
    //set background to yellow
    //client.print("<body style=background-color:yellow>");
    client.println("<h1><center>Controlo Interruptores</center></h1>");
    client.println("<font color='black'>");
    client.println("<br />");

//************************************************************MODOS***************************************************************************************************

//------------------------------------------------------------------------------------------------------------
    client.println("<form method=get name=LED><input type=submit name=L9 value=ON>  Interruptor da Cozinha..........<form>");
    client.println("<form method=get name=  LED><input type=submit name=L9 value=OFF  ><form>");
if (luzDaCozinhaON)
{
client.print("<font color='green' size='3'> ON");
}
else
{
client.print("<font color='red' size = '3'> OFF");
}
client.println("<font color='black' <br /><br>");


//-----------------SALA DE ESTAR---------------------------------------------------------------.------------------------------------
               client.println("<form method=get name=LED><input type=submit name=L8 value=ON>  Interruptor da Sala de Estar..<form>");
      client.println("<form method=get name=  LED><input type=submit name=L8 value=OFF  ><form>");
if (luzDaSalaDeEstarON)
{
client.print("<font color='green' size='3'> ON");
}
else
{
client.print("<font color='red' size = '3'> OFF");
}
client.println("<font color='black' <br /><br>"); //muda de linha
//----------------HALL------------------------------------------------HALL--------------------------------------------------------------
                 client.println("<form method=get name=LED><input type=submit name=L7 value=ON>  Interruptor do Hall...............<form>");
      client.println("<form method=get name=  LED><input type=submit name=L7 value=OFF  ><form>");
if (luzDoHallON)
{
client.print("<font color='green' size='3'> ON");
}
else
{
client.print("<font color='red' size = '3'> OFF");
}
client.println("<font color='black' <br /><br>"); //muda de linha

//----------------MUDA A COR LUZ DO QUARTO 1-----------------------------------------------------Interruptor da Sala de Estar----------------------------------------------
                 client.println("<form method=get name=LED><input type=submit name=L6 value=ON>  Interruptor do Hall Quarto 1<form>");
      client.println("<form method=get name=  LED><input type=submit name=L6 value=OFF  ><form>");
if (luzDoQuarto1ON)
{
client.print("<font color='green' size='3'> ON");
}
else
{
client.print("<font color='red' size = '3'> OFF");
}
client.println("<font color='black' <br /><br>"); //muda de linha

//----------------MUDA A COR LUZ DO WC 1-----------------------------------------------------    Interruptor da Sala de Estar----------------------------------------------
                 client.println("<form method=get name=LED><input type=submit name=L5 value=ON>  Interruptor dO WC 1...........<form>");
      client.println("<form method=get name=  LED><input type=submit name=L5 value=OFF  ><form>");
if (luzDoWc1ON)
{
client.print("<font color='green' size='3'> ON");
}
else
{
client.print("<font color='red' size = '3'> OFF");
}
client.println("<font color='black' <br /><br>"); //muda de linha
//---------------------------------luz do quarto do QUARTO2 ---------------------------------------------

   client.println("<form method=get name=LED><input type=submit name=L4 value=ON>  Interruptor do Quarto 2...........<form>");
      client.println("<form method=get name=  LED><input type=submit name=L4 value=OFF  ><form>");
if (luzDoQuartoDoSimaoON)
{
client.print("<font color='green' size='3'> ON");
}
else
{
client.print("<font color='red' size = '3'> OFF");
}
client.println("<font color='black' <br /><br>"); //muda de linha

/*----------------------------------------------INTERRUPTOR WC 2----------------------------------------
Ao acrestar esta parte do código, o browser fica a moer, nao abrindo a pagina


 client.println("<form method=get name=LED><input type=submit name=L3 value=ON>  Interruptor do WC 2.......<form>");
      client.println("<form method=get name=  LED><input type=submit name=L3 value=OFF  ><form>");
if (luzDoWc1ON)
{
client.print("<font color='green' size='3'> ON");
}
else
{
client.print("<font color='red' size = '3'> OFF");
}
client.println("<font color='black' <br /><br>"); //muda de linha
*/



//------------------------------------------------------------------------------------------------------********
//**************************************************************************************************************





    client.println("</body></html>");
    //clearing string for next read
    readString="";
    //stopping client
    client.stop();
}
    }
  }
}
    }


Obrigado

Offline amando96

  • Mini Robot
  • *
  • Mensagens: 1.631
  • MAC address? But I have windows...
    • Projects, News, Blog, Tutorials
Re: Ajuda com Código
« Responder #1 em: 25 de Agosto de 2011, 22:29 »
Estás a usar uma carrada de tags que já não existem e parece que nunca fechas os <forms> mas só olhei rápido.

Offline senso

  • Global Moderator
  • Mini Robot
  • *****
  • Mensagens: 9.733
  • Helpdesk do sitio
Re: Ajuda com Código
« Responder #2 em: 25 de Agosto de 2011, 22:51 »
Essas strings todas não cabem na RAM, isto se for um Atmega328p..
Avr fanboy

Offline m2snd

  • Mini Robot
  • *
  • Mensagens: 65
Re: Ajuda com Código
« Responder #3 em: 25 de Agosto de 2011, 22:57 »
Olá Senso!

Sei que vou dizer uma grande asneirada, mas o sketch size não ocupa nem metade dos bytes ainda disponíveis....
Binary sketch size: 11498 bytes (of a 32256 byte maximum)



Offline senso

  • Global Moderator
  • Mini Robot
  • *****
  • Mensagens: 9.733
  • Helpdesk do sitio
Re: Ajuda com Código
« Responder #4 em: 25 de Agosto de 2011, 23:01 »
Isso é a flash, mas a RAM o IDE do Arduino estupidamente não diz quanto é ocupada, por enquanto não deves ter problemas com isso, mas se continuares a adicionar assim texto de certeza que vais ficar sem ram.
Avr fanboy