teste de publish

Dependencies:   DS1820 HighSpeedAnalogIn devices mbed

Committer:
brunofgc
Date:
Tue Jul 18 20:00:43 2017 +0000
Revision:
8:9f8ad3dbeb87
Parent:
7:ae9c47f62946
Child:
9:cf406384efd9
Ultima Vers?o piloto UCSal

Who changed what in which revision?

UserRevisionLine numberNew contents of line
brunofgc 0:1c0a769988ee 1 #include "modem.h"
brunofgc 0:1c0a769988ee 2
brunofgc 0:1c0a769988ee 3 modemStatus modemCom::status;
brunofgc 0:1c0a769988ee 4 char* modemCom::bufIn; //Ponteiro para buffer de entrada do modem;
brunofgc 0:1c0a769988ee 5 uint32_t modemCom::timeOutModem;
brunofgc 0:1c0a769988ee 6 bool modemCom::atendendoWebServer;
brunofgc 0:1c0a769988ee 7 bool modemCom::exibeEntradaPacote;
brunofgc 0:1c0a769988ee 8 int16_t numeroDeBytesPorEnvio;
brunofgc 0:1c0a769988ee 9 uint8_t connID;
brunofgc 0:1c0a769988ee 10 uint16_t IPDNumBytes;
brunofgc 0:1c0a769988ee 11 bool enviaSendData;
brunofgc 0:1c0a769988ee 12 char *bufInPtr;
brunofgc 0:1c0a769988ee 13 bool mudaRede = false;
brunofgc 0:1c0a769988ee 14
brunofgc 0:1c0a769988ee 15 void modemCom::atendeSRING(uint8_t conId){
brunofgc 6:d4ebbaaba295 16 //pc.printf("Atendendo a conexao entrante.\n");
brunofgc 0:1c0a769988ee 17 modemCom::status.socketEntranteAtivo=true;
brunofgc 0:1c0a769988ee 18 modemCom::status.timeOut = 30;
brunofgc 0:1c0a769988ee 19 modemCom::timeOutModem = 50;
brunofgc 0:1c0a769988ee 20 while(modemCom::status.timeOut||modemCom::status.NO_CARRIER){
brunofgc 0:1c0a769988ee 21 modemCom::status.timeOut--;
brunofgc 0:1c0a769988ee 22 /*//Aqui devo perguntar e pedir os dados em buffer
brunofgc 0:1c0a769988ee 23 */
brunofgc 0:1c0a769988ee 24 osDelay(100);
brunofgc 0:1c0a769988ee 25 }
brunofgc 0:1c0a769988ee 26
brunofgc 0:1c0a769988ee 27 //Para parar de colocar dentro do arquivo
brunofgc 0:1c0a769988ee 28 modemCom::status.recebendoArquivoDoServer = false;
brunofgc 0:1c0a769988ee 29
brunofgc 0:1c0a769988ee 30 modemCom::status.serverConnected=0;
brunofgc 0:1c0a769988ee 31 modemCom::timeOutModem = 10;
brunofgc 0:1c0a769988ee 32
brunofgc 0:1c0a769988ee 33 //Fechando o socket
brunofgc 0:1c0a769988ee 34 modemCom::closeConnection(conId);
brunofgc 0:1c0a769988ee 35 modemCom::status.socketEntranteAtivo=false;
brunofgc 0:1c0a769988ee 36 modemCom::status.emComunicacao = false;
brunofgc 0:1c0a769988ee 37 modemCom::timeOutModem = 10;
brunofgc 0:1c0a769988ee 38 }
brunofgc 0:1c0a769988ee 39
brunofgc 0:1c0a769988ee 40 bool modemCom::sendBufferCommandMode(uint8_t sId, char *buffer, uint16_t bufferLength){
brunofgc 0:1c0a769988ee 41 char aux[25];
brunofgc 0:1c0a769988ee 42 uint16_t numeroByteSendoEnviado;
brunofgc 0:1c0a769988ee 43
brunofgc 0:1c0a769988ee 44 sprintf(aux,"AT+CIPSEND=%u,%lu\r\n",sId,bufferLength);
brunofgc 7:ae9c47f62946 45 if(modemCom::sendToModem(aux,1,&modemCom::status.PROMPT_ENVIO_COMMAND_MODE,NULL,300,10,1)) {
brunofgc 0:1c0a769988ee 46 for(numeroByteSendoEnviado = 0; numeroByteSendoEnviado<bufferLength; numeroByteSendoEnviado++) {
brunofgc 0:1c0a769988ee 47 modem.printf("%c",buffer[numeroByteSendoEnviado]);
brunofgc 0:1c0a769988ee 48 #ifdef xereta_modem
brunofgc 0:1c0a769988ee 49 pc.printf("%c",buffer[numeroByteSendoEnviado]);
brunofgc 0:1c0a769988ee 50 #endif
brunofgc 0:1c0a769988ee 51 }
brunofgc 7:ae9c47f62946 52 numeroByteSendoEnviado = modemCom::sendToModem(NULL,1,&modemCom::status.SEND_OK,NULL,500,1,1);
brunofgc 0:1c0a769988ee 53 }else{
brunofgc 0:1c0a769988ee 54 numeroByteSendoEnviado = false; //Reaproveitando numeroByteSendoEnviado para resultado de retorno
brunofgc 0:1c0a769988ee 55 }
brunofgc 0:1c0a769988ee 56 return numeroByteSendoEnviado; //Reaproveitando numeroByteSendoEnviado para resultado de retorno
brunofgc 0:1c0a769988ee 57 }
brunofgc 0:1c0a769988ee 58
brunofgc 0:1c0a769988ee 59 void modemCom::leMAC(void)
brunofgc 0:1c0a769988ee 60 {
brunofgc 0:1c0a769988ee 61 char *ptr;
brunofgc 7:ae9c47f62946 62 if(modemCom::sendToModem("AT+CIPSTAMAC?\r\n",1,&modemCom::status.modemResponse,NULL,250,20,1)){
brunofgc 0:1c0a769988ee 63 //resposta: +CIPSTAMAC:"18:fe:34:f4:5f:c4"
brunofgc 0:1c0a769988ee 64 ptr = strtok(bufModem.getRowBuffer(),"\"");
brunofgc 0:1c0a769988ee 65 ptr = strtok(NULL,"\"");
brunofgc 0:1c0a769988ee 66 if(ptr) {
brunofgc 0:1c0a769988ee 67 strcpy(modemCom::status.MAC,ptr);
brunofgc 0:1c0a769988ee 68 pc.printf("Lido MAC <%s>.\n",modemCom::status.MAC);
brunofgc 0:1c0a769988ee 69 }
brunofgc 0:1c0a769988ee 70 }
brunofgc 0:1c0a769988ee 71 }
brunofgc 0:1c0a769988ee 72
brunofgc 7:ae9c47f62946 73
brunofgc 0:1c0a769988ee 74
brunofgc 1:0e0967c88590 75 bool modemCom::writeStatusToSD(void){
brunofgc 1:0e0967c88590 76 char aux[30];
brunofgc 1:0e0967c88590 77 int16_t RSSI;
brunofgc 1:0e0967c88590 78 RSSI = modemCom::getRSSI();
brunofgc 1:0e0967c88590 79 sdCardBuf.del();
brunofgc 1:0e0967c88590 80 sdCardBuf.fill("log{status:ip=255.255.255.255;csq=",34);
brunofgc 1:0e0967c88590 81
brunofgc 1:0e0967c88590 82 sprintf(aux,"%d",RSSI);
brunofgc 1:0e0967c88590 83 sdCardBuf.fill(aux,strlen(aux));
brunofgc 1:0e0967c88590 84
brunofgc 1:0e0967c88590 85 sprintf(aux,";imsi=%s}log",modemCom::status.MAC);
brunofgc 1:0e0967c88590 86 sdCardBuf.fill(aux,strlen(aux));
brunofgc 1:0e0967c88590 87
brunofgc 7:ae9c47f62946 88 return sdCard::insereDadosArquivo(&sdCard::armazenamento,sdCardBuf.get(),sdCardBuf.getLength());
brunofgc 1:0e0967c88590 89 }
brunofgc 1:0e0967c88590 90
brunofgc 0:1c0a769988ee 91 bool modemCom::montaStatus(void)
brunofgc 0:1c0a769988ee 92 {
brunofgc 0:1c0a769988ee 93 if(sdCard::abreArquivo(&sdCard::status,"w")) {
brunofgc 0:1c0a769988ee 94 fprintf(sdCard::status.fp,"log{status:ip:255.255.255.255;csq:30;imsi:%s}log",modemCom::status.MAC);
brunofgc 0:1c0a769988ee 95 sdCard::fechaArquivo(&sdCard::status);
brunofgc 0:1c0a769988ee 96 sdCard::exibeArquivo(&sdCard::status);
brunofgc 0:1c0a769988ee 97 } else {
brunofgc 0:1c0a769988ee 98 return 0;
brunofgc 0:1c0a769988ee 99 }
brunofgc 0:1c0a769988ee 100 return true;
brunofgc 0:1c0a769988ee 101 }
brunofgc 0:1c0a769988ee 102
brunofgc 0:1c0a769988ee 103
brunofgc 0:1c0a769988ee 104
brunofgc 0:1c0a769988ee 105 uint8_t modemCom::enviaDados(char tipoDado)
brunofgc 0:1c0a769988ee 106 {
brunofgc 0:1c0a769988ee 107 uint8_t result=0;
brunofgc 0:1c0a769988ee 108 modemCom::status.emComunicacao = true;
brunofgc 0:1c0a769988ee 109
brunofgc 0:1c0a769988ee 110 switch(tipoDado) {
brunofgc 0:1c0a769988ee 111 case dadosArmazenados:
brunofgc 0:1c0a769988ee 112 if(!sdCard::preparaEnvio()){
brunofgc 0:1c0a769988ee 113 pc.printf("Nao foi possivel preparar o envio.\n");
brunofgc 2:55b7b466e742 114 return false;
brunofgc 0:1c0a769988ee 115 }
brunofgc 7:ae9c47f62946 116 sdCard::getFileTam(&sdCard::envio);
brunofgc 0:1c0a769988ee 117 pc.printf("Preparado o envio do arquivo com %lu bytes.\n",sdCard::envio.bytes);
brunofgc 0:1c0a769988ee 118 break;
brunofgc 0:1c0a769988ee 119 case dadosStatus:
brunofgc 0:1c0a769988ee 120 modemCom::montaStatus();
brunofgc 0:1c0a769988ee 121 break;
brunofgc 0:1c0a769988ee 122 }
brunofgc 0:1c0a769988ee 123
brunofgc 0:1c0a769988ee 124 switch(tipoDado) {
brunofgc 0:1c0a769988ee 125 case dadosArmazenados:
brunofgc 2:55b7b466e742 126 result = modemCom::postFileCommandMode(serverAddress,"/drome/Parser/",&sdCard::envio);
brunofgc 0:1c0a769988ee 127 break;
brunofgc 0:1c0a769988ee 128 case dadosStatus:
brunofgc 2:55b7b466e742 129 result = modemCom::postFileCommandMode(serverAddress,"/drome/Parser/",&sdCard::status);
brunofgc 0:1c0a769988ee 130 break;
brunofgc 0:1c0a769988ee 131 }
brunofgc 0:1c0a769988ee 132
brunofgc 0:1c0a769988ee 133 if(!result){
brunofgc 0:1c0a769988ee 134 return result;
brunofgc 0:1c0a769988ee 135 }
brunofgc 0:1c0a769988ee 136
brunofgc 0:1c0a769988ee 137 //Envia uma string nula e faz o processador esperar a resposta do server!
brunofgc 0:1c0a769988ee 138 if(modemCom::status.ServerAck) {
brunofgc 0:1c0a769988ee 139 pc.printf("Enviado e recebido resposta do server (*ServerAck*).\n");
brunofgc 0:1c0a769988ee 140 } else {
brunofgc 0:1c0a769988ee 141 pc.printf("Enviado mas nao recebido resposta do server (*ServerAck*).\n");
brunofgc 0:1c0a769988ee 142 pc.printf("Conteudo de getRowBuffer <%s>.\n",bufModem.getRowBuffer());
brunofgc 0:1c0a769988ee 143 }
brunofgc 0:1c0a769988ee 144 return result;
brunofgc 0:1c0a769988ee 145 }
brunofgc 0:1c0a769988ee 146
brunofgc 0:1c0a769988ee 147
brunofgc 0:1c0a769988ee 148
brunofgc 0:1c0a769988ee 149 uint8_t modemCom::postFileCommandMode(char *host, char *uri, arquivoSD *arquivo)
brunofgc 0:1c0a769988ee 150 {
brunofgc 0:1c0a769988ee 151 #define maxRetentativasEnvioParteArquivo 20
brunofgc 0:1c0a769988ee 152 uint32_t numeroDePartes;
brunofgc 0:1c0a769988ee 153 uint16_t restoDoEnvio;
brunofgc 0:1c0a769988ee 154 int32_t parteSendoEnviada;
brunofgc 0:1c0a769988ee 155 uint16_t numeroByteSendoEnviado;
brunofgc 0:1c0a769988ee 156 uint16_t maxTentativas=0;
brunofgc 0:1c0a769988ee 157 //unsigned int result;
brunofgc 0:1c0a769988ee 158 char header[512];
brunofgc 0:1c0a769988ee 159 char aux[40];
brunofgc 0:1c0a769988ee 160 uint16_t headerTam;
brunofgc 0:1c0a769988ee 161 uint32_t dataTam=0;
brunofgc 0:1c0a769988ee 162 char c;
brunofgc 0:1c0a769988ee 163 bool passaParaProximaParte = false;
brunofgc 0:1c0a769988ee 164
brunofgc 0:1c0a769988ee 165 //Para garantir que não seja duvidoso proveniente de outra conexão.
brunofgc 0:1c0a769988ee 166 modemCom::status.ServerAck=0;
brunofgc 0:1c0a769988ee 167 modemCom::status.NO_CARRIER=0;
brunofgc 0:1c0a769988ee 168
brunofgc 8:9f8ad3dbeb87 169 if(arquivo->bytes==0){
brunofgc 0:1c0a769988ee 170 if((!sdCard::getFileTam(arquivo))||(arquivo->bytes == 0)){
brunofgc 7:ae9c47f62946 171 if(arquivo->bytes == 0){
brunofgc 7:ae9c47f62946 172 sdCard::excluiArquivo(arquivo);
brunofgc 7:ae9c47f62946 173 }
brunofgc 0:1c0a769988ee 174 return false;
brunofgc 0:1c0a769988ee 175 }
brunofgc 0:1c0a769988ee 176 }
brunofgc 0:1c0a769988ee 177
brunofgc 0:1c0a769988ee 178 pc.printf("Abrindo o socket em <%s>.\n",host);
brunofgc 0:1c0a769988ee 179 sprintf(header,"AT+CIPSTART=1,\"TCP\",\"%s\",80\r\n",host);
brunofgc 7:ae9c47f62946 180 if(modemCom::sendToModem(header,1,&modemCom::status.OK,NULL,20000,1,1)) {
brunofgc 0:1c0a769988ee 181 modemCom::status.NO_CARRIER=0; //Socket Aberto!
brunofgc 0:1c0a769988ee 182 pc.printf("Aberto o socket em command mode.\n");
brunofgc 0:1c0a769988ee 183 pc.printf("Enviando arquivo com nome %s.\n",arquivo->nome);
brunofgc 0:1c0a769988ee 184 modemCom::status.serverConnected=1;
brunofgc 0:1c0a769988ee 185 modemCom::timeOutModem = 100;
brunofgc 0:1c0a769988ee 186 modemCom::status.emComunicacao = true;
brunofgc 0:1c0a769988ee 187 } else {
brunofgc 0:1c0a769988ee 188 pc.printf("Nao foi possivel Abrir o socket. Abortando tentativa.\n");
brunofgc 0:1c0a769988ee 189 modemCom::timeOutModem = 10;
brunofgc 0:1c0a769988ee 190 return 0;
brunofgc 0:1c0a769988ee 191 }
brunofgc 0:1c0a769988ee 192
brunofgc 0:1c0a769988ee 193 numeroDePartes = arquivo->bytes / numeroDeBytesPorEnvio;
brunofgc 0:1c0a769988ee 194 restoDoEnvio = arquivo->bytes % numeroDeBytesPorEnvio;
brunofgc 0:1c0a769988ee 195
brunofgc 3:9598af355293 196
brunofgc 3:9598af355293 197 pc.printf("Iniciando o envio do arquivo de %lu bytes\nnumeroDePartes = %lu\nrestoDoEnvio = %lu\n",arquivo->bytes,numeroDePartes,restoDoEnvio);
brunofgc 0:1c0a769988ee 198
brunofgc 0:1c0a769988ee 199 if(!sdCard::abreArquivo(arquivo,"r")){
brunofgc 7:ae9c47f62946 200 pc.printf("Nao foi posssivel abrir o arquivo de dentro da funcao postFileCommandMode().\n");
brunofgc 0:1c0a769988ee 201 modemCom::status.emComunicacao = false;
brunofgc 0:1c0a769988ee 202 return 0;
brunofgc 0:1c0a769988ee 203 }
brunofgc 0:1c0a769988ee 204
brunofgc 4:13ff9c81dc10 205
brunofgc 0:1c0a769988ee 206 //Monta Header aqui!
brunofgc 4:13ff9c81dc10 207 //application/octet-stream
brunofgc 4:13ff9c81dc10 208 sprintf(header,"--xxBOUNDARYxx\r\nContent-Type: text/plain\r\nContent-Disposition: form-data; name=\"IMEI\"\r\n\r\n%s\r\n--xxBOUNDARYxx\r\nContent-Type: application/octet-stream\r\nContent-Disposition: form-data; name=\"file\"; filename=\"%s\"\r\n\r\n",modemCom::status.MAC,arquivo->nome);
brunofgc 0:1c0a769988ee 209
brunofgc 0:1c0a769988ee 210 dataTam = strlen(header);
brunofgc 0:1c0a769988ee 211 dataTam+=arquivo->bytes;
brunofgc 4:13ff9c81dc10 212 dataTam+= strlen("\r\n--xxBOUNDARYxx--");
brunofgc 0:1c0a769988ee 213 //"/drome/parser/index.php" uri drome
brunofgc 4:13ff9c81dc10 214 sprintf(header,"POST %s HTTP/1.1\r\nHost: %s\r\nContent-Type: multipart/form-data; boundary=xxBOUNDARYxx\r\nContent-Length: %lu\r\n\r\n",uri,host,dataTam);
brunofgc 0:1c0a769988ee 215 headerTam = strlen(header); //Pego o tamanho parcial para fazer a concatenaçao a fim de predizer o tamanho do post total
brunofgc 0:1c0a769988ee 216
brunofgc 4:13ff9c81dc10 217 sprintf(&header[headerTam],"--xxBOUNDARYxx\r\nContent-Type: text/plain\r\nContent-Disposition: form-data; name=\"IMEI\"\r\n\r\n%s\r\n--xxBOUNDARYxx\r\nContent-Type: application/octet-stream\r\nContent-Disposition: form-data; name=\"file\"; filename=\"%s\"\r\n\r\n",modemCom::status.MAC,arquivo->nome);
brunofgc 0:1c0a769988ee 218 headerTam = strlen(header);
brunofgc 0:1c0a769988ee 219
brunofgc 0:1c0a769988ee 220 sprintf(aux,"AT+CIPSEND=1,%u\r\n",headerTam);
brunofgc 7:ae9c47f62946 221 if(modemCom::sendToModem(aux,1,&modemCom::status.PROMPT_ENVIO_COMMAND_MODE,NULL,100,10,1)) {
brunofgc 7:ae9c47f62946 222 if(!modemCom::sendToModem(header,1,&modemCom::status.SEND_OK,NULL,1000,1,1)) {
brunofgc 0:1c0a769988ee 223 sdCard::fechaArquivo(arquivo);
brunofgc 0:1c0a769988ee 224 modemCom::status.emComunicacao = false;
brunofgc 3:9598af355293 225 pc.printf("Cabecalho http nao enviado.\n");
brunofgc 0:1c0a769988ee 226 return 0;
brunofgc 0:1c0a769988ee 227 } else {
brunofgc 3:9598af355293 228 pc.printf("Cabecalho http enviado.\n");
brunofgc 0:1c0a769988ee 229 }
brunofgc 0:1c0a769988ee 230 } else {
brunofgc 0:1c0a769988ee 231 pc.printf("Erro enviando arquivo.\n");
brunofgc 0:1c0a769988ee 232 sdCard::fechaArquivo(arquivo);
brunofgc 0:1c0a769988ee 233 modemCom::status.emComunicacao = false;
brunofgc 0:1c0a769988ee 234 return 0;
brunofgc 0:1c0a769988ee 235 }
brunofgc 0:1c0a769988ee 236
brunofgc 0:1c0a769988ee 237 //Enviando as partes inteiras
brunofgc 0:1c0a769988ee 238 maxTentativas = maxRetentativasEnvioParteArquivo;
brunofgc 0:1c0a769988ee 239 for(parteSendoEnviada=0; parteSendoEnviada<numeroDePartes; parteSendoEnviada++) {
brunofgc 0:1c0a769988ee 240 //Aqui realizo o envio de cada parte.
brunofgc 0:1c0a769988ee 241 passaParaProximaParte = false;
brunofgc 0:1c0a769988ee 242 while((maxTentativas)&&(!passaParaProximaParte)) {
brunofgc 0:1c0a769988ee 243 sprintf(aux,"AT+CIPSEND=1,%u\r\n",numeroDeBytesPorEnvio);
brunofgc 7:ae9c47f62946 244 if(modemCom::sendToModem(aux,1,&modemCom::status.PROMPT_ENVIO_COMMAND_MODE,NULL,100,20,1)) {
brunofgc 0:1c0a769988ee 245 if(maxTentativas!=maxRetentativasEnvioParteArquivo) {
brunofgc 0:1c0a769988ee 246 //Estou realizando reenvio desta parte logo preciso fazer fseek para a quantidade de bytes do envio anterior
brunofgc 0:1c0a769988ee 247 fseek(arquivo->fp,-numeroDeBytesPorEnvio,SEEK_CUR);
brunofgc 0:1c0a769988ee 248 }
brunofgc 3:9598af355293 249 pc.printf("Numero de bytes por envio = %lu.\r\n",numeroDeBytesPorEnvio);
brunofgc 0:1c0a769988ee 250 for(numeroByteSendoEnviado=0; numeroByteSendoEnviado<(numeroDeBytesPorEnvio); numeroByteSendoEnviado++) {
brunofgc 0:1c0a769988ee 251 c = fgetc(arquivo->fp);
brunofgc 0:1c0a769988ee 252 modem.printf("%c",c);
brunofgc 0:1c0a769988ee 253 #ifdef xereta_modem
brunofgc 4:13ff9c81dc10 254 pc.printf("%c",c);
brunofgc 0:1c0a769988ee 255 #endif
brunofgc 0:1c0a769988ee 256 }
brunofgc 0:1c0a769988ee 257
brunofgc 7:ae9c47f62946 258 if(modemCom::sendToModem(NULL,1,&modemCom::status.SEND_OK,NULL,5000,1,1)) {
brunofgc 0:1c0a769988ee 259 diversos::progressBar(parteSendoEnviada,numeroDePartes);
brunofgc 0:1c0a769988ee 260 //Preciso verificar se o buffer esvaziou. Se deu "flush"
brunofgc 0:1c0a769988ee 261 //if(modemCom::aguardaFlush(0)==1) {
brunofgc 0:1c0a769988ee 262 //passa pra proxima parte
brunofgc 0:1c0a769988ee 263 passaParaProximaParte = true;
brunofgc 0:1c0a769988ee 264 maxTentativas = maxRetentativasEnvioParteArquivo;
brunofgc 0:1c0a769988ee 265 } else {
brunofgc 0:1c0a769988ee 266 maxTentativas--;
brunofgc 0:1c0a769988ee 267 if(maxTentativas == 1) {
brunofgc 0:1c0a769988ee 268 pc.printf("MaxTentativas dentro de envio das partes == 1, vou aguardar o flush.\n");
brunofgc 0:1c0a769988ee 269 }
brunofgc 0:1c0a769988ee 270 if(maxTentativas == 0) {
brunofgc 0:1c0a769988ee 271 sdCard::fechaArquivo(arquivo);
brunofgc 0:1c0a769988ee 272 modemCom::status.emComunicacao = false;
brunofgc 0:1c0a769988ee 273 return 0;
brunofgc 0:1c0a769988ee 274 }
brunofgc 0:1c0a769988ee 275 }
brunofgc 0:1c0a769988ee 276 } else {
brunofgc 0:1c0a769988ee 277 pc.printf("Erro enviando o arquivo nao recebeu a tentativa de envio de parte inteira.\n");
brunofgc 0:1c0a769988ee 278 sdCard::fechaArquivo(arquivo);
brunofgc 0:1c0a769988ee 279 modemCom::status.emComunicacao = false;
brunofgc 0:1c0a769988ee 280 return 0;
brunofgc 0:1c0a769988ee 281 }
brunofgc 0:1c0a769988ee 282 }
brunofgc 0:1c0a769988ee 283 if(!passaParaProximaParte) {
brunofgc 0:1c0a769988ee 284 pc.printf("Erro enviando o arquivo nao recebeu a tentativa de envio de parte inteira.\n");
brunofgc 0:1c0a769988ee 285 sdCard::fechaArquivo(arquivo);
brunofgc 0:1c0a769988ee 286 modemCom::status.emComunicacao = false;
brunofgc 0:1c0a769988ee 287 return 0;
brunofgc 0:1c0a769988ee 288 }
brunofgc 0:1c0a769988ee 289 }
brunofgc 0:1c0a769988ee 290
brunofgc 0:1c0a769988ee 291 //Enviando o resto
brunofgc 0:1c0a769988ee 292 passaParaProximaParte = false;
brunofgc 0:1c0a769988ee 293 maxTentativas = maxRetentativasEnvioParteArquivo;
brunofgc 0:1c0a769988ee 294 while((maxTentativas)&&(!passaParaProximaParte)) {
brunofgc 4:13ff9c81dc10 295 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
brunofgc 7:ae9c47f62946 296 if(modemCom::sendToModem(aux,1,&modemCom::status.PROMPT_ENVIO_COMMAND_MODE,NULL,100,3,1)) {
brunofgc 0:1c0a769988ee 297 for(numeroByteSendoEnviado=0; numeroByteSendoEnviado<restoDoEnvio; numeroByteSendoEnviado++) {
brunofgc 0:1c0a769988ee 298 //Envio os bytes aqui! Menos o ultimo para ter o check;
brunofgc 0:1c0a769988ee 299 c = fgetc(arquivo->fp);
brunofgc 0:1c0a769988ee 300 modem.printf("%c",c);
brunofgc 0:1c0a769988ee 301 #ifdef xereta_modem
brunofgc 0:1c0a769988ee 302 pc.printf("%c",c);
brunofgc 0:1c0a769988ee 303 #endif
brunofgc 0:1c0a769988ee 304 }
brunofgc 7:ae9c47f62946 305 if(modemCom::sendToModem("\r\n--xxBOUNDARYxx--\r\n\r\n",1,&modemCom::status.SEND_OK,NULL,5000,1,1)) {
brunofgc 0:1c0a769988ee 306 if(numeroDePartes) {
brunofgc 0:1c0a769988ee 307 diversos::progressBar(parteSendoEnviada,numeroDePartes);
brunofgc 0:1c0a769988ee 308 }
brunofgc 0:1c0a769988ee 309 passaParaProximaParte = true;
brunofgc 0:1c0a769988ee 310 pc.printf("\nEnviado o resto do envio com fim de cabecalho!\n",parteSendoEnviada);
brunofgc 0:1c0a769988ee 311 modemCom::timeOutModem = 250;
brunofgc 0:1c0a769988ee 312 //}
brunofgc 0:1c0a769988ee 313 /*else {
brunofgc 0:1c0a769988ee 314 pc.printf("Erro enviando arquivo.\n");
brunofgc 0:1c0a769988ee 315 fclose(fp);
brunofgc 0:1c0a769988ee 316 *aberto = false;
brunofgc 0:1c0a769988ee 317 return 0;
brunofgc 0:1c0a769988ee 318 }*/
brunofgc 0:1c0a769988ee 319 } else {
brunofgc 0:1c0a769988ee 320 sdCard::fechaArquivo(arquivo);
brunofgc 0:1c0a769988ee 321 modemCom::status.emComunicacao = false;
brunofgc 0:1c0a769988ee 322 return 0;
brunofgc 0:1c0a769988ee 323 }
brunofgc 0:1c0a769988ee 324 } else {
brunofgc 0:1c0a769988ee 325 maxTentativas--;
brunofgc 7:ae9c47f62946 326 modemCom::sendToModem("AT\r\n",1,&modemCom::status.OK,NULL,1000,100,1);
brunofgc 0:1c0a769988ee 327 }
brunofgc 0:1c0a769988ee 328 }
brunofgc 0:1c0a769988ee 329
brunofgc 0:1c0a769988ee 330 if(!passaParaProximaParte) {
brunofgc 0:1c0a769988ee 331 pc.printf("Erro enviando o arquivo nao recebeu a tentativa de envio de parte inteira.\n");
brunofgc 0:1c0a769988ee 332 sdCard::fechaArquivo(arquivo);
brunofgc 0:1c0a769988ee 333 modemCom::status.emComunicacao = false;
brunofgc 0:1c0a769988ee 334 return 0;
brunofgc 0:1c0a769988ee 335 }
brunofgc 0:1c0a769988ee 336
brunofgc 0:1c0a769988ee 337 //Logica de timeout esperando confirmação modemCom::status.ServerAck 20 segundos
brunofgc 7:ae9c47f62946 338 parteSendoEnviada = 200;
brunofgc 0:1c0a769988ee 339 while((parteSendoEnviada)&&(!modemCom::status.ServerAck)&&(!modemCom::status.NO_CARRIER)) {
brunofgc 0:1c0a769988ee 340 osDelay(100);
brunofgc 0:1c0a769988ee 341 parteSendoEnviada--;
brunofgc 0:1c0a769988ee 342 }
brunofgc 0:1c0a769988ee 343
brunofgc 0:1c0a769988ee 344 modemCom::status.serverConnected=0;
brunofgc 0:1c0a769988ee 345 sdCard::fechaArquivo(arquivo);
brunofgc 0:1c0a769988ee 346
brunofgc 0:1c0a769988ee 347 //modemCom::sendToModem("AT+CIPCLOSE=1\r\n",1,&modemCom::status.OK,500,3);
brunofgc 0:1c0a769988ee 348 modemCom::closeConnection(1);
brunofgc 0:1c0a769988ee 349 modemCom::status.emComunicacao = false;
brunofgc 0:1c0a769988ee 350 return modemCom::status.ServerAck;
brunofgc 0:1c0a769988ee 351 }
brunofgc 0:1c0a769988ee 352
brunofgc 7:ae9c47f62946 353 uint8_t modemCom::sendToModem(char *string,uint8_t confirmado,char *codigoConfirmacao,char *stringConfirmacao,uint16_t timeOut,uint8_t maxTentativas,uint16_t delayEntreTentativas)
brunofgc 0:1c0a769988ee 354 {
brunofgc 0:1c0a769988ee 355 uint16_t timeOutProcesso;
brunofgc 0:1c0a769988ee 356 uint16_t indexString,strLen; //Para exibir retentativas!
brunofgc 7:ae9c47f62946 357
brunofgc 0:1c0a769988ee 358 while(maxTentativas){
brunofgc 0:1c0a769988ee 359 timeOutProcesso=timeOut;
brunofgc 7:ae9c47f62946 360
brunofgc 7:ae9c47f62946 361
brunofgc 7:ae9c47f62946 362 bufModem.del(); //Deletando o buffer antes de iniciar envio
brunofgc 7:ae9c47f62946 363
brunofgc 0:1c0a769988ee 364 if(string!=NULL) {
brunofgc 7:ae9c47f62946 365 modem.puts(string);
brunofgc 7:ae9c47f62946 366 #ifdef xereta_modem
brunofgc 7:ae9c47f62946 367 pc.printf("Sai pro modem <%s>\n",string); //Enviando na serial PC para debug
brunofgc 7:ae9c47f62946 368 #endif
brunofgc 0:1c0a769988ee 369 }
brunofgc 7:ae9c47f62946 370 if(confirmado==1){
brunofgc 0:1c0a769988ee 371 modemCom::status.ERROR=0;
brunofgc 7:ae9c47f62946 372 modemCom::status.busy=0;
brunofgc 7:ae9c47f62946 373
brunofgc 7:ae9c47f62946 374 if(codigoConfirmacao!=NULL){
brunofgc 7:ae9c47f62946 375 *codigoConfirmacao=0;
brunofgc 7:ae9c47f62946 376 while((timeOutProcesso)&&(!(*codigoConfirmacao))&&(!modemCom::status.ERROR)&&(!modemCom::status.busy)){
brunofgc 7:ae9c47f62946 377 osDelay(5); //timeOut em mS
brunofgc 7:ae9c47f62946 378 timeOutProcesso--;
brunofgc 7:ae9c47f62946 379 }
brunofgc 7:ae9c47f62946 380 }else{
brunofgc 7:ae9c47f62946 381 while((timeOutProcesso)&&(!modemCom::status.ERROR)&&(!modemCom::status.busy)&&(!strstr(bufModem.getRowBuffer(),stringConfirmacao))) {
brunofgc 7:ae9c47f62946 382 osDelay(1); //timeOut em mS
brunofgc 7:ae9c47f62946 383 timeOutProcesso--;
brunofgc 7:ae9c47f62946 384 }
brunofgc 7:ae9c47f62946 385 }
brunofgc 7:ae9c47f62946 386 if(modemCom::status.ERROR||modemCom::status.busy) {
brunofgc 7:ae9c47f62946 387 osDelay(1000);//espera 1S
brunofgc 0:1c0a769988ee 388 }
brunofgc 7:ae9c47f62946 389
brunofgc 7:ae9c47f62946 390 if(timeOutProcesso) {
brunofgc 0:1c0a769988ee 391 return maxTentativas;
brunofgc 7:ae9c47f62946 392 }
brunofgc 7:ae9c47f62946 393
brunofgc 0:1c0a769988ee 394 strLen = strlen(string);
brunofgc 0:1c0a769988ee 395 for(indexString=0; indexString<(strLen-1); indexString++) {
brunofgc 0:1c0a769988ee 396 pc.putc(string[indexString]);
brunofgc 0:1c0a769988ee 397 }
brunofgc 7:ae9c47f62946 398 #ifdef xereta_modem
brunofgc 7:ae9c47f62946 399 pc.printf("> maxTentativas = %lu.\n",maxTentativas);
brunofgc 7:ae9c47f62946 400 #endif
brunofgc 0:1c0a769988ee 401 }
brunofgc 7:ae9c47f62946 402 maxTentativas--;
brunofgc 7:ae9c47f62946 403 osDelay(delayEntreTentativas);
brunofgc 7:ae9c47f62946 404 }
brunofgc 0:1c0a769988ee 405 return 0;
brunofgc 0:1c0a769988ee 406 }
brunofgc 0:1c0a769988ee 407
brunofgc 0:1c0a769988ee 408 bool modemCom::closeConnection(uint8_t id){
brunofgc 0:1c0a769988ee 409 char command[20];
brunofgc 0:1c0a769988ee 410 sprintf(command,"AT+CIPCLOSE=%u\r\n",id);
brunofgc 7:ae9c47f62946 411 return modemCom::sendToModem(command,1,&modemCom::status.OK,NULL,500,3,1);
brunofgc 0:1c0a769988ee 412 }
brunofgc 0:1c0a769988ee 413
brunofgc 0:1c0a769988ee 414 char modemCom::cipSend(uint8_t connID,char *buffer,uint16_t len){
brunofgc 0:1c0a769988ee 415 char aux[20];
brunofgc 0:1c0a769988ee 416 uint16_t i;
brunofgc 0:1c0a769988ee 417 if(!len){
brunofgc 0:1c0a769988ee 418 len = strlen(buffer);
brunofgc 0:1c0a769988ee 419 }
brunofgc 0:1c0a769988ee 420 printf("conteudo de cipsend.<");
brunofgc 0:1c0a769988ee 421 sprintf(aux,"AT+CIPSENDEX=%u,%lu\r\n",connID,len);
brunofgc 7:ae9c47f62946 422 if(sendToModem(aux,1,&modemCom::status.OK,NULL,500,1,1)){
brunofgc 0:1c0a769988ee 423 for(i=0;i<len;i++){
brunofgc 0:1c0a769988ee 424 modem.putc(buffer[i]);
brunofgc 0:1c0a769988ee 425 pc.putc(buffer[i]);
brunofgc 0:1c0a769988ee 426 }
brunofgc 0:1c0a769988ee 427 }else{
brunofgc 0:1c0a769988ee 428 return 0;
brunofgc 0:1c0a769988ee 429 }
brunofgc 0:1c0a769988ee 430 printf(">\r\n");
brunofgc 7:ae9c47f62946 431 if(sendToModem("",1,&modemCom::status.SEND_OK,NULL,2000,1,1)){
brunofgc 0:1c0a769988ee 432 return 1;
brunofgc 0:1c0a769988ee 433 }
brunofgc 0:1c0a769988ee 434 return 2;
brunofgc 0:1c0a769988ee 435 }
brunofgc 0:1c0a769988ee 436
brunofgc 0:1c0a769988ee 437 void modemCom::webServer(void){
brunofgc 0:1c0a769988ee 438 char buf[512];
brunofgc 7:ae9c47f62946 439 //char auxMsg[50];
brunofgc 0:1c0a769988ee 440 bool encontrado=0;
brunofgc 7:ae9c47f62946 441 //uint32_t aux_int;
brunofgc 0:1c0a769988ee 442
brunofgc 0:1c0a769988ee 443
brunofgc 0:1c0a769988ee 444
brunofgc 2:55b7b466e742 445 if(strstr(bufInPtr,"favicon.ico")){
brunofgc 2:55b7b466e742 446 //sprintf(buf,"<!DOCTYPE html><html><body><h1>DROME-Seu processo na palma da sua mao!</h1><img src='http://criandoriquezaimagens.s3.amazonaws.com/wp-content/uploads/2014/12/casaPropria.png' width='200' height='210'><br><p><a href='/lecomandocontrole.htm'>Ler comando do controle.</a></p><br></body></html>");
brunofgc 2:55b7b466e742 447 sprintf(buf,"<!DOCTYPE html><html><link rel=\"icon\" href=\"http://vitaesolucoes.com.br/drome/assets/local/images/favicon/favicon.ico\" type=\"image/x-icon\"></html>");
brunofgc 2:55b7b466e742 448 if(cipSend(connID,buf,0)==1){
brunofgc 2:55b7b466e742 449 printf("Requisicao enviada!\n");
brunofgc 2:55b7b466e742 450 }else{
brunofgc 2:55b7b466e742 451 printf("Requisicao nao enviada 1!!\n");
brunofgc 2:55b7b466e742 452 }
brunofgc 2:55b7b466e742 453 encontrado = 1;
brunofgc 2:55b7b466e742 454 }
brunofgc 2:55b7b466e742 455
brunofgc 0:1c0a769988ee 456 if(strstr(bufInPtr,"comandos.htm")){
brunofgc 0:1c0a769988ee 457
brunofgc 0:1c0a769988ee 458 //sprintf(buf,"<!DOCTYPE html><html><body><h1>DROME-Seu processo na palma da sua mao!</h1><img src='http://criandoriquezaimagens.s3.amazonaws.com/wp-content/uploads/2014/12/casaPropria.png' width='200' height='210'><br><p><a href='/lecomandocontrole.htm'>Ler comando do controle.</a></p><br></body></html>");
brunofgc 0:1c0a769988ee 459 sprintf(buf,"<!DOCTYPE html><html><body><h1>DROME-Dispositivo Remoto de Operacao e Monitoramento de Equipamentos</h1><br><p><a href='/lecomandocontrole.htm'>Ler comando do controle.</a><a href='/configRede.htm'><br>Configurar rede.</a></p><br></body></html>");
brunofgc 0:1c0a769988ee 460 if(cipSend(connID,buf,0)==1){
brunofgc 0:1c0a769988ee 461 printf("Requisicao enviada!\n");
brunofgc 0:1c0a769988ee 462 }else{
brunofgc 0:1c0a769988ee 463 printf("Requisicao nao enviada 1!!\n");
brunofgc 0:1c0a769988ee 464 }
brunofgc 0:1c0a769988ee 465 encontrado = 1;
brunofgc 0:1c0a769988ee 466 }
brunofgc 0:1c0a769988ee 467
brunofgc 7:ae9c47f62946 468 if(strstr(bufInPtr,"configRede.htm")){
brunofgc 0:1c0a769988ee 469 //Pegando o IP
brunofgc 7:ae9c47f62946 470 modemCom::leIP();
brunofgc 0:1c0a769988ee 471 //sprintf(buf,"<script>window.location.href = 'http://www.vitaesolucoes.com.br/controladorawifi/config.php?ip=%s'</script>",modemStatus.STAIP);
brunofgc 0:1c0a769988ee 472
brunofgc 0:1c0a769988ee 473 //sprintf(buf,"<!DOCTYPE html><form action='cwjap.htm' method='GET'><fieldset><legend>Parametros de Configuracao da rede:</legend>SSID WiFi:<br><input type='text' name='ssid' value=''><br>Senha WiFi:<br><input type='text' name='password' value=''><br>IP:(0 para DHCP)<br><input type='text' name='ip' value='0'><br>Porta:<br><input type='text' name='port' value=''><br><input type='submit' value='Configurar'></fieldset></form>");
brunofgc 0:1c0a769988ee 474 sprintf(buf,"<!DOCTYPE html>IP Atual = %s.<br><form action='cwjap.htm' method='GET'><fieldset><legend>Parametros de Configuracao da rede:</legend>SSID WiFi:<br><input type='text' name='ssid' value='%s'><br>Senha WiFi:<br><input type='text' name='password' value='%s'><br>PORTA:<br><input type='text' name='porta' value='%s'><br><input type='submit' value='Configurar'></fieldset></form>",modemCom::status.STAIP,modemCom::status.ssid,modemCom::status.password,modemCom::status.port);
brunofgc 0:1c0a769988ee 475
brunofgc 0:1c0a769988ee 476 cipSend(connID,buf,0);
brunofgc 0:1c0a769988ee 477 encontrado = 1;
brunofgc 0:1c0a769988ee 478 }
brunofgc 0:1c0a769988ee 479
brunofgc 0:1c0a769988ee 480 if(strstr(bufInPtr,"cwjap.htm")){
brunofgc 0:1c0a769988ee 481 //cwjap.htm?ssid=VSA&password=vitaeBBYP&ip=0&port=80
brunofgc 0:1c0a769988ee 482
brunofgc 0:1c0a769988ee 483 strtok(bufInPtr,"=");
brunofgc 3:9598af355293 484 strcpy(modemCom::status.ssid,strtok(NULL,"&")); //pegando ssid
brunofgc 0:1c0a769988ee 485
brunofgc 0:1c0a769988ee 486 strtok(NULL,"=");
brunofgc 0:1c0a769988ee 487 strcpy(modemCom::status.password,strtok(NULL,"&")); //pegando password
brunofgc 0:1c0a769988ee 488
brunofgc 0:1c0a769988ee 489 //strtok(NULL,"=");
brunofgc 0:1c0a769988ee 490 //strcpy(modemStatus.STAIP,strtok(NULL,"&")); //pegando ip
brunofgc 0:1c0a769988ee 491
brunofgc 0:1c0a769988ee 492 strtok(NULL,"=");
brunofgc 3:9598af355293 493 strcpy(modemCom::status.port,strtok(NULL," ")); //pegando port
brunofgc 0:1c0a769988ee 494
brunofgc 3:9598af355293 495 pc.printf("Antes <%s>.\r\n",modemCom::status.ssid);
brunofgc 3:9598af355293 496 diversos::strReplace(modemCom::status.ssid,"%20"," ");
brunofgc 3:9598af355293 497 pc.printf("Tirado %%20 <%s>.\r\n",modemCom::status.ssid);
brunofgc 3:9598af355293 498 diversos::strReplace(modemCom::status.ssid,"+"," ");
brunofgc 3:9598af355293 499 pc.printf("Tirado + <%s>.\r\n",modemCom::status.ssid);
brunofgc 3:9598af355293 500
brunofgc 3:9598af355293 501 if((modemCom::status.ssid[0]!=0) && (modemCom::status.password[0]!=0)){
brunofgc 3:9598af355293 502 sprintf(buf,"HTTP/1.1 200 OK\n\nACK");
brunofgc 0:1c0a769988ee 503 mudaRede = true;
brunofgc 0:1c0a769988ee 504 }else{
brunofgc 2:55b7b466e742 505 sprintf(buf,"HTTP/1.1 200 OK\n\nNACK");
brunofgc 3:9598af355293 506 }
brunofgc 3:9598af355293 507 cipSend(connID,buf,0);
brunofgc 0:1c0a769988ee 508 encontrado = 1;
brunofgc 0:1c0a769988ee 509 }
brunofgc 0:1c0a769988ee 510
brunofgc 0:1c0a769988ee 511 /*if(strstr(bufInPtr,"leTemperaturas.htm")){
brunofgc 0:1c0a769988ee 512
brunofgc 0:1c0a769988ee 513
brunofgc 0:1c0a769988ee 514
brunofgc 0:1c0a769988ee 515 strtok(bufInPtr,"=");
brunofgc 0:1c0a769988ee 516 bufInPtr = strtok(NULL,NULL);
brunofgc 0:1c0a769988ee 517 //sprintf(buf,"%s",bufInPtr);
brunofgc 0:1c0a769988ee 518 aux_int = atoi(bufInPtr);
brunofgc 0:1c0a769988ee 519 aux_int--;
brunofgc 0:1c0a769988ee 520 */
brunofgc 0:1c0a769988ee 521
brunofgc 0:1c0a769988ee 522 /*if(num_temperatureSensors){
brunofgc 0:1c0a769988ee 523 //Zerano conteudo de buff
brunofgc 0:1c0a769988ee 524 sprintf(buf,"callback({\"response\":\"");
brunofgc 0:1c0a769988ee 525 probe[0]->convertTemperature(true, DS1820::all_devices); //Start temperature conversion, wait until ready
brunofgc 0:1c0a769988ee 526 for (int i = 0; i<num_temperatureSensors; i++){
brunofgc 0:1c0a769988ee 527 sprintf(auxMsg,"%3.1f;",probe[i]->temperature());
brunofgc 0:1c0a769988ee 528 strcat(buf,auxMsg);
brunofgc 0:1c0a769988ee 529 }
brunofgc 0:1c0a769988ee 530 buf[strlen(buf)-1]=0;
brunofgc 0:1c0a769988ee 531 sprintf(auxMsg,"\"})");
brunofgc 0:1c0a769988ee 532 strcat(buf,auxMsg);
brunofgc 0:1c0a769988ee 533 }else{
brunofgc 0:1c0a769988ee 534 sprintf(buf,"callback({\"response\":\"Sensor_ERROR\"})");
brunofgc 0:1c0a769988ee 535 }
brunofgc 0:1c0a769988ee 536 if(cipSend(connID,buf,0)==1){
brunofgc 0:1c0a769988ee 537 printf("Requisicao enviada!\n");
brunofgc 0:1c0a769988ee 538 }else{
brunofgc 0:1c0a769988ee 539 printf("Requisicao nao enviada 1!!\n");
brunofgc 0:1c0a769988ee 540 }
brunofgc 0:1c0a769988ee 541 encontrado = 1;
brunofgc 0:1c0a769988ee 542 }*/
brunofgc 0:1c0a769988ee 543
brunofgc 0:1c0a769988ee 544
brunofgc 0:1c0a769988ee 545
brunofgc 0:1c0a769988ee 546 if(strstr(bufInPtr,"lecomandocontrole.htm")){
brunofgc 7:ae9c47f62946 547
brunofgc 0:1c0a769988ee 548 uint16_t timeout = 5000;
brunofgc 0:1c0a769988ee 549 IrDetect.reset();
brunofgc 0:1c0a769988ee 550 IrDetect.start();
brunofgc 0:1c0a769988ee 551
brunofgc 0:1c0a769988ee 552 while((IrDetect.read_ms()<timeout) && (!detectaIRIn()));
brunofgc 0:1c0a769988ee 553 if(IrDetect.read_ms()<timeout){
brunofgc 0:1c0a769988ee 554 serializaPacoteIR(connID);
brunofgc 0:1c0a769988ee 555 }else{
brunofgc 2:55b7b466e742 556 sprintf(buf,"erro");
brunofgc 0:1c0a769988ee 557 if(cipSend(connID,buf,0)==1){
brunofgc 0:1c0a769988ee 558 printf("Requisicao enviada!\n");
brunofgc 0:1c0a769988ee 559 }
brunofgc 0:1c0a769988ee 560 }
brunofgc 6:d4ebbaaba295 561 IrDetect.stop();
brunofgc 7:ae9c47f62946 562 encontrado = 1;
brunofgc 0:1c0a769988ee 563 }
brunofgc 0:1c0a769988ee 564
brunofgc 2:55b7b466e742 565 if(!encontrado){
brunofgc 0:1c0a769988ee 566 sprintf(buf,"Pagina Nao Encontrada.");
brunofgc 0:1c0a769988ee 567 if(cipSend(connID,buf,0)==1){
brunofgc 0:1c0a769988ee 568 printf("Requisicao enviada!\n");
brunofgc 0:1c0a769988ee 569 }else{
brunofgc 0:1c0a769988ee 570 printf("Requisicao nao enviada 3!!\n");
brunofgc 0:1c0a769988ee 571 }
brunofgc 0:1c0a769988ee 572 }
brunofgc 0:1c0a769988ee 573
brunofgc 2:55b7b466e742 574 modemCom::closeConnection(connID);
brunofgc 2:55b7b466e742 575 /*sprintf(buf,"AT+CIPCLOSE=%u\r\n",connID);
brunofgc 2:55b7b466e742 576 sendToModem(buf,1,&modemCom::status.OK,300,1);*/
brunofgc 0:1c0a769988ee 577
brunofgc 0:1c0a769988ee 578 if(mudaRede){
brunofgc 0:1c0a769988ee 579 mudaRede = false;
brunofgc 7:ae9c47f62946 580 modemCom::sendToModem("AT+CIPSERVER=0\r\n",1,&modemCom::status.OK,NULL,2000,1,1);
brunofgc 0:1c0a769988ee 581 pc.printf("Mudando para rede:\r\nSSID:%s\r\nPASSWORD:%S\r\nPORTA:%s\r\n\r\n",modemCom::status.ssid,modemCom::status.password,modemCom::status.port);
brunofgc 0:1c0a769988ee 582 if(sdCard::abreArquivo(&sdCard::config,"w")){
brunofgc 0:1c0a769988ee 583 pc.printf("Guardando config.\r\n");
brunofgc 0:1c0a769988ee 584 fprintf(sdCard::config.fp,"SSID:%s\r\nPASSWORD:%s\r\nPORT:%s",modemCom::status.ssid,modemCom::status.password,modemCom::status.port);
brunofgc 0:1c0a769988ee 585 sdCard::fechaArquivo(&sdCard::config);
brunofgc 0:1c0a769988ee 586 modemCom::conectaWiFi();
brunofgc 0:1c0a769988ee 587 }
brunofgc 0:1c0a769988ee 588 }
brunofgc 0:1c0a769988ee 589 }
brunofgc 1:0e0967c88590 590
brunofgc 7:ae9c47f62946 591 bool modemCom::leIP(void){
brunofgc 7:ae9c47f62946 592 char *ptr;
brunofgc 7:ae9c47f62946 593 sendToModem("AT+CIFSR\r\n",1,NULL,"+CIFSR:STAIP,",200,1,1);
brunofgc 7:ae9c47f62946 594 ptr=strstr(modemCom::bufIn,"+CIFSR:STAIP,");
brunofgc 7:ae9c47f62946 595 if(ptr) {
brunofgc 7:ae9c47f62946 596 ptr = strtok(ptr,"\"");
brunofgc 7:ae9c47f62946 597 ptr = strtok(NULL,"\"");
brunofgc 7:ae9c47f62946 598 strcpy(modemCom::status.STAIP,ptr);
brunofgc 7:ae9c47f62946 599 }
brunofgc 7:ae9c47f62946 600 if(strstr(modemCom::status.STAIP,"0.0.0.0")){return false;}
brunofgc 7:ae9c47f62946 601 return true;
brunofgc 7:ae9c47f62946 602 }
brunofgc 7:ae9c47f62946 603
brunofgc 1:0e0967c88590 604 int16_t modemCom::getRSSI(void){
brunofgc 2:55b7b466e742 605 /*char *ptr;
brunofgc 1:0e0967c88590 606 int16_t RSSI = 0;
brunofgc 2:55b7b466e742 607 if(modemCom::sendToModem("AT+CWLAP\r\n",1,&modemCom::status.OK,1000,1)){
brunofgc 1:0e0967c88590 608 ptr = strstr(modemCom::bufIn,(const char*)modemCom::status.ssid);
brunofgc 1:0e0967c88590 609 if(ptr){
brunofgc 1:0e0967c88590 610 ptr = strtok(ptr,",");
brunofgc 1:0e0967c88590 611 ptr = strtok(NULL,",");
brunofgc 1:0e0967c88590 612 RSSI = atoi(ptr);
brunofgc 1:0e0967c88590 613 }
brunofgc 1:0e0967c88590 614 }
brunofgc 2:55b7b466e742 615 return RSSI;*/
brunofgc 2:55b7b466e742 616 return -50;
brunofgc 1:0e0967c88590 617 }
brunofgc 7:ae9c47f62946 618
brunofgc 7:ae9c47f62946 619 bool modemCom::verificaConexao(void){
brunofgc 7:ae9c47f62946 620 uint8_t i = 1;
brunofgc 7:ae9c47f62946 621 while(i){
brunofgc 7:ae9c47f62946 622 if(!modemCom::sendToModem("AT+CWJAP?\r\n",1,NULL,"+CWJAP:",100,10,1000)){
brunofgc 7:ae9c47f62946 623 modemCom::conectaWiFi();
brunofgc 7:ae9c47f62946 624 i--;
brunofgc 7:ae9c47f62946 625 }else{
brunofgc 7:ae9c47f62946 626 return true;
brunofgc 7:ae9c47f62946 627 }
brunofgc 7:ae9c47f62946 628 }
brunofgc 7:ae9c47f62946 629 return false;
brunofgc 7:ae9c47f62946 630 }
brunofgc 0:1c0a769988ee 631
brunofgc 0:1c0a769988ee 632 void modemCom::conectaWiFi(void){
brunofgc 0:1c0a769988ee 633 //Função para mudança de rede
brunofgc 0:1c0a769988ee 634 char *ptr;
brunofgc 0:1c0a769988ee 635 char aux[128];
brunofgc 0:1c0a769988ee 636 if(sdCard::abreArquivo(&sdCard::config,"r")){
brunofgc 0:1c0a769988ee 637 pc.printf("Abrindo arquivo de config para buscar dados de conexao.\r\n");
brunofgc 0:1c0a769988ee 638 //"SSID:DROME\r\nPASSWORD:VITAE\r\nPORT:80"
brunofgc 0:1c0a769988ee 639
brunofgc 0:1c0a769988ee 640 //Pegando SSID
brunofgc 0:1c0a769988ee 641 fgets(modemCom::status.ssid,40,sdCard::config.fp);
brunofgc 2:55b7b466e742 642 ptr = strstr(modemCom::status.ssid,"SSID");
brunofgc 2:55b7b466e742 643 if(ptr!=NULL){
brunofgc 2:55b7b466e742 644 ptr = strtok(modemCom::status.ssid,":");
brunofgc 2:55b7b466e742 645 ptr = strtok(NULL,"\r\n");
brunofgc 2:55b7b466e742 646 strcpy(modemCom::status.ssid,ptr);
brunofgc 2:55b7b466e742 647
brunofgc 2:55b7b466e742 648 //Pegando PASSWORD
brunofgc 2:55b7b466e742 649 fgets(modemCom::status.password,50,sdCard::config.fp);
brunofgc 2:55b7b466e742 650 ptr = strtok(modemCom::status.password,":");
brunofgc 2:55b7b466e742 651 ptr = strtok(NULL,"\r\n");
brunofgc 2:55b7b466e742 652 strcpy(modemCom::status.password,ptr);
brunofgc 2:55b7b466e742 653
brunofgc 2:55b7b466e742 654 //Pegando PORT
brunofgc 2:55b7b466e742 655 fgets(modemCom::status.port,20,sdCard::config.fp);
brunofgc 2:55b7b466e742 656 ptr = strtok(modemCom::status.port,":");
brunofgc 2:55b7b466e742 657 ptr = strtok(NULL,"\r\n");
brunofgc 2:55b7b466e742 658 strcpy(modemCom::status.port,ptr);
brunofgc 2:55b7b466e742 659 }else{
brunofgc 2:55b7b466e742 660 strcpy(modemCom::status.ssid,"VSA");
brunofgc 2:55b7b466e742 661 strcpy(modemCom::status.password,"vitaeBBYP");
brunofgc 2:55b7b466e742 662 strcpy(modemCom::status.port,"80");
brunofgc 2:55b7b466e742 663 }
brunofgc 0:1c0a769988ee 664 sdCard::fechaArquivo(&sdCard::config);
brunofgc 0:1c0a769988ee 665 pc.printf("Lidos os parametros de configuracao de wifi como sendo:\r\nSSID:<%s>\r\nPASSWORD:<%s>\r\nPORT:<%s>\r\n\r\n",modemCom::status.ssid,modemCom::status.password,modemCom::status.port);
brunofgc 2:55b7b466e742 666 pc.printf("Iniciando conexao wifi.\r\n");
brunofgc 2:55b7b466e742 667 }else{
brunofgc 7:ae9c47f62946 668 strcpy(modemCom::status.ssid,"VSE");
brunofgc 2:55b7b466e742 669 strcpy(modemCom::status.password,"vitaeBBYP");
brunofgc 7:ae9c47f62946 670 strcpy(modemCom::status.port,"4000");
brunofgc 2:55b7b466e742 671 }
brunofgc 0:1c0a769988ee 672
brunofgc 2:55b7b466e742 673 //Mudando mode para AP e Station
brunofgc 7:ae9c47f62946 674 if(modemCom::sendToModem("AT+CWMODE=3\r\n",1,&modemCom::status.OK,NULL,10000,1,1)) {
brunofgc 2:55b7b466e742 675 pc.printf("Modo AP+STATION aceito.\n");
brunofgc 2:55b7b466e742 676 }
brunofgc 2:55b7b466e742 677
brunofgc 2:55b7b466e742 678 //AT+CWJAP=\"\",\"\"\r\n
brunofgc 2:55b7b466e742 679 sprintf(aux,"AT+CWJAP=\"%s\",\"%s\"\r\n",modemCom::status.ssid,modemCom::status.password);
brunofgc 7:ae9c47f62946 680 if(modemCom::sendToModem(aux,1,&modemCom::status.OK,NULL,10000,1,1)) {
brunofgc 2:55b7b466e742 681 pc.printf("WiFi Conectado.\n");
brunofgc 2:55b7b466e742 682 }
brunofgc 0:1c0a769988ee 683
brunofgc 0:1c0a769988ee 684 //AT+CIPSERVER=1,80
brunofgc 7:ae9c47f62946 685 if(modemCom::sendToModem("AT+CIPMUX=1\r\n",1,&modemCom::status.OK,NULL,250,4,1)) {
brunofgc 0:1c0a769988ee 686 pc.printf("Recebeu o comando AT+CIPMUX=1.\n");
brunofgc 0:1c0a769988ee 687 }
brunofgc 0:1c0a769988ee 688
brunofgc 0:1c0a769988ee 689 //AT+CIPSERVER=1,80
brunofgc 0:1c0a769988ee 690 sprintf(aux,"AT+CIPSERVER=1,%s\r\n",modemCom::status.port);
brunofgc 7:ae9c47f62946 691 if(modemCom::sendToModem(aux,1,&modemCom::status.OK,NULL,250,4,1)) {
brunofgc 0:1c0a769988ee 692 pc.printf("Recebeu o comando <%s>.\n",aux);
brunofgc 0:1c0a769988ee 693 }
brunofgc 0:1c0a769988ee 694
brunofgc 7:ae9c47f62946 695 if(modemCom::sendToModem("AT+CIPSTO=60\r\n",1,&modemCom::status.OK,NULL,250,4,1)) {
brunofgc 0:1c0a769988ee 696 pc.printf("Recebeu o comando AT+CIPSTO=60.\n");
brunofgc 2:55b7b466e742 697 }
brunofgc 0:1c0a769988ee 698
brunofgc 0:1c0a769988ee 699 sprintf(aux,"AT+CWSAP_CUR=\"DROME_WIFI_%s\",\"VsaDROME\",5,3\r\n",modemCom::status.MAC);
brunofgc 7:ae9c47f62946 700 if(modemCom::sendToModem(aux,1,&modemCom::status.OK,NULL,250,4,1)) {
brunofgc 0:1c0a769988ee 701 pc.printf("Recebeu o comando %s.\n",aux);
brunofgc 0:1c0a769988ee 702 }
brunofgc 0:1c0a769988ee 703
brunofgc 0:1c0a769988ee 704
brunofgc 7:ae9c47f62946 705 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)) {
brunofgc 0:1c0a769988ee 706 pc.printf("Recebeu o comando AT+CIPAP_CUR=\"192.168.4.1\",\"192.168.4.1\",\"255.255.255.0\".\n");
brunofgc 0:1c0a769988ee 707 }
brunofgc 0:1c0a769988ee 708
brunofgc 7:ae9c47f62946 709 if(modemCom::sendToModem("AT+CWDHCP_CUR=2,1\r\n",1,&modemCom::status.OK,NULL,250,4,1)) {
brunofgc 0:1c0a769988ee 710 pc.printf("Recebeu o comando AT+CWDHCP_CUR=2,1.\n");
brunofgc 2:55b7b466e742 711 }
brunofgc 0:1c0a769988ee 712
brunofgc 0:1c0a769988ee 713 }
brunofgc 0:1c0a769988ee 714
brunofgc 0:1c0a769988ee 715 void modemCom::processaPacote(void const *args){
brunofgc 7:ae9c47f62946 716 char *ptr,*scanPtr;
brunofgc 0:1c0a769988ee 717 uint16_t bufInLength = bufModem.getLength();
brunofgc 7:ae9c47f62946 718 uint16_t timeOut;
brunofgc 7:ae9c47f62946 719 modemCom::bufIn = bufModem.get();
brunofgc 3:9598af355293 720
brunofgc 7:ae9c47f62946 721 modemCom::status.modemResponse=true;
brunofgc 7:ae9c47f62946 722
brunofgc 7:ae9c47f62946 723 //pc.printf("Vem do modem <%s>.\r\n",modemCom::bufIn);
brunofgc 0:1c0a769988ee 724
brunofgc 7:ae9c47f62946 725 if(strstr(modemCom::bufIn,"WIFI")==NULL){
brunofgc 7:ae9c47f62946 726 //Buscando connect
brunofgc 7:ae9c47f62946 727 if(!modemCom::atendendoWebServer){
brunofgc 7:ae9c47f62946 728 ptr=strstr(modemCom::bufIn,"CONNECT\r\n");
brunofgc 7:ae9c47f62946 729 //if(strstr(modemCom::bufIn,"WIFI")){ptr=NULL;}
brunofgc 7:ae9c47f62946 730 if(ptr) {
brunofgc 7:ae9c47f62946 731 ptr = strtok(modemCom::bufIn,",");
brunofgc 7:ae9c47f62946 732 connID = atoi(ptr);
brunofgc 7:ae9c47f62946 733 modemCom::status.serverConnected=1;
brunofgc 7:ae9c47f62946 734 pc.printf("Recebido string CONNECT socket na conexao %u.\n",connID);
brunofgc 7:ae9c47f62946 735 if(!modemCom::status.emComunicacao){
brunofgc 7:ae9c47f62946 736 pc.printf("Atendendo socket entrante na conexao %u.\n",connID);
brunofgc 7:ae9c47f62946 737 modemCom::status.SRINGsockEntrante = true;
brunofgc 7:ae9c47f62946 738 }
brunofgc 7:ae9c47f62946 739 modemCom::status.emComunicacao=true;
brunofgc 7:ae9c47f62946 740 modemCom::bufIn = strtok(NULL,"");
brunofgc 7:ae9c47f62946 741 }
brunofgc 0:1c0a769988ee 742 }
brunofgc 0:1c0a769988ee 743 }
brunofgc 0:1c0a769988ee 744
brunofgc 0:1c0a769988ee 745 IPDNumBytes = 0;
brunofgc 0:1c0a769988ee 746 ptr = strstr(modemCom::bufIn,"+IPD");
brunofgc 0:1c0a769988ee 747 if(ptr!=NULL){
brunofgc 0:1c0a769988ee 748 //+IPD,0,480:GET
brunofgc 0:1c0a769988ee 749 strtok(ptr,","); //Separando +IPD
brunofgc 0:1c0a769988ee 750
brunofgc 0:1c0a769988ee 751 ptr = strtok(NULL,","); //Pegando o numero da conexão
brunofgc 0:1c0a769988ee 752 connID = atoi(ptr);
brunofgc 0:1c0a769988ee 753
brunofgc 0:1c0a769988ee 754 ptr = strtok(NULL,":"); //Pegando o numero de caracteres IPD
brunofgc 0:1c0a769988ee 755 IPDNumBytes = atoi(ptr);
brunofgc 0:1c0a769988ee 756
brunofgc 7:ae9c47f62946 757 modemCom::bufIn = strtok(NULL,"");
brunofgc 0:1c0a769988ee 758
brunofgc 7:ae9c47f62946 759 //printf("Recebido pacote via conexao %u com %lu bytes.\n",connID,IPDNumBytes);
brunofgc 0:1c0a769988ee 760
brunofgc 0:1c0a769988ee 761 }
brunofgc 0:1c0a769988ee 762
brunofgc 7:ae9c47f62946 763 //Reconhecendo GET HTTP e atendendo com um servidor web
brunofgc 7:ae9c47f62946 764 if(strstr(modemCom::bufIn,"GET /") && strstr(modemCom::bufIn,"HTTP/1.1")){
brunofgc 7:ae9c47f62946 765 ptr=strstr(modemCom::bufIn,"GET /");
brunofgc 7:ae9c47f62946 766 if(ptr) {
brunofgc 7:ae9c47f62946 767 ptr = strtok(ptr,"/");
brunofgc 7:ae9c47f62946 768 ptr = strtok(NULL," ");
brunofgc 7:ae9c47f62946 769 bufInPtr = ptr;
brunofgc 7:ae9c47f62946 770 modemCom::atendendoWebServer = true;
brunofgc 7:ae9c47f62946 771 }
brunofgc 0:1c0a769988ee 772 }
brunofgc 0:1c0a769988ee 773
brunofgc 0:1c0a769988ee 774 ptr=strstr(modemCom::bufIn,"*ServerAck*");
brunofgc 7:ae9c47f62946 775 if(ptr) {
brunofgc 7:ae9c47f62946 776 modemCom::status.ServerAck=1;
brunofgc 0:1c0a769988ee 777 }
brunofgc 0:1c0a769988ee 778
brunofgc 0:1c0a769988ee 779 ptr=strstr(modemCom::bufIn,"*ServerCommand*");
brunofgc 7:ae9c47f62946 780 if(ptr) {
brunofgc 0:1c0a769988ee 781 scanPtr = strtok (ptr,"\\");
brunofgc 7:ae9c47f62946 782 scanPtr = strtok (NULL,">");
brunofgc 0:1c0a769988ee 783 strcpy(commands::buffer,scanPtr);
brunofgc 0:1c0a769988ee 784 pc.printf("Comandos <%s>.\n",commands::buffer);
brunofgc 0:1c0a769988ee 785 executaComandoServer = true;
brunofgc 0:1c0a769988ee 786 }
brunofgc 0:1c0a769988ee 787
brunofgc 0:1c0a769988ee 788 //if(modemCom::status.recebendoArquivoDoServer){
brunofgc 7:ae9c47f62946 789 if(IPDNumBytes && modemCom::status.recebendoArquivoDoServer && (strstr(modemCom::bufIn,"CONNECT")==NULL) && (strstr(modemCom::bufIn,"*ServerCommand*")==NULL) ){
brunofgc 0:1c0a769988ee 790 sdCard::insereDadosArquivo(&sdCard::tempFile,modemCom::bufIn,IPDNumBytes);
brunofgc 7:ae9c47f62946 791 //modemCom::status.timeOut=100;
brunofgc 1:0e0967c88590 792
brunofgc 7:ae9c47f62946 793 bufModem.del();
brunofgc 0:1c0a769988ee 794
brunofgc 0:1c0a769988ee 795 sprintf(modemCom::bufIn,"AT+CIPSEND=%u,%lu\r\n",connID,10);
brunofgc 0:1c0a769988ee 796 modem.puts(modemCom::bufIn);
brunofgc 7:ae9c47f62946 797 timeOut = 5000;
brunofgc 7:ae9c47f62946 798 while(timeOut && (strstr(bufModem.getRowBuffer(),">")==NULL)){
brunofgc 7:ae9c47f62946 799 osDelay(1);
brunofgc 7:ae9c47f62946 800 timeOut--;
brunofgc 7:ae9c47f62946 801 }
brunofgc 0:1c0a769988ee 802 modem.puts("sendData\r\n");
brunofgc 0:1c0a769988ee 803 pc.printf("sendData\n");
brunofgc 0:1c0a769988ee 804 return;
brunofgc 0:1c0a769988ee 805 }
brunofgc 0:1c0a769988ee 806
brunofgc 0:1c0a769988ee 807 //Reconhecimento dos status
brunofgc 0:1c0a769988ee 808 modemCom::status.PROMPT_ENVIO_COMMAND_MODE=0;
brunofgc 0:1c0a769988ee 809 ptr=strstr(modemCom::bufIn,"> ");
brunofgc 0:1c0a769988ee 810 if(ptr) {
brunofgc 7:ae9c47f62946 811
brunofgc 0:1c0a769988ee 812 modemCom::status.serverConnected=1;
brunofgc 0:1c0a769988ee 813 modemCom::status.commandMode=1;
brunofgc 0:1c0a769988ee 814 modemCom::status.NO_CARRIER=0;
brunofgc 0:1c0a769988ee 815 modemCom::status.PROMPT_ENVIO_COMMAND_MODE=1;
brunofgc 0:1c0a769988ee 816 }
brunofgc 0:1c0a769988ee 817
brunofgc 0:1c0a769988ee 818 modemCom::status.OK=0;
brunofgc 0:1c0a769988ee 819 ptr=strstr(modemCom::bufIn,"OK\r");
brunofgc 7:ae9c47f62946 820 if(ptr) {
brunofgc 0:1c0a769988ee 821 modemCom::status.OK=1;
brunofgc 7:ae9c47f62946 822 }
brunofgc 0:1c0a769988ee 823
brunofgc 0:1c0a769988ee 824 modemCom::status.busy=false;
brunofgc 0:1c0a769988ee 825 ptr=strstr(modemCom::bufIn,"busy s...");
brunofgc 0:1c0a769988ee 826 if(ptr) {
brunofgc 7:ae9c47f62946 827
brunofgc 0:1c0a769988ee 828 modemCom::status.busy=1;
brunofgc 0:1c0a769988ee 829 }
brunofgc 0:1c0a769988ee 830
brunofgc 0:1c0a769988ee 831 modemCom::status.SEND_OK=0;
brunofgc 0:1c0a769988ee 832 ptr=strstr(modemCom::bufIn,"SEND OK");
brunofgc 0:1c0a769988ee 833 if(ptr) {
brunofgc 7:ae9c47f62946 834
brunofgc 0:1c0a769988ee 835 modemCom::status.SEND_OK=1;
brunofgc 0:1c0a769988ee 836 }
brunofgc 0:1c0a769988ee 837
brunofgc 0:1c0a769988ee 838 modemCom::status.ERROR=0;
brunofgc 0:1c0a769988ee 839 ptr=strstr(modemCom::bufIn,"ERROR");
brunofgc 0:1c0a769988ee 840 if(ptr) {
brunofgc 7:ae9c47f62946 841
brunofgc 0:1c0a769988ee 842 modemCom::status.ERROR=1;
brunofgc 0:1c0a769988ee 843 modemCom::status.OK=0;
brunofgc 7:ae9c47f62946 844 }
brunofgc 7:ae9c47f62946 845 ptr=strstr(modemCom::bufIn,"FAIL");
brunofgc 7:ae9c47f62946 846 if(ptr) {
brunofgc 7:ae9c47f62946 847
brunofgc 7:ae9c47f62946 848 modemCom::status.ERROR=1;
brunofgc 7:ae9c47f62946 849 modemCom::status.OK=0;
brunofgc 7:ae9c47f62946 850 }
brunofgc 7:ae9c47f62946 851
brunofgc 7:ae9c47f62946 852 //modemCom::status.CLOSED=false;
brunofgc 7:ae9c47f62946 853 ptr=strstr(modemCom::bufIn,"CLOSED");
brunofgc 7:ae9c47f62946 854 if(ptr) {
brunofgc 7:ae9c47f62946 855
brunofgc 7:ae9c47f62946 856 modemCom::status.CLOSED=1;
brunofgc 0:1c0a769988ee 857 }
brunofgc 0:1c0a769988ee 858
brunofgc 0:1c0a769988ee 859
brunofgc 0:1c0a769988ee 860 }
brunofgc 0:1c0a769988ee 861
brunofgc 0:1c0a769988ee 862 uint8_t modemCom::inicializaModem(void)
brunofgc 0:1c0a769988ee 863 {
brunofgc 0:1c0a769988ee 864 //uint8_t maxTentativas=0;
brunofgc 0:1c0a769988ee 865
brunofgc 0:1c0a769988ee 866 //char config[255];
brunofgc 0:1c0a769988ee 867 //char *ptr;
brunofgc 7:ae9c47f62946 868 //char *buf;
brunofgc 7:ae9c47f62946 869 //buf = bufModem.getRowBuffer();
brunofgc 0:1c0a769988ee 870
brunofgc 0:1c0a769988ee 871 modemCom::timeOutModem = 10;
brunofgc 0:1c0a769988ee 872 modemCom::status.emComunicacao = true;
brunofgc 0:1c0a769988ee 873
brunofgc 7:ae9c47f62946 874 if(modemCom::sendToModem("ATE0\r\n",1,&modemCom::status.OK,NULL,1000,10,1)) {
brunofgc 0:1c0a769988ee 875 pc.printf("Recebeu o comando ATE0.\n");
brunofgc 0:1c0a769988ee 876 }
brunofgc 0:1c0a769988ee 877
brunofgc 7:ae9c47f62946 878 modemCom::leMAC();
brunofgc 0:1c0a769988ee 879
brunofgc 0:1c0a769988ee 880 modemCom::status.emComunicacao = false;
brunofgc 0:1c0a769988ee 881 return 1;
brunofgc 0:1c0a769988ee 882 }
brunofgc 0:1c0a769988ee 883
brunofgc 0:1c0a769988ee 884