teste de publish

Dependencies:   DS1820 HighSpeedAnalogIn devices mbed

Committer:
brunofgc
Date:
Sat Jun 02 14:48:26 2018 +0000
Revision:
34:348991c54ff3
Parent:
33:a60abda630f7
Child:
36:fd239680e427
vers?o 30/05/2018 Ainda dando WDT com Bootloader

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 33:a60abda630f7 9 uint16_t modemCom::timeOutEnvioDados;
brunofgc 0:1c0a769988ee 10 uint8_t connID;
brunofgc 0:1c0a769988ee 11 uint16_t IPDNumBytes;
brunofgc 0:1c0a769988ee 12 bool enviaSendData;
brunofgc 0:1c0a769988ee 13 char *bufInPtr;
brunofgc 0:1c0a769988ee 14 bool mudaRede = false;
brunofgc 9:cf406384efd9 15 char webServerBuff[256];
brunofgc 0:1c0a769988ee 16
brunofgc 0:1c0a769988ee 17 void modemCom::atendeSRING(uint8_t conId){
brunofgc 6:d4ebbaaba295 18 //pc.printf("Atendendo a conexao entrante.\n");
brunofgc 15:0f78bf9c13ec 19
brunofgc 15:0f78bf9c13ec 20 if(modemCom::status.emComunicacao){
brunofgc 15:0f78bf9c13ec 21 modemCom::cipSend(conId,"ocupado",7);
brunofgc 22:cb832a9bc704 22 pc.printf("Fechando socket chave 1.\r\n");
brunofgc 33:a60abda630f7 23 modemCom::closeConnection(&modemCom::status.connIDServerCommand);
brunofgc 33:a60abda630f7 24 modemCom::closeConnection(&modemCom::status.connIDWebServer);
brunofgc 33:a60abda630f7 25 modemCom::closeConnection(&modemCom::status.connIDSendData);
brunofgc 15:0f78bf9c13ec 26 }
brunofgc 15:0f78bf9c13ec 27
brunofgc 0:1c0a769988ee 28 modemCom::status.socketEntranteAtivo=true;
brunofgc 0:1c0a769988ee 29 modemCom::status.timeOut = 30;
brunofgc 9:cf406384efd9 30 modemCom::timeOutModem = 10;
brunofgc 9:cf406384efd9 31
brunofgc 9:cf406384efd9 32 //pc.printf("Entrei em modemCom::atendeSRING.\r\n");
brunofgc 9:cf406384efd9 33
brunofgc 33:a60abda630f7 34 while(modemCom::status.timeOut){
brunofgc 9:cf406384efd9 35 if(modemCom::status.timeOut){modemCom::status.timeOut--;}
brunofgc 0:1c0a769988ee 36 /*//Aqui devo perguntar e pedir os dados em buffer
brunofgc 0:1c0a769988ee 37 */
brunofgc 9:cf406384efd9 38 osDelay(100);
brunofgc 0:1c0a769988ee 39 }
brunofgc 9:cf406384efd9 40
brunofgc 0:1c0a769988ee 41 //Para parar de colocar dentro do arquivo
brunofgc 0:1c0a769988ee 42 modemCom::status.recebendoArquivoDoServer = false;
brunofgc 0:1c0a769988ee 43
brunofgc 0:1c0a769988ee 44 modemCom::status.serverConnected=0;
brunofgc 0:1c0a769988ee 45 modemCom::timeOutModem = 10;
brunofgc 0:1c0a769988ee 46
brunofgc 22:cb832a9bc704 47 //Fechando o socket
brunofgc 22:cb832a9bc704 48 pc.printf("Fechando socket chave 2.\r\n");
brunofgc 33:a60abda630f7 49 modemCom::closeConnection(&modemCom::status.connIDServerCommand);
brunofgc 33:a60abda630f7 50 modemCom::closeConnection(&modemCom::status.connIDWebServer);
brunofgc 33:a60abda630f7 51 modemCom::closeConnection(&modemCom::status.connIDSendData);
brunofgc 0:1c0a769988ee 52 modemCom::status.socketEntranteAtivo=false;
brunofgc 0:1c0a769988ee 53 modemCom::status.emComunicacao = false;
brunofgc 0:1c0a769988ee 54 modemCom::timeOutModem = 10;
brunofgc 0:1c0a769988ee 55 }
brunofgc 0:1c0a769988ee 56
brunofgc 0:1c0a769988ee 57 bool modemCom::sendBufferCommandMode(uint8_t sId, char *buffer, uint16_t bufferLength){
brunofgc 0:1c0a769988ee 58 char aux[25];
brunofgc 0:1c0a769988ee 59 uint16_t numeroByteSendoEnviado;
brunofgc 0:1c0a769988ee 60
brunofgc 0:1c0a769988ee 61 sprintf(aux,"AT+CIPSEND=%u,%lu\r\n",sId,bufferLength);
brunofgc 34:348991c54ff3 62 if(modemCom::sendToModem(aux,1,&modemCom::status.PROMPT_ENVIO_COMMAND_MODE,NULL,500,2,1)) {
brunofgc 0:1c0a769988ee 63 for(numeroByteSendoEnviado = 0; numeroByteSendoEnviado<bufferLength; numeroByteSendoEnviado++) {
brunofgc 0:1c0a769988ee 64 modem.printf("%c",buffer[numeroByteSendoEnviado]);
brunofgc 30:8a06a85d8807 65 if(debug){
brunofgc 0:1c0a769988ee 66 pc.printf("%c",buffer[numeroByteSendoEnviado]);
brunofgc 30:8a06a85d8807 67 }
brunofgc 30:8a06a85d8807 68
brunofgc 0:1c0a769988ee 69 }
brunofgc 7:ae9c47f62946 70 numeroByteSendoEnviado = modemCom::sendToModem(NULL,1,&modemCom::status.SEND_OK,NULL,500,1,1);
brunofgc 0:1c0a769988ee 71 }else{
brunofgc 0:1c0a769988ee 72 numeroByteSendoEnviado = false; //Reaproveitando numeroByteSendoEnviado para resultado de retorno
brunofgc 0:1c0a769988ee 73 }
brunofgc 0:1c0a769988ee 74 return numeroByteSendoEnviado; //Reaproveitando numeroByteSendoEnviado para resultado de retorno
brunofgc 0:1c0a769988ee 75 }
brunofgc 0:1c0a769988ee 76
brunofgc 0:1c0a769988ee 77 void modemCom::leMAC(void)
brunofgc 0:1c0a769988ee 78 {
brunofgc 0:1c0a769988ee 79 char *ptr;
brunofgc 34:348991c54ff3 80 if(modemCom::sendToModem("AT+CIPSTAMAC?\r\n",1,&modemCom::status.modemResponse,NULL,500,2,1)){
brunofgc 0:1c0a769988ee 81 //resposta: +CIPSTAMAC:"18:fe:34:f4:5f:c4"
brunofgc 0:1c0a769988ee 82 ptr = strtok(bufModem.getRowBuffer(),"\"");
brunofgc 0:1c0a769988ee 83 ptr = strtok(NULL,"\"");
brunofgc 0:1c0a769988ee 84 if(ptr) {
brunofgc 0:1c0a769988ee 85 strcpy(modemCom::status.MAC,ptr);
brunofgc 9:cf406384efd9 86 //pc.printf("Lido MAC <%s>.\n",modemCom::status.MAC);
brunofgc 0:1c0a769988ee 87 }
brunofgc 0:1c0a769988ee 88 }
brunofgc 0:1c0a769988ee 89 }
brunofgc 0:1c0a769988ee 90
brunofgc 7:ae9c47f62946 91
brunofgc 0:1c0a769988ee 92
brunofgc 1:0e0967c88590 93 bool modemCom::writeStatusToSD(void){
brunofgc 30:8a06a85d8807 94 char aux[50];
brunofgc 1:0e0967c88590 95 int16_t RSSI;
brunofgc 1:0e0967c88590 96 RSSI = modemCom::getRSSI();
brunofgc 1:0e0967c88590 97 sdCardBuf.del();
brunofgc 1:0e0967c88590 98 sdCardBuf.fill("log{status:ip=255.255.255.255;csq=",34);
brunofgc 1:0e0967c88590 99
brunofgc 1:0e0967c88590 100 sprintf(aux,"%d",RSSI);
brunofgc 1:0e0967c88590 101 sdCardBuf.fill(aux,strlen(aux));
brunofgc 1:0e0967c88590 102
brunofgc 33:a60abda630f7 103
brunofgc 33:a60abda630f7 104
brunofgc 33:a60abda630f7 105 sprintf(aux,";fv=%s;rc=%s",firmVersion,resetCauses);
brunofgc 33:a60abda630f7 106 sdCardBuf.fill(aux,strlen(aux));
brunofgc 30:8a06a85d8807 107
brunofgc 1:0e0967c88590 108 sprintf(aux,";imsi=%s}log",modemCom::status.MAC);
brunofgc 30:8a06a85d8807 109 sdCardBuf.fill(aux,strlen(aux));
brunofgc 10:263c093f8977 110 return sdCard::insereDadosBank(sdCardBuf.get(),sdCardBuf.getLength());
brunofgc 1:0e0967c88590 111 }
brunofgc 1:0e0967c88590 112
brunofgc 0:1c0a769988ee 113 bool modemCom::montaStatus(void)
brunofgc 0:1c0a769988ee 114 {
brunofgc 0:1c0a769988ee 115 if(sdCard::abreArquivo(&sdCard::status,"w")) {
brunofgc 0:1c0a769988ee 116 fprintf(sdCard::status.fp,"log{status:ip:255.255.255.255;csq:30;imsi:%s}log",modemCom::status.MAC);
brunofgc 0:1c0a769988ee 117 sdCard::fechaArquivo(&sdCard::status);
brunofgc 0:1c0a769988ee 118 sdCard::exibeArquivo(&sdCard::status);
brunofgc 0:1c0a769988ee 119 } else {
brunofgc 0:1c0a769988ee 120 return 0;
brunofgc 0:1c0a769988ee 121 }
brunofgc 0:1c0a769988ee 122 return true;
brunofgc 0:1c0a769988ee 123 }
brunofgc 0:1c0a769988ee 124
brunofgc 0:1c0a769988ee 125
brunofgc 0:1c0a769988ee 126
brunofgc 10:263c093f8977 127 uint8_t modemCom::enviaDados()
brunofgc 0:1c0a769988ee 128 {
brunofgc 29:823a9da3696b 129 uint8_t result=false;
brunofgc 10:263c093f8977 130 pc.printf("modemCom::enviaDados[1].\r\n");
brunofgc 10:263c093f8977 131 if(!sdCard::preparaEnvio()){
brunofgc 10:263c093f8977 132 pc.printf("modemCom::enviaDados[2].\r\n");
brunofgc 10:263c093f8977 133 //pc.printf("Nao foi possivel preparar o envio.\n");
brunofgc 10:263c093f8977 134 return false;
brunofgc 0:1c0a769988ee 135 }
brunofgc 13:b9183b4bc049 136 sdCard::verificaCurrentBank();
brunofgc 11:631bea162800 137 pc.printf("modemCom::enviaDados[3], currentBank = %lu currentBankSending = %lu.\r\n",sdCard::currentBank,sdCard::currentBankSending);
brunofgc 13:b9183b4bc049 138 sdCard::getFileTam(&sdCard::bank0);
brunofgc 13:b9183b4bc049 139 sdCard::getFileTam(&sdCard::bank1);
brunofgc 13:b9183b4bc049 140 if((sdCard::bank0.bytes > 230400) || (sdCard::bank1.bytes > 230400)){
brunofgc 13:b9183b4bc049 141 pc.printf("Arquivo muito grande. Deletado.");
brunofgc 13:b9183b4bc049 142 sdCard::excluiArquivo(&sdCard::currentBankFile);
brunofgc 13:b9183b4bc049 143 sdCard::excluiArquivo(&sdCard::bank0);
brunofgc 13:b9183b4bc049 144 sdCard::excluiArquivo(&sdCard::bank1);
brunofgc 13:b9183b4bc049 145 return false;
brunofgc 13:b9183b4bc049 146 }
brunofgc 11:631bea162800 147 switch(sdCard::currentBankSending){
brunofgc 10:263c093f8977 148 case 0:
brunofgc 16:9a19ac33957e 149 if(sdCard::currentBank==0){
brunofgc 11:631bea162800 150 sdCard::modificaCurrentBank(1,0);
brunofgc 11:631bea162800 151 }
brunofgc 10:263c093f8977 152 pc.printf("modemCom::enviaDados[4].\r\n");
brunofgc 16:9a19ac33957e 153
brunofgc 16:9a19ac33957e 154 if(!sdCard::getFileTam(&sdCard::bank0)){
brunofgc 16:9a19ac33957e 155 sdCard::modificaCurrentBank(0,1);
brunofgc 16:9a19ac33957e 156 }else{
brunofgc 11:631bea162800 157 pc.printf("modemCom::enviaDados[11].\r\n");
brunofgc 18:1eefda1f7736 158 if(modemCom::postFileCommandMode(modemCom::status.serverIP,modemCom::status.host,"/drome/Parser/",&sdCard::bank0)){
brunofgc 25:a6da63ed025b 159 //if(modemCom::postFileCommandMode(modemCom::status.serverIP,modemCom::status.host,"/sistema/Parser/",&sdCard::bank0)){
brunofgc 16:9a19ac33957e 160 pc.printf("Enviado o bank0.\r\n");
brunofgc 16:9a19ac33957e 161 result = true;
brunofgc 10:263c093f8977 162 }
brunofgc 11:631bea162800 163 }
brunofgc 16:9a19ac33957e 164
brunofgc 0:1c0a769988ee 165 break;
brunofgc 10:263c093f8977 166 case 1:
brunofgc 13:b9183b4bc049 167 if(sdCard::currentBank==1){
brunofgc 11:631bea162800 168 sdCard::modificaCurrentBank(0,1);
brunofgc 11:631bea162800 169 }
brunofgc 11:631bea162800 170 pc.printf("modemCom::enviaDados[5].\r\n");
brunofgc 16:9a19ac33957e 171 if(!sdCard::getFileTam(&sdCard::bank1)){
brunofgc 16:9a19ac33957e 172 sdCard::modificaCurrentBank(1,0);
brunofgc 16:9a19ac33957e 173 }else{
brunofgc 16:9a19ac33957e 174 pc.printf("modemCom::enviaDados[12].\r\n");
brunofgc 18:1eefda1f7736 175 if(modemCom::postFileCommandMode(modemCom::status.serverIP,modemCom::status.host,"/drome/Parser/",&sdCard::bank1)){
brunofgc 25:a6da63ed025b 176 //if(modemCom::postFileCommandMode(modemCom::status.serverIP,modemCom::status.host,"/sistema/Parser/",&sdCard::bank1)){
brunofgc 16:9a19ac33957e 177 pc.printf("Enviado o bank1.\r\n");
brunofgc 16:9a19ac33957e 178 result = true;
brunofgc 10:263c093f8977 179 }
brunofgc 16:9a19ac33957e 180 }
brunofgc 11:631bea162800 181 break;
brunofgc 10:263c093f8977 182 case 2:
brunofgc 29:823a9da3696b 183 pc.printf("modemCom::enviaDados[10].\r\n");
brunofgc 15:0f78bf9c13ec 184 result = false;
brunofgc 10:263c093f8977 185 break;
brunofgc 10:263c093f8977 186 }
brunofgc 0:1c0a769988ee 187 return result;
brunofgc 0:1c0a769988ee 188 }
brunofgc 0:1c0a769988ee 189
brunofgc 0:1c0a769988ee 190
brunofgc 0:1c0a769988ee 191
brunofgc 18:1eefda1f7736 192 uint8_t modemCom::postFileCommandMode(char *serverIP, char *host, char *uri, arquivoSD *arquivo)
brunofgc 0:1c0a769988ee 193 {
brunofgc 0:1c0a769988ee 194 #define maxRetentativasEnvioParteArquivo 20
brunofgc 0:1c0a769988ee 195 uint32_t numeroDePartes;
brunofgc 0:1c0a769988ee 196 uint16_t restoDoEnvio;
brunofgc 0:1c0a769988ee 197 int32_t parteSendoEnviada;
brunofgc 0:1c0a769988ee 198 uint16_t numeroByteSendoEnviado;
brunofgc 0:1c0a769988ee 199 uint16_t maxTentativas=0;
brunofgc 0:1c0a769988ee 200 //unsigned int result;
brunofgc 0:1c0a769988ee 201 char header[512];
brunofgc 0:1c0a769988ee 202 char aux[40];
brunofgc 0:1c0a769988ee 203 uint16_t headerTam;
brunofgc 0:1c0a769988ee 204 uint32_t dataTam=0;
brunofgc 0:1c0a769988ee 205 char c;
brunofgc 0:1c0a769988ee 206 bool passaParaProximaParte = false;
brunofgc 10:263c093f8977 207 char nomeArquivo[50];
brunofgc 12:95eb36d5e82d 208 uint32_t parteEnviadaAntes = 0;
brunofgc 10:263c093f8977 209 sdCard::deleteSentFiles = false;
brunofgc 10:263c093f8977 210
brunofgc 10:263c093f8977 211 if(strstr(arquivo->nome,"bank0.txt")||strstr(arquivo->nome,"bank1.txt")){
brunofgc 10:263c093f8977 212 strcpy(nomeArquivo,"/sd/RAD/envio.txt");
brunofgc 10:263c093f8977 213 }else{
brunofgc 10:263c093f8977 214 strcpy(nomeArquivo,arquivo->nome);
brunofgc 10:263c093f8977 215 }
brunofgc 0:1c0a769988ee 216
brunofgc 0:1c0a769988ee 217 //Para garantir que não seja duvidoso proveniente de outra conexão.
brunofgc 0:1c0a769988ee 218 modemCom::status.ServerAck=0;
brunofgc 33:a60abda630f7 219
brunofgc 11:631bea162800 220 modemCom::status.dnsError=0;
brunofgc 0:1c0a769988ee 221
brunofgc 30:8a06a85d8807 222 pc.printf("Iniciando envio de arquivo.\r\n");
brunofgc 8:9f8ad3dbeb87 223 if(arquivo->bytes==0){
brunofgc 0:1c0a769988ee 224 if((!sdCard::getFileTam(arquivo))||(arquivo->bytes == 0)){
brunofgc 7:ae9c47f62946 225 if(arquivo->bytes == 0){
brunofgc 7:ae9c47f62946 226 sdCard::excluiArquivo(arquivo);
brunofgc 7:ae9c47f62946 227 }
brunofgc 0:1c0a769988ee 228 return false;
brunofgc 0:1c0a769988ee 229 }
brunofgc 0:1c0a769988ee 230 }
brunofgc 0:1c0a769988ee 231
brunofgc 18:1eefda1f7736 232 pc.printf("Abrindo o socket em <%s>.\n",serverIP);
brunofgc 25:a6da63ed025b 233 modemCom::status.ALREADY_CONNECTED=0;
brunofgc 18:1eefda1f7736 234 sprintf(header,"AT+CIPSTART=1,\"TCP\",\"%s\",80\r\n",serverIP);
brunofgc 11:631bea162800 235 if(modemCom::sendToModem(header,1,&modemCom::status.OK,NULL,20000,3,1000)){
brunofgc 33:a60abda630f7 236
brunofgc 0:1c0a769988ee 237 pc.printf("Aberto o socket em command mode.\n");
brunofgc 10:263c093f8977 238 pc.printf("Enviando arquivo com nome %s.\n",nomeArquivo);
brunofgc 33:a60abda630f7 239 modemCom::status.connIDSendData=1;
brunofgc 0:1c0a769988ee 240 modemCom::status.serverConnected=1;
brunofgc 29:823a9da3696b 241 modemCom::timeOutModem = 50;
brunofgc 0:1c0a769988ee 242 modemCom::status.emComunicacao = true;
brunofgc 0:1c0a769988ee 243 } else {
brunofgc 0:1c0a769988ee 244 pc.printf("Nao foi possivel Abrir o socket. Abortando tentativa.\n");
brunofgc 25:a6da63ed025b 245 if(modemCom::status.ALREADY_CONNECTED){
brunofgc 25:a6da63ed025b 246 //Socket aberto, fecho-o antes de partir.
brunofgc 33:a60abda630f7 247 modemCom::closeConnection(&modemCom::status.connIDSendData);
brunofgc 25:a6da63ed025b 248 }
brunofgc 29:823a9da3696b 249 modemCom::timeOutModem = 20;
brunofgc 29:823a9da3696b 250 modemCom::status.emComunicacao = false;
brunofgc 0:1c0a769988ee 251 return 0;
brunofgc 0:1c0a769988ee 252 }
brunofgc 0:1c0a769988ee 253
brunofgc 0:1c0a769988ee 254 numeroDePartes = arquivo->bytes / numeroDeBytesPorEnvio;
brunofgc 0:1c0a769988ee 255 restoDoEnvio = arquivo->bytes % numeroDeBytesPorEnvio;
brunofgc 0:1c0a769988ee 256
brunofgc 3:9598af355293 257
brunofgc 30:8a06a85d8807 258 if(xeretaModem){
brunofgc 30:8a06a85d8807 259 pc.printf("Iniciando o envio do arquivo de %lu bytes\nnumeroDePartes = %lu\nrestoDoEnvio = %lu\n",arquivo->bytes,numeroDePartes,restoDoEnvio);
brunofgc 30:8a06a85d8807 260 }
brunofgc 0:1c0a769988ee 261
brunofgc 0:1c0a769988ee 262 if(!sdCard::abreArquivo(arquivo,"r")){
brunofgc 7:ae9c47f62946 263 pc.printf("Nao foi posssivel abrir o arquivo de dentro da funcao postFileCommandMode().\n");
brunofgc 0:1c0a769988ee 264 modemCom::status.emComunicacao = false;
brunofgc 0:1c0a769988ee 265 return 0;
brunofgc 0:1c0a769988ee 266 }
brunofgc 0:1c0a769988ee 267
brunofgc 4:13ff9c81dc10 268
brunofgc 0:1c0a769988ee 269 //Monta Header aqui!
brunofgc 4:13ff9c81dc10 270 //application/octet-stream
brunofgc 10:263c093f8977 271 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,nomeArquivo);
brunofgc 0:1c0a769988ee 272
brunofgc 0:1c0a769988ee 273 dataTam = strlen(header);
brunofgc 0:1c0a769988ee 274 dataTam+=arquivo->bytes;
brunofgc 4:13ff9c81dc10 275 dataTam+= strlen("\r\n--xxBOUNDARYxx--");
brunofgc 0:1c0a769988ee 276 //"/drome/parser/index.php" uri drome
brunofgc 4:13ff9c81dc10 277 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 278 headerTam = strlen(header); //Pego o tamanho parcial para fazer a concatenaçao a fim de predizer o tamanho do post total
brunofgc 0:1c0a769988ee 279
brunofgc 10:263c093f8977 280 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,nomeArquivo);
brunofgc 0:1c0a769988ee 281 headerTam = strlen(header);
brunofgc 0:1c0a769988ee 282
brunofgc 0:1c0a769988ee 283 sprintf(aux,"AT+CIPSEND=1,%u\r\n",headerTam);
brunofgc 34:348991c54ff3 284 if(modemCom::sendToModem(aux,1,&modemCom::status.PROMPT_ENVIO_COMMAND_MODE,NULL,1000,1,1)) {
brunofgc 7:ae9c47f62946 285 if(!modemCom::sendToModem(header,1,&modemCom::status.SEND_OK,NULL,1000,1,1)) {
brunofgc 0:1c0a769988ee 286 sdCard::fechaArquivo(arquivo);
brunofgc 0:1c0a769988ee 287 modemCom::status.emComunicacao = false;
brunofgc 3:9598af355293 288 pc.printf("Cabecalho http nao enviado.\n");
brunofgc 0:1c0a769988ee 289 return 0;
brunofgc 0:1c0a769988ee 290 } else {
brunofgc 3:9598af355293 291 pc.printf("Cabecalho http enviado.\n");
brunofgc 0:1c0a769988ee 292 }
brunofgc 0:1c0a769988ee 293 } else {
brunofgc 0:1c0a769988ee 294 pc.printf("Erro enviando arquivo.\n");
brunofgc 0:1c0a769988ee 295 sdCard::fechaArquivo(arquivo);
brunofgc 0:1c0a769988ee 296 modemCom::status.emComunicacao = false;
brunofgc 0:1c0a769988ee 297 return 0;
brunofgc 0:1c0a769988ee 298 }
brunofgc 0:1c0a769988ee 299
brunofgc 0:1c0a769988ee 300 //Enviando as partes inteiras
brunofgc 0:1c0a769988ee 301 maxTentativas = maxRetentativasEnvioParteArquivo;
brunofgc 0:1c0a769988ee 302 for(parteSendoEnviada=0; parteSendoEnviada<numeroDePartes; parteSendoEnviada++) {
brunofgc 0:1c0a769988ee 303 //Aqui realizo o envio de cada parte.
brunofgc 0:1c0a769988ee 304 passaParaProximaParte = false;
brunofgc 30:8a06a85d8807 305 if((parteSendoEnviada%10)==0){
brunofgc 12:95eb36d5e82d 306 //Kick no watchdog
brunofgc 12:95eb36d5e82d 307 if(parteEnviadaAntes!=parteSendoEnviada){
brunofgc 12:95eb36d5e82d 308 diversos::wdt.kick(90.0);
brunofgc 12:95eb36d5e82d 309 parteEnviadaAntes=parteSendoEnviada;
brunofgc 30:8a06a85d8807 310 if(debug){pc.printf("Watchdog KICK!.");}
brunofgc 12:95eb36d5e82d 311 }
brunofgc 12:95eb36d5e82d 312 }
brunofgc 0:1c0a769988ee 313 while((maxTentativas)&&(!passaParaProximaParte)) {
brunofgc 0:1c0a769988ee 314 sprintf(aux,"AT+CIPSEND=1,%u\r\n",numeroDeBytesPorEnvio);
brunofgc 34:348991c54ff3 315 if(modemCom::sendToModem(aux,1,&modemCom::status.PROMPT_ENVIO_COMMAND_MODE,NULL,1000,1,1)) {
brunofgc 0:1c0a769988ee 316 if(maxTentativas!=maxRetentativasEnvioParteArquivo) {
brunofgc 0:1c0a769988ee 317 //Estou realizando reenvio desta parte logo preciso fazer fseek para a quantidade de bytes do envio anterior
brunofgc 0:1c0a769988ee 318 fseek(arquivo->fp,-numeroDeBytesPorEnvio,SEEK_CUR);
brunofgc 0:1c0a769988ee 319 }
brunofgc 30:8a06a85d8807 320 if(debug){pc.printf("Numero de bytes por envio = %lu.\r\n",numeroDeBytesPorEnvio);}
brunofgc 0:1c0a769988ee 321 for(numeroByteSendoEnviado=0; numeroByteSendoEnviado<(numeroDeBytesPorEnvio); numeroByteSendoEnviado++) {
brunofgc 0:1c0a769988ee 322 c = fgetc(arquivo->fp);
brunofgc 0:1c0a769988ee 323 modem.printf("%c",c);
brunofgc 30:8a06a85d8807 324 if(debug){
brunofgc 4:13ff9c81dc10 325 pc.printf("%c",c);
brunofgc 30:8a06a85d8807 326 }
brunofgc 0:1c0a769988ee 327 }
brunofgc 0:1c0a769988ee 328
brunofgc 7:ae9c47f62946 329 if(modemCom::sendToModem(NULL,1,&modemCom::status.SEND_OK,NULL,5000,1,1)) {
brunofgc 0:1c0a769988ee 330 diversos::progressBar(parteSendoEnviada,numeroDePartes);
brunofgc 0:1c0a769988ee 331 //Preciso verificar se o buffer esvaziou. Se deu "flush"
brunofgc 0:1c0a769988ee 332 //if(modemCom::aguardaFlush(0)==1) {
brunofgc 0:1c0a769988ee 333 //passa pra proxima parte
brunofgc 0:1c0a769988ee 334 passaParaProximaParte = true;
brunofgc 0:1c0a769988ee 335 maxTentativas = maxRetentativasEnvioParteArquivo;
brunofgc 0:1c0a769988ee 336 } else {
brunofgc 0:1c0a769988ee 337 maxTentativas--;
brunofgc 0:1c0a769988ee 338 if(maxTentativas == 1) {
brunofgc 30:8a06a85d8807 339 if(debug){pc.printf("MaxTentativas dentro de envio das partes == 1, vou aguardar o flush.\n");}
brunofgc 0:1c0a769988ee 340 }
brunofgc 0:1c0a769988ee 341 if(maxTentativas == 0) {
brunofgc 0:1c0a769988ee 342 sdCard::fechaArquivo(arquivo);
brunofgc 0:1c0a769988ee 343 modemCom::status.emComunicacao = false;
brunofgc 0:1c0a769988ee 344 return 0;
brunofgc 0:1c0a769988ee 345 }
brunofgc 0:1c0a769988ee 346 }
brunofgc 0:1c0a769988ee 347 } else {
brunofgc 0:1c0a769988ee 348 pc.printf("Erro enviando o arquivo nao recebeu a tentativa de envio de parte inteira.\n");
brunofgc 0:1c0a769988ee 349 sdCard::fechaArquivo(arquivo);
brunofgc 0:1c0a769988ee 350 modemCom::status.emComunicacao = false;
brunofgc 0:1c0a769988ee 351 return 0;
brunofgc 0:1c0a769988ee 352 }
brunofgc 0:1c0a769988ee 353 }
brunofgc 0:1c0a769988ee 354 if(!passaParaProximaParte) {
brunofgc 0:1c0a769988ee 355 pc.printf("Erro enviando o arquivo nao recebeu a tentativa de envio de parte inteira.\n");
brunofgc 0:1c0a769988ee 356 sdCard::fechaArquivo(arquivo);
brunofgc 0:1c0a769988ee 357 modemCom::status.emComunicacao = false;
brunofgc 0:1c0a769988ee 358 return 0;
brunofgc 0:1c0a769988ee 359 }
brunofgc 0:1c0a769988ee 360 }
brunofgc 0:1c0a769988ee 361
brunofgc 0:1c0a769988ee 362 //Enviando o resto
brunofgc 0:1c0a769988ee 363 passaParaProximaParte = false;
brunofgc 0:1c0a769988ee 364 maxTentativas = maxRetentativasEnvioParteArquivo;
brunofgc 0:1c0a769988ee 365 while((maxTentativas)&&(!passaParaProximaParte)) {
brunofgc 4:13ff9c81dc10 366 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 34:348991c54ff3 367 if(modemCom::sendToModem(aux,1,&modemCom::status.PROMPT_ENVIO_COMMAND_MODE,NULL,1000,1,1)) {
brunofgc 0:1c0a769988ee 368 for(numeroByteSendoEnviado=0; numeroByteSendoEnviado<restoDoEnvio; numeroByteSendoEnviado++) {
brunofgc 0:1c0a769988ee 369 //Envio os bytes aqui! Menos o ultimo para ter o check;
brunofgc 0:1c0a769988ee 370 c = fgetc(arquivo->fp);
brunofgc 0:1c0a769988ee 371 modem.printf("%c",c);
brunofgc 30:8a06a85d8807 372 if(debug){
brunofgc 0:1c0a769988ee 373 pc.printf("%c",c);
brunofgc 30:8a06a85d8807 374 }
brunofgc 0:1c0a769988ee 375 }
brunofgc 7:ae9c47f62946 376 if(modemCom::sendToModem("\r\n--xxBOUNDARYxx--\r\n\r\n",1,&modemCom::status.SEND_OK,NULL,5000,1,1)) {
brunofgc 0:1c0a769988ee 377 if(numeroDePartes) {
brunofgc 0:1c0a769988ee 378 diversos::progressBar(parteSendoEnviada,numeroDePartes);
brunofgc 0:1c0a769988ee 379 }
brunofgc 0:1c0a769988ee 380 passaParaProximaParte = true;
brunofgc 30:8a06a85d8807 381 if(debug){
brunofgc 30:8a06a85d8807 382 pc.printf("\nEnviado o resto do envio com fim de cabecalho!\n",parteSendoEnviada);
brunofgc 30:8a06a85d8807 383 }
brunofgc 0:1c0a769988ee 384 modemCom::timeOutModem = 250;
brunofgc 0:1c0a769988ee 385 //}
brunofgc 0:1c0a769988ee 386 /*else {
brunofgc 0:1c0a769988ee 387 pc.printf("Erro enviando arquivo.\n");
brunofgc 0:1c0a769988ee 388 fclose(fp);
brunofgc 0:1c0a769988ee 389 *aberto = false;
brunofgc 0:1c0a769988ee 390 return 0;
brunofgc 0:1c0a769988ee 391 }*/
brunofgc 0:1c0a769988ee 392 } else {
brunofgc 0:1c0a769988ee 393 sdCard::fechaArquivo(arquivo);
brunofgc 0:1c0a769988ee 394 modemCom::status.emComunicacao = false;
brunofgc 0:1c0a769988ee 395 return 0;
brunofgc 0:1c0a769988ee 396 }
brunofgc 0:1c0a769988ee 397 } else {
brunofgc 0:1c0a769988ee 398 maxTentativas--;
brunofgc 34:348991c54ff3 399 modemCom::sendToModem("AT\r\n",1,&modemCom::status.OK,NULL,1000,1,1);
brunofgc 0:1c0a769988ee 400 }
brunofgc 0:1c0a769988ee 401 }
brunofgc 0:1c0a769988ee 402
brunofgc 0:1c0a769988ee 403 if(!passaParaProximaParte) {
brunofgc 0:1c0a769988ee 404 pc.printf("Erro enviando o arquivo nao recebeu a tentativa de envio de parte inteira.\n");
brunofgc 0:1c0a769988ee 405 sdCard::fechaArquivo(arquivo);
brunofgc 0:1c0a769988ee 406 modemCom::status.emComunicacao = false;
brunofgc 0:1c0a769988ee 407 return 0;
brunofgc 0:1c0a769988ee 408 }
brunofgc 0:1c0a769988ee 409
brunofgc 9:cf406384efd9 410 sdCard::fechaArquivo(arquivo);
brunofgc 9:cf406384efd9 411
brunofgc 0:1c0a769988ee 412 //Logica de timeout esperando confirmação modemCom::status.ServerAck 20 segundos
brunofgc 33:a60abda630f7 413 parteSendoEnviada = 300; //Reaproveitando variável
brunofgc 33:a60abda630f7 414 while((parteSendoEnviada)&&(!modemCom::status.ServerAck)) {
brunofgc 0:1c0a769988ee 415 osDelay(100);
brunofgc 0:1c0a769988ee 416 parteSendoEnviada--;
brunofgc 0:1c0a769988ee 417 }
brunofgc 0:1c0a769988ee 418
brunofgc 9:cf406384efd9 419 modemCom::status.serverConnected=0;
brunofgc 0:1c0a769988ee 420 //modemCom::sendToModem("AT+CIPCLOSE=1\r\n",1,&modemCom::status.OK,500,3);
brunofgc 33:a60abda630f7 421 modemCom::closeConnection(&modemCom::status.connIDSendData);
brunofgc 0:1c0a769988ee 422 modemCom::status.emComunicacao = false;
brunofgc 29:823a9da3696b 423
brunofgc 0:1c0a769988ee 424 return modemCom::status.ServerAck;
brunofgc 0:1c0a769988ee 425 }
brunofgc 0:1c0a769988ee 426
brunofgc 7:ae9c47f62946 427 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 428 {
brunofgc 0:1c0a769988ee 429 uint16_t timeOutProcesso;
brunofgc 21:b9315cdd9275 430 uint16_t indexString,strLen; //Para exibir retentativas!
brunofgc 29:823a9da3696b 431 timeOut/=5;
brunofgc 0:1c0a769988ee 432 while(maxTentativas){
brunofgc 0:1c0a769988ee 433 timeOutProcesso=timeOut;
brunofgc 7:ae9c47f62946 434
brunofgc 7:ae9c47f62946 435
brunofgc 7:ae9c47f62946 436 bufModem.del(); //Deletando o buffer antes de iniciar envio
brunofgc 7:ae9c47f62946 437
brunofgc 0:1c0a769988ee 438 if(string!=NULL) {
brunofgc 30:8a06a85d8807 439 modem.puts(string);
brunofgc 30:8a06a85d8807 440 if(xeretaModem){
brunofgc 7:ae9c47f62946 441 pc.printf("Sai pro modem <%s>\n",string); //Enviando na serial PC para debug
brunofgc 30:8a06a85d8807 442 }
brunofgc 0:1c0a769988ee 443 }
brunofgc 7:ae9c47f62946 444 if(confirmado==1){
brunofgc 0:1c0a769988ee 445 modemCom::status.ERROR=0;
brunofgc 7:ae9c47f62946 446 modemCom::status.busy=0;
brunofgc 7:ae9c47f62946 447
brunofgc 7:ae9c47f62946 448 if(codigoConfirmacao!=NULL){
brunofgc 7:ae9c47f62946 449 *codigoConfirmacao=0;
brunofgc 7:ae9c47f62946 450 while((timeOutProcesso)&&(!(*codigoConfirmacao))&&(!modemCom::status.ERROR)&&(!modemCom::status.busy)){
brunofgc 7:ae9c47f62946 451 osDelay(5); //timeOut em mS
brunofgc 7:ae9c47f62946 452 timeOutProcesso--;
brunofgc 7:ae9c47f62946 453 }
brunofgc 7:ae9c47f62946 454 }else{
brunofgc 7:ae9c47f62946 455 while((timeOutProcesso)&&(!modemCom::status.ERROR)&&(!modemCom::status.busy)&&(!strstr(bufModem.getRowBuffer(),stringConfirmacao))) {
brunofgc 7:ae9c47f62946 456 osDelay(1); //timeOut em mS
brunofgc 7:ae9c47f62946 457 timeOutProcesso--;
brunofgc 7:ae9c47f62946 458 }
brunofgc 7:ae9c47f62946 459 }
brunofgc 7:ae9c47f62946 460 if(modemCom::status.ERROR||modemCom::status.busy) {
brunofgc 7:ae9c47f62946 461 osDelay(1000);//espera 1S
brunofgc 0:1c0a769988ee 462 }
brunofgc 7:ae9c47f62946 463
brunofgc 11:631bea162800 464 if(modemCom::status.dnsError){
brunofgc 11:631bea162800 465 modemCom::status.dnsError=false;
brunofgc 11:631bea162800 466 return 0;
brunofgc 11:631bea162800 467 }
brunofgc 11:631bea162800 468
brunofgc 21:b9315cdd9275 469 if(timeOutProcesso) {
brunofgc 21:b9315cdd9275 470 if(confirmado==1){
brunofgc 21:b9315cdd9275 471 if(!(*codigoConfirmacao)){return 0;}
brunofgc 21:b9315cdd9275 472 }else{
brunofgc 21:b9315cdd9275 473 if(!strstr(bufModem.getRowBuffer(),stringConfirmacao)){return 0;}
brunofgc 21:b9315cdd9275 474 }
brunofgc 0:1c0a769988ee 475 return maxTentativas;
brunofgc 7:ae9c47f62946 476 }
brunofgc 7:ae9c47f62946 477
brunofgc 0:1c0a769988ee 478 strLen = strlen(string);
brunofgc 0:1c0a769988ee 479 for(indexString=0; indexString<(strLen-1); indexString++) {
brunofgc 0:1c0a769988ee 480 pc.putc(string[indexString]);
brunofgc 0:1c0a769988ee 481 }
brunofgc 30:8a06a85d8807 482
brunofgc 30:8a06a85d8807 483 if(xeretaModem){
brunofgc 7:ae9c47f62946 484 pc.printf("> maxTentativas = %lu.\n",maxTentativas);
brunofgc 30:8a06a85d8807 485 }
brunofgc 30:8a06a85d8807 486
brunofgc 22:cb832a9bc704 487 }else{return 1;}
brunofgc 7:ae9c47f62946 488 maxTentativas--;
brunofgc 7:ae9c47f62946 489 osDelay(delayEntreTentativas);
brunofgc 7:ae9c47f62946 490 }
brunofgc 0:1c0a769988ee 491 return 0;
brunofgc 0:1c0a769988ee 492 }
brunofgc 0:1c0a769988ee 493
brunofgc 33:a60abda630f7 494 char modemCom::closeConnection(uint8_t *id){
brunofgc 0:1c0a769988ee 495 char command[20];
brunofgc 33:a60abda630f7 496 if(debug){pc.printf("Lido %u como sendo o id em closeConnection.\r\n",*id);}
brunofgc 33:a60abda630f7 497 if((*id)==255){
brunofgc 33:a60abda630f7 498 return 2;
brunofgc 33:a60abda630f7 499 }
brunofgc 33:a60abda630f7 500 sprintf(command,"AT+CIPCLOSE=%u\r\n",*id);
brunofgc 34:348991c54ff3 501 if(modemCom::sendToModem(command,1,NULL,",CLOSED",1000,1,300)){
brunofgc 33:a60abda630f7 502 *id = 255;
brunofgc 33:a60abda630f7 503 return 1;
brunofgc 33:a60abda630f7 504 }
brunofgc 33:a60abda630f7 505 return 0;
brunofgc 0:1c0a769988ee 506 }
brunofgc 0:1c0a769988ee 507
brunofgc 29:823a9da3696b 508 char modemCom::cipSend(uint8_t idConnection,char *buffer,uint16_t len){
brunofgc 0:1c0a769988ee 509 char aux[20];
brunofgc 0:1c0a769988ee 510 uint16_t i;
brunofgc 0:1c0a769988ee 511 if(!len){
brunofgc 0:1c0a769988ee 512 len = strlen(buffer);
brunofgc 0:1c0a769988ee 513 }
brunofgc 30:8a06a85d8807 514 if(debug){printf("conteudo de cipsend.<");}
brunofgc 29:823a9da3696b 515 sprintf(aux,"AT+CIPSENDEX=%u,%lu\r\n",idConnection,len);
brunofgc 29:823a9da3696b 516 if(sendToModem(aux,1,&modemCom::status.OK,NULL,2000,1,1)){
brunofgc 0:1c0a769988ee 517 for(i=0;i<len;i++){
brunofgc 0:1c0a769988ee 518 modem.putc(buffer[i]);
brunofgc 30:8a06a85d8807 519 if(debug){pc.putc(buffer[i]);}
brunofgc 0:1c0a769988ee 520 }
brunofgc 0:1c0a769988ee 521 }else{
brunofgc 0:1c0a769988ee 522 return 0;
brunofgc 0:1c0a769988ee 523 }
brunofgc 30:8a06a85d8807 524 if(debug){printf(">\r\n");}
brunofgc 7:ae9c47f62946 525 if(sendToModem("",1,&modemCom::status.SEND_OK,NULL,2000,1,1)){
brunofgc 0:1c0a769988ee 526 return 1;
brunofgc 0:1c0a769988ee 527 }
brunofgc 0:1c0a769988ee 528 return 2;
brunofgc 0:1c0a769988ee 529 }
brunofgc 0:1c0a769988ee 530
brunofgc 15:0f78bf9c13ec 531 void modemCom::webServer(uint8_t id){
brunofgc 33:a60abda630f7 532 //char aux[50];
brunofgc 9:cf406384efd9 533 bool encontrado=0;
brunofgc 18:1eefda1f7736 534 char buf[1024];
brunofgc 25:a6da63ed025b 535 char *strOutput;
brunofgc 9:cf406384efd9 536 //uint32_t aux_int;
brunofgc 9:cf406384efd9 537
brunofgc 9:cf406384efd9 538 if(strstr(webServerBuff,"favicon.ico")){
brunofgc 9:cf406384efd9 539 //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 18:1eefda1f7736 540 sprintf(buf,"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE html><html><body><link rel=\"icon\" href=\"http://%s/drome/assets/local/images/favicon/favicon.ico\" type=\"image/x-icon\"></body></html>",modemCom::status.host);
brunofgc 15:0f78bf9c13ec 541 if(cipSend(id,buf,0)==1){
brunofgc 30:8a06a85d8807 542 //printf("Requisicao enviada!\n");
brunofgc 9:cf406384efd9 543 }else{
brunofgc 9:cf406384efd9 544 printf("Requisicao nao enviada 1!!\n");
brunofgc 9:cf406384efd9 545 }
brunofgc 9:cf406384efd9 546 encontrado = 1;
brunofgc 9:cf406384efd9 547 }
brunofgc 9:cf406384efd9 548
brunofgc 9:cf406384efd9 549 if(strstr(webServerBuff,"comandos.htm")&&(!encontrado)){
brunofgc 9:cf406384efd9 550
brunofgc 9:cf406384efd9 551 //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 18:1eefda1f7736 552 sprintf(buf,"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE html><html><head><title>ConfigRede DROME</title></head><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 15:0f78bf9c13ec 553 if(cipSend(id,buf,0)==1){
brunofgc 9:cf406384efd9 554 printf("Requisicao enviada!\n");
brunofgc 9:cf406384efd9 555 }else{
brunofgc 30:8a06a85d8807 556 //printf("Requisicao nao enviada 1!!\n");
brunofgc 9:cf406384efd9 557 }
brunofgc 9:cf406384efd9 558 encontrado = 1;
brunofgc 9:cf406384efd9 559 }
brunofgc 9:cf406384efd9 560
brunofgc 9:cf406384efd9 561 if(strstr(webServerBuff,"configRede.htm")&&(!encontrado)){
brunofgc 9:cf406384efd9 562 //Pegando o IP
brunofgc 21:b9315cdd9275 563 modemCom::leIP();
brunofgc 25:a6da63ed025b 564 sprintf(buf,"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE html><html><head><title>ConfigRede DROME</title></head><body><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>ServerIP:<br><input type='text' name='serverIP' value='%s'><br>Host:<br><input type='text' name='host' value='%s'><br>Periodo<br><input type='text' name='periodo' value='%lu'><br>IP<br><input type='text' name='STAIP' value='%s'><br>Mascara de Sub Rede<br><input type='text' name='subnetmask' value='%s'><br>Gateway/dhcp<br><input type='text' name='gateway' value='%s'><br>------ModBus------<br>BaudRate<br><input type='text' name='baudrate' value='%lu'><br>TimeOut<br><input type='text' name='timeout' value='%lu'><br><input type='submit' value='Configurar'></fieldset></form></body>",modemCom::status.ssid,modemCom::status.password,modemCom::status.port,modemCom::status.serverIP,modemCom::status.host,modemCom::status.periodo,modemCom::status.STAIP,modemCom::status.subnetmask,modemCom::status.gateway,modBusMaster1::MODBUS_SERIAL_BAUD,modBusMaster1::MODBUS_TIMEOUT);
brunofgc 15:0f78bf9c13ec 565 cipSend(id,buf,0);
brunofgc 9:cf406384efd9 566 encontrado = 1;
brunofgc 9:cf406384efd9 567 }
brunofgc 9:cf406384efd9 568
brunofgc 20:da1b8d80ba00 569 if(strstr(webServerBuff,"lecomandocontrole.htm")&&(!encontrado)){
brunofgc 20:da1b8d80ba00 570 uint16_t timeout = 5000;
brunofgc 20:da1b8d80ba00 571
brunofgc 9:cf406384efd9 572 IrDetect.reset();
brunofgc 9:cf406384efd9 573 IrDetect.start();
brunofgc 20:da1b8d80ba00 574
brunofgc 29:823a9da3696b 575 diversos::wdt.kick(90.0);
brunofgc 21:b9315cdd9275 576 ledUsoGeral = true;
brunofgc 9:cf406384efd9 577 while((IrDetect.read_ms()<timeout) && (!detectaIRIn()));
brunofgc 9:cf406384efd9 578 if(IrDetect.read_ms()<timeout){
brunofgc 9:cf406384efd9 579 serializaPacoteIR(modemCom::status.connIDWebServer);
brunofgc 9:cf406384efd9 580 }else{
brunofgc 18:1eefda1f7736 581 sprintf(buf,"HTTP/1.1 200 OK\r\nContent-Type: text\r\n\r\nerro");
brunofgc 15:0f78bf9c13ec 582 if(cipSend(id,buf,0)==1){
brunofgc 30:8a06a85d8807 583 //printf("Requisicao enviada!\n");
brunofgc 9:cf406384efd9 584 }
brunofgc 9:cf406384efd9 585 }
brunofgc 21:b9315cdd9275 586 IrDetect.stop();
brunofgc 21:b9315cdd9275 587 ledUsoGeral = false;
brunofgc 9:cf406384efd9 588 encontrado = 1;
brunofgc 9:cf406384efd9 589 }
brunofgc 9:cf406384efd9 590
brunofgc 9:cf406384efd9 591 if(strstr(webServerBuff,"cwjap.htm")&&(!encontrado)){
brunofgc 18:1eefda1f7736 592 pc.printf("Lido de cwjap <%s>.\r\n\r\n",webServerBuff);
brunofgc 9:cf406384efd9 593
brunofgc 9:cf406384efd9 594 strtok(webServerBuff,"=");
brunofgc 9:cf406384efd9 595 strcpy(modemCom::status.ssid,strtok(NULL,"&")); //pegando ssid
brunofgc 9:cf406384efd9 596
brunofgc 9:cf406384efd9 597 strtok(NULL,"=");
brunofgc 9:cf406384efd9 598 strcpy(modemCom::status.password,strtok(NULL,"&")); //pegando password
brunofgc 18:1eefda1f7736 599
brunofgc 18:1eefda1f7736 600 strtok(NULL,"=");
brunofgc 18:1eefda1f7736 601 strcpy(modemCom::status.port,strtok(NULL,"&")); //pegando port
brunofgc 9:cf406384efd9 602
brunofgc 9:cf406384efd9 603 strtok(NULL,"=");
brunofgc 18:1eefda1f7736 604 strcpy(modemCom::status.serverIP,strtok(NULL,"&")); //pegando serverIP
brunofgc 9:cf406384efd9 605
brunofgc 9:cf406384efd9 606 strtok(NULL,"=");
brunofgc 9:cf406384efd9 607 strcpy(modemCom::status.host,strtok(NULL,"&")); //pegando host
brunofgc 9:cf406384efd9 608
brunofgc 9:cf406384efd9 609 strtok(NULL,"=");
brunofgc 21:b9315cdd9275 610 strcpy(buf,strtok(NULL,"&")); //pegando periodo
brunofgc 9:cf406384efd9 611 modemCom::status.periodo = atoi(buf);
brunofgc 18:1eefda1f7736 612 modemCom::status.periodoConfiguracao = modemCom::status.periodo;
brunofgc 9:cf406384efd9 613
brunofgc 21:b9315cdd9275 614 //*************************IP ou DHCP****************************
brunofgc 21:b9315cdd9275 615
brunofgc 21:b9315cdd9275 616 strtok(NULL,"=");
brunofgc 21:b9315cdd9275 617 strcpy(modemCom::status.STAIP,strtok(NULL,"&")); //pegando IP/DHCP
brunofgc 21:b9315cdd9275 618
brunofgc 21:b9315cdd9275 619 strtok(NULL,"=");
brunofgc 21:b9315cdd9275 620 strcpy(modemCom::status.subnetmask,strtok(NULL,"&")); //pegando subnetmask
brunofgc 21:b9315cdd9275 621
brunofgc 21:b9315cdd9275 622 strtok(NULL,"=");
brunofgc 25:a6da63ed025b 623 strcpy(modemCom::status.gateway,strtok(NULL,"&")); //pegando gateway
brunofgc 25:a6da63ed025b 624
brunofgc 25:a6da63ed025b 625 //************************* ModBus ****************************
brunofgc 21:b9315cdd9275 626
brunofgc 25:a6da63ed025b 627 strtok(NULL,"=");
brunofgc 25:a6da63ed025b 628 strcpy(buf,strtok(NULL,"&")); //pegando BaudRate
brunofgc 25:a6da63ed025b 629 modBusMaster1::MODBUS_SERIAL_BAUD = atoi(buf);
brunofgc 21:b9315cdd9275 630
brunofgc 21:b9315cdd9275 631
brunofgc 25:a6da63ed025b 632 strtok(NULL,"=");
brunofgc 25:a6da63ed025b 633 strcpy(buf,strtok(NULL," ")); //pegando timeout
brunofgc 25:a6da63ed025b 634 modBusMaster1::MODBUS_TIMEOUT = atoi(buf);
brunofgc 25:a6da63ed025b 635
brunofgc 21:b9315cdd9275 636
brunofgc 25:a6da63ed025b 637 //Decodificando URL
brunofgc 25:a6da63ed025b 638 strOutput = (char *) malloc(strlen(modemCom::status.ssid)+1);
brunofgc 25:a6da63ed025b 639 diversos::urldecode2(strOutput, modemCom::status.ssid);
brunofgc 25:a6da63ed025b 640 strcpy(modemCom::status.ssid,strOutput);
brunofgc 25:a6da63ed025b 641 free(strOutput);
brunofgc 25:a6da63ed025b 642
brunofgc 25:a6da63ed025b 643 strOutput = (char *) malloc(strlen(modemCom::status.password)+1);
brunofgc 25:a6da63ed025b 644 diversos::urldecode2(strOutput, modemCom::status.password);
brunofgc 25:a6da63ed025b 645 strcpy(modemCom::status.password,strOutput);
brunofgc 25:a6da63ed025b 646 free(strOutput);
brunofgc 25:a6da63ed025b 647
brunofgc 9:cf406384efd9 648
brunofgc 9:cf406384efd9 649 if((modemCom::status.ssid[0]!=0) && (modemCom::status.password[0]!=0)){
brunofgc 9:cf406384efd9 650 sprintf(buf,"HTTP/1.1 200 OK\n\nACK");
brunofgc 9:cf406384efd9 651 mudaRede = true;
brunofgc 9:cf406384efd9 652 }else{
brunofgc 9:cf406384efd9 653 sprintf(buf,"HTTP/1.1 200 OK\n\nNACK");
brunofgc 9:cf406384efd9 654 }
brunofgc 15:0f78bf9c13ec 655 cipSend(id,buf,0);
brunofgc 9:cf406384efd9 656 encontrado = 1;
brunofgc 9:cf406384efd9 657 }
brunofgc 9:cf406384efd9 658
brunofgc 9:cf406384efd9 659 if(!encontrado){
brunofgc 9:cf406384efd9 660 sprintf(buf,"Pagina Nao Encontrada.");
brunofgc 15:0f78bf9c13ec 661 if(cipSend(id,buf,0)==1){
brunofgc 30:8a06a85d8807 662 //printf("Requisicao enviada!\n");
brunofgc 9:cf406384efd9 663 }else{
brunofgc 9:cf406384efd9 664 printf("Requisicao nao enviada 3!!\n");
brunofgc 9:cf406384efd9 665 }
brunofgc 9:cf406384efd9 666 }
brunofgc 30:8a06a85d8807 667 if(debug){pc.printf("Fechando socket chave 3.\r\n");}
brunofgc 33:a60abda630f7 668 modemCom::closeConnection(&modemCom::status.connIDWebServer);
brunofgc 9:cf406384efd9 669 if(mudaRede){
brunofgc 9:cf406384efd9 670 mudaRede = false;
brunofgc 9:cf406384efd9 671 modemCom::sendToModem("AT+CIPSERVER=0\r\n",1,&modemCom::status.OK,NULL,2000,1,1);
brunofgc 25:a6da63ed025b 672 pc.printf("Mudando para rede:\r\nSSID:%s\r\nPASSWORD:%S\r\nPORTA:%s\r\nserverIP:%s\r\nHOST:%s\r\nPERIODO:%lu\r\nIP/DHCP:%s\r\nsubnetmask:%s\r\ngateway:%s\r\nBaudRate:%lu\r\nTimeOut:%lu\r\n\r\n",modemCom::status.ssid,modemCom::status.password,modemCom::status.port,modemCom::status.serverIP,modemCom::status.host,modemCom::status.periodo,modemCom::status.STAIP,modemCom::status.subnetmask,modemCom::status.gateway,modBusMaster1::MODBUS_SERIAL_BAUD,modBusMaster1::MODBUS_TIMEOUT);
brunofgc 21:b9315cdd9275 673
brunofgc 21:b9315cdd9275 674 if(strstr(modemCom::status.gateway,"dhcp")){
brunofgc 21:b9315cdd9275 675 strcpy(modemCom::status.STAIP,"dhcp");
brunofgc 21:b9315cdd9275 676 strcpy(modemCom::status.subnetmask,"dhcp");
brunofgc 21:b9315cdd9275 677 }
brunofgc 21:b9315cdd9275 678
brunofgc 9:cf406384efd9 679 if(sdCard::abreArquivo(&sdCard::config,"w")){
brunofgc 9:cf406384efd9 680 pc.printf("Guardando config.\r\n");
brunofgc 25:a6da63ed025b 681 fprintf(sdCard::config.fp,"SSID:%s\r\nPASSWORD:%s\r\nPORT:%s\r\nserverIP:%s\r\nHOST:%s\r\nPERIODO:%lu\r\nSTAIP:%s\r\nsubnetmask:%s\r\ngateway:%s\r\nModBus_BaudRate:%lu\r\nModBus_TimeOut:%lu\r\n",modemCom::status.ssid,modemCom::status.password,modemCom::status.port,modemCom::status.serverIP,modemCom::status.host,modemCom::status.periodo,modemCom::status.STAIP,modemCom::status.subnetmask,modemCom::status.gateway,modBusMaster1::MODBUS_SERIAL_BAUD,modBusMaster1::MODBUS_TIMEOUT);
brunofgc 9:cf406384efd9 682 sdCard::fechaArquivo(&sdCard::config);
brunofgc 15:0f78bf9c13ec 683 modemCom::inicializaModem();
brunofgc 9:cf406384efd9 684 modemCom::conectaWiFi();
brunofgc 9:cf406384efd9 685 }
brunofgc 9:cf406384efd9 686 }
brunofgc 9:cf406384efd9 687 }
brunofgc 9:cf406384efd9 688
brunofgc 7:ae9c47f62946 689 bool modemCom::leIP(void){
brunofgc 7:ae9c47f62946 690 char *ptr;
brunofgc 31:a1ba855c6e8a 691 sendToModem("AT+CIFSR\r\n",1,NULL,"+CIFSR:STAIP,",2000,1,1);
brunofgc 31:a1ba855c6e8a 692 pc.printf("Lido de leIP <%s>.\r\n",modemCom::bufIn);
brunofgc 7:ae9c47f62946 693 ptr=strstr(modemCom::bufIn,"+CIFSR:STAIP,");
brunofgc 7:ae9c47f62946 694 if(ptr) {
brunofgc 7:ae9c47f62946 695 ptr = strtok(ptr,"\"");
brunofgc 7:ae9c47f62946 696 ptr = strtok(NULL,"\"");
brunofgc 7:ae9c47f62946 697 strcpy(modemCom::status.STAIP,ptr);
brunofgc 7:ae9c47f62946 698 }
brunofgc 7:ae9c47f62946 699 if(strstr(modemCom::status.STAIP,"0.0.0.0")){return false;}
brunofgc 7:ae9c47f62946 700 return true;
brunofgc 7:ae9c47f62946 701 }
brunofgc 7:ae9c47f62946 702
brunofgc 1:0e0967c88590 703 int16_t modemCom::getRSSI(void){
brunofgc 9:cf406384efd9 704 char *ptr;
brunofgc 15:0f78bf9c13ec 705 int16_t RSSI = 255;
brunofgc 15:0f78bf9c13ec 706
brunofgc 34:348991c54ff3 707 if(modemCom::sendToModem("AT+CWJAP?\r\n",1,&modemCom::status.OK,NULL,10000,1,1000)){
brunofgc 1:0e0967c88590 708 ptr = strstr(modemCom::bufIn,(const char*)modemCom::status.ssid);
brunofgc 1:0e0967c88590 709 if(ptr){
brunofgc 15:0f78bf9c13ec 710 ptr = strtok(ptr,","); //Descarta SSID
brunofgc 15:0f78bf9c13ec 711 ptr = strtok(NULL,","); //Descarta MAC
brunofgc 15:0f78bf9c13ec 712 ptr = strtok(NULL,","); //Descarta Canal
brunofgc 15:0f78bf9c13ec 713 ptr = strtok(NULL,","); //Captura RSSI
brunofgc 1:0e0967c88590 714 RSSI = atoi(ptr);
brunofgc 1:0e0967c88590 715 }
brunofgc 1:0e0967c88590 716 }
brunofgc 9:cf406384efd9 717 return RSSI;
brunofgc 9:cf406384efd9 718 //return -50;
brunofgc 1:0e0967c88590 719 }
brunofgc 7:ae9c47f62946 720
brunofgc 7:ae9c47f62946 721 bool modemCom::verificaConexao(void){
brunofgc 7:ae9c47f62946 722 uint8_t i = 1;
brunofgc 7:ae9c47f62946 723 while(i){
brunofgc 15:0f78bf9c13ec 724 if(modemCom::getRSSI()==255){
brunofgc 15:0f78bf9c13ec 725 if(modemCom::conectaWiFi()){
brunofgc 15:0f78bf9c13ec 726 return true;
brunofgc 15:0f78bf9c13ec 727 }
brunofgc 7:ae9c47f62946 728 i--;
brunofgc 7:ae9c47f62946 729 }else{
brunofgc 7:ae9c47f62946 730 return true;
brunofgc 7:ae9c47f62946 731 }
brunofgc 7:ae9c47f62946 732 }
brunofgc 7:ae9c47f62946 733 return false;
brunofgc 7:ae9c47f62946 734 }
brunofgc 0:1c0a769988ee 735
brunofgc 15:0f78bf9c13ec 736 bool modemCom::conectaWiFi(void){
brunofgc 0:1c0a769988ee 737 //Função para mudança de rede
brunofgc 15:0f78bf9c13ec 738
brunofgc 15:0f78bf9c13ec 739 char aux[128];
brunofgc 21:b9315cdd9275 740 //modemCom::leParametrosConexaoSDCard();
brunofgc 15:0f78bf9c13ec 741 //AT+CWJAP=\"\",\"\"\r\n
brunofgc 15:0f78bf9c13ec 742 sprintf(aux,"AT+CWJAP=\"%s\",\"%s\"\r\n",modemCom::status.ssid,modemCom::status.password);
brunofgc 34:348991c54ff3 743 if(modemCom::sendToModem(aux,1,&modemCom::status.wifi_connected,NULL,7000,2,1000)) {
brunofgc 30:8a06a85d8807 744 if(debug){pc.printf("WiFi Conectado.\n");}
brunofgc 15:0f78bf9c13ec 745 return true;
brunofgc 15:0f78bf9c13ec 746 }else{
brunofgc 15:0f78bf9c13ec 747 return false;
brunofgc 15:0f78bf9c13ec 748 }
brunofgc 15:0f78bf9c13ec 749 }
brunofgc 15:0f78bf9c13ec 750
brunofgc 15:0f78bf9c13ec 751 void modemCom::processaPacote(void const *args){
brunofgc 15:0f78bf9c13ec 752 char *ptr,*scanPtr;
brunofgc 15:0f78bf9c13ec 753 uint16_t bufInLength = bufModem.getLength();
brunofgc 15:0f78bf9c13ec 754 uint16_t timeOut;
brunofgc 15:0f78bf9c13ec 755 //bool getFound=false;
brunofgc 15:0f78bf9c13ec 756 modemCom::bufIn = bufModem.get();
brunofgc 15:0f78bf9c13ec 757
brunofgc 15:0f78bf9c13ec 758 modemCom::status.modemResponse=true;
brunofgc 15:0f78bf9c13ec 759
brunofgc 30:8a06a85d8807 760 if(xeretaModem){pc.printf("Vem do modem <%s>.\r\n",modemCom::bufIn);}
brunofgc 15:0f78bf9c13ec 761
brunofgc 15:0f78bf9c13ec 762 //Reconhecimento dos status
brunofgc 15:0f78bf9c13ec 763 modemCom::status.PROMPT_ENVIO_COMMAND_MODE=0;
brunofgc 15:0f78bf9c13ec 764 ptr=strstr(modemCom::bufIn,"> ");
brunofgc 15:0f78bf9c13ec 765 if(ptr) {
brunofgc 15:0f78bf9c13ec 766
brunofgc 15:0f78bf9c13ec 767 modemCom::status.serverConnected=1;
brunofgc 15:0f78bf9c13ec 768 modemCom::status.commandMode=1;
brunofgc 33:a60abda630f7 769
brunofgc 15:0f78bf9c13ec 770 modemCom::status.PROMPT_ENVIO_COMMAND_MODE=1;
brunofgc 15:0f78bf9c13ec 771 }
brunofgc 15:0f78bf9c13ec 772
brunofgc 15:0f78bf9c13ec 773 modemCom::status.busy=false;
brunofgc 29:823a9da3696b 774 ptr=strstr(modemCom::bufIn,"busy p...");
brunofgc 29:823a9da3696b 775 if(ptr) {
brunofgc 29:823a9da3696b 776 modemCom::status.OK=0;
brunofgc 29:823a9da3696b 777 modemCom::status.ERROR=1;
brunofgc 29:823a9da3696b 778 modemCom::status.busy=1;
brunofgc 29:823a9da3696b 779 }
brunofgc 29:823a9da3696b 780
brunofgc 29:823a9da3696b 781 /*modemCom::status.busy=false;
brunofgc 15:0f78bf9c13ec 782 ptr=strstr(modemCom::bufIn,"busy s...");
brunofgc 15:0f78bf9c13ec 783 if(ptr) {
brunofgc 29:823a9da3696b 784 modemCom::status.OK=0;
brunofgc 29:823a9da3696b 785 //modemCom::status.ERROR=1;
brunofgc 15:0f78bf9c13ec 786 modemCom::status.busy=1;
brunofgc 29:823a9da3696b 787 }*/
brunofgc 15:0f78bf9c13ec 788
brunofgc 15:0f78bf9c13ec 789 modemCom::status.SEND_OK=0;
brunofgc 15:0f78bf9c13ec 790 ptr=strstr(modemCom::bufIn,"SEND OK");
brunofgc 15:0f78bf9c13ec 791 if(ptr) {
brunofgc 15:0f78bf9c13ec 792
brunofgc 15:0f78bf9c13ec 793 modemCom::status.SEND_OK=1;
brunofgc 15:0f78bf9c13ec 794 }
brunofgc 15:0f78bf9c13ec 795
brunofgc 15:0f78bf9c13ec 796 modemCom::status.ERROR=0;
brunofgc 15:0f78bf9c13ec 797 ptr=strstr(modemCom::bufIn,"ERROR");
brunofgc 15:0f78bf9c13ec 798 if(ptr) {
brunofgc 15:0f78bf9c13ec 799
brunofgc 15:0f78bf9c13ec 800 modemCom::status.ERROR=1;
brunofgc 15:0f78bf9c13ec 801 modemCom::status.OK=0;
brunofgc 15:0f78bf9c13ec 802 }
brunofgc 15:0f78bf9c13ec 803
brunofgc 15:0f78bf9c13ec 804 ptr=strstr(modemCom::bufIn,"FAIL");
brunofgc 15:0f78bf9c13ec 805 if(ptr) {
brunofgc 15:0f78bf9c13ec 806
brunofgc 15:0f78bf9c13ec 807 modemCom::status.ERROR=1;
brunofgc 15:0f78bf9c13ec 808 modemCom::status.OK=0;
brunofgc 15:0f78bf9c13ec 809 }
brunofgc 15:0f78bf9c13ec 810
brunofgc 29:823a9da3696b 811
brunofgc 29:823a9da3696b 812
brunofgc 15:0f78bf9c13ec 813 ptr=strstr(modemCom::bufIn,"DNS Fail");
brunofgc 15:0f78bf9c13ec 814 if(ptr) {
brunofgc 15:0f78bf9c13ec 815 modemCom::status.dnsError=1;
brunofgc 15:0f78bf9c13ec 816 modemCom::status.ERROR=1;
brunofgc 15:0f78bf9c13ec 817 modemCom::status.OK=0;
brunofgc 15:0f78bf9c13ec 818 }
brunofgc 33:a60abda630f7 819
brunofgc 33:a60abda630f7 820 ptr=strstr(modemCom::bufIn,"WIFI CONNECTED");
brunofgc 33:a60abda630f7 821 if(ptr) {
brunofgc 33:a60abda630f7 822 modemCom::status.wifi_connected=1;
brunofgc 33:a60abda630f7 823
brunofgc 33:a60abda630f7 824 }
brunofgc 33:a60abda630f7 825
brunofgc 25:a6da63ed025b 826 ptr=strstr(modemCom::bufIn,"ALREADY CONNECTED");
brunofgc 25:a6da63ed025b 827 if(ptr) {
brunofgc 25:a6da63ed025b 828 modemCom::status.ALREADY_CONNECTED=1;
brunofgc 25:a6da63ed025b 829 modemCom::status.ERROR=1;
brunofgc 25:a6da63ed025b 830 modemCom::status.OK=0;
brunofgc 25:a6da63ed025b 831 }
brunofgc 25:a6da63ed025b 832
brunofgc 29:823a9da3696b 833 modemCom::status.OK=0;
brunofgc 29:823a9da3696b 834 ptr=strstr(modemCom::bufIn,"OK\r");
brunofgc 29:823a9da3696b 835 if(ptr) {
brunofgc 29:823a9da3696b 836 modemCom::status.OK=1;
brunofgc 29:823a9da3696b 837 modemCom::status.ERROR=0;
brunofgc 29:823a9da3696b 838 modemCom::status.busy=0;
brunofgc 29:823a9da3696b 839 }
brunofgc 29:823a9da3696b 840
brunofgc 15:0f78bf9c13ec 841 //modemCom::status.CLOSED=false;
brunofgc 15:0f78bf9c13ec 842 ptr=strstr(modemCom::bufIn,"CLOSED");
brunofgc 15:0f78bf9c13ec 843 if(ptr) {
brunofgc 15:0f78bf9c13ec 844 modemCom::status.CLOSED=1;
brunofgc 15:0f78bf9c13ec 845 }
brunofgc 15:0f78bf9c13ec 846
brunofgc 15:0f78bf9c13ec 847 /*if(strstr(modemCom::bufIn,"GET /")){
brunofgc 15:0f78bf9c13ec 848 getFound = true;
brunofgc 15:0f78bf9c13ec 849 }*/
brunofgc 15:0f78bf9c13ec 850
brunofgc 15:0f78bf9c13ec 851 //Buscando connect
brunofgc 15:0f78bf9c13ec 852 /*if(!modemCom::atendendoWebServer){
brunofgc 15:0f78bf9c13ec 853 ptr=strstr(modemCom::bufIn,"CONNECT\r\n");
brunofgc 15:0f78bf9c13ec 854 if(ptr) {
brunofgc 15:0f78bf9c13ec 855 ptr = strstr(ptr,"+IPD");
brunofgc 15:0f78bf9c13ec 856 ptr = strtok(ptr,",");
brunofgc 15:0f78bf9c13ec 857 ptr = strtok(NULL,",");
brunofgc 15:0f78bf9c13ec 858 connID = atoi(ptr);
brunofgc 15:0f78bf9c13ec 859 modemCom::status.connIDServerCommand = connID;
brunofgc 15:0f78bf9c13ec 860 modemCom::status.serverConnected=1;
brunofgc 15:0f78bf9c13ec 861 pc.printf("Recebido string CONNECT socket na conexao %u.\n",connID);
brunofgc 15:0f78bf9c13ec 862 if(!modemCom::status.emComunicacao){
brunofgc 15:0f78bf9c13ec 863 if(!getFound){
brunofgc 15:0f78bf9c13ec 864 pc.printf("Atendendo socket entrante na conexao %u.\n",connID);
brunofgc 15:0f78bf9c13ec 865 modemCom::status.SRINGsockEntrante = true;
brunofgc 15:0f78bf9c13ec 866 }
brunofgc 15:0f78bf9c13ec 867 }
brunofgc 15:0f78bf9c13ec 868 modemCom::status.emComunicacao=true;
brunofgc 15:0f78bf9c13ec 869 modemCom::bufIn = strtok(NULL,"");
brunofgc 15:0f78bf9c13ec 870 }
brunofgc 15:0f78bf9c13ec 871 }*/
brunofgc 15:0f78bf9c13ec 872
brunofgc 15:0f78bf9c13ec 873 IPDNumBytes = 0;
brunofgc 15:0f78bf9c13ec 874 ptr = strstr(modemCom::bufIn,"+IPD");
brunofgc 15:0f78bf9c13ec 875 if(ptr!=NULL){
brunofgc 15:0f78bf9c13ec 876 //+IPD,0,480:GET
brunofgc 15:0f78bf9c13ec 877 strtok(ptr,","); //Separando +IPD
brunofgc 15:0f78bf9c13ec 878
brunofgc 15:0f78bf9c13ec 879 ptr = strtok(NULL,","); //Pegando o numero da conexão
brunofgc 29:823a9da3696b 880 connID = atoi(ptr);
brunofgc 15:0f78bf9c13ec 881
brunofgc 15:0f78bf9c13ec 882 ptr = strtok(NULL,":"); //Pegando o numero de caracteres IPD
brunofgc 15:0f78bf9c13ec 883 IPDNumBytes = atoi(ptr);
brunofgc 15:0f78bf9c13ec 884
brunofgc 15:0f78bf9c13ec 885 modemCom::bufIn = strtok(NULL,"");
brunofgc 15:0f78bf9c13ec 886
brunofgc 15:0f78bf9c13ec 887 //printf("Recebido pacote via conexao %u com %lu bytes.\n",connID,IPDNumBytes);
brunofgc 15:0f78bf9c13ec 888
brunofgc 15:0f78bf9c13ec 889 }
brunofgc 29:823a9da3696b 890
brunofgc 29:823a9da3696b 891 if((connID==modemCom::status.connIDServerCommand)&& IPDNumBytes && modemCom::status.recebendoArquivoDoServer && (strstr(modemCom::bufIn,"CONNECT")==NULL) && (strstr(modemCom::bufIn,"*ServerCommand*")==NULL) ){
brunofgc 31:a1ba855c6e8a 892 pc.printf("sendData recebidos %lu bytes\n",sdCard::nBytesArquivoRecebidos/2);
brunofgc 15:0f78bf9c13ec 893 sdCard::insereDadosArquivoHex(&sdCard::tempFile,modemCom::bufIn,IPDNumBytes);
brunofgc 15:0f78bf9c13ec 894 //sdCard::insereDadosArquivo(&sdCard::tempFile,modemCom::bufIn,IPDNumBytes);
brunofgc 15:0f78bf9c13ec 895 sdCard::nBytesArquivoRecebidos+=IPDNumBytes;
brunofgc 15:0f78bf9c13ec 896 bufModem.del();
brunofgc 29:823a9da3696b 897 sprintf(modemCom::bufIn,"AT+CIPSEND=%u,%lu\r\n",modemCom::status.connIDServerCommand,10);
brunofgc 15:0f78bf9c13ec 898 modem.puts(modemCom::bufIn);
brunofgc 15:0f78bf9c13ec 899 timeOut = 5000;
brunofgc 15:0f78bf9c13ec 900 while(timeOut && (strstr(bufModem.getRowBuffer(),">")==NULL)){
brunofgc 15:0f78bf9c13ec 901 osDelay(1);
brunofgc 15:0f78bf9c13ec 902 timeOut--;
brunofgc 15:0f78bf9c13ec 903 }
brunofgc 15:0f78bf9c13ec 904 modemCom::status.timeOut = 30;
brunofgc 22:cb832a9bc704 905
brunofgc 22:cb832a9bc704 906 modem.puts("sendData\r\n");
brunofgc 15:0f78bf9c13ec 907 diversos::wdt.kick();
brunofgc 33:a60abda630f7 908 modemCom::status.recebendoArquivoDoServer = 250;
brunofgc 15:0f78bf9c13ec 909 return;
brunofgc 15:0f78bf9c13ec 910 }
brunofgc 29:823a9da3696b 911
brunofgc 15:0f78bf9c13ec 912 //Reconhecendo GET HTTP e atendendo com um servidor web
brunofgc 15:0f78bf9c13ec 913 if(strstr(modemCom::bufIn,"HTTP/1.1")){
brunofgc 15:0f78bf9c13ec 914 ptr=strstr(modemCom::bufIn,"GET /");
brunofgc 15:0f78bf9c13ec 915 if(ptr) {
brunofgc 15:0f78bf9c13ec 916 ptr = strtok(ptr,"/");
brunofgc 15:0f78bf9c13ec 917 ptr = strtok(NULL," ");
brunofgc 15:0f78bf9c13ec 918 bufInPtr = ptr;
brunofgc 15:0f78bf9c13ec 919 strcpy(webServerBuff,ptr);
brunofgc 15:0f78bf9c13ec 920 modemCom::atendendoWebServer = true;
brunofgc 15:0f78bf9c13ec 921 modemCom::status.connIDWebServer = connID;
brunofgc 15:0f78bf9c13ec 922 }
brunofgc 15:0f78bf9c13ec 923 }
brunofgc 15:0f78bf9c13ec 924
brunofgc 15:0f78bf9c13ec 925 ptr=strstr(modemCom::bufIn,"*ServerAck*");
brunofgc 15:0f78bf9c13ec 926 if(ptr) {
brunofgc 15:0f78bf9c13ec 927 modemCom::status.ServerAck=1;
brunofgc 15:0f78bf9c13ec 928 }
brunofgc 15:0f78bf9c13ec 929
brunofgc 15:0f78bf9c13ec 930 ptr=strstr(modemCom::bufIn,"*ServerCommand*");
brunofgc 15:0f78bf9c13ec 931 if(ptr) {
brunofgc 15:0f78bf9c13ec 932 scanPtr = strtok (ptr,"\\");
brunofgc 15:0f78bf9c13ec 933 scanPtr = strtok (NULL,">");
brunofgc 15:0f78bf9c13ec 934 strcpy(commands::buffer,scanPtr);
brunofgc 30:8a06a85d8807 935 if(debug){pc.printf("Comandos <%s>.\n",commands::buffer);}
brunofgc 15:0f78bf9c13ec 936 modemCom::status.connIDServerCommand = connID;
brunofgc 15:0f78bf9c13ec 937 executaComandoServer = true;
brunofgc 29:823a9da3696b 938 }
brunofgc 15:0f78bf9c13ec 939 }
brunofgc 15:0f78bf9c13ec 940
brunofgc 15:0f78bf9c13ec 941 bool modemCom::leParametrosConexaoSDCard(){
brunofgc 0:1c0a769988ee 942 char *ptr;
brunofgc 0:1c0a769988ee 943 char aux[128];
brunofgc 0:1c0a769988ee 944 if(sdCard::abreArquivo(&sdCard::config,"r")){
brunofgc 30:8a06a85d8807 945 //pc.printf("Abrindo arquivo de config para buscar dados de conexao.\r\n");
brunofgc 0:1c0a769988ee 946 //"SSID:DROME\r\nPASSWORD:VITAE\r\nPORT:80"
brunofgc 0:1c0a769988ee 947
brunofgc 0:1c0a769988ee 948 //Pegando SSID
brunofgc 0:1c0a769988ee 949 fgets(modemCom::status.ssid,40,sdCard::config.fp);
brunofgc 2:55b7b466e742 950 ptr = strstr(modemCom::status.ssid,"SSID");
brunofgc 2:55b7b466e742 951 if(ptr!=NULL){
brunofgc 2:55b7b466e742 952 ptr = strtok(modemCom::status.ssid,":");
brunofgc 2:55b7b466e742 953 ptr = strtok(NULL,"\r\n");
brunofgc 2:55b7b466e742 954 strcpy(modemCom::status.ssid,ptr);
brunofgc 2:55b7b466e742 955
brunofgc 2:55b7b466e742 956 //Pegando PASSWORD
brunofgc 2:55b7b466e742 957 fgets(modemCom::status.password,50,sdCard::config.fp);
brunofgc 2:55b7b466e742 958 ptr = strtok(modemCom::status.password,":");
brunofgc 2:55b7b466e742 959 ptr = strtok(NULL,"\r\n");
brunofgc 2:55b7b466e742 960 strcpy(modemCom::status.password,ptr);
brunofgc 2:55b7b466e742 961
brunofgc 2:55b7b466e742 962 //Pegando PORT
brunofgc 2:55b7b466e742 963 fgets(modemCom::status.port,20,sdCard::config.fp);
brunofgc 2:55b7b466e742 964 ptr = strtok(modemCom::status.port,":");
brunofgc 2:55b7b466e742 965 ptr = strtok(NULL,"\r\n");
brunofgc 9:cf406384efd9 966 strcpy(modemCom::status.port,ptr);
brunofgc 9:cf406384efd9 967
brunofgc 18:1eefda1f7736 968 //Pegando serverIP
brunofgc 21:b9315cdd9275 969 fgets(aux,50,sdCard::config.fp);
brunofgc 21:b9315cdd9275 970 ptr = strtok(aux,":");
brunofgc 18:1eefda1f7736 971 ptr = strtok(NULL,"\r\n");
brunofgc 18:1eefda1f7736 972 strcpy(modemCom::status.serverIP,ptr);
brunofgc 18:1eefda1f7736 973
brunofgc 9:cf406384efd9 974 //Pegando host
brunofgc 21:b9315cdd9275 975 fgets(aux,50,sdCard::config.fp);
brunofgc 21:b9315cdd9275 976 ptr = strtok(aux,":");
brunofgc 9:cf406384efd9 977 ptr = strtok(NULL,"\r\n");
brunofgc 9:cf406384efd9 978 strcpy(modemCom::status.host,ptr);
brunofgc 9:cf406384efd9 979
brunofgc 9:cf406384efd9 980 //Pegando periodo
brunofgc 9:cf406384efd9 981 fgets(aux,20,sdCard::config.fp);
brunofgc 9:cf406384efd9 982 ptr = strtok(aux,":");
brunofgc 9:cf406384efd9 983 ptr = strtok(NULL,"\r\n");
brunofgc 9:cf406384efd9 984 modemCom::status.periodo = atoi(ptr);
brunofgc 19:5559f7570e6f 985 modemCom::status.periodoConfiguracao = modemCom::status.periodo;
brunofgc 21:b9315cdd9275 986
brunofgc 21:b9315cdd9275 987 //*************IP ou DHCP*****************
brunofgc 21:b9315cdd9275 988
brunofgc 21:b9315cdd9275 989 //Pegando STAIP
brunofgc 21:b9315cdd9275 990 fgets(aux,50,sdCard::config.fp);
brunofgc 21:b9315cdd9275 991 ptr = strtok(aux,":");
brunofgc 21:b9315cdd9275 992 ptr = strtok(NULL,"\r\n");
brunofgc 21:b9315cdd9275 993 strcpy(modemCom::status.STAIP,ptr);
brunofgc 21:b9315cdd9275 994
brunofgc 21:b9315cdd9275 995 //Pegando subnetmask
brunofgc 21:b9315cdd9275 996 fgets(aux,50,sdCard::config.fp);
brunofgc 21:b9315cdd9275 997 ptr = strtok(aux,":");
brunofgc 21:b9315cdd9275 998 ptr = strtok(NULL,"\r\n");
brunofgc 21:b9315cdd9275 999 strcpy(modemCom::status.subnetmask,ptr);
brunofgc 21:b9315cdd9275 1000
brunofgc 21:b9315cdd9275 1001 //Pegando gateway
brunofgc 21:b9315cdd9275 1002 fgets(aux,50,sdCard::config.fp);
brunofgc 21:b9315cdd9275 1003 ptr = strtok(aux,":");
brunofgc 21:b9315cdd9275 1004 ptr = strtok(NULL,"\r\n");
brunofgc 21:b9315cdd9275 1005 strcpy(modemCom::status.gateway,ptr);
brunofgc 21:b9315cdd9275 1006
brunofgc 25:a6da63ed025b 1007 //------ModBus_BaudRate------
brunofgc 25:a6da63ed025b 1008 fgets(aux,50,sdCard::config.fp);
brunofgc 25:a6da63ed025b 1009 ptr = strtok(aux,":");
brunofgc 25:a6da63ed025b 1010 ptr = strtok(NULL,"\r\n");
brunofgc 25:a6da63ed025b 1011 modBusMaster1::MODBUS_SERIAL_BAUD = atoi(ptr);
brunofgc 25:a6da63ed025b 1012 modBusMaster1::setBaud(modBusMaster1::MODBUS_SERIAL_BAUD);
brunofgc 21:b9315cdd9275 1013
brunofgc 25:a6da63ed025b 1014 //------ModBus_TimeOut------
brunofgc 25:a6da63ed025b 1015 fgets(aux,50,sdCard::config.fp);
brunofgc 25:a6da63ed025b 1016 ptr = strtok(aux,":");
brunofgc 25:a6da63ed025b 1017 ptr = strtok(NULL,"\r\n");
brunofgc 25:a6da63ed025b 1018 modBusMaster1::MODBUS_TIMEOUT = atoi(ptr);
brunofgc 2:55b7b466e742 1019 }else{
brunofgc 9:cf406384efd9 1020 strcpy(modemCom::status.ssid,"VSE");
brunofgc 2:55b7b466e742 1021 strcpy(modemCom::status.password,"vitaeBBYP");
brunofgc 29:823a9da3696b 1022 strcpy(modemCom::status.port,"4012");
brunofgc 29:823a9da3696b 1023 strcpy(modemCom::status.serverIP,"191.252.119.127");
brunofgc 29:823a9da3696b 1024 strcpy(modemCom::status.host,"www.drome.com.br");
brunofgc 21:b9315cdd9275 1025 strcpy(modemCom::status.gateway,"dhcp");
brunofgc 9:cf406384efd9 1026 modemCom::status.periodo = 900;
brunofgc 25:a6da63ed025b 1027 modBusMaster1::MODBUS_SERIAL_BAUD = 19200;
brunofgc 25:a6da63ed025b 1028 modBusMaster1::setBaud(modBusMaster1::MODBUS_SERIAL_BAUD);
brunofgc 25:a6da63ed025b 1029 modBusMaster1::MODBUS_TIMEOUT = 100;
brunofgc 21:b9315cdd9275 1030 modemCom::status.periodoConfiguracao = modemCom::status.periodo;
brunofgc 2:55b7b466e742 1031 }
brunofgc 0:1c0a769988ee 1032 sdCard::fechaArquivo(&sdCard::config);
brunofgc 30:8a06a85d8807 1033 if(debug){pc.printf("Lidos os parametros de configuracao de wifi como sendo:\r\nSSID:<%s>\r\nPASSWORD:<%s>\r\nPORT:<%s>\r\nserverIP:<%s>\r\nHOST:<%s>\r\nPERIODO:<%lu>\r\nSTAIP:<%s>\r\nsubnetmask:<%s>\r\ngateway:<%s>\r\nbaudRateModbus:<%lu>\r\ntimeOutModbus:<%lu>\r\n",modemCom::status.ssid,modemCom::status.password,modemCom::status.port,modemCom::status.serverIP,modemCom::status.host,modemCom::status.periodo,modemCom::status.STAIP,modemCom::status.subnetmask,modemCom::status.gateway,modBusMaster1::MODBUS_SERIAL_BAUD,modBusMaster1::MODBUS_TIMEOUT);
brunofgc 30:8a06a85d8807 1034 pc.printf("Iniciando conexao wifi.\r\n");}
brunofgc 15:0f78bf9c13ec 1035 return true;
brunofgc 2:55b7b466e742 1036 }else{
brunofgc 7:ae9c47f62946 1037 strcpy(modemCom::status.ssid,"VSE");
brunofgc 2:55b7b466e742 1038 strcpy(modemCom::status.password,"vitaeBBYP");
brunofgc 29:823a9da3696b 1039 strcpy(modemCom::status.port,"4012");
brunofgc 29:823a9da3696b 1040 strcpy(modemCom::status.serverIP,"191.252.119.127");
brunofgc 29:823a9da3696b 1041 strcpy(modemCom::status.host,"www.drome.com.br");
brunofgc 21:b9315cdd9275 1042 strcpy(modemCom::status.gateway,"dhcp");
brunofgc 25:a6da63ed025b 1043 modemCom::status.periodo = 900;
brunofgc 25:a6da63ed025b 1044 modBusMaster1::MODBUS_SERIAL_BAUD = 19200;
brunofgc 25:a6da63ed025b 1045 modBusMaster1::setBaud(modBusMaster1::MODBUS_SERIAL_BAUD);
brunofgc 25:a6da63ed025b 1046 modBusMaster1::MODBUS_TIMEOUT = 100;
brunofgc 19:5559f7570e6f 1047 modemCom::status.periodoConfiguracao = modemCom::status.periodo;
brunofgc 15:0f78bf9c13ec 1048 return false;
brunofgc 2:55b7b466e742 1049 }
brunofgc 0:1c0a769988ee 1050 }
brunofgc 0:1c0a769988ee 1051
brunofgc 0:1c0a769988ee 1052 uint8_t modemCom::inicializaModem(void)
brunofgc 15:0f78bf9c13ec 1053 {
brunofgc 25:a6da63ed025b 1054 char aux[255];
brunofgc 0:1c0a769988ee 1055 modemCom::timeOutModem = 10;
brunofgc 0:1c0a769988ee 1056 modemCom::status.emComunicacao = true;
brunofgc 33:a60abda630f7 1057
brunofgc 33:a60abda630f7 1058 serialModem::configBaud();
brunofgc 0:1c0a769988ee 1059
brunofgc 15:0f78bf9c13ec 1060 modemCom::leMAC();
brunofgc 15:0f78bf9c13ec 1061
brunofgc 15:0f78bf9c13ec 1062 modemCom::leParametrosConexaoSDCard();
brunofgc 15:0f78bf9c13ec 1063
brunofgc 15:0f78bf9c13ec 1064 //Colocando aqui o conteudo de conectaWiFi
brunofgc 15:0f78bf9c13ec 1065 //Mudando mode para AP e Station
brunofgc 31:a1ba855c6e8a 1066 if(modemCom::sendToModem("AT+CWMODE=3\r\n",1,&modemCom::status.OK,NULL,3000,2,250)) {
brunofgc 15:0f78bf9c13ec 1067 pc.printf("Modo AP+STATION aceito.\n");
brunofgc 15:0f78bf9c13ec 1068 }
brunofgc 15:0f78bf9c13ec 1069
brunofgc 15:0f78bf9c13ec 1070
brunofgc 34:348991c54ff3 1071 if(modemCom::sendToModem("AT+CIPMUX=1\r\n",1,&modemCom::status.OK,NULL,500,2,100)) {
brunofgc 15:0f78bf9c13ec 1072 pc.printf("Recebeu o comando AT+CIPMUX=1.\n");
brunofgc 15:0f78bf9c13ec 1073 }
brunofgc 15:0f78bf9c13ec 1074
brunofgc 15:0f78bf9c13ec 1075
brunofgc 15:0f78bf9c13ec 1076 //AT+CIPSERVER=1,portaLidaDoSDCard
brunofgc 15:0f78bf9c13ec 1077 sprintf(aux,"AT+CIPSERVER=1,%s\r\n",modemCom::status.port);
brunofgc 34:348991c54ff3 1078 if(modemCom::sendToModem(aux,1,&modemCom::status.OK,NULL,400,2,100)) {
brunofgc 15:0f78bf9c13ec 1079 pc.printf("Recebeu o comando <%s>.\n",aux);
brunofgc 15:0f78bf9c13ec 1080 }
brunofgc 15:0f78bf9c13ec 1081
brunofgc 34:348991c54ff3 1082 if(modemCom::sendToModem("AT+CIPSTO=10\r\n",1,&modemCom::status.OK,NULL,400,2,100)) {
brunofgc 29:823a9da3696b 1083 pc.printf("Recebeu o comando AT+CIPSTO=10.\n");
brunofgc 15:0f78bf9c13ec 1084 }
brunofgc 15:0f78bf9c13ec 1085
brunofgc 21:b9315cdd9275 1086 sprintf(aux,"AT+CWSAP_CUR=\"DROME_WIFI_%s\",\"VseDROME\",5,3\r\n",modemCom::status.MAC);
brunofgc 31:a1ba855c6e8a 1087 if(modemCom::sendToModem(aux,1,&modemCom::status.OK,NULL,1000,2,300)) {
brunofgc 15:0f78bf9c13ec 1088 pc.printf("Recebeu o comando %s.\n",aux);
brunofgc 15:0f78bf9c13ec 1089 }
brunofgc 15:0f78bf9c13ec 1090
brunofgc 15:0f78bf9c13ec 1091
brunofgc 34:348991c54ff3 1092 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,2,100)) {
brunofgc 15:0f78bf9c13ec 1093 pc.printf("Recebeu o comando AT+CIPAP_CUR=\"192.168.4.1\",\"192.168.4.1\",\"255.255.255.0\".\n");
brunofgc 15:0f78bf9c13ec 1094 }
brunofgc 15:0f78bf9c13ec 1095
brunofgc 21:b9315cdd9275 1096 //Aqui decido se uso DHCP ou não.
brunofgc 25:a6da63ed025b 1097 if(strstr(modemCom::status.gateway,"dhcp")||(strlen(modemCom::status.gateway)==0)){
brunofgc 21:b9315cdd9275 1098 //usando dhcp
brunofgc 34:348991c54ff3 1099 if(modemCom::sendToModem("AT+CWDHCP_CUR=2,1\r\n",1,&modemCom::status.OK,NULL,500,2,100)) {
brunofgc 21:b9315cdd9275 1100 pc.printf("Recebeu o comando AT+CWDHCP_CUR=2,1.\n");
brunofgc 21:b9315cdd9275 1101 }
brunofgc 21:b9315cdd9275 1102 }else{
brunofgc 34:348991c54ff3 1103 if(modemCom::sendToModem("AT+CWDHCP_CUR=2,0\r\n",1,&modemCom::status.OK,NULL,500,2,100)) {
brunofgc 21:b9315cdd9275 1104 pc.printf("Recebeu o comando AT+CWDHCP_CUR=2,0.\n");
brunofgc 21:b9315cdd9275 1105 }
brunofgc 21:b9315cdd9275 1106 //AT+CIPSTA_DEF="192.168.6.100","192.168.6.1","255.255.255.0"
brunofgc 21:b9315cdd9275 1107 sprintf(aux,"AT+CIPSTA_CUR=\"%s\",\"%s\",\"%s\"\r\n",modemCom::status.STAIP,modemCom::status.gateway,modemCom::status.subnetmask);
brunofgc 34:348991c54ff3 1108 if(modemCom::sendToModem(aux,1,&modemCom::status.OK,NULL,500,2,100)) {
brunofgc 21:b9315cdd9275 1109 pc.printf("Recebeu o comando <%s>.\n",aux);
brunofgc 21:b9315cdd9275 1110 }
brunofgc 0:1c0a769988ee 1111
brunofgc 21:b9315cdd9275 1112 }
brunofgc 0:1c0a769988ee 1113 modemCom::status.emComunicacao = false;
brunofgc 0:1c0a769988ee 1114 return 1;
brunofgc 0:1c0a769988ee 1115 }
brunofgc 0:1c0a769988ee 1116
brunofgc 0:1c0a769988ee 1117