Show Posts
Pages: 1 [2] 3 4 ... 8
16  Using Arduino / Programming Questions / Re: Program Compiles but doesn't run at 100% on: April 30, 2013, 06:35:52 pm
The packet should be RXXX or BXXXX  (for example R245 or B5.99). You pointed to the noise and that could be a problem and make buffer overflow but i thought that only a message with the specific lenght transmitted will be received and enter in the IF function, so i supposed that even if noise could add something to message it won't perform the BUFLEN. Can you give me more "know how" about that?
17  Using Arduino / Programming Questions / Re: Program Compiles but doesn't run at 100% on: April 30, 2013, 06:16:01 pm
RAM: 466
18  Using Arduino / Programming Questions / Re: Program Compiles but doesn't run at 100% on: April 30, 2013, 06:07:08 pm
Can you give me an example how to put this
Quote
"this\0is\0a\multi\0string\0\0"
in PROGMEM and how to point to each string?

By the way if i have to get an arduino mega because its extended memory, this sketch suits well in it or do i have to make some changes?

Thanks a lot for helping me.
19  Using Arduino / Programming Questions / Re: Program Compiles but doesn't run at 100% on: April 30, 2013, 06:03:02 pm
Disabling the part when it saves data to SD Card and the RTC it runs OK. If i disable the part were it looks for a client connected and let only RTC and save data to SD Card it runs OK. All together it restarts.
20  Using Arduino / Programming Questions / Re: Program Compiles but doesn't run at 100% on: April 30, 2013, 05:55:20 pm
I've done the FreeRam() to check ram level periodically and i tried in many parts of the code but i couldn't get it reading like 4 or 5 bytes or so that let me know that memory is almost full (at least its what i saw in serial monitor).
I've disabled part of code too and after some parts disabled it runs without any problem, but i need the full code. By doing this i thought that i was running out of ram...
21  Using Arduino / Programming Questions / Re: Program Compiles but doesn't run at 100% on: April 30, 2013, 05:39:16 pm
Code:
void clienteLigado() {
  char clientline[BUFSIZ];
  int index = 0;
  client = server.available();
  if (client) {
    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;
        Serial.println(clientline);
        if (strstr(clientline, "GET / ") != 0) {
          headerRespostaHttp();
          conTypeTxt();
          strcpy_P(ficheiroLer, (char*)pgm_read_word(&(fichPag[0])));
          lerFicheiroCartao();
        }
        else if (strstr(clientline, "GET /tqe") != 0) {
          headerRespostaHttp();
          conTypeImg();
          strcpy_P(ficheiroLer, (char*)pgm_read_word(&(fichPag[1])));
          lerFicheiroCartao();
        }
        else if (strstr(clientline, "GET /bdr") != 0) {
          headerRespostaHttp();
          conTypeImg();
          strcpy_P(ficheiroLer, (char*)pgm_read_word(&(fichPag[2])));
          lerFicheiroCartao();
        }
        else if (strstr(clientline, "GET /fin") != 0) {
          headerRespostaHttp();
          client.println(F("Content-Type: image/x-icon"));
          client.println();
          strcpy_P(ficheiroLer, (char*)pgm_read_word(&(fichPag[3])));
          lerFicheiroCartao();
        }
        else if (strstr(clientline, "GET /&agbt") != 0) {
          headerRespostaHttp();
          conTypeTxt();
          client.print(dadosAgua);
          client.print(F("px&"));
          client.println(dadosBat);
        }
        else if (strstr(clientline, "GET /&logg") != 0) {
          boolean conFirma = false;
          char carMes = clientline[10];
          byte num = atoi(&carMes);
          if (num > 0 && num < 10) {
            strcpy_P(nomeMes, (char*)pgm_read_word(&(noMes[num])));
            sprintf(ficheiroLer,"%s.csv", nomeMes);
            conFirma = true;
          }
          else {
            switch (carMes) {
            case 'o':
              strcpy_P(nomeMes, (char*)pgm_read_word(&(noMes[10])));
              sprintf(ficheiroLer,"%s.csv", nomeMes);
              conFirma = true;
              break;
            case 'n':
              strcpy_P(nomeMes, (char*)pgm_read_word(&(noMes[11])));
              sprintf(ficheiroLer,"%s.csv", nomeMes);
              conFirma = true;
              break;
            case 'd':
              strcpy_P(nomeMes, (char*)pgm_read_word(&(noMes[12])));
              sprintf(ficheiroLer,"%s.csv", nomeMes);
              conFirma = true;
              break;
            default:
              conFirma = false;
              break;
            }
          }
          if (conFirma) {
            headerRespostaHttp();
            client.print(F("Content-Disposition: attachment; filename=\"LOG_"));
            client.print(ficheiroLer);
            client.println(F("\""));
            client.println();
            lerFicheiroCartao();
          }
          conFirma = false;
          erro404();
        }
        else {
          erro404();
        }
        break;
      }
    }
    delay(1);
    digitalWrite(ledInfo, HIGH);
    delay(1);
    digitalWrite(ledInfo, LOW);
    client.stop();
  }
}
void headerRespostaHttp() {
  client.println(F("HTTP/1.1 200 OK"));
}
void conTypeTxt() {
  client.println(F("Content-Type: text/html"));
  client.println();
}
void conTypeImg() {
  client.println(F("Content-Type: image/jpeg"));
  client.println();
}
void erro404() {
  client.println(F("HTTP/1.1 404 Not Found"));
  conTypeTxt();
  client.println(F("<h2>Erro 404</h2>"));
  client.println(F("<s2>Caminho/ficheiro nao existe.<s2>"));
}
void lerFicheiroCartao() {
  boolean ficheiro = false;
  ficheiro = file.open(&root, ficheiroLer, O_READ);
  if (ficheiro) {
    byte clientBuf[64];
    int clientCount = 0;
    while(file.available()) {
      clientBuf[clientCount] = file.read();
      clientCount++;
      if (clientCount > 63) {
        client.write(clientBuf, 64);
        clientCount = 0;
      }
    }
    if (clientCount > 0) {
      client.write(clientBuf, clientCount);
    }
    file.close();
    ficheiro = false;
  }
  else {
    erro404();
  }
}
22  Using Arduino / Programming Questions / Re: Program Compiles but doesn't run at 100% on: April 30, 2013, 05:38:42 pm
Code:
#include <SPI.h>
#include <avr/pgmspace.h>
#include <Ethernet.h>
#include <VirtualWire.h>
#include <Wire.h>
#include "SdFatUtil.h"
const byte ledInfo = 2;
const byte ledRececao = 3;
const byte pinoRececao = 8;
#define DS1307_I2C_Endereco 0x68  //SCL<--> Analog Input 5  SDA<--> Analog Input 4
#define I2C_Write Wire.write
#define I2C_Read Wire.read
prog_char zeroRTC[] PROGMEM  = "0";
prog_char virGula[] PROGMEM  = " , ";
prog_char exTensao[] PROGMEM = ".csv";
prog_char noMes_0[] PROGMEM = "";
prog_char noMes_1[] PROGMEM = "Jan";
prog_char noMes_2[] PROGMEM = "Fev";
prog_char noMes_3[] PROGMEM = "Mar";
prog_char noMes_4[] PROGMEM = "Abr";
prog_char noMes_5[] PROGMEM = "Mai";
prog_char noMes_6[] PROGMEM = "Jun";
prog_char noMes_7[] PROGMEM = "Jul";
prog_char noMes_8[] PROGMEM = "Ago";
prog_char noMes_9[] PROGMEM = "Set";
prog_char noMes_10[] PROGMEM = "Out";
prog_char noMes_11[] PROGMEM = "Nov";
prog_char noMes_12[] PROGMEM = "Dez";
PROGMEM const char* noMes[] = {
  noMes_0, noMes_1, noMes_2, noMes_3, noMes_4, noMes_5, noMes_6, noMes_7, noMes_8, noMes_9, noMes_10,
  noMes_11, noMes_12};
