teste de publish
Dependencies: DS1820 HighSpeedAnalogIn devices mbed
Diff: modem.cpp
- Revision:
- 29:823a9da3696b
- Parent:
- 25:a6da63ed025b
- Child:
- 30:8a06a85d8807
--- a/modem.cpp Mon May 07 23:09:49 2018 +0000 +++ b/modem.cpp Thu May 24 00:42:23 2018 +0000 @@ -115,8 +115,7 @@ uint8_t modemCom::enviaDados() { - uint8_t result=false; - modemCom::status.emComunicacao = true; + uint8_t result=false; pc.printf("modemCom::enviaDados[1].\r\n"); if(!sdCard::preparaEnvio()){ pc.printf("modemCom::enviaDados[2].\r\n"); @@ -170,8 +169,7 @@ } break; case 2: - pc.printf("modemCom::enviaDados[10].\r\n"); - modemCom::status.emComunicacao = false; + pc.printf("modemCom::enviaDados[10].\r\n"); result = false; break; } @@ -228,7 +226,7 @@ pc.printf("Aberto o socket em command mode.\n"); pc.printf("Enviando arquivo com nome %s.\n",nomeArquivo); modemCom::status.serverConnected=1; - modemCom::timeOutModem = 100; + modemCom::timeOutModem = 50; modemCom::status.emComunicacao = true; } else { pc.printf("Nao foi possivel Abrir o socket. Abortando tentativa.\n"); @@ -236,7 +234,8 @@ //Socket aberto, fecho-o antes de partir. modemCom::closeConnection(1); } - modemCom::timeOutModem = 10; + modemCom::timeOutModem = 20; + modemCom::status.emComunicacao = false; return 0; } @@ -268,7 +267,7 @@ headerTam = strlen(header); sprintf(aux,"AT+CIPSEND=1,%u\r\n",headerTam); - if(modemCom::sendToModem(aux,1,&modemCom::status.PROMPT_ENVIO_COMMAND_MODE,NULL,100,10,1)) { + if(modemCom::sendToModem(aux,1,&modemCom::status.PROMPT_ENVIO_COMMAND_MODE,NULL,250,10,1)) { if(!modemCom::sendToModem(header,1,&modemCom::status.SEND_OK,NULL,1000,1,1)) { sdCard::fechaArquivo(arquivo); modemCom::status.emComunicacao = false; @@ -299,7 +298,7 @@ } while((maxTentativas)&&(!passaParaProximaParte)) { sprintf(aux,"AT+CIPSEND=1,%u\r\n",numeroDeBytesPorEnvio); - if(modemCom::sendToModem(aux,1,&modemCom::status.PROMPT_ENVIO_COMMAND_MODE,NULL,100,20,1)) { + if(modemCom::sendToModem(aux,1,&modemCom::status.PROMPT_ENVIO_COMMAND_MODE,NULL,250,20,1)) { if(maxTentativas!=maxRetentativasEnvioParteArquivo) { //Estou realizando reenvio desta parte logo preciso fazer fseek para a quantidade de bytes do envio anterior fseek(arquivo->fp,-numeroDeBytesPorEnvio,SEEK_CUR); @@ -351,7 +350,7 @@ maxTentativas = maxRetentativasEnvioParteArquivo; while((maxTentativas)&&(!passaParaProximaParte)) { sprintf(aux,"AT+CIPSEND=1,%u\r\n",restoDoEnvio+strlen("\r\n--xxBOUNDARYxx--\r\n\r\n")); //Para incluir "\n--xxBOUNDARYxx--\n\n" no fim da msg http - if(modemCom::sendToModem(aux,1,&modemCom::status.PROMPT_ENVIO_COMMAND_MODE,NULL,100,3,1)) { + if(modemCom::sendToModem(aux,1,&modemCom::status.PROMPT_ENVIO_COMMAND_MODE,NULL,500,3,1)) { for(numeroByteSendoEnviado=0; numeroByteSendoEnviado<restoDoEnvio; numeroByteSendoEnviado++) { //Envio os bytes aqui! Menos o ultimo para ter o check; c = fgetc(arquivo->fp); @@ -405,6 +404,7 @@ //modemCom::sendToModem("AT+CIPCLOSE=1\r\n",1,&modemCom::status.OK,500,3); modemCom::closeConnection(1); modemCom::status.emComunicacao = false; + return modemCom::status.ServerAck; } @@ -412,7 +412,7 @@ { uint16_t timeOutProcesso; uint16_t indexString,strLen; //Para exibir retentativas! - + timeOut/=5; while(maxTentativas){ timeOutProcesso=timeOut; @@ -481,15 +481,15 @@ return modemCom::sendToModem(command,1,NULL,",CLOSED",500,3,1); } -char modemCom::cipSend(uint8_t connID,char *buffer,uint16_t len){ +char modemCom::cipSend(uint8_t idConnection,char *buffer,uint16_t len){ char aux[20]; uint16_t i; if(!len){ len = strlen(buffer); } printf("conteudo de cipsend.<"); - sprintf(aux,"AT+CIPSENDEX=%u,%lu\r\n",connID,len); - if(sendToModem(aux,1,&modemCom::status.OK,NULL,500,1,1)){ + sprintf(aux,"AT+CIPSENDEX=%u,%lu\r\n",idConnection,len); + if(sendToModem(aux,1,&modemCom::status.OK,NULL,2000,1,1)){ for(i=0;i<len;i++){ modem.putc(buffer[i]); pc.putc(buffer[i]); @@ -548,7 +548,7 @@ IrDetect.reset(); IrDetect.start(); - diversos::wdt.kick(360.0); + diversos::wdt.kick(90.0); ledUsoGeral = true; while((IrDetect.read_ms()<timeout) && (!detectaIRIn())); if(IrDetect.read_ms()<timeout){ @@ -680,7 +680,7 @@ char *ptr; int16_t RSSI = 255; - if(modemCom::sendToModem("AT+CWJAP?\r\n",1,&modemCom::status.OK,NULL,10000,2,1000)){ + if(modemCom::sendToModem("AT+CWJAP?\r\n",1,&modemCom::status.OK,NULL,10000,1,1000)){ ptr = strstr(modemCom::bufIn,(const char*)modemCom::status.ssid); if(ptr){ ptr = strtok(ptr,","); //Descarta SSID @@ -716,7 +716,7 @@ //modemCom::leParametrosConexaoSDCard(); //AT+CWJAP=\"\",\"\"\r\n sprintf(aux,"AT+CWJAP=\"%s\",\"%s\"\r\n",modemCom::status.ssid,modemCom::status.password); - if(modemCom::sendToModem(aux,1,&modemCom::status.OK,NULL,10000,1,1)) { + if(modemCom::sendToModem(aux,1,&modemCom::status.OK,NULL,5000,1,1)) { pc.printf("WiFi Conectado.\n"); return true; }else{ @@ -745,20 +745,22 @@ modemCom::status.NO_CARRIER=0; modemCom::status.PROMPT_ENVIO_COMMAND_MODE=1; } - modemCom::status.OK=0; - ptr=strstr(modemCom::bufIn,"OK\r"); - if(ptr) { - modemCom::status.OK=1; - } - - modemCom::status.busy=false; + ptr=strstr(modemCom::bufIn,"busy p..."); + if(ptr) { + modemCom::status.OK=0; + modemCom::status.ERROR=1; + modemCom::status.busy=1; + } + + /*modemCom::status.busy=false; ptr=strstr(modemCom::bufIn,"busy s..."); if(ptr) { - + modemCom::status.OK=0; + //modemCom::status.ERROR=1; modemCom::status.busy=1; - } + }*/ modemCom::status.SEND_OK=0; ptr=strstr(modemCom::bufIn,"SEND OK"); @@ -782,6 +784,8 @@ modemCom::status.OK=0; } + + ptr=strstr(modemCom::bufIn,"DNS Fail"); if(ptr) { modemCom::status.dnsError=1; @@ -796,6 +800,14 @@ modemCom::status.OK=0; } + modemCom::status.OK=0; + ptr=strstr(modemCom::bufIn,"OK\r"); + if(ptr) { + modemCom::status.OK=1; + modemCom::status.ERROR=0; + modemCom::status.busy=0; + } + //modemCom::status.CLOSED=false; ptr=strstr(modemCom::bufIn,"CLOSED"); if(ptr) { @@ -835,7 +847,7 @@ strtok(ptr,","); //Separando +IPD ptr = strtok(NULL,","); //Pegando o numero da conexão - connID = atoi(ptr); + connID = atoi(ptr); ptr = strtok(NULL,":"); //Pegando o numero de caracteres IPD IPDNumBytes = atoi(ptr); @@ -845,14 +857,14 @@ //printf("Recebido pacote via conexao %u com %lu bytes.\n",connID,IPDNumBytes); } - - if(IPDNumBytes && modemCom::status.recebendoArquivoDoServer && (strstr(modemCom::bufIn,"CONNECT")==NULL) && (strstr(modemCom::bufIn,"*ServerCommand*")==NULL) ){ + + if((connID==modemCom::status.connIDServerCommand)&& IPDNumBytes && modemCom::status.recebendoArquivoDoServer && (strstr(modemCom::bufIn,"CONNECT")==NULL) && (strstr(modemCom::bufIn,"*ServerCommand*")==NULL) ){ pc.printf("sendData recebidos %lu bytes\n",sdCard::nBytesArquivoRecebidos/2); sdCard::insereDadosArquivoHex(&sdCard::tempFile,modemCom::bufIn,IPDNumBytes); //sdCard::insereDadosArquivo(&sdCard::tempFile,modemCom::bufIn,IPDNumBytes); sdCard::nBytesArquivoRecebidos+=IPDNumBytes; bufModem.del(); - sprintf(modemCom::bufIn,"AT+CIPSEND=%u,%lu\r\n",connID,10); + sprintf(modemCom::bufIn,"AT+CIPSEND=%u,%lu\r\n",modemCom::status.connIDServerCommand,10); modem.puts(modemCom::bufIn); timeOut = 5000; while(timeOut && (strstr(bufModem.getRowBuffer(),">")==NULL)){ @@ -863,9 +875,10 @@ modem.puts("sendData\r\n"); diversos::wdt.kick(); + modemCom::status.recebendoArquivoDoServer = 600; return; } - + //Reconhecendo GET HTTP e atendendo com um servidor web if(strstr(modemCom::bufIn,"HTTP/1.1")){ ptr=strstr(modemCom::bufIn,"GET /"); @@ -892,7 +905,7 @@ pc.printf("Comandos <%s>.\n",commands::buffer); modemCom::status.connIDServerCommand = connID; executaComandoServer = true; - } + } } bool modemCom::leParametrosConexaoSDCard(){ @@ -976,9 +989,9 @@ }else{ strcpy(modemCom::status.ssid,"VSE"); strcpy(modemCom::status.password,"vitaeBBYP"); - strcpy(modemCom::status.port,"80"); - strcpy(modemCom::status.serverIP,"191.252.142.51"); - strcpy(modemCom::status.host,"www.vitaesolucoes.com.br"); + strcpy(modemCom::status.port,"4012"); + strcpy(modemCom::status.serverIP,"191.252.119.127"); + strcpy(modemCom::status.host,"www.drome.com.br"); strcpy(modemCom::status.gateway,"dhcp"); modemCom::status.periodo = 900; modBusMaster1::MODBUS_SERIAL_BAUD = 19200; @@ -993,9 +1006,9 @@ }else{ strcpy(modemCom::status.ssid,"VSE"); strcpy(modemCom::status.password,"vitaeBBYP"); - strcpy(modemCom::status.port,"80"); - strcpy(modemCom::status.serverIP,"191.252.142.51"); - strcpy(modemCom::status.host,"www.vitaesolucoes.com.br"); + strcpy(modemCom::status.port,"4012"); + strcpy(modemCom::status.serverIP,"191.252.119.127"); + strcpy(modemCom::status.host,"www.drome.com.br"); strcpy(modemCom::status.gateway,"dhcp"); modemCom::status.periodo = 900; modBusMaster1::MODBUS_SERIAL_BAUD = 19200; @@ -1021,7 +1034,7 @@ //Colocando aqui o conteudo de conectaWiFi //Mudando mode para AP e Station - if(modemCom::sendToModem("AT+CWMODE=3\r\n",1,&modemCom::status.OK,NULL,10000,1,1)) { + if(modemCom::sendToModem("AT+CWMODE=3\r\n",1,&modemCom::status.OK,NULL,3000,1,1)) { pc.printf("Modo AP+STATION aceito.\n"); } @@ -1037,8 +1050,8 @@ pc.printf("Recebeu o comando <%s>.\n",aux); } - if(modemCom::sendToModem("AT+CIPSTO=60\r\n",1,&modemCom::status.OK,NULL,250,4,1)) { - pc.printf("Recebeu o comando AT+CIPSTO=60.\n"); + if(modemCom::sendToModem("AT+CIPSTO=10\r\n",1,&modemCom::status.OK,NULL,250,4,1)) { + pc.printf("Recebeu o comando AT+CIPSTO=10.\n"); } sprintf(aux,"AT+CWSAP_CUR=\"DROME_WIFI_%s\",\"VseDROME\",5,3\r\n",modemCom::status.MAC); @@ -1047,7 +1060,7 @@ } - if(modemCom::sendToModem("AT+CIPAP_CUR=\"192.168.4.1\",\"192.168.4.1\",\"255.255.255.0\"\r\n",1,&modemCom::status.OK,NULL,250,4,1)) { + if(modemCom::sendToModem("AT+CIPAP_CUR=\"192.168.4.1\",\"192.168.4.1\",\"255.255.255.0\"\r\n",1,&modemCom::status.OK,NULL,500,4,1)) { pc.printf("Recebeu o comando AT+CIPAP_CUR=\"192.168.4.1\",\"192.168.4.1\",\"255.255.255.0\".\n"); }