teste de publish

Dependencies:   DS1820 HighSpeedAnalogIn devices mbed

Committer:
brunofgc
Date:
Fri Jun 08 22:14:21 2018 +0000
Revision:
38:07d3907b74e5
Parent:
37:0e95c85f0160
teste de publish para compilar no mbed-cli

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