Show Posts
|
|
Pages: 1 2 3 [4] 5 6 7
|
|
46
|
Using Arduino / Programming Questions / Program to clear files from root when SD Card is full
|
on: April 03, 2013, 07:51:29 am
|
|
Hello, is it possible to code something like when SD Card is full, clear specified files in the root to get some space? I've been searching for something like this but i can't find nothing that talks about it. If possible can you please show me an example to see the schematic to how to do it?
Thanks in advance!
|
|
|
|
|
51
|
Using Arduino / Programming Questions / Re: Help debugging client connected ethernet shield
|
on: March 11, 2013, 12:57:58 pm
|
I'm having this on serial monitor... Memoria RAM Livre: 284 O volume e FAT16
Ficheiros na raiz do cartao: IFRAME.HTM 2013-02-04 17:01:50 816 INDEX.HTM 2013-03-11 17:19:04 10934 TANQUE.JPG 2013-01-30 17:23:20 73287 2IFRAME.HTM 2013-02-04 16:57:22 359 BORDER.JPG 2013-02-01 13:44:54 110590 &LOGG.TXT 2013-03-01 14:13:58 9338 FAVICON.ICO 2013-01-17 19:48:32 4150
Ficheiros encontrados em todos os directorios do cartao: IFRAME.HTM INDEX.HTM TANQUE.JPG 2IFRAME.HTM BORDER.JPG &LOGG.TXT FAVICON.ICO
Concluida a inicializacao do Cartao SD Escrita do header no ficheiro LOG concluida! Configuracao Concluida GET P Concluida GET / HTTP/1,\( E,§ @G Ãfiguracao Concluida GET / HTTP/1,\( E,§ @G Ãfiguracao Concluida GET / HTTP/1,\( E,§ @G Ãfiguracao Concluida GET / HTTP/1,\( E,§ @G Ãfiguracao Concluida GET / HTTP/1,\( E,§ @G Ãfiguracao Concluida GET / HTTP/1,\( E,§ @G Ãfiguracao Concluida GET / HTTP/1,\( E,§ @G Ãfiguracao Concluida GET / HTTP/1,\( E,§ @G Ãfiguracao Concluida GET / HTTP/1,\( E,§ @G Ãfiguracao Concluida
...Memoria RAM Livre: 284 O volume e FAT16
Ficheiros na raiz do cartao: IFRAME.HTM 2013-02-04 17:01:50 816 INDEX.HTM 2013-03-11 17:19:04 10934 TANQUE.JPG 2013-01-30 17:23:20 73287 2IFRAME.HTM 2013-02-04 16:57:22 359 BORDER.JPG 2013-02-01 13:44:54 110590 &LOGG.TXT 2013-03-01 14:13:58 9384 FAVICON.ICO 2013-01-17 19:48:32 4150
Ficheiros encontrados em todos os directorios do cartao: IFRAME.HTM INDEX.HTM TANQUE.JPG 2IFRAME.HTM BORDER.JPG &LOGG.TXT FAVICON.ICO
Concluida a inicializacao do Cartao SD Escrita do header no ficheiro LOG concluida! Configuraciguracao Con
As you can see, Ethernet shield restarts a lot of time and browser stays like "thinking" and stays this for a long time...
|
|
|
|
|
52
|
Using Arduino / Programming Questions / Re: Help debugging client connected ethernet shield
|
on: March 11, 2013, 12:42:15 pm
|
OK, i think this forum has good vibes! Meanwhile i've just discovered the issue... i have to put EthernetServer server = EthernetServer(80); and char* ficheiroLer; must be a global variable because of lerFicheiroCartao(); function... but compiler doesn't give me any error code. and now it is working... that part! I'm experienced that when arduino is given the index.htm file and images it resets a lot of times, and some of them are not displayed on browser...
|
|
|
|
|
53
|
Using Arduino / Programming Questions / Re: Help debugging client connected ethernet shield
|
on: March 11, 2013, 11:36:15 am
|
void clienteLigado() { char clientline[BUFSIZ]; char* ficheiroLer; int index = 0; Serial.println(F("variaveis feito")); client = server.available(); Serial.println(F("client server available feito")); if (client) { Serial.println(F("Cliente ligado-------------------------")); 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); digitalWrite(ledInfo, HIGH); delay(1); digitalWrite(ledInfo, LOW); if (strstr(clientline, "GET / ") != 0) { client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println(); ficheiroLer = ficheiroIndex; lerFicheiroCartao(); } else if (strstr(clientline, "GET /tanque") != 0) { client.println("HTTP/1.1 200 OK"); client.println("Content-Type: image/jpeg"); client.println(); ficheiroLer = ficheiroTanque; lerFicheiroCartao(); } else if (strstr(clientline, "GET /border") != 0) { client.println("HTTP/1.1 200 OK"); client.println("Content-Type: image/jpeg"); client.println(); ficheiroLer = ficheiroBorder; lerFicheiroCartao(); } else if (strstr(clientline, "GET /rodape") != 0) { client.println("HTTP/1.1 200 OK"); client.println("Content-Type: image/jpeg"); client.println(); ficheiroLer = ficheiroRodape; lerFicheiroCartao(); } else if (strstr(clientline, "GET /iframe") != 0) { client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println(); ficheiroLer = ficheiroIframe; lerFicheiroCartao(); client.println(F("<html><body>")); client.println(F("<div id=\"outer\">")); client.print(F("<div id=\"inner\" style=\"height:")); client.print(percentagem, 1); client.println(F("%\">")); client.println(F("</div></div>")); client.println(F("</p></body></html>")); } else if (strstr(clientline, "GET /2iframe") != 0) { client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println(); ficheiroLer = ficheiro2Iframe; lerFicheiroCartao(); client.println(F("<html><body>")); if (percentagem >= 90 || percentagem <=10){ client.println(F("<table width=\"210\" height=\"42\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\">")); client.println(F("<tr>")); client.print(F(" <td width=\"69\" height=\"40\" class=\"iframe2\"><div align=\"center\"><b><font color=#E60000>")); client.print(percentagem, 1); client.println(F("%</font></b></div></td>")); client.print(F("<td width=\"134\" class=\"iframe2\"><div align=\"center\"><b><font color=#E60000>")); client.print(litros); client.print(F("</font></b></div></td>")); client.println(F("</tr>")); client.println(F("</table>")); client.println(F("</p></body></html>")); } else { client.println(F("<table width=\"210\" height=\"42\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\">")); client.println(F("<tr>")); client.print(F(" <td width=\"69\" height=\"40\" class=\"iframe2\"><div align=\"center\"><b>")); client.print(percentagem, 1); client.println(F("%</b></div></td>")); client.print(F("<td width=\"134\" class=\"iframe2\"><div align=\"center\"><b>")); client.print(litros); client.print(F("</b></div></td>")); client.println(F("</tr>")); client.println(F("</table>")); client.println(F("</p></body></html>")); } } else if (strstr(clientline, "GET /&logg") != 0) { client.println("HTTP/1.1 200 OK"); client.println("Content-Disposition: attachment; filename=\"Ficheiro_LOG_Tanque.txt\""); client.println(); ficheiroLer = ficheiroLog; lerFicheiroCartao(); } else { client.println("HTTP/1.1 404 Not Found"); client.println("Content-Type: text/html"); client.println(); client.println("<h2>Erro 404</h2>"); client.println("<s2>O caminho ou ficheiro especificado nao existe.<s2>"); client.println(""); } break; } } digitalWrite(ledInfo, HIGH); delay(1); digitalWrite(ledInfo, LOW); delay(2); client.stop(); } Serial.println(F("ClienteLigado Concluida")); }
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(); ficheiroLer = '\0'; } Serial.println(F("LerFicheiroCartao Concluida")); }
Because the code is a little big i had to put it in two parts... Many Serial.println was there for me to try to find the issue. Many thanks in advance!
|
|
|
|
|
54
|
Using Arduino / Programming Questions / Help debugging client connected ethernet shield [SOLVED]
|
on: March 11, 2013, 11:35:04 am
|
Hello, need your help again debugging an issue that is driving me crazy... I can't get the code to pass the IF (client) statement when there is a client connected to the ip adress of ethernet shield. i've done a lot of debugging but i can't see why... could you please look at my code and tell me what is wrong? #include <SPI.h> #include <SdFatUtil.h> #include <Ethernet.h> #include <VirtualWire.h>
//DECLARAÇÃO DOS PINOS const byte ledInfo = 2; const byte ledRececao = 3; const byte pinoRececao = 8; const byte BUFSIZ = 128;
//DECLARAÇÃO DAS VARIÁVEIS GLOBAIS char mensagem[5]; unsigned int dadosAgua = 0; float dadosBat = 0; //confirmar se é melhor float ou int float percentagem = 0; unsigned long litros = 0; unsigned int nrLeitura = 1; boolean Log = false;
//CONFIGURAÇÃO DO ETHERNET SHIELD byte mac[] = {0x80, 0xA2, 0xDA, 0x00, 0xEA, 0x8C}; IPAddress ip = (196, 168, 0, 3); char ficheiroIndex[] = "index.htm"; char ficheiroLog[] = "&logg.txt"; char ficheiroTanque[] = "tanque.jpg"; char ficheiroBorder[] = "border.jpg"; char ficheiroRodape[] = "rodape.jpg"; char ficheiroIframe[] = "iframe.htm"; char ficheiro2Iframe[] = "2iframe.htm"; char* ficheiroLer = '\0'; EthernetServer server(80); EthernetClient client;
//PROGRAMAÇÃO DO CARTÃO SD Sd2Card card; SdVolume volume; SdFile root; SdFile file; SdFile LOGfile;
//ARMAZENA SEQUÊNCIAS DE ERRO NA MEMÓRIA FLASH PARA ECONOMIZAR RAM #define error(s) error_P(PSTR(s)) void error_P(const char* str) { PgmPrint("Erro: "); SerialPrintln_P(str); if (card.errorCode()) { PgmPrint("Erro cartao 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);
//LIGA E DESLIGA OS 2 LEDS PARA INDICAR QUE ESTÃO OPERACIONAIS digitalWrite(ledInfo, HIGH); digitalWrite(ledRececao, HIGH); digitalWrite(10, HIGH); delay(1000); digitalWrite(ledInfo, LOW); digitalWrite(ledRececao, LOW);
PgmPrint("Memoria RAM Livre: "); Serial.println(FreeRam());
//INICIALIZA O CARTÃO SD EM "FULL SPEED", MÁXIMO DESEMPENHO. (PARA EVITAR ERROS COM LIGAÇÃO À BREADBOARD DEVE ESTAR EM "HALF SPEED") if (!card.init(SPI_FULL_SPEED, 4)) error("Falha ao inicializar o Cartão SD!");
//INICIALIZA O VOLUME FAT if (!volume.init(&card)) error("Falha ao inicializar Volume do Cartão SD!"); PgmPrint("O volume e FAT"); Serial.println(volume.fatType(),DEC); Serial.println();
//LISTA NA SÉRIE OS FICHEIROS QUE ESTÃO NA RAIZ DO CARTÃO SD, COM DATA E TAMANHO if (!root.openRoot(&volume)) error("Falha ao abrir raiz do cartao!"); PgmPrintln("Ficheiros na raiz do cartao:"); root.ls(LS_DATE | LS_SIZE); Serial.println();
//LISTA OS FICHEIROS DE TODOS OS DIRECTÓRIOS DO CARTÃO SD PgmPrintln("Ficheiros encontrados em todos os directorios do cartao:"); root.ls(LS_R); Serial.println(); PgmPrintln("Concluida a inicializacao do Cartao SD");
//ESCREVE O CABEÇALHO DO FICHEIRO DE DATALOGGER Log = file.open(&root, ficheiroLog, O_WRITE | O_APPEND); if (Log){ file.println("Leitura , Nivel Tanque , Quantidade Agua"); file.close(); Serial.println(F("Escrita do header no ficheiro LOG concluida!")); } else{ Serial.println(F("ERRO! Nao foi possivel abrir o ficheiro LOG."));
//SE NÃO CONSEGUIR ABRIR O FICHEIRO LOG, LED FICA A PISCAR PARA INDICAR AVARIA while(true) { digitalWrite(ledInfo, HIGH); delay(1000); digitalWrite(ledInfo, LOW); delay(1000); } }
//INICIA O SERVIDOR Ethernet.begin(mac, ip); server.begin(); delay(100);
//CONFIGURA E INICIA O RECEPTOR vw_set_rx_pin(pinoRececao); vw_setup(2000); vw_rx_start();
//LED PISCA 3 VEZES A INDICAR TODA A CONFIGURAÇÂO CONCLUÍDA COM SUCESSO for (int i = 0; i<3; i++) { digitalWrite(ledInfo, HIGH); delay(250); digitalWrite(ledInfo, LOW); delay(250); } Serial.println(F("Configuracao Concluida")); }
void loop() {
rececaoRF(); clienteLigado(); }
//RECEPÇÃO DOS DADOS POR RF 433MHz void rececaoRF() {
byte buf[VW_MAX_MESSAGE_LEN]; byte buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) { digitalWrite(ledRececao, HIGH); for (int j = 0; j<buflen; j++) { mensagem[j] = buf[j]; } if (mensagem[0] == 'R') { dadosAgua = atoi(&mensagem[1]); percentAgua(); } else if (mensagem[0] == 'B') { dadosBat = atoi(&mensagem[1]); litrosAgua(); } Serial.print(F("Mensagem Recebida: ")); Serial.println(mensagem); memset(&buf, 0, sizeof(buf)); memset(&mensagem, 0, sizeof(mensagem)); gravarDados(); } Serial.println(F("RececaoRF Concluida")); }
void percentAgua() { percentagem = ((465-dadosAgua)*100)/465; Serial.print(F("Percentagem: ")); Serial.println(percentagem); }
void litrosAgua() { litros = ((465-dadosAgua)*700000)/465; Serial.print(F("Litros: ")); Serial.println(litros); }
void gravarDados() { Log = file.open(&root, ficheiroLog, O_WRITE | O_APPEND); if (Log){ file.print(nrLeitura); file.print(" , "); file.print(percentagem, 1); file.print(" , "); file.println(litros); file.close(); Serial.println(F("Valores gravados com sucesso!")); nrLeitura++; Log = false; } else { Serial.println(F("ERRO ao gravar dados no ficheiro LOG!")); } }
|
|
|
|
|
57
|
Using Arduino / Programming Questions / Void Functions and Jumps
|
on: March 08, 2013, 05:02:30 am
|
Hello, i've already readed the functions section on the reference page of arduino, but i still have some doubts about it. I really don't understand how the program flows (jumps and returns) to the loop function. I want to make something like this: void loop() { functionReceiveMsg(); //All the stuff to receive the sensor reading with VirtualWire library funcionDataConversion(); //To make some percentage of values and conversions (maths) funcionClientOnline(); //To provide an html page to client (with Ethernet Shield) to client when requested }
void functionReceiveMsg() { ... receive message code }
int funcionDataConversion() { ... data conversion and maths }
void funcionClientOnline() { ... Ethernet client stuff }
void htmlSdRead() { ...when it provides html pages from sd card to client it jumps to here } My questions are: 1- If i change functionReceiveMsg(); with funcionClientOnline(); position in void loop() it makes any difference? 2- When program jumps to function it will return to void loop() position where it jumped or to the end of void loop()? 3- How can i return from int funcionDataConversion() two values: data percentage and battery level (for example)? 4- When it jumps to void htmlSdRead() it will read file from sd card and client.print it, after that it will continue the void funcionClientOnline() in the poinst where it jumped or return to void loop()? 5- Can you provide me any webpage that explains the jumps, voids and anything ralation to this and arduino for me to read and understand? Thanks in advance!
|
|
|
|
|
58
|
Topics / Home Automation and Networked Objects / Re: Avoid strange characters from serial buffer
|
on: March 01, 2013, 05:57:13 pm
|
|
Thanks it's always good to know another and better options. In my case and because i'm expecting only receive data from sensor and since there is at least 5 bytes in serial buffer, the sensor is disabled i will not receive no other data after that, but sure that the options you gave are more efficient and prevents this possible issue that for loop have if data is received after var gets the number of bytes of serial buffer at that time.
|
|
|
|
|
59
|
Topics / Home Automation and Networked Objects / Re: Avoid strange characters from serial buffer
|
on: March 01, 2013, 02:39:26 pm
|
I've made it. After a lots of tests i could make the code get always good readings. For people who may have this issue i let the new code here: #include <SPI.h> #include <VirtualWire.h> #define TEMPO_LIMITE 200 //Tempo de espera por dados na serie
//DECLARAÇÃO DAS VARIÁVEIS GLOBAIS //ENABLE/DISABLE PARA O SENSOR const int sensor = 7;
//LED'S const int ledTransmissao = 4; const int ledActivacao = 5;
//ENABLE/DISABLE DO TRANSMISSOR E PINO DE TRANSMISSÃO const int pinoTransmissao = 8; const int pinoActTransm = 3;
//VARIÁVEL QUE GUARDA A MENSAGEM A TRANSMITIR char mensagem[5];
//VARIÁVEIS PARA DADOS LIDOS DO SENSOR int dados; char buffer[4]; boolean estado = false; unsigned long inicioContagem; unsigned char limpezaSerial;
void setup(){ //DEFINIÇÃO DOS PINOS DE ENTRADA E DE SAÍDA pinMode(sensor, OUTPUT); pinMode(ledTransmissao, OUTPUT); pinMode(ledActivacao, OUTPUT); digitalWrite(sensor, LOW); //digitalWrite(pinoActTransm, LOW); digitalWrite(ledTransmissao, LOW); digitalWrite(ledActivacao, LOW); //CONFIGURAÇÃO DO VIRTUALWIRE -TRANSMISSÃO- vw_set_tx_pin(pinoTransmissao); vw_set_ptt_pin(pinoActTransm); vw_setup(2000); //VELOCIDADE DE TRANSMISSÃO DE 2000 BITS POR SEGUNDO
//INICIAR A UART PARA DEBUG Serial.begin(9600); delay(1000); }
void loop() { //ENABLE DO SENSOR E LED DE ACTIVAÇÃO LIGADO
digitalWrite(sensor, HIGH); digitalWrite(ledActivacao, HIGH); //LEITURA DOS DADOS ENVIADOS PELO SENSOR inicioContagem = millis(); while ((Serial.available () < 5) && ((millis() - inicioContagem) < TEMPO_LIMITE)) { //Espera que o buffer tenha pelo menos 5 bytes para ler e que não demore mais que 1 segundo } if (Serial.available() < 5) { Serial.println("Nao foram recebidos 5 bytes de dados"); delay(5000); } else { digitalWrite(sensor, LOW); digitalWrite(ledActivacao, LOW); char c = Serial.read(); if (c == 'R') { Serial.readBytesUntil ('\r', &buffer[0], 4); dados = atoi (buffer); //CONVERSÃO DOS DADOS RECEBIDOS PARA VALORES INTEIROS //ENVIO PARA A SÉRIE DO VALOR, PARA DEPURAÇÃO Serial.print("BUFFER:"); Serial.print(buffer); Serial.print(" "); Serial.print("DADOS:"); Serial.println(dados); memset(&buffer, 0, sizeof(buffer)); //LIMPEZA DO BUFFER Serial.print("BUFFER:"); Serial.println(buffer); /*VERIFICAÇÃO SE OS DADOS RECEBIDOS DO SENSOR SÃO VÁLIDOS. O MÁXIMO VALOR É 465 -ALTURA MÁXIMA DA ÁGUA- E O MÍNIMO É ZERO -TANQUE VAZIO-*/ if(dados >= 1 && dados <= 465) { mensagem[0] = 'R'; itoa (dados, &mensagem[1], 10); Serial.print("MENSAGEM A TRANSMITIR:"); Serial.println(mensagem); //LED DE TRANSMISSÃO ACTIVA LIGADO digitalWrite(ledTransmissao, HIGH);
//ENVIO DA MENSAGEM 2 VEZES PARA GARANTIR QUE É RECEBIDA for (int i = 0; i<2; i++) { vw_send ((uint8_t*)mensagem, strlen(mensagem)); //ENVIO DA MENSAGEM vw_wait_tx(); //ESPERA QUE MENSAGEM SEJA TOTALMENTE ENVIADA delay(2000); } digitalWrite(ledTransmissao, LOW); memset(&mensagem, 0, sizeof(mensagem)); //LIMPA O BUFFER DA MENSAGEM ENVIADA } //LED DE TRANSMISSÃO ACTIVA DESLIGADO Serial.print("MENSAGEM:"); Serial.println(mensagem); delay(5000); } } limpezaSerial = Serial.available(); for (int s=limpezaSerial; s>=0; s--) { Serial.read(); } }
/*End of Program*/ I had two wrong things. The first was the char array "Buffer" that only had 3 bytes and it needed 4 bytes (i have ever this problem of calculating the number of vectors needed  ); The second was the Serial.readBytesUntil function that was only reading 3 bytes and needed to read 4. The last was the Serial.flush that i thought that was clearing the serial buffer, but it was changed since version 1.0 of IDE, so i cleared it this way: limpezaSerial = Serial.available(); for (int s=limpezaSerial; s>=0; s--) { Serial.read(); } Cheers!
|
|
|
|
|