prog_char ficheiroIndex[] PROGMEM = "i.htm";
prog_char ficheiroTanque[] PROGMEM = "t.jpg";
prog_char ficheiroBorder[] PROGMEM = "b.jpg";
prog_char ficheiroFavicon[] PROGMEM = "f.ico";
PROGMEM const char* fichPag[] = {
  ficheiroIndex, ficheiroTanque, ficheiroBorder, ficheiroFavicon};
byte segundo, minuto, hora, diaSemana, diaMes, mes, ano;
char nomeMes[10];
char ficheiroLer[10];
unsigned int dadosAgua = 0;
float dadosBat = 0.0;
float percentagem = 0;
unsigned long litros = 0;
byte mac[] = {
  0x80, 0xA2, 0xDA, 0x00, 0xEA, 0x8C };
byte ip[] = {
  10, 45, 198, 30 };
const byte BUFSIZ = 64;
EthernetServer server = EthernetServer(80);
EthernetClient client;
Sd2Card card;
SdVolume volume;
SdFile root;
SdFile file;
#define error(s) error_P(PSTR(s))
void error_P(const char* str) {
  PgmPrint("Erro: ");
  SerialPrintln_P(str);
  if (card.errorCode()) {
    PgmPrint("Erro cart.SD: ");
    Serial.print(card.errorCode(), HEX);
    Serial.print(',');
    Serial.println(card.errorData(), HEX);
  }
  digitalWrite(ledInfo, HIGH);
  while(1);
}
void setup() {
  Serial.begin(9600);
  delay(100);
  pinMode(ledInfo, OUTPUT);
  pinMode(ledRececao, OUTPUT);
  pinMode(10, OUTPUT);
  Wire.begin();
  digitalWrite(ledInfo, HIGH);
  digitalWrite(ledRececao, HIGH);
  digitalWrite(10, HIGH);
  delay(1000);
  digitalWrite(ledInfo, LOW);
  digitalWrite(ledRececao, LOW);
  PgmPrint("RAM: ");
  Serial.println(FreeRam());
  if (!card.init(SPI_FULL_SPEED, 4)) error("Erro Init cart.SD!");
  if (!volume.init(&card)) error("Erro vol cart.SD!");
  if (!root.openRoot(&volume)) error("Erro root cart.SD!");
  Ethernet.begin(mac, ip);
  server.begin();
  delay(100);
  vw_set_rx_pin(pinoRececao);
  vw_setup(2000);
  vw_rx_start();
  for (int i = 0; i<3; i++) {
    digitalWrite(ledInfo, HIGH);
    delay(250);
    digitalWrite(ledInfo, LOW);
    delay(250);
  }
  Serial.println(F("Config concl"));
}
void loop() {
  actDataHora();
  rececaoRF();
  clienteLigado();
}
void actDataHora() {
  Wire.beginTransmission(DS1307_I2C_Endereco);
  I2C_Write(0x00);
  Wire.endTransmission();
  Wire.requestFrom(DS1307_I2C_Endereco, 7);
  segundo  = bcdToDec(I2C_Read() & 0x7f);
  minuto   = bcdToDec(I2C_Read());
  hora     = bcdToDec(I2C_Read() & 0x3f);
  diaSemana= bcdToDec(I2C_Read());
  diaMes   = bcdToDec(I2C_Read());
  mes      = bcdToDec(I2C_Read());
  ano      = bcdToDec(I2C_Read());
}
byte bcdToDec(byte val)
{
  return ((val/16*10) + (val%16));
}
void rececaoRF() {
  char mensagem[6];
  byte buf[VW_MAX_MESSAGE_LEN];
  byte buflen = VW_MAX_MESSAGE_LEN;
  if (vw_get_message(buf, &buflen)) {
    digitalWrite(ledRececao, HIGH);
    Serial.println(FreeRam()); //PARA APAGAR. SO TESTE
    for (int j = 0; j<buflen; j++) {
      mensagem[j] = buf[j];
    }
    if (mensagem[0] == 'R') {
      dadosAgua = atoi(&mensagem[1]);
    }
    else if (mensagem[0] == 'B') {
      dadosBat = atof(&mensagem[1]);
    }
    memset(&buf, 0, sizeof(buf));
    memset(&mensagem, 0, sizeof(mensagem));
    calcAgua();
    gravarDados();
    digitalWrite(ledRececao, LOW);
  }
}
void calcAgua() {
  percentagem = ((465-dadosAgua)*100)/465;
  litros = ((465-dadosAgua)*600000)/465;
}
void gravarDados() {
  char ficheiroLog[8];
  char zero;
  char virg;
  strcpy_P(nomeMes, (char*)pgm_read_word(&(noMes[mes])));
  sprintf(ficheiroLog,"%s.csv", nomeMes);
  zero = pgm_read_byte_near(zeroRTC);
  virg = pgm_read_byte_near(virGula);
  boolean Log = false;
  Log = file.open(&root, ficheiroLog, O_WRITE | O_APPEND);
  if (Log){
    file.print(diaMes, DEC);
    file.print(" ");
    file.print(nomeMes);
    file.print(" ");
    file.print("20");
    if (ano < 10) {
      file.print(zero);
    }
    file.print(ano, DEC);
    file.print(virg);
    if (hora < 10) {
      file.print(zero);
    }
    file.print(hora, DEC);
    file.print(":");
    if (minuto < 10) {
      file.print(zero);
    }
    file.print(minuto, DEC);
    file.print(":");
    if (segundo < 10) {
      file.print(zero);
    }
    file.print(segundo, DEC); 
    file.print(virg);
    file.print(percentagem, 1);
    file.print(virg);
    file.println(litros);
    file.close();
    Log = false;
  }
  else {
    Serial.println(F("ERRO grav LOG!"));
  }
}
23  Using Arduino / Programming Questions / Program Compiles but doesn't run at 100% on: April 30, 2013, 05:37:22 pm
Hello my sketch compiles well with no error, but when it is running it keeps restarting the arduino. I thought (think) that the problem is because it runs out of memory and then i'v put som char arrays into PROGMEM and used the F() macro too to free more memory, but it still doesn't works good. I don't know what to do more and i ask you some help to confirm if it is memory problem or any other thing.
My sketch is below.
Thanks in advance!
24  Using Arduino / Programming Questions / Re: Lack of SRAM memory on: April 23, 2013, 08:45:05 pm
you're right i know that but write it wrong...  smiley-red
25  Using Arduino / Programming Questions / Re: How to put const char in sprintf func on: April 23, 2013, 08:35:17 pm
variable is a char array, file i want it to be a const char that will be in progmem and var is another char array.
I would like to put it something like: sprintf(char array to store, "%s[const char in progmem]", mychar) the final char array must be like    mychar.const char in progmem

