
Como funciona
A UNO R4 WiFi roda seu sketch no RA4M1 e chega ao Wi-Fi pelo módulo de rádio complementar da placa, usando a biblioteca oficial WiFiS3, como na placa real. WiFi.begin("BreadboardNet") entra na rede aberta virtual da bancada. client.connect() abre uma conexão TCP com api.open-meteo.com na porta 80, e o sketch envia uma requisição GET HTTP/1.1 simples pedindo o tempo atual na latitude 51.5 e longitude -0.12, que é Londres. Depois, ele copia a resposta para a Serial byte a byte, até 4096 bytes, e para de esperar depois de 15 segundos.
Por padrão, a internet de testes responde localmente à consulta do sketch sobre as condições meteorológicas atuais. Depois que a bancada é carregada, o sketch pode fazer essa consulta offline e sem conta. Com Real internet ligado, a requisição passa pelo gateway seguro do Breadboard, que só permite destinos aprovados e acrescenta HTTPS na saída. O sketch usa a API comum do WiFiClient nos dois modos, não o WiFiSSLClient, então o código não muda quando você passa para a internet real.
O que observar
A Serial imprime UNO R4 HTTP: sandbox by default e uma linha sobre Real internet. Em Sandbox, a Serial imprime a resposta, que começa com HTTP/1.0 200 OK, e termina com HTTP request finished. A requisição roda uma única vez, a partir do setup(); o loop() está vazio.
O que está na bancada
- Arduino Uno R4
O código
Este sketch Arduino C++ fica em “Code”. Entre na sua conta e clique em “Compile & upload” para compilar firmware real para a placa emulada.
// SPDX-License-Identifier: MIT // UNO R4 WiFi: one HTTP request using the public WiFiS3 client. // Sandbox is the default. In the board's Wi-Fi inspector, signed-in Pro // users can select Real internet, give consent, then restart this sketch. // The secure gateway supplies HTTPS to the approved destination. This // sketch uses WiFiClient, not WiFiSSLClient or native board TLS. #include <WiFiS3.h> const char HOST[] = "api.open-meteo.com"; const char PATH[] = "/v1/forecast?latitude=51.5&longitude=-0.12¤t_weather=true"; WiFiClient client; void setup() { Serial.begin(115200); Serial.println("UNO R4 HTTP: sandbox by default"); Serial.println("Real internet: select the board, enable it in Wi-Fi, consent, then restart."); if (WiFi.begin("BreadboardNet") != WL_CONNECTED) { Serial.println("Wi-Fi join failed"); return; } if (!client.connect(HOST, 80)) { Serial.println("HTTP connection failed"); client.stop(); return; } client.print("GET "); client.print(PATH); client.print(" HTTP/1.1\r\nHost: "); client.print(HOST); client.print("\r\nConnection: close\r\n\r\n"); const unsigned long started = millis(); unsigned int printed = 0; while (millis() - started < 15000 && (client.connected() || client.available())) { while (client.available() && millis() - started < 15000) { const int value = client.read(); if (value >= 0 && printed < 4096) { Serial.write(static_cast<uint8_t>(value)); printed++; } } delay(1); } const bool timedOut = millis() - started >= 15000; client.stop(); Serial.println(); Serial.println(timedOut ? "HTTP response timed out" : "HTTP request finished"); if (printed == 4096) Serial.println("Serial output limited to 4096 bytes"); } void loop() {}
Licença do firmware (em inglês)
Notice: this firmware uses the LGPL-licensed Arduino core library
arduino-unor4wifi-http-gallery.bin is statically linked with ArduinoCore-renesas 1.6.0, in Breadboard's port of its UNO R4 WiFi variant to Renesas FSP 5.3.0. Parts of that core are licensed under the GNU Lesser General Public License, version 2.1 or (at your option) any later version ("the Library"). Breadboard distributes this firmware under terms that permit you to modify the work for your own use and to reverse engineer it for debugging such modifications.
- Relink package: arduino-unor4wifi-http-gallery-relink.zip (385 KB)
- Corresponding source: ArduinoCore-renesas-1.6.0-fsp53-source.zip (3.7 MB)
- Licence texts and relink instructions
Experimente
- Com uma conta Pro verificada e o gateway ativado, selecione a placa, escolha Real internet em Internet access, na seção Wi-Fi do Inspector, e clique em Restart. A resposta agora vem do serviço Open-Meteo real.
- Abra o Code e mude a latitude e a longitude em PATH para as da sua cidade, depois entre na sua conta e clique em Compile & upload. Com Real internet ligado, a resposta traz o tempo atual dessa cidade.
- Abra o Wi-Fi sniffer e clique em Restart para acompanhar os pacotes da placa enquanto ela entra na rede e envia a requisição.



