Fórum
- Busca avançada
- Informacoes
- Regras
- PMF
- Glossário
- Dicas e Dúvidas
- Tutoriais
- Tutoriais
- Build Reports
- Desafio RoboCore
- Discussoes
- Arduino
- Albatross
- Técnicas
- Gerais
- Competições
- Iniciantes
- CAD/CAM/CAE
- Classificados
- Compra
- Venda
- Troca
- Vagas de Emprego
- Suporte
- Erros
- Sugestões
Autor
Mensagem
Senhores bom dia! Estou iniciando na programação de arduino e agora estou com um problema que não consigo resolver. Meu projeto, tenho três botões Pull Up cada um com um CEP diferente. Ao ser clicado, o botão envia uma solicitação HTTP GET para o link “viacep.com.br/ws/” + CEP + ”/json/”. Na primeira vez, segunda e até na terceira vez que chamo a função getApi() ele funciona certinho. O que acontece e que após varias chamadas o arduino simplesmente para e não executa mais as chamadas HTTP’s. Não sei se isso é algum tipo de estouro de memória ou limitação de acesso. Alguém que poderia Ajudar? Obrigado! Codigo. #include <SPI.h> #include <Ethernet2.h> #include <ArduinoJson.h> // =============== I N T E R N E T E ==================== // byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; // =============== B O T A O ==================== // int startBotao = 0; unsigned long int tempoAnterior = 0; int time_milisedundos = 5000; int PINO_2 = 1; int PINO_3 = 1; int PINO_4 = 1; int START = 0; void setup(){ pinMode(2, INPUT_PULLUP); pinMode(3, INPUT_PULLUP); pinMode(4, INPUT_PULLUP); } void loop(){ if(START == 0){ if(digitalRead(2) != PINO_2){ START = 1; getApi("89010070"); PINO_2 = digitalRead(2); } } if(START == 0){ if(digitalRead(3) != PINO_3){ START = 1; getApi("20751060"); PINO_3 = digitalRead(2); } } if(START == 0){ if(digitalRead(4) != PINO_4){ START = 1; getApi("04843425"); PINO_4 = digitalRead(2); } } if(millis() - tempoAnterior >= time_milisedundos){ tempoAnterior = millis(); START = 0; } } void getApi(String CEP){ // Initialize Serial port Serial.begin(9600); while (!Serial) continue; // Initialize Ethernet library //byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; if (!Ethernet.begin(mac)) { Serial.println(F("Failed to configure Ethernet")); return; } delay(1000); Serial.println(F("Connected!")); EthernetClient client; // Send HTTP request client.println("GET /ws/" + CEP + "/json HTTP/1.1"); client.println("Host: viacep.com.br/"); client.println(F("Connection: close")); if (client.println() == 0) { Serial.println(F("Failed to send request")); client.stop(); } // Check HTTP status char status[32] = {0}; client.readBytesUntil('\r', status, sizeof(status)); // It should be "HTTP/1.0 200 OK" or "HTTP/1.1 200 OK" if (strcmp(status + 9, "200 OK") != 0) { Serial.print(F("Unexpected response: ")); Serial.println(status); client.stop(); } // Skip HTTP headers char endOfHeaders[] = "\r\n\r\n"; if (!client.find(endOfHeaders)) { Serial.println(F("Invalid response")); client.stop(); } const size_t capacity = JSON_OBJECT_SIZE(3) + JSON_ARRAY_SIZE(2) + 60; DynamicJsonDocument doc(capacity); // Parse JSON object DeserializationError error = deserializeJson(doc, client); if (error) { Serial.print(F("deserializeJson() failed: ")); Serial.println(error.f_str()); client.stop(); } Serial.println(doc["localidade"].as<const char*>()); // Preciso retornar o valor da localidade. client.stop(); }
|
|
|
Todos os horários são GMT - 3 Horas | Você não tem permissão para escrever novas mensagens v não tem permissão para responder às mensagens Você não tem permissão para editar suas mensagens Você não tem permissão para deletar suas mensagens Você não tem permissão para classificar tópicos Você não tem permissão para classificar mensagens Você não tem permissão para votar em enquetes Anexar downloads : Proibido Fazer Download de Arquivos: Proibido |
Powered by phpBB © 2001 phpBB Group
ROBOCORE TECNOLOGIA
RoboCore was created in 2008 with the aim of encouraging technological development, manufacturing and supplying high quality automation and robotics parts at affordable prices.
RoboCore Tecnologia LTDA
CNPJ 10.383.409/0001-98
D-U-N-S Certified: 89-963-8833
Santana de Parnaiba/SP - Brasil
CNPJ 10.383.409/0001-98
D-U-N-S Certified: 89-963-8833
Santana de Parnaiba/SP - Brasil
OUR SOCIAL NETWORKS
USEFUL LINKS
STORE POLICIES
CONTACT INFORMATION
ROBOCORE® 2023. All rights reserved