Thanks for reply
26  Using Arduino / Programming Questions / How to put const char in sprintf func on: April 23, 2013, 08:23:00 pm
How do i put (if possible) a const char like char mychar = "weee" into the sprintf function like
Quote
sprintf(variable,"%s.file", var);
where where it is file change it by mychar.

Thanks
27  Using Arduino / Programming Questions / Re: Lack of SRAM memory on: April 23, 2013, 06:03:15 pm
I've done this:
Code:
prog_char ficheiroIndex[] PROGMEM = "i.htm";
prog_char ficheiroTanque[] PROGMEM = "t.jpg";
prog_char ficheiroBorder[] PROGMEM = "b.jpg";
prog_char ficheiroFavicon[] PROGMEM = "f.ico";
PROGMEM const char* fichPag[] = {
  ficheiroIndex, ficheiroTanque, ficheiroBorder, ficheiroFavicon};
char* ficheiroLer;
So the char array will be stored in progmem.


And for log file i've done this:
Code:
else if (strstr(clientline, "GET /&logg") != 0) {
          
          char carMes = clientline[10];
          byte num = atoi(&carMes);
          if (num > 0 && num<10) {
            strcpy_P(nomeMes, (char*)pgm_read_word(&(noMes[carMes - '0'])));
            sprintf(ficheiroLer,"%s.csv", nomeMes);  <------- printing nomeMes before this line returns Jan as expected
            Serial.println(ficheiroLer);  <-------- This isn't printed and arduino restarts...
          }
          else {
          switch (carMes) {
          case 'o':
            strcpy_P(nomeMes, (char*)pgm_read_word(&(noMes[10])));
            sprintf(ficheiroLer,"%s.csv", nomeMes);
            break;
          case 'n':
            strcpy_P(nomeMes, (char*)pgm_read_word(&(noMes[11])));
            sprintf(ficheiroLer,"%s.csv", nomeMes);
            break;
          case 'd':
            strcpy_P(nomeMes, (char*)pgm_read_word(&(noMes[12])));
            sprintf(ficheiroLer,"%s.csv", nomeMes);
            break;
          }
          }
          headerRespostaHttp();
          client.print(F("Content-Disposition: attachment; filename=\"LOG_\""));
          //client.print(ficheiroLer);
          //client.println(F("\""));
          client.println();
          lerFicheiroCartao();
        }

But when it receives GET /&logg1  (for example) arduino restarts. FreeRam() tells me that it has 925 bytes of memory, because i've comment almost the entire program to see if this part works, but it restarts...
28  Using Arduino / Programming Questions / Re: Lack of SRAM memory on: April 23, 2013, 03:52:32 pm
Wich is the best way to save RAM? I've putted the month char array to progmem already
29  Using Arduino / Programming Questions / Re: Lack of SRAM memory on: April 23, 2013, 03:43:50 pm
I realize that i have a problem using
Quote
sprintf(ficheiroLer,"%s.csv", noMes[carmes - '0' + 1]);
because i have 12 log files -> one for each month <- and i'm expecting to receive &logg1 (for Jan), &logg2 (for Feb) ... until &logg9 (for Sep) and because i'm looking only to position 10:
Quote
char carMes = clientline[10];
  i've put &loggo (for Oct), &loggn (for Nov) and &loggd (for December). So that function will not work for the last 3 months.
It's possible to do something like char carMes be equal to position 10 and 11 of clientline and then naming &logg from 01 to 12 for this function to work?
30  Using Arduino / Programming Questions / Re: Lack of SRAM memory on: April 23, 2013, 01:40:32 pm
dc42 thank you very much, i will look to do what you have recommended.
Quote
3. You use the same string literal several times, for example ".csv", "%s%s" and " , ". Depending on whether gcc is performing string pooling or not, you might save memory by naming string literals that you use more than once.
You're telling to use like
Code:
char name[]=".csv"
and everytime i need to "write" that i point to "name" char. Is this?


AWOL ok i've understanding it now. So... looking to dc42 comment i suppose that i can put your ideas in the function, and it will look like:
Code:
sprintf(ficheiroLer,"%s.csv", noMes[carmes - '0' + 1]);
It's good like that?

(sorry for my english but it is not my native language)

Thanks for helping me!
Pages: 1 [2] 3 4 ... 8