Ir ao conteúdo
  • Cadastre-se

nickmetin9

Membro Pleno
  • Posts

    358
  • Cadastrado em

  • Última visita

Reputação

1
  1. ola estou montando uma central web de acionamentos de rele com o ethernet shield porém estou com algumas dificuldades 1 o arquivo index.htm esta no cartao sd (isso consegui resolver tranquilo) 2 pensei em ultilizar o metodo de formulario get pra poder controlar o funcionamento das portas porém nao consegui a url é gerada no navegador porém o arduino não faz a leitura do mesmo ja consegui aplicar este metodo apenas quando o html esta dentro da memoria do arduino e nao no sd card e logo nao aciona nen uma porta ja vi varios tutoriais porém nao comsegui aplicalos no meu projeto logo a baixo tem o codigo do projeto deste ja agradeço #include <SPI.h> #include <Ethernet.h> #include <SD.h> String readString; int buzer = 7; int rele8 = 8; /********************************************************************************** ********************************FIM BIBLIOTECAS************************************ **********************************************************************************/ /********************************************************************************** *************************ROTINAS USUARIO E SENHA*********************************** ***********************************************************************************/ boolean validar_usuario(char * linebuf) { /* nesse exemplo o usuario e senha estão definidos dentro do código fonte. mas o usuário e senha poderiam ser autenticados de diversas maneiras, lendo os dados de um servidor web, arquivo texto, etc, bastando apenas atribuir o valor lido para a variável usuario_senha. */ char usuario_senha[] = "admin:123"; //usuario e senha para acessar a pagina byte t = strlen(usuario_senha); int tamanhoEnc = (((t-1) / 3) + 1) * 4; //tamanho da string codificada char out[tamanhoEnc]; char out2[tamanhoEnc]; for (t=0; t<(tamanhoEnc); t++) { out2[t] = linebuf[21+t]; } return (strstr(out2, out)>0); } /********************************************************************************** *************************FIM ROTINA USUARIO E SENHA******************************** ***********************************************************************************/ /**************************************************************************************** ****************************SD CARD INICIO*********************************************** ****************************************************************************************/ #define PIN_SD_CARD 4 boolean iniciar_sd_card() { pinMode(10, OUTPUT); digitalWrite(10, HIGH); if (!SD.begin(PIN_SD_CARD)) { return false; } return true; } /**************************************************************************************** ****************************SD CARD FIM************************************************** ****************************************************************************************/ /********************************************************************************** ***********************************PAGINAS HTML************************************ ***********************************************************************************/ EthernetServer * server; void write_from_file(EthernetClient &client, char * filename){ File webFile = SD.open(filename); if (webFile) { while(webFile.available()) { client.write(webFile.read()); } webFile.close(); } else { Serial.print("Erro SD CARD: "); Serial.println(filename); } } void iniciar_ethernet_01(){ byte ip[4] = {192,168,1,190}; //definir aqui o ip byte gateway[4] = {192,168,200,254}; byte subnet[4] = {255,255,255,0}; byte mac[6] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; int porta = 80; server = new EthernetServer(porta); Ethernet.begin(mac, ip, gateway, subnet); //caso necessario gateway utilizar essa linha server->begin(); }void iniciar_ethernet() { //escolher apenas um dos dois modos de iniciar o ethernet shield iniciar_ethernet_01(); //inicia com ip, gateway, mascara e porta //iniciar_ethernet_02(); //inicia só com ip e porta } void html_logoff(EthernetClient &client){ client.print(F( "HTTP/1.1 401 Authorization Required\n" "Content-Type: text/html\n" "Connnection: close\n\n" "<!DOCTYPE HTML>\n" "<html><head><title>Logoff</title>\n" "<script>document.execCommand('ClearAuthenticationCache', 'false');</script>" //IE logoff "<script>try {" //mozila logoff " var agt=navigator.userAgent.toLowerCase();" " if (agt.indexOf(\"msie\") != -1) { document.execCommand(\"ClearAuthenticationCache\"); }" " else {" " var xmlhttp = createXMLObject();" " xmlhttp.open(\"GET\",\"URL\",true,\"logout\",\"logout\");" " xmlhttp.send(\"\");" " xmlhttp.abort();" " }" " } catch(e) {" " alert(\"erro ao fazer logoff\");" " }" "function createXMLObject() {" " try {if (window.XMLHttpRequest) {xmlhttp = new XMLHttpRequest();} else if (window.ActiveXObject) {xmlhttp=new ActiveXObject(\"Microsoft.XMLHTTP\");}} catch (e) {xmlhttp=false;}" " return xmlhttp;" "}</script>" "</head><body><h1>voce nao esta mais conectado</h1></body></html>\n")); } void html_autenticar(EthernetClient &client) { client.print(F("HTTP/1.1 401 Authorization Required\n" "WWW-Authenticate: Basic realm=\"Area Restrita\"\n" "Content-Type: text/html\n" "Connnection: close\n\n" "<!DOCTYPE HTML>\n" "<html><head><title>Error</title>\n" "</head><body><h1>401 Acesso nao autorizado</h1></body></html>\n")); } void html_autenticado(EthernetClient &client, char * filename){ client.println(F("HTTP/1.1 200 OK\n" "Content-Type: text/html\n" "Connection: keep-alive\n")); write_from_file(client, filename); } void js_file(EthernetClient &client, char * filename){ client.println(F("HTTP/1.1 200 OK\n" "Content-Type: text/javascript\n" "Connection: keep-alive\n")); write_from_file(client, filename); } void css_file(EthernetClient &client, char * filename){ client.println(F("HTTP/1.1 200 OK\n" "Content-Type: text/css\n" "Connection: keep-alive\n")); write_from_file(client, filename); } void favicon_file(EthernetClient &client, char * filename){ client.println(F("HTTP/1.1 200 OK\n" "Content-Type: image/x-icon\n" "Connection: keep-alive\n")); write_from_file(client, filename); } void pdf_file_download(EthernetClient &client, char * filename){ client.println(F("HTTP/1.1 200 OK\n" "Content-Type: application/download\n" "Connection: close\n")); write_from_file(client, filename); } void jpg_file(EthernetClient &client, char * filename){ client.println(F("HTTP/1.1 200 OK\n" "Content-Type: file/jpg\n" "Connection: close\n")); write_from_file(client, filename); } void exec_ethernet() { EthernetClient client = server->available(); if (client) { char linebuf[80]; memset(linebuf, 0, sizeof(linebuf)); int charCount = 0; boolean autenticado = false; boolean currentLineIsBlank = true; boolean logoff = false; boolean indCss = false; boolean indJs = false; boolean indPdfDataSheet = false; boolean indJpgUno = false; boolean indJpgUno1 = false; boolean indFavicon = false; while (client.connected()) { if (client.available()) { char c = client.read(); if (readString.length() < 100) { readString += c; } linebuf[charCount] = c; if (charCount<sizeof(linebuf)-1) { charCount++; } Serial.write(c); if (c == '\n' && currentLineIsBlank) { if (autenticado && !logoff ) { if (indJs){ js_file(client, "js.js"); //js file } else if(indCss){ css_file(client, "css.css"); //css file } else if(indPdfDataSheet){ pdf_file_download(client, "atmel.pdf"); //datasheet download } else if(indJpgUno){ jpg_file(client, "uno.jpg"); //jpg file } else if(indJpgUno1){ jpg_file(client, "uno1.jpg"); //jpg file } else if(indFavicon){ jpg_file(client, "favicon.ico"); //icone do browser } else { html_autenticado(client, "index.htm"); //página inicial } } else { logoff ? html_logoff(client) : html_autenticar(client); } break; } if (c == '\n') { currentLineIsBlank = true; if (strstr(linebuf, "GET /logoff" )>0 ) { logoff = true; } if (strstr(linebuf, "Authorization: Basic")>0 ) { if ( validar_usuario(linebuf) ) { autenticado = true; } } if (strstr(linebuf, "GET /css.css" )>0 ) { indCss = true; } if (strstr(linebuf, "GET /js.js" )>0 ) { indJs = true; } if (strstr(linebuf, "GET /atmel.pdf" )>0 ) { indPdfDataSheet = true; } if (strstr(linebuf, "GET /uno.jpg" )>0 ) { indJpgUno = true; } if (strstr(linebuf, "GET /favicon.ico" )>0 ) { indFavicon = true; } memset(linebuf, 0, sizeof(linebuf)); charCount = 0; } else if (c != '\r') { currentLineIsBlank = false; } } } delay(1); client.stop(); } } /********************************************************************************** **************************************** FIM PAGINAS HTML************************** ***********************************************************************************/ /********************************************************************************** *************************BASE 64 CODE/DECODE DO USUARIO E SENHA******************** ***********************************************************************************/ void a3_to_a4(unsigned char * a4, unsigned char * a3); void a4_to_a3(unsigned char * a3, unsigned char * a4); unsigned char b64_lookup(char c); int base64_encode(char *output, char *input, int inputLen) { const char b64_alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; int i=0, j=0, encLen=0; unsigned char a3[3], a4[4]; while(inputLen--) { a3[i++] = *(input++); if(i == 3) { a3_to_a4(a4, a3); for(i=0; i<4; i++) { output[encLen++] = b64_alphabet[a4[i]]; } i = 0; } } if (i) { for(j = i; j < 3; j++) { a3[j] = '\0'; } a3_to_a4(a4, a3); for(j = 0; j < i + 1; j++) { output[encLen++] = b64_alphabet[a4[j]]; } while((i++ < 3)) { output[encLen++] = '='; } } output[encLen] = '\0'; return encLen; } /* int base64_decode(char * output, char * input, int inputLen) { int i = 0, j = 0; int decLen = 0; unsigned char a3[3]; unsigned char a4[4]; while (inputLen--) { if (*input == '=') { break; } a4[i++] = *(input++); if (i == 4) { for (i = 0; i <4; i++) { a4[i] = b64_lookup(a4[i]); } a4_to_a3(a3,a4); for (i = 0; i < 3; i++) { output[decLen++] = a3[i]; } i = 0; } } if (i) { for (j=i; j<4; j++) { a4[j] = '\0'; } for (j=0; j<4; j++) { a4[j] = b64_lookup(a4[j]);} a4_to_a3(a3,a4); for (j=0; j<i-1; j++) { output[decLen++] = a3[j]; } } output[decLen] = '\0'; return decLen; } */ //int base64_enc_len(int plainLen) { // int n = plainLen; // return (n + 2 - ((n + 2) % 3)) / 3 * 4; //} //int base64_dec_len(char * input, int inputLen) { // int i = 0; // int numEq = 0; // for(i = inputLen - 1; input[i] == '='; i--) { numEq++; } // return ((6 * inputLen) / 8) - numEq; //} void a3_to_a4(unsigned char * a4, unsigned char * a3) { a4[0] = (a3[0] & 0xfc) >> 2; a4[1] = ((a3[0] & 0x03) << 4) + ((a3[1] & 0xf0) >> 4); a4[2] = ((a3[1] & 0x0f) << 2) + ((a3[2] & 0xc0) >> 6); a4[3] = (a3[2] & 0x3f); } //void a4_to_a3(unsigned char * a3, unsigned char * a4) { // a3[0] = (a4[0] << 2) + ((a4[1] & 0x30) >> 4); // a3[1] = ((a4[1] & 0xf) << 4) + ((a4[2] & 0x3c) >> 2); // a3[2] = ((a4[2] & 0x3) << 6) + a4[3]; //} unsigned char b64_lookup(char c) { if(c >='A' && c <='Z') return c - 'A'; if(c >='a' && c <='z') return c - 71; if(c >='0' && c <='9') return c + 4; if(c == '+') return 62; if(c == '/') return 63; return -1; } /********************************************************************************** *************************FIM BASE 64 CODE/DECODE DO USUARIO E SENHA**************** ***********************************************************************************/ /********************************************************************************** **************************************** VOID / ****************************** ***********************************************************************************/ void setup() { Serial.begin(9600); iniciar_sd_card(); iniciar_ethernet(); pinMode (buzer, OUTPUT); } void loop() { exec_ethernet(); }
  2. voce nao entendeu em relação ao pir ele nao mede temperatura e sim movimento ,sim se você para de se mover para de dectar logo dispara o alarme o sistema esta funcionando esta apenas gostaria de adicionar uma função extra.. para marcar quanto tempo a luz ficou acesa sem necessidade e sim ja fiz um led piscar
  3. ola tenho um projeto com o arduino onde ele dispara um alarme caso a luz seja esquecida ligada mais gostaria de encrementar um contador onde ele marca por quanto tempo a luz esta ligada sem ter pessoas no local (uso arduino uno, sensor ldr,sensor pir, e um buzzer para emitir um alarme) a ideia e que usar o sensor ldr para registrar a luminosidae(luz acesa) mais o sensor pir(sem pessoas no ambiente) marcar por quanto tempo isso aconteceu para ter um controle melhor dos dados gostaria de saber qual comando usar andei dando uma pesquisada e nao achei nada relacionado pensei em usar ()millis mais ja uso a mesmo para controlar o tempo que demora para o alarme disparar depois de nao tem ninguem no local deste ja muito obrigado
  4. ola eu estou em duvida se minha fonte aguenta essa configuração gtx 570 /560 /hd6870(eu ainda nao comprei porque estou com medo da fonte nao aguentar) processador x4 955 2x2gb kingston 1333 1tb seagete 7200rpm e fonte corsair vx 450
  5. meu caro amigo le a primera pagina do topico e dai re poste da maneira CERTA pois desse modo fica difícil nos avilarmos algo se posivel poste a temp do ambiente tambem
  6. olah cara o teste era de cara famoso o 3dgameman http://www.3dgameman.com/reviews/1080/corsair-h50-cpu-cooler eu achei o teste bom mais os resultatos finais eu achei muito bom para ser verdade rriariariariair ei tipo o h70 tem muita diferensa pro frio desculpa é qeu eu nun mancho nada de wc
  7. cara tipo eu vi um video neu desconfiei um pouco um h 50 ele manteve em full um i7 [email protected] a 40 graus e temp ambiente era de 22 graus sera que é posivel isso mesmo ou é historia pra boi durmi ?
  8. então minha ideia inicial era um h70 mais achei aqui no py so o h 50 mais cara em que temp ambiente esse server fica ? ou intao se tiver um water legal ate uns 200 250 eu topo tambem
  9. cara ele tem um frio mano era pra ta bem mais baixo coisa tipo idle 30 35 full 45 no maxx
  10. olha nao estão ruim levando em consideração a temp ambiente mais se leva em consideração que é um frio tá ruim sim bem é seguinte coloque as ventuina nos 100% faz o teste de novo e manda para nos grato
  11. ola eu estou pensando em comprar um wc eu vi um h 50por 200 reasi no py gostei muito mais minha duvida é sera que o h 50 é melhor que o termaltake frio ? estou com uma duvida enorme alguem ai pode me ajuda rs
  12. olha silencioso tem o ice age e o v8 sendo o ice um pouco melhor nao muito coisa de 2 a 5graus eu iria de v8 mais barato rs a geuntaria seu i5 de boa
  13. voce que sabe cara os dois sao otimos mais sobre essa sua teoria nao condordo muito pois a função do ar nos cooler tipo torre é retirar o ar quente das atelas (ou algo assim ano sei o nome direi mais sao a quelas chapinhas que forma o dissipador) e com o fan no meio ele fai retirar o calor do dissipador mais facill sobre o amigo ai de cima ja conta sim cara mais se voce que quiser fazer um over mais pessado acho que ele nao da nao
  14. o ice age ele bom cara mais tambem tem pouquisima diferensa se for pra espera mais um mes leva logo o frio pois o ice ele é 190 180 e frio 200 210 e o desempenho fai ser melhor
  15. cara so uma coisa nao sei quem falo para ele pega um tx3 bem eu tenho um buffalo (a margen de desempenho dois sao muito paresidos ) quanto eu colocoquei o buffalo foi perfeito tá uns 35 37 graus em idle mais foi chega o verão e bate 35 37 graus ambiente e apara nao deu conta ele mandei meu proc a 47 50 o v8 no caso dele é melhor coisa pois ele ja falou que fai fazer upgrade e o v8 ageunta o i7 de boa sem reclama e ainda mais em salvador que todos aqui sabem que é quente então não adianta melhor gasta um pouco mais agora e ficar de boa do que economizar hoje e gastar o resto e muito mais depois

